Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add a comment to a json IAM policy?

IAM policy are complicated beasts. It would be nice to add a comment when crafting them. For example,

{   "Version": "2012-10-17",   "Statement": [     {       "Sid": "Stmt1422979261000",       "Effect": "Allow",       "Action": [         "route53:ListHostedZones",       ],       "Comment": "Foo"       # or Bar       "Resource": [         "*"       ]     }   ] } 

Neither of these work. Does there exist a way to add comments to these policies?

like image 756
seanmcl Avatar asked Feb 03 '15 16:02

seanmcl


People also ask

What is JSON policy in AWS?

Overview of JSON policies. Most policies are stored in AWS as JSON documents. Identity-based policies and policies used to set permissions boundaries are JSON policy documents that you attach to a user or role. Resource-based policies are JSON policy documents that you attach to a resource.

How do I modify my IAM policy?

To edit a customer managed policy (console)Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/ . In the navigation pane, choose Policies. In the list of policies, choose the policy name of the policy to edit. You can use the search box to filter the list of policies.

What is Sid in JSON?

PDFRSS. You can provide an optional identifier, Sid (statement ID) for the policy statement. You can assign a Sid value to each statement in a statement array. In services that let you specify an ID element, such as SQS and SNS, the Sid value is just a sub-ID of the policy document ID.


1 Answers

Hyper Anthony's answer is correct in the strict sense of 'comment' - however, in most situations you can at least use the Sid for pseudo comments to communicate the intent or any constraints etc.:

The Sid (statement ID) is an optional identifier that you provide for the policy statement. You can assign a Sid value to each statement in a statement array. In services that let you specify an ID element, such as SQS and SNS, the Sid value is just a sub-ID of the policy document's ID. In IAM, the Sid value must be unique within a policy. [emphasis mine]

This is e.g. exemplified by the use of TheseActionsSupportResourceLevelPermissions within the (very helpful) AWS blog post Demystifying EC2 Resource-Level Permissions:

{     "Version": "2012-10-17",     "Statement": [         {             "Sid": "TheseActionsSupportResourceLevelPermissions",             "Effect": "Allow",             "Action": [                 "ec2:RunInstances",                 "ec2:TerminateInstances",                 "ec2:StopInstances",                 "ec2:StartInstances"             ],             "Resource": "arn:aws:ec2:us-east-1:accountid:instance/*"         }     ] } 
  • As mentioned in Sid some services might require this element and have uniqueness requirements for it, but I haven't experienced resulting naming constraints yet.
like image 150
Steffen Opel Avatar answered Oct 12 '22 13:10

Steffen Opel