question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(secretsmanager ): grant_read/grant_write on secret throws KMS key error on role from same account

See original GitHub issue

Giving a preexisting role read/write access to a secret using the grant_read/grant_write method on a secret throws the error: “KMS Key must be provided for cross account access to Secret” Even though both secret and role are from the same AWS account.

Reproduction Steps

Use an existing role and create a new secret Give it read/write access

from aws_cdk import (
    aws_iam as iam,
    aws_secretsmanager as secretsmanager,
    core
)

class Stack(core.Stack):
  role = iam.Role.from_role_arn(self, "role", <existing iam role>)
  
  secret = secretsmanager.Secret(
      scope=self,
      id="secret-id",
      description='secret desc'
  )
  secret.grant_read(role)
  secret.grant_write(role)


app = core.App()
Stack(app, "SecretKMSError")
app.synth()

What did you expect to happen?

I expect the created secret to be created with read and write rights added to the existing role.

What actually happened?

CDK deploy throws an error: KMS Key must be provided for cross account access to Secret Even though both the (pre-existing) and the secret are on the same AWS account

Environment

  • CDK CLI Version : 1.111.0
  • Framework Version: 1.111.0
  • Node.js Version: v12.20.1
  • OS : Windows 10
  • Language (Version): Python (3.8)

Other

This worked before version 1.111.0

Workaround:

role.add_to_policy(iam.PolicyStatement(effect=iam.Effect.ALLOW, actions=['secretsmanager:PutSecretValue', 'secretsmanager:UpdateSecret', 'secretsmanager:GetSecretValue', 'secretsmanager:DescribeSecret'], resources=[secret._arn_for_policies]))

I think it was introduced by this commit: https://github.com/aws/aws-cdk/commit/ea40cfe1b85ce4aee9c8f871de08d3c3739589d1


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kaiziocommented, Jan 25, 2022
1reaction
madeline-kcommented, Jul 16, 2021

@nwouda and @mooiweer if either of you are interesting in fixing this yourself, please take a look at the contributing guide.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve Secrets Manager secret access errors after updating ...
"You can't access a secret from a different AWS account if you encrypt ... This version of secret is not encrypted with the...
Read more >
AWS secret manager access deny issue - Stack Overflow
To use the Secrets Manager (even in the same account), the IAM Role must be given permission such as secretsmanager:GetSecretValue -- otherwise ...
Read more >
Best practice rules for AWS Secrets Manager - Medium
AWS Secrets Manager with the following rules: Secret Encrypted With KMS Customer Master Keys; Ensure that AWS Secrets Manager service enforces data-at-rest ...
Read more >
Creating an encryption key to store secrets - Authress
In the case of using AWS KMS, create a KMS key and alias. Make sure to give your application access to encrypt and...
Read more >
"access to kms is not allowed" error returned when trying to ...
Those are be provided by the key policy. The user has attached IAM policy to give them permissions to Secrets Manager via API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found