Skip to content

Fix AWS CLI access using AWS OIDC integration#57843

Merged
r0mant merged 2 commits intomasterfrom
marco/awsoidc/fix-aws-cli-access
Aug 15, 2025
Merged

Fix AWS CLI access using AWS OIDC integration#57843
r0mant merged 2 commits intomasterfrom
marco/awsoidc/fix-aws-cli-access

Conversation

@marcoandredinis
Copy link
Copy Markdown
Contributor

Fixes #57831

changelog: Fix AWS CLI access using AWS OIDC integration

Comment thread lib/auth/auth_with_roles_test.go Outdated
@marcoandredinis marcoandredinis force-pushed the marco/awsoidc/fix-aws-cli-access branch from 3fcc63d to a34d230 Compare August 14, 2025 10:23
@marcoandredinis marcoandredinis force-pushed the marco/awsoidc/fix-aws-cli-access branch from a34d230 to 00e30aa Compare August 14, 2025 10:25
@marcoandredinis marcoandredinis requested a review from zmb3 August 14, 2025 10:26
Comment thread lib/auth/auth.go
Comment on lines +3569 to 3574
awsCredentialProcessCredentials, err := generateAWSClientSideCredentials(ctx, a, req, notAfter)
switch {
case errors.Is(err, errNotIntegrationApp):
case errors.Is(err, errAppWithoutAWSClientSideCredentials):
case err != nil:
return nil, trace.Wrap(err)
}
Copy link
Copy Markdown
Collaborator

@r0mant r0mant Aug 14, 2025

Choose a reason for hiding this comment

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

I think that trying to determine whether to generate credentials or not based on the returned error is very awkward and error-prone (and not very Go idiomatic) - which is why I suspect we got this regression in the first place.

Can this be done by doing explicit checks on the integration type and request instead of doing this opportunistically based on the error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Integration type is explicitly checked.
The request is not checked because it is un-changed from regular AWS App access, the client does not explicitly ask for client side credentials.

I can add other sentinel errors, and check all of them here.

	// Generate AWS client side credentials if the user is trying to access an AWS App with an AWS Roles Anywhere Integration.
	awsCredentialProcessCredentials, err := generateAWSClientSideCredentials(ctx, a, req, notAfter)
	switch {
	case errors.Is(err, errNotAWSAccessApp) || errors.Is(err, errAWSAppWithoutIntegration) || errors.Is(err, errProxiedAWSApp):
	case err != nil:
		return nil, trace.Wrap(err)
	}

I'm not convinced by this, it adds a list of errors which can become an oversight later on.
On 2nd thought, maybe this is not what you meant.

I don't think moving the logic from the function to here is a good approach as it would add quite a lot of code to an already large method.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i'm not strongly opposed to leaving it as-is, but you could refactor this to just return nil in cases where you would return the errAppWithoutAWSClientSideCredentials?

It seems like the graceful error handling behavior just ignores the error anyway and allowing for empty credentials is the expected behavior, so return "", nil makes sense to me.

I'm not convinced the error handling scheme had anything to do with the bug though. We just forgot to check for the AWS OIDC subkind, and for other subkinds it makes sense to return an error e.g. it should be an error to request an --aws-role with an Azure OIDC integration subkind.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

imo we should have an exported list of integration subkinds and then table test against that.
That way if a subkind is added in the future that supports aws client side credentials, the tests will force us to update the switch statement to account for it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so return "", nil makes sense to me.

(when I first implemented, it was like that before code review 😅)

As for adding all the integration subkinds to table test them, maybe that's a good idea.
For now, their features barely intercept, so that's why it wasn't an issue in the past.

@marcoandredinis marcoandredinis requested a review from r0mant August 14, 2025 17:16
Comment thread lib/auth/auth.go
Comment on lines +3569 to 3574
awsCredentialProcessCredentials, err := generateAWSClientSideCredentials(ctx, a, req, notAfter)
switch {
case errors.Is(err, errNotIntegrationApp):
case errors.Is(err, errAppWithoutAWSClientSideCredentials):
case err != nil:
return nil, trace.Wrap(err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i'm not strongly opposed to leaving it as-is, but you could refactor this to just return nil in cases where you would return the errAppWithoutAWSClientSideCredentials?

It seems like the graceful error handling behavior just ignores the error anyway and allowing for empty credentials is the expected behavior, so return "", nil makes sense to me.

I'm not convinced the error handling scheme had anything to do with the bug though. We just forgot to check for the AWS OIDC subkind, and for other subkinds it makes sense to return an error e.g. it should be an error to request an --aws-role with an Azure OIDC integration subkind.

@r0mant r0mant enabled auto-merge August 14, 2025 23:43
@r0mant r0mant added this pull request to the merge queue Aug 15, 2025
Merged via the queue into master with commit 18b3dda Aug 15, 2025
40 of 41 checks passed
@r0mant r0mant deleted the marco/awsoidc/fix-aws-cli-access branch August 15, 2025 00:28
@backport-bot-workflows
Copy link
Copy Markdown
Contributor

@marcoandredinis See the table below for backport results.

Branch Result
branch/v18 Create PR

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.

tsh app login fails with a AWS OIDC integration

4 participants