Sub topic 2
Identity-Based Policies: Managed and Inline
Assume you know basic AWS authentication, authorization, JSON, and AWS CLI commands.
Managed and Inline Policies
An identity-based policy grants permissions to a user, group, or role. A managed policy is a reusable policy object. AWS managed policies are maintained by AWS. Customer managed policies are maintained by you and can be attached to several identities.
An inline policy is embedded directly in one identity. It is useful when permissions must have the same lifecycle as that identity, but it is harder to reuse and audit.
A policy normally specifies an effect, actions, resources, and optional conditions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:ListBucket"],
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket"
},
{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
}
]
}Notice that listing a bucket and reading objects use different resource Amazon Resource Names (ARNs).
Groups and Conditions
An IAM group is a collection of users. Attach a customer managed policy to a group when several users need the same access. Groups cannot contain roles, and applications should not use groups as identities.
A condition narrows when a statement applies. For example, you can require a specific region, source VPC, or MFA (multi-factor authentication) context. Conditions should restrict broad permissions rather than replace precise resources.
Roles, Trust, and Temporary Credentials
An IAM role is an identity with permissions but no permanent password or access key. A workload or person assumes the role and receives temporary credentials from AWS Security Token Service (STS). This avoids storing long-lived keys in applications.
A role has two related policies:
- The permissions policy says what the role can do.
- The trust policy says which principal may assume it.
The caller also needs permission to call sts:AssumeRole. Both sides must permit the assumption.
aws sts assume-role \
--role-arn arn:aws:iam::444455556666:role/ReadOnlyAuditor \
--role-session-name audit-session
aws sts get-caller-identityThe first command returns temporary credentials. Configure them in the environment or an AWS CLI profile. The second command confirms which principal subsequent requests use.
Exercise
A group policy allows s3:GetObject, but a user's inline policy explicitly denies it. Can the user read the object?
Show answer
No. An explicit deny overrides an allow.