Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Identity] allowLoggingAccountIdentifiers support #20516

Merged
merged 11 commits into from
Mar 18, 2022

Conversation

sadasant
Copy link
Contributor

@sadasant sadasant commented Feb 24, 2022

While investigating what sensitive logging to add to our credentials, we have determined that the most useful information we could log are the account identifiers after retrieving a token. This issue describes a flexible approach to add support to log the account information on our credentials.

Since we specifically didn’t want to depend on MSAL for this feature, and we only wanted the account identifiers, I’m parsing the access token and extracting some of the values for this feature. I’m doing that, and the logging, at the network layer of the Identity library, which covers all credentials.

This PR:

  1. Adds allowLoggingAccountIdentifiers to the options of the credentials’ constructors.
  2. Retrieves the account identifiers after authenticating.
  • Parses the first section of the access token after the . (which can be obtained with access_token.split(“.”)[1]), then extracts the following properties: appid, upn, tid, oid.
  1. After a token is retrieved and the identifiers have been extracted, if allowLoggingAccountIdentifiers was set in the constructor of the credential, now we log a message similar to the following: [Authenticated account] Client ID: ${appid}. Tenant ID: ${tid}. User Principal Name: ${upn || "No User Principal Name available"}. Object ID (user): ${oid}.

Feedback appreciated 🙏

Fixes #20502
Fixes #17460

@azure-sdk
Copy link
Collaborator

API changes have been detected in @azure/identity. You can review API changes here

API changes

+     allowLoggingAccountIdentifiers?: boolean;

}
const unavailableUpn = "No User Principal Name available";
try {
const parsed = (response as any).parsedBody || JSON.parse(response.bodyAsText);
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to get any of this info from MSAL in a way that doesn't require us to parse the raw response? I'm a bit concerned that we could somehow unintentionally log the wrong sensitive data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As long as we limit ourselves to these 4 values we should be ok to not log something too sensitive.

MSAL does allow you to retrieve this with their AccountRecord, but we don’t use MSAL in every credential.

@azure-sdk
Copy link
Collaborator

API changes have been detected in @azure/identity. You can review API changes here

API changes

+     loggingOptions?: LogPolicyOptions & {
+             allowLoggingAccountIdentifiers?: boolean;
+         };

@check-enforcer
Copy link

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

Copy link
Member

@KarishmaGhiya KarishmaGhiya left a comment

Choose a reason for hiding this comment

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

Looks great!!

@sadasant sadasant requested review from christothes and removed request for ramya-rao-a March 16, 2022 17:13
@sadasant sadasant merged commit dccf667 into Azure:main Mar 18, 2022
@sadasant sadasant deleted the identity/fix20502 branch March 18, 2022 20:20
WeiJun428 pushed a commit to WeiJun428/azure-sdk-for-js that referenced this pull request Mar 20, 2022
- All of our credentials now support a new option on their constructor: `loggingOptions`, which allows configuring the logging options of the HTTP pipelines.
 - Within the new `loggingOptions` we have also added `allowLoggingAccountIdentifiers`, a property that if set to true logs information specific to the authenticated account after each successful authentication, including: the Client ID, the Tenant ID, the Object ID of the authenticated user, and if possible the User Principal Name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants