Permissions required for Lambda to access KMS

Viewed 2186

I'm using AWS CDK.

I have created Customer Managed CMK KMS key to enable Server Side encryption on dynamoDB tables.

KMS Key Policy:

  public static getKMSKeyPolicyDocument(): PolicyDocument {
    return new PolicyDocument({
      statements: [
        //Allow root in IAM Policy: https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default-allow-root-enable-iam
        new PolicyStatement({
          principals: [new AccountRootPrincipal()],
          actions: ["kms:*"],
          resources: ["*"],
        }),
 
        new PolicyStatement({
          principals: [
            new ServicePrincipal("dynamodb.amazonaws.com"),
            new ServicePrincipal("lambda.amazonaws.com"),
          ],
          actions: [
            "kms:Encrypt",
            "kms:Decrypt",
            "kms:ReEncrypt*",
            "kms:GenerateDataKey*",
            "kms:DescribeKey",
            "kms:Get*",
            "kms:List*",
          ],
          resources: ["*"],
        }),
      ],
    });
  }

Some Lambdas use these dynamo db tables to get the data. So, my question is:

Do we again need to give permissions explicitly to each lambda to access KMS key like this??

public static grantAccessToKMSKey(role: IRole, kmsKey: IKey): void {
    role.addToPrincipalPolicy(
      new PolicyStatement({
        actions: [
          "kms:CreateGrant",
          "kms:Decrypt",
          "kms:DescribeKey",
          "kms:Encrypt",
          "kms:GenerateDataKey*",
          "kms:ReEncrypt*",
          "kms:Get*",
          "kms:List*",
        ],
        resources: [kmsKey.keyArn],
      })
    );
  }

0 Answers
Related