32
loading...
This website collects cookies to deliver better user experience
Parameters:
WhitelistedRoleIds:
Type: CommaDelimitedList
Description: >
IDs (AROA*, or AIDA*) to whitelist access for on the created secret.
Find the Role ID by running aws iam get-role --role-name ROLE-NAME.
Remember to append :* to the end of the Role IDs.
Find the User ID by running aws iam get-user --user-name USER-NAME.
User IDs do not need :* appended to the end.
Resources:
...
SecretResourcePolicy:
Type: 'AWS::SecretsManager::ResourcePolicy'
Properties:
SecretId: !Ref MySecret
ResourcePolicy:
Version: 2012-10-17
Statement:
- Resource: !Ref MySecret
Action: 'secretsmanager:GetSecretValue'
Effect: Deny
Principal: '*'
Condition:
StringNotLike:
aws:userId: !Ref WhitelistedRoleIds
NotPrincipal
. This is similar to the Principal
that sits in the aforementioned resource policy except it does the opposite. I set out attempting to accomplish the same goal but using NotPrincipal
, which I hoped would look like the following.- Resource: !Ref MySecret
Action: 'secretsmanager:GetSecretValue'
Effect: Deny
NotPrincipal:
AWS: !Ref WhitelistedPrincipals
arn:aws:sts::AWS_ACCOUNT_ID:assumed-role/ROLE_NAME/SESSION_NAME
which is also referred to as the assumed role ARN. Since the Principal
is made up of both the IAM Role’s ARN and the assumed role ARN, IAM will deny access to the resource since the Principal
does not match exactly.aws:userId
incoming. After much scouring, I eventually landed on a page listing the IAM policy condition keys. This was part one. Part two was a blog post about restricting access to an S3 bucket similarly to what I wanted to do with my Secret. The post explains that an IAM Role that has been assumed will always pass the same Role ID in the aws:userId
variable along with the session name. I like to think of that unique Role ID as some mixture of the IAM Role ARN and the assumed role ARN. Since it is a singular variable, we can grant access based on it in the resource policy.AROA*
and AIDA*
are unique prefixes that are predefined by AWS. I remember noticing that pattern while looking through logs about something unrelated and wondering if they all meant something. Turns out they do.aws:userId
variable allows us to whitelist both IAM Users and Roles. An IAM Role needs to be whitelisted as something like AROAJQABLZS4A3QDU576Q:*
because the session name is appended onto the Role ID at the end. (Roles must be assumed first before making an API call.) An IAM User needs to be whitelisted as something like AIDAJQABLZS4A3QDU576Q
without the :*
appended. To find those funky-looking IDs, run aws iam get-role --role-name ROLE_NAME
or aws iam get-user --user-name USER_NAME
.