AWSTemplateFormatVersion: '2010-09-09' Description: >- mirasim AWS connection. One role, mirasim-access, that mirasim assumes as the person on the Users list (their mirasim sign-in email is the session's source identity, so CloudTrail shows who made each call). No permissions are attached unless you add them. Metadata: AWS::CloudFormation::Interface: ParameterGroups: - Label: default: Who can use this role Parameters: - Users - Label: default: Permissions Parameters: - ManagedPolicyArns - PermissionsBoundaryArn - Label: default: Filled in by mirasim Parameters: - ExternalId ParameterLabels: Users: default: mirasim sign-in emails ManagedPolicyArns: default: Policies to attach PermissionsBoundaryArn: default: Permissions boundary ExternalId: default: External ID Parameters: ExternalId: Type: String AllowedPattern: '^mrs_acct_[0-9a-f]{32}$' ConstraintDescription: The External ID from the link mirasim gave you. Users: Type: CommaDelimitedList Description: >- Lowercase emails, comma separated, e.g. alice@acme.com,bob@acme.com. *@acme.com lets everyone with an acme.com sign-in use the role. ManagedPolicyArns: Type: CommaDelimitedList Default: '' Description: >- Policy ARNs, comma separated, e.g. arn:aws:iam::aws:policy/ReadOnlyAccess. Leave empty to attach policies yourself later. PermissionsBoundaryArn: Type: String Default: '' Description: Optional. Conditions: HasPolicies: !Not [!Equals [!Join ['', !Ref ManagedPolicyArns], '']] HasBoundary: !Not [!Equals [!Ref PermissionsBoundaryArn, '']] Resources: Role: Type: AWS::IAM::Role Properties: RoleName: mirasim-access Description: Assumed by mirasim as the person on the Users list. MaxSessionDuration: 3600 ManagedPolicyArns: !If [HasPolicies, !Ref ManagedPolicyArns, !Ref AWS::NoValue] PermissionsBoundary: !If [HasBoundary, !Ref PermissionsBoundaryArn, !Ref AWS::NoValue] # Two statements on purpose: sts:ExternalId is only present when AWS checks sts:AssumeRole, so # a single statement with that condition also refuses sts:SetSourceIdentity / sts:TagSession. # The External ID and the list both gate AssumeRole; the other two grant nothing on their own. AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Sid: MirasimAsListedPerson Effect: Allow Principal: AWS: arn:aws:iam::475554723467:role/mirasim-aws-connect Action: sts:AssumeRole Condition: StringEquals: sts:ExternalId: !Ref ExternalId StringLike: sts:SourceIdentity: !Ref Users - Sid: MirasimSetsIdentityAndTags Effect: Allow Principal: AWS: arn:aws:iam::475554723467:role/mirasim-aws-connect Action: - sts:SetSourceIdentity - sts:TagSession Outputs: RoleArn: Value: !GetAtt Role.Arn