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(codebuild): allow passing the ARN of the Secret in environment variables #13706

Merged
merged 2 commits into from
Mar 26, 2021

Conversation

skinny85
Copy link
Contributor

In the SecretsManager-typed environment variables in CodeBuild,
the code in the Project class assumed those would be passed as names.
As it turns out, CodeBuild also allows passing there entire ARNs of secrets
(both partial, and full), and also optional qualifiers,
separated by colons, that specify SecretsManager attributes like the JSON key,
or the secret version.
Add handling of all of these cases.

Fixes #12703


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

…riables

In the SecretsManager-typed environment variables in CodeBuild,
the code in the Project class assumed those would be passed as names.
As it turns out, CodeBuild also allows passing there entire ARNs of secrets
(both partial, and full), and also optional qualifiers,
separated by colons, that specify SecretsManager attributes like the JSON key,
or the secret version.
Add handling of all of these cases.

Fixes aws#12703
@skinny85 skinny85 requested a review from njlynch March 19, 2021 22:24
@skinny85 skinny85 self-assigned this Mar 19, 2021
@gitpod-io
Copy link

gitpod-io bot commented Mar 19, 2021

@github-actions github-actions bot added the @aws-cdk/aws-codebuild Related to AWS CodeBuild label Mar 19, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 19, 2021
resourceName: `${envVariable.value}-??????`,
sep: ':',
}));
if (Token.isUnresolved(envVariableValue)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a test for this condition? I'm not seeing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep - those are the can be provided as the ARN attribute of a new Secret and can be provided as the ARN attribute of a new Secret, followed by a JSON key tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I guess I was looking for a test where a Fn:Split call was expected, as we might be splitting a token. Now I see that we're assuming the input is partially an unresolved token (e.g., ${secretArn}:jsonKey).

If I understand correctly, you're supporting something like the above, but not a "full" token'ed value. So if I create a custom resource which returns back my-secret-name:jsonKey as a Token, then we will be passing the Token as a whole to secretsManagerIamResources, and the grant won't work. Am I reading that correctly now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, you're reading it correctly.

What's the behavior that you would want to see here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Frankly, I'm not sure. I don't know that there's a good solution here. I'm hoping this is a relatively edge-of-the-corner case. :D

@mergify
Copy link
Contributor

mergify bot commented Mar 26, 2021

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: c0c70e4
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify
Copy link
Contributor

mergify bot commented Mar 26, 2021

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

@mergify mergify bot merged commit 6f6e079 into aws:master Mar 26, 2021
@skinny85 skinny85 deleted the fix/codebuild-secretsmanager-variables branch March 27, 2021 01:20
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Mar 31, 2021
…riables (aws#13706)

In the SecretsManager-typed environment variables in CodeBuild,
the code in the Project class assumed those would be passed as names.
As it turns out, CodeBuild also allows passing there entire ARNs of secrets
(both partial, and full), and also optional qualifiers,
separated by colons, that specify SecretsManager attributes like the JSON key,
or the secret version.
Add handling of all of these cases.

Fixes aws#12703

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
…riables (aws#13706)

In the SecretsManager-typed environment variables in CodeBuild,
the code in the Project class assumed those would be passed as names.
As it turns out, CodeBuild also allows passing there entire ARNs of secrets
(both partial, and full), and also optional qualifiers,
separated by colons, that specify SecretsManager attributes like the JSON key,
or the secret version.
Add handling of all of these cases.

Fixes aws#12703

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(codebuild): Secret manager env vars get the wrong arn on grant
3 participants