-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(aws_iam.PolicyDocument): Method 'fromJson(obj)' only takes parent 'Statement' JSON element #29975
Comments
Reproducible using code below: const myJsonText ={
"Version": "testversion",
"Id": "KMS-Key-Policy-Example",
"Statement": [
{
"Sid": "Example SID",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:root"
},
"Action": "kms:*",
"Resource": "*"
}
]
};
const myPolicyTest = iam.PolicyDocument.fromJson(myJsonText);
console.debug(myPolicyTest.toJSON());
const key = new kms.Key(this, "myKMSkey", {
policy: myPolicyTest,
}); It generates the following debug output during {
Statement: [
{
Action: 'kms:*',
Effect: 'Allow',
Principal: [Object],
Resource: '*',
Sid: 'Example SID'
}
],
Version: '2012-10-17'
} Resources:
myKMSkey6B023671:
Type: AWS::KMS::Key
Properties:
KeyPolicy:
Statement:
- Action: kms:*
Effect: Allow
Principal:
AWS: arn:aws:iam::123456789012:root
Resource: "*"
Sid: Example SID
Version: "2012-10-17"
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Metadata:
aws:cdk:path: TypescriptStack/myKMSkey/Resource
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Analytics: v2:deflate64:H4sIAAAAAAAA/yXGsQ5AMBAA0G+xt0dZ7EYbHyDVnuSUa+KKiPh3EdN7JZiqhiKzp2jng15ohLtP1gVlTxnCKnC3eKlm4hav57NDifvm8HsT2VOiyI/i6BFmyY+yAGPAZLMQ6W3nRCtC9/sC8s+Yhm8AAAA=
Metadata:
aws:cdk:path: TypescriptStack/CDKMetadata/Default
Condition: CDKMetadataAvailable
...
... |
@frfavoreto I was able to reproduce the issue at my end. According to this, setting |
@ashishdhingra However, Additionally, some services like SQS and SNS might require this element and have specific requirements for it. |
Describe the bug
Method
fromJson()
from aws_iam.PolicyDocument ignoresId
andVersion
parent elements of a JSON Policy text, taking only theStatement
and its nested elements.}
https://github.com/aws/aws-cdk/blob/v2.137.0/packages/aws-cdk-lib/aws-iam/lib/policy-document.ts#L61
Expected Behavior
Method
fromJson()
to accept all the JSON elements passed as an input.Current Behavior
When using the method, it only considers
Statement
element (and its sub elements) and auto generateVersion
one. During this process,Id
is ignored and the synth'ed template doesn't have anyId
element in the Policy Document.Reproduction Steps
Create any IAM Policy from a JSON text (with
Version
andId
elements included) like below:The generated policy does not have
Id
element."Version": "2012-10-17"
is automatically generated.Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
All supported versions, including latest 2.139.0
Framework Version
No response
Node.js Version
20
OS
Mac
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: