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

Support Secret with partial Arn #7994

Closed
2 tasks
tuler opened this issue May 15, 2020 · 1 comment · Fixed by #10309
Closed
2 tasks

Support Secret with partial Arn #7994

tuler opened this issue May 15, 2020 · 1 comment · Fixed by #10309
Assignees
Labels
@aws-cdk/aws-secretsmanager Related to AWS Secrets Manager effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@tuler
Copy link

tuler commented May 15, 2020

When a container in a TaskDefinition uses a secret, it automatically adds to the taskDefinition generated ExecutionRole the IAM permission to read the secret value.

If the secret is imported from an existing resource, by using secretsmanager.Secret.fromSecretAttributes or secretsmanager.Secret.fromSecretArn the Arn can be an partial Arn, without the - and 6 random chars AWS appends to the friendly name.

The problem is that Secret.grantRead gives permission to the exact Arn only, so the task fails to execute.

Use Case

It's common to use partial Arn when using secrets, because they represent friendly names.

Proposed Solution

I tried to manually add a more relaxed policy to the taskDefinition execution role, but it did not work.

taskDefinition.addToExecutionRolePolicy(new iam.PolicyStatement({
  actions: ["secretsmanager:GetSecretValue"],
  resources: [secretArn + '*'],
}));

I don't know why it did not work, or if this is the best approach.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@tuler tuler added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 15, 2020
@SomayaB SomayaB added the @aws-cdk/aws-secretsmanager Related to AWS Secrets Manager label May 18, 2020
@skinny85
Copy link
Contributor

Related: #7444, #6889 (comment)

@skinny85 skinny85 added effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 29, 2020
@SomayaB SomayaB assigned njlynch and unassigned skinny85 Jul 10, 2020
@njlynch njlynch added the p1 label Aug 21, 2020
njlynch added a commit that referenced this issue Sep 11, 2020
Adds the ability to import secrets by name, including without the SecretsManager
assigned suffix. As long as a secret with the same name has been created in each
region with the same name, this allows for the same `fromSecretName` usage in
stacks across regions.

Oddly enough, most CloudFormation templates that take references to secrets
accept either the full-form ARN, including the suffix or just the base secret
name (not in ARN format). The one place where a full ARN format is needed is in
IAM policy statements, where the wildcard is necessary to account for the
suffix.

Tested this manually against an existing secret with a CodeBuild project; per
the CloudFormation docs, this should work equally well with other
SecretsManager-integrated services.

fixes #7444
fixes #7949
fixes #7994
njlynch added a commit that referenced this issue Sep 11, 2020
Adds the ability to import secrets by name, including without the SecretsManager
assigned suffix. As long as a secret with the same name has been created in each
region with the same name, this allows for the same `fromSecretName` usage in
stacks across regions.

Oddly enough, most CloudFormation templates that take references to secrets
accept either the full-form ARN, including the suffix or just the base secret
name (not in ARN format). The one place where a full ARN format is needed is in
IAM policy statements, where the wildcard is necessary to account for the
suffix.

Tested this manually against an existing secret with a CodeBuild project; per
the CloudFormation docs, this should work equally well with other
SecretsManager-integrated services.

fixes #7444
fixes #7949
fixes #7994
njlynch added a commit that referenced this issue Sep 14, 2020
Adds the ability to import secrets by name, including without the SecretsManager
assigned suffix. As long as a secret with the same name has been created in each
region with the same name, this allows for the same `fromSecretName` usage in
stacks across regions.

Oddly enough, most CloudFormation templates that take references to secrets
accept either the full-form ARN, including the suffix or just the base secret
name (not in ARN format). The one place where a full ARN format is needed is in
IAM policy statements, where the wildcard is necessary to account for the
suffix.

Tested this manually against an existing secret with a CodeBuild project; per
the CloudFormation docs, this should work equally well with other
SecretsManager-integrated services.

fixes #7444
fixes #7949
fixes #7994
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-secretsmanager Related to AWS Secrets Manager effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants