Identity in the cloud: roles, trust and limits
Unit 1 of 5 in Cloud identity, network and data protection.
You will be able to say who can become a role, what a permissions boundary caps, and how an explicit deny or a guardrail changes the answer.
Lesson
Roles instead of long-lived keys
AWS describes an IAM role as an identity with specific permissions that is meant to be assumable by anyone who needs it. A role has no password or access keys of its own. When you assume it, you get temporary security credentials for that session. AWS lists uses such as giving people in one account access to resources in another, letting an app use AWS without embedding keys, and letting third parties audit your resources.
AWS's security best practices point the same way. They say to require people to use federation with an identity provider so they get temporary credentials, to require workloads to use roles for temporary credentials, and to update access keys when needed for the cases that still require long-term credentials. A long-lived key is a secret that works from anywhere until someone turns it off.
The first lab makes an assessor role: no key at all, MFA required to assume it, and a session name that shows up in the audit log. The key-rotation lab covers the case where a key cannot be avoided, on a local emulator with dummy credentials, and ends on the honest point that rotation limits the damage and does not remove the risk.
Two halves of access: the trust policy and the permissions policy
A role has two kinds of policy. The permissions policy says what the role can do. The trust policy says who may assume it. AWS describes a trust policy as a JSON document naming the principals you trust to assume the role, and as a required resource-based policy attached to the role. The principals can be users, roles, accounts and services.
For access between accounts, AWS says the trust policy in the trusting account is one half and a permissions policy that lets the other account's user assume the role is the other half. It also says an optional external ID helps ensure secure use of roles between accounts that are not controlled by the same organization.
That is why the trust policy is where over-wide access hides. A trust that names a whole account, or a service without a condition, lets everything in that account or service become the role. The trust-review lab builds a reviewer that reads every role trust in a synthetic account export, applies seven rules and writes the corrected trust for each fixable finding.
The confused deputy and the external ID
AWS defines the confused deputy problem as a security issue where an entity that does not have permission to perform an action can coerce a more-privileged entity to perform it. It arises when you give a third party, called cross-account, or another AWS service, called cross-service, access to your resources.
For a third party, AWS says the primary function of the external ID in a role trust policy is to address and prevent this problem. In the page's example, a monitoring company works for many customers. The external ID lets each customer's role insist on an identifier tied to that one arrangement, so another customer of the same company cannot reuse the company's access. For services, AWS gives the example of CloudTrail writing logs to a central bucket in another account, where the bucket policy allows the CloudTrail service, and says to add conditions that tie the access to your resources.
How AWS decides: allow, intersect and deny
AWS's policy evaluation page gives the combining rules in plain terms. Within one account, the permissions of identity-based and resource-based policies are the union: if either allows, the action is allowed. A permissions boundary changes that: the result is the intersection of the identity policies and the boundary. In an organization, an action must be allowed by the identity policy, any service control policy (SCP) and any resource control policy (RCP). In every case an explicit deny overrides an allow.
A permissions boundary is described as a managed policy that sets the maximum permissions an identity-based policy can grant to a user or role. It grants nothing by itself. The boundary lab proves this by attaching full administrator access to a throwaway role, capping it with a boundary that allows only storage and logging, and watching a call outside the boundary get denied while a call inside succeeds.
Use this picture when something is denied that looks allowed: check for a boundary, an SCP or RCP, a session policy and an explicit deny, because each can shrink the result.
Finding what is too wide, and what is unused
The best practices page also says to apply least-privilege permissions, to use IAM Access Analyzer to generate least-privilege policies and verify public and cross-account access, and to regularly review and remove unused users, roles, permissions, policies and credentials.
Access Analyzer has separate analyzers for different questions: external access analyzers identify resources shared with an external entity, internal access analyzers identify internal access to selected resources, and unused access analyzers identify unused access. Run it as a regular check, not once.
The CloudFox lab takes the assessor's first view: what exists, which regions are really used, who can do what, who is trusted and what runs with an administrator role. The lab notes that the tool's own README says it creates no findings and checks no benchmark, so you write the findings and the fix beside each one.
Key points
- Prefer roles and temporary credentials; keep long-lived keys only where nothing else works, and rotate them.
- A role has two policies: the permissions policy says what it can do, the trust policy says who can become it.
- An external ID, and conditions on service trusts, protect against the confused deputy.
- Allow policies add up, a boundary or an SCP or RCP intersects, and an explicit deny always wins.
- Review unused and external access on a schedule; a map of the account is not a list of findings.
Sources
- AWS IAM User Guide: IAM roles
- AWS IAM User Guide: Security best practices in IAM
- AWS IAM User Guide: Permissions boundaries for IAM entities
- AWS IAM User Guide: Policy evaluation logic
- AWS IAM User Guide: The confused deputy problem
- AWS IAM User Guide: What is IAM Access Analyzer?
Practice in the labs
Build the assessor role, map the account, review every trust, cap a role and rotate a key. Labs 1 and 2 use your own AWS account (free tier, read-only), lab 3 is offline, lab 4 uses a throwaway role in your own account, lab 5 runs on a local emulator.
- Create a read-only assessor role in your OWN AWS account and assume it with MFA: You create a role with no long-term key, require MFA to assume it and name the session so the account's audit log shows it. The later labs in the series reuse this role.
- Inventory your OWN AWS account with CloudFox and read who can reach what: You run an inventory with the assessor role and read the principals, trusts and workloads tables as a map, then write the findings yourself.
- Review every IAM role trust policy in an AWS account: who can assume what, and which trusts are too wide: You build a reviewer for the trusts of 44 synthetic roles, score it against a planted answer key and write the corrected trust documents.
- Cap privileges safely with an IAM permissions boundary: You attach administrator access to a throwaway role, cap it with a boundary and watch a call outside the cap get denied.
- Rotate AWS IAM access keys with zero downtime: On a local emulator you find stale and unused keys and rotate one by creating the new key before retiring the old.
Knowledge check
- A role's trust policy answers which question? Answer: Who is allowed to assume the role. AWS describes the trust policy as the document naming the principals trusted to assume the role. The permissions policy attached to the role says what it can do.
- A user has an identity policy allowing S3 and EC2, and a permissions boundary allowing only S3. What can the user do? Answer: Only S3 actions. A boundary sets the maximum. Effective permissions are the intersection of the identity policy and the boundary, so only the S3 actions allowed by both remain.
- What is the primary job of an external ID in a cross-account role trust policy? Answer: To address and prevent the confused deputy problem. AWS says the primary function of the external ID is to address and prevent the confused deputy problem when you give a third party access to your account.
- One policy allows an action and another policy explicitly denies it. What happens? Answer: The action is denied. AWS says an explicit deny in any of the evaluated policy types overrides an allow.
Back to the syllabus or see all classes.
Related
- Cloud identity, network and data protection
- Create a read-only assessor role in your OWN AWS account and assume it with MFA
- Inventory your OWN AWS account with CloudFox and read who can reach what
- Review every IAM role trust policy in an AWS account: who can assume what, and which trusts are too wide
- Cap privileges safely with an IAM permissions boundary
- Rotate AWS IAM access keys with zero downtime
- All classes
- Free cyber labs