TS2345: ‘trustAccountIdentities’在类型’KeyProps’中不存在,cdkv2中出现的错误。

huangapple go评论56阅读模式
英文:

TS2345: 'trustAccountIdentities' does not exist in type 'KeyProps' error in cdkv2

问题

I upgraded my cdk project from v1 to v2. It's complaining about trustAccountIdentities existence in cdkv2.

error at the time of build:

> error TS2345: Argument of type '{ enableKeyRotation: true; enabled: true; removalPolicy: cdk.RemovalPolicy.DESTROY; trustAccountIdentities: boolean; }' is not assignable to parameter of type 'KeyProps'.
Object literal may only specify known properties, and 'trustAccountIdentities' does not exist in type 'KeyProps'.

It was given the same way in cdkv1. My code is as below

const account = new AccountCustomResource(this, StackConfiguration.name+ '-BucketKmsAccountCustomResource');
/** Added code to create Custom kms key*/
const MyKmsKey =  new kms.Key(this, (mykey).toLowerCase(), {
 enableKeyRotation: true,
 enabled: true,
 removalPolicy: cdk.RemovalPolicy.DESTROY,
 trustAccountIdentities: true
});
MyKmsKey.addAlias(mykey);

I tried commenting the trustAccountIdentities line and the build worked fine, but then it's giving an issue while deployment with the below error.

> Stack Deployments Failed: AccessDenied: User: arn:aws:sts::<arn#>:assumed-role/cdk-<some#>-deploy-role-<some#>-/aws-cdk-bamboo is not authorized to perform: iam:PassRole on resource: arn:aws:iam::<some#>:role/cloud-services/pipeline-elevated-access with an explicit deny in an identity-based policy

英文:

I upgraded my cdk project from v1 to v2. It's complaining about trustAccountIdentities existance in cdkv2.

error at the time of build:

> error TS2345: Argument of type '{ enableKeyRotation: true; enabled: true; removalPolicy: cdk.RemovalPolicy.DESTROY; trustAccountIdentities: boolean; }' is not assignable to parameter of type 'KeyProps'.
Object literal may only specify known properties, and 'trustAccountIdentities' does not exist in type 'KeyProps'.

It was given same way in cdkv1. My code is as below

    const account = new AccountCustomResource(this, StackConfiguration.name+ &#39;-BucketKmsAccountCustomResource&#39;);
     /** Added code to create Custom kms key*/ 
     const MyKmsKey =  new kms.Key(this, (mykey).toLowerCase(), {
      enableKeyRotation: true,
      enabled: true,
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      trustAccountIdentities: true
     });
     MyKmsKey.addAlias(mykey); 

I tried commenting trustAccountIdentities line and build worked fine but then it's giving issue while deployment with below error.

> Stack Deployments Failed: AccessDenied: User: arn:aws:sts::<arn#>:assumed-role/cdk-<some#>-deploy-role-<some#>-<AWS-region>/aws-cdk-bamboo is not authorized to perform: iam:PassRole on resource: arn:aws:iam::<some#>:role/cloud-services/pipeline-elevated-access with an explicit deny in an identity-based policy

答案1

得分: 1

trustAccountIdentities 属性已弃用。如果您希望将其视为 true,请使用 @aws-cdk/aws-kms:defaultKeyPolicies feature flag

该信息来源于 KMSProps source code 文档字符串。它还解释了:

> 如果设置了 @aws-cdk/aws-kms:defaultKeyPolicies 功能标志(新项目的默认设置),此标志将始终被视为 'true',无需显式设置。

英文:

The trustAccountIdentities property is deprecated. If you need it treated as true, use the @aws-cdk/aws-kms:defaultKeyPolicies feature flag.

That info is from the KMSProps source code docstrings. It also explains that:

> If the @aws-cdk/aws-kms:defaultKeyPolicies feature flag is set (the default for new projects), this flag will always be treated as 'true' and does not need to be explicitly set.

huangapple
  • 本文由 发表于 2023年4月20日 03:30:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058192.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定