-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Support exchanging k8s token to AAD token #16688
Conversation
I took this out of draft before fixing conflicts. One moment. |
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenFilePathMsi.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenFilePathMsi.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenFilePathMsi.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenFilePathMsi.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenFilePathMsi.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenFilePathMsi.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenFilePathMsi.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/test/internal/node/managedIdentityCredential.spec.ts
Show resolved
Hide resolved
sdk/identity/identity/test/internal/node/managedIdentityCredential.spec.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenExchangeMsi.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenExchangeMsi.ts
Outdated
Show resolved
Hide resolved
sdk/identity/identity/test/internal/node/managedIdentityCredential.spec.ts
Outdated
Show resolved
Hide resolved
@@ -4,6 +4,8 @@ | |||
|
|||
### Features Added | |||
|
|||
- `ManagedIdentityCredential` now supports token exchange authentication. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentionally vague.
sdk/identity/identity/test/internal/node/managedIdentityCredential.spec.ts
Show resolved
Hide resolved
@chlowell ok now I’ve tested this in the real test environment, and this works 😃 |
I’m investigating the CI issue. |
I don’t quite get what’s going on on CI. Tomorrow is a new day! |
const err = new AggregateAuthenticationError( | ||
errors, | ||
"ChainedTokenCredential authentication failed." | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, this error had an initial segment with an undefined
string. This PR adds a test to ensure this is never silently broken in the future.
…his new MSI, and improve MSI logs
@@ -164,7 +164,7 @@ export class AggregateAuthenticationError extends Error { | |||
|
|||
constructor(errors: any[], errorMessage?: string) { | |||
const errorDetail = errors.join("\n"); | |||
super(`${errorMessage}\n\n${errorDetail}`); | |||
super(`${errorMessage}\n${errorDetail}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This meant a whole empty line, which I didn’t like now that I re-reviewed these errors.
@@ -214,7 +223,7 @@ export class ManagedIdentityCredential implements TokenCredential { | |||
// and it means that the endpoint is working, but that no identity is available. | |||
if (err.statusCode === 400) { | |||
throw new CredentialUnavailableError( | |||
"The managed identity endpoint is indicating there's no available identity" | |||
`ManagedIdentityCredential: The managed identity endpoint is indicating there's no available identity. Message: ${err.message}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the root of the CI issue: The changes in this PR made it so now this credential only failed due to the IMDS MSI on CI. Since CI is in Azure, the IMDS endpoint is reachable, so the execution reaches this statement, and this statement didn’t match the format we had for all of the other errors in this credential.
Oh, the taste of a green CI build 😌💚 |
sdk/identity/identity/src/credentials/managedIdentityCredential/models.ts
Outdated
Show resolved
Hide resolved
bf2064e
to
2f07e3a
Compare
sdk/identity/identity/src/credentials/managedIdentityCredential/utils.ts
Outdated
Show resolved
Hide resolved
…h multiple resources, and an internal cleanup was in order (including slightly better logs and errors
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenExchangeMsi.ts
Outdated
Show resolved
Hide resolved
|
||
const authDetails = await sendCredentialRequests({ | ||
scopes: ["https://service/.default"], | ||
credential: new ManagedIdentityCredential("client"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a test for the parameter overriding AZURE_CLIENT_ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m adding one! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added one!
…l/tokenExchangeMsi.ts Co-authored-by: Charles Lowell <chlowe@microsoft.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Token exchange logic looks good to me 👍
sdk/identity/identity/src/credentials/managedIdentityCredential/tokenExchangeMsi.ts
Outdated
Show resolved
Hide resolved
Hello @sadasant! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
This is a simplified version of what @chlowell did on this PR: Azure/azure-sdk-for-python#19902
This is based on what I understood. I’ll make sure to circle back with Charles before I get this PR out of draft.
Fixes #15800