-
Notifications
You must be signed in to change notification settings - Fork 2.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
Possible to attach customer-managed policies? #76
Comments
You can set Policies to be your IAM Managed Policy ARN. It will work even if the ARN points to a custom managed policy. I guess this needs an example and clarification in the spec |
Thanks, in my tests these policies did not work! I.e. I created them in another template and passed their names as parameters to a SAM template, then referenced these parameters in 'Policies'. The roles created by SAM appear to ignore these, and only attach AWSLambdaBasicExecutionRole and no inline policies, which is why I'm interested if that is supported. |
@dinvlad would you mind sharing the template you're trying to work on? I've just locally modified and re-run the encryption proxy example adding a custom IAM policy and it worked just fine for me -- IAM Role sample below: EncryptionServiceIAMRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
- "arn:aws:iam::<account_number>:policy/PHD-FullAccess-WideOrg" # customer managed policy
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "AllowLambdaServiceToAssumeRole"
Effect: "Allow"
Action:
- "sts:AssumeRole"
Principal:
Service:
- "lambda.amazonaws.com" After deployment, I ran the following command to confirm that policy got attached to this Role: $ aws iam list-attached-role-policies --role-name "encryption-proxy-IAM-EncryptionServiceIAMRole-1UN7Z5T13JN9C"
{
"AttachedPolicies": [
{
"PolicyName": "AWSLambdaBasicExecutionRole",
"PolicyArn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
},
{
"PolicyName": "PHD-FullAccess-WideOrg",
"PolicyArn": "arn:aws:iam::<account_number>:policy/PHD-FullAccess-WideOrg"
}
]
} |
Hi @heitorlessa, The example above is different, because it's passing a role instead of a policy. I was more interested in passing the policies directly, like so (though irl using a separate template to export policy names):
Hope that makes sense. Best |
Hi, I have a problem which seems related. I have a first stack which contains an AWS::SNS::Topic and an AWS::IAM::ManagedPolicy. Resources:
Topic:
Type: AWS::SNS::Topic
Policy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: sns:Publish
Resource: !Ref Topic
Outputs:
TopicARN:
Value: !Ref Topic
Export:
Name: TopicARN
PolicyARN:
Value: !Ref Policy
Export:
Name: TopicPolicyARN And the second stack contains an AWS::Serverless::Function. Resources:
Function:
Type: AWS::Serverless::Function
Properties:
Runtime: python2.7
CodeUri: lambda.zip
Handler: lambda.handler
Policies: !ImportValue TopicPolicyARN When I deploy this stack, no error, but the policy is not appended to the default created role. |
+1, that's how I was trying to do it in a real scenario. Though shouldn't it be policy Name instead of ARN (according to the spec)? |
@dinvlad You can use the custom policy name in here. IAM wants managed policy's ARN. SAM tries to convert AWS managed policy names to ARNs, but it doesn't know about your custom policies. When #22 is fixed, you can do something like @chtison Again, due to #22 !ImportValue will not work. Sorry for the problems. We are working on getting #22 done which will unblock a lot of usecases. Hang on tight until then :-) |
Got it, sounds good, thanks! Closing in favor of #22 |
Now that #22 is completed, is this issue still valid? I've tried using |
@seanmcro I am not understanding what you are asking. Can you add snippets of your template? |
Sure. Based on @sanathkr's response above, I expected the following to work (but it doesn't):
I expected the IAM role generated by SAM for |
following template works for me:
|
…MQ events (#76) (#2078) Co-authored-by: Renato Valenzuela <[email protected]>
* Release/v1.37.0 (#2069) * chore: bump version to 1.37.0 (#2068) * fix: Increase PageSize of ListPolicies Paginator (#2033) Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> * feat: Support VIRTUAL_HOST as Type for SourceAccessConfiguration for MQ events (#76) (#2078) Co-authored-by: Renato Valenzuela <[email protected]>
…MQ events (aws#76) (aws#2078) Co-authored-by: Renato Valenzuela <[email protected]>
…MQ events (#76) (#2078) (#2080) Co-authored-by: Renato Valenzuela <[email protected]>
I've tried to follow the pattern setup above by @martinwangjian but when I run sam validate with the --lint option it tells me
Is managing custom managed policies from sam templates no longer supported? |
Hi @sanathkr,
The spec says that
Policies
can be astring | List of string
equal toNames of AWS managed IAM policies
. Are there any plans to enable reuse of existing customer-managed policies in SAM templates?Thanks
EDIT: Please ignore my earlier use case for this regarding separation of concerns. It looks like that's better addressed by Approvals in CodePipeline. I'm keeping this question open now just out of curiosity.
The text was updated successfully, but these errors were encountered: