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

fix(cli): short-lived credentials are not refreshed #32354

Merged
merged 12 commits into from
Dec 4, 2024

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Dec 2, 2024

The CLI immediately invokes credential providers to produce credentials, and passes the credentials around instead of the providers. This means that if short-lived credentials expire (like session credentials from roles), there is no way to refresh them.

CLI calls will start to fail if that happens.

To fix this, instead of resolving providers to credentials, pass providers around instead.

Implications for auth plugins

This widens the plugin protocol: the new plugin protocol forced a translation to V3 credentials, and had no way to return V3 providers. While it is now possible to return V3 Credential Providers from the plugin protocol, plugin writers cannot easily take advantage of that protocol because there have been ~8 CLI releases that only support V3 credentials and will fail at runtime of V3 providers are returned.

To support this, pass a new options argument into getProvider(): this will indicate whether V3 Providers are supported or not. Plugins can return a provider if the CLI indicates that it supports V3 providers, and avoid doing that if the CLI indicates it won't. That way, plugins can be rewritten to take advantage of returning V3 providers without crashing on CLI versions 2.167.0..(this releases).

This also affects #32111 in which the plugin contract is being moved.

Closes #32287.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

The CLI immediately invokes credential *providers* to produce
*credentials*, and passes the credentials around instead of the
providers. This means that if short-lived credentials expire (like
session credentials from roles), there is no way to refresh them.

CLI calls will start to fail if that happens.

To fix this, instead of resolving providers to credentials, pass
providers around instead.

Implications for auth plugins
-------------

This widens the plugin protocol: the new plugin protocol *forced* a
translation to V3 credentials, and had no way to return V3 providers.
While it is now possible to return V3 Credential Providers from the
plugin protocol, plugin writers cannot easily take advantage of that
protocol because there have been ~8 CLI releases that only support V3
credentials and will fail at runtime of V3 providers are returned.

To support this, pass a new options argument into `getProvider()`:
this will indicate whether V3 Providers are supported or not. Plugins
can return a provider if the CLI indicates that it supports V3
providers, and avoid doing that if the CLI indicates it won't. That way,
plugins can be rewritten to take advantage of returning V3 providers
without crashing on CLI versions `2.167.0..(this releases)`.

This also affects #32111 in which the plugin contract is being moved.
@rix0rrr rix0rrr requested a review from a team as a code owner December 2, 2024 12:51
@aws-cdk-automation aws-cdk-automation requested a review from a team December 2, 2024 12:51
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels Dec 2, 2024
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 2, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation added the pr/needs-cli-test-run This PR needs CLI tests run against it. label Dec 2, 2024
*/
getProvider(accountId: string, mode: Mode): Promise<AwsCredentialIdentity>;
readonly supportsV3Providers?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing a flag, which puts an additional cognitive burden on the plugin writer, we could create an adapter that implements the AwsCredentialIdentityProvider interface and wraps a plugin credential source:

// Not sure whether identityProperties is even necessary for our use case, but still...
const pluginWrapper = (identityProperties?: Record<string, any>) => { 
  return transformTheResulAsNeeded(
    await source.getProvider(awsAccountId, mode, identityProperties));
};

return {
  credentials: pluginWrapper,
  pluginName: source.name,
};

@rix0rrr rix0rrr added pr-linter/exempt-test The PR linter will not require test changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels Dec 2, 2024
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.67%. Comparing base (bf77e51) to head (8ee2216).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #32354      +/-   ##
==========================================
+ Coverage   78.50%   78.67%   +0.17%     
==========================================
  Files         106      107       +1     
  Lines        7201     7237      +36     
  Branches     1321     1329       +8     
==========================================
+ Hits         5653     5694      +41     
+ Misses       1361     1357       -4     
+ Partials      187      186       -1     
Flag Coverage Δ
suite.unit 78.67% <100.00%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 78.67% <100.00%> (+0.17%) ⬆️

@aws-cdk-automation
Copy link
Collaborator

➡️ PR build request submitted to test-main-pipeline ⬅️

A maintainer must now check the pipeline and add the pr-linter/cli-integ-tested label once the pipeline succeeds.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 8ee2216
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@rix0rrr rix0rrr added the pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested label Dec 3, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review December 3, 2024 15:03

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-cli-test-run This PR needs CLI tests run against it. labels Dec 3, 2024
* in caches which will return the cached value until it expires.
*/
export function makeCachingProvider(provider: AwsCredentialIdentityProvider): AwsCredentialIdentityProvider {
return memoize(
Copy link
Contributor

Choose a reason for hiding this comment

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

Usage
You probably shouldn't, at least directly.

A rebel, lol.

Copy link
Contributor

mergify bot commented Dec 3, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 3, 2024
Copy link
Contributor

mergify bot commented Dec 3, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@rix0rrr rix0rrr merged commit 058a0bf into main Dec 4, 2024
29 of 31 checks passed
@rix0rrr rix0rrr deleted the huijbers/refresh-creds branch December 4, 2024 14:06
Copy link

github-actions bot commented Dec 4, 2024

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p2 pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-test The PR linter will not require test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI: short-lived credentials are not refreshed
3 participants