Skip to content

[Identity] Ensuring the claims get sent through the getToken requests.#18445

Merged
sadasant merged 36 commits intoAzure:mainfrom
sadasant:identity/CAEImprovements
Nov 5, 2021
Merged

[Identity] Ensuring the claims get sent through the getToken requests.#18445
sadasant merged 36 commits intoAzure:mainfrom
sadasant:identity/CAEImprovements

Conversation

@sadasant
Copy link
Contributor

@sadasant sadasant commented Oct 29, 2021

By this point, core is ready to handle challenges. Identity should have been ready a while ago, but as I tested this feature, I realized I had forgotten to ensure the claims would go through the getToken requests. I believe this happened as we decided to drop the claims from the GetTokenOption. The reason why we dropped claims were, if I remember correctly, that claims could be either strings or objects with potentially arbitrary properties, and that they were only used internally and not expected to be used by customers.

Anyway, this PR intends to do something rather narrow:

  • Ensure claims are sent through correctly.
  • See what other properties we can send through that could have been missed.
  • Add two recorded tests for the challenge flow.

There are some questions I have remaining, regarding the recorder. I’ll route those questions outside of this PR. I’ll potentially make issues.

If you’re wondering why am I not using ARM endpoints for this test, the reason is that I wasn’t able to revoke the ARM session when I tested this. I tried many times. The Identity SDK crew is investigating that outside of this PR. Once that is resolved, I will add recorded tests for the ARM endpoints.

I may open some issues based on this PR, but give me some time to discuss our findings with the team.

/**
* Claims received from challenges.
*/
claims?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an internal type.

});

let clientCapabilities: string[] = ["CP1"];
let clientCapabilities: string[] = ["cp1"];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If one goes to the service documentation, this value appears in lowercase: https://docs.microsoft.com/azure/active-directory/develop/claims-challenge

This change has no effect other than helping me have a more 1:1 comparison between our recordings and our docs.

Copy link
Member

@witemple-msft witemple-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Checking my notes: this is part of the internal token options, but not the public GetTokenOptions, so this is meant to be used for challenges, but a user who is using identity will not have the option to pass in claims?

@sadasant
Copy link
Contributor Author

sadasant commented Nov 2, 2021

@witemple-msft (thank you)

I believe we deferred the decision of exposing the “claims” to end users. Claims can be either a base64 string or a JSON object, but the properties of that JSON objects are not well defined. Perhaps they will be in the future.

Better comment regarding dotenv.config
"Waiting for the revocation of the token. Retrying in 30 seconds. Retry number",
++count
);
await delay(30000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's reasonable to give up after 8 minutes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only gets executed on record mode. On playback mode this shrinks to 0. I’m only running this in playback mode on CI, so it won’t wait

// Important:
// IN PLAYBACK MODE...
// Verifying that the first access token and the final one are different will not work consistently in this test.
// The recorder strips out the access tokens from the responses on the recordings.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My solution in Python was to record hashes of the access tokens. That way the values are unique and no longer secret.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our recorder in JS strips the access token, but the service sometimes answers with different expiration dates. I could add some boilerplate code to fix the resulting access tokens to different values, but it will get really cumbersome given that the recorder doesn’t play well with other mocking tools. For unit-tests, we already have unit tests in core-client and core-rest-pipeline about the underlying code used here.

@sadasant
Copy link
Contributor Author

sadasant commented Nov 4, 2021

(well, that didn’t work)

@check-enforcer
Copy link

check-enforcer bot commented Nov 4, 2021

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run js - [service] - ci

@sadasant
Copy link
Contributor Author

sadasant commented Nov 4, 2021

I’ll merge this as soon as CI agrees with me.

@sadasant sadasant enabled auto-merge (squash) November 4, 2021 20:56
@sadasant sadasant merged commit 13c97f3 into Azure:main Nov 5, 2021
sadasant added a commit to sadasant/azure-sdk-for-js that referenced this pull request Nov 6, 2021
Azure#18445)

This PR:
- Ensures claims are sent through correctly.
- Sees what other properties we can send through that could have been missed.
- Adds two recorded tests for the challenge flow.

I’m not using ARM endpoints for this test since I wasn’t able to revoke the ARM session when I tested this. I tried many times. The Identity SDK crew is investigating that outside of this PR.
@sadasant sadasant deleted the identity/CAEImprovements branch February 3, 2022 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants