Overview and What You Will Learn
Once you run several AWS accounts and many engineers, basic users and groups are not enough. You need guardrails that apply to whole groups of accounts, safe ways to cross account boundaries, and sign-in that does not depend on long-lived keys. This topic covers AWS Organizations and service control policies (SCPs), advanced IAM conditions, cross-account access, permission boundaries, policy evaluation, OIDC federation for CI/CD, IAM Identity Center, directory options and Control Tower. In the lab you create an OU and an SCP, cap a user with a permission boundary, and set up a GitHub OIDC role, all from the CLI.
By the end you will be able to:
- Structure accounts with Organizations and OUs, and explain what SCPs can and cannot do
- Write blocklist and allowlist SCP strategies and predict how inheritance works
- Use conditions such as region, source IP, tags, MFA and organization ID
- Choose between role assumption and resource-based policies for cross-account access
- Use permission boundaries to delegate IAM safely
- Walk through the policy evaluation order for any request
- Give CI/CD pipelines short-lived access with OIDC instead of access keys
- Explain IAM Identity Center, directory choices and Control Tower guardrails
Why This Matters in Production
A startup with one account and one admin can get by with basic IAM. A company with separate accounts for production, staging, development, security and logging, and hundreds of engineers, needs controls that scale. Without them, the choices are to lock engineers out of work they need to do, or leave production open to accidental and malicious changes.
SCPs, permission boundaries, tag-based conditions, federation and Identity Center are the building blocks serious environments use to give people exactly the access they need, across many accounts, with no shared keys and a clear audit trail.
Core Principles
What Is AWS Organizations and Why Use Multiple Accounts?
Organizations lets you manage many AWS accounts under one structure, with consolidated billing and central policies. One management account controls the organization, and all other accounts are member accounts organized into organizational units (OUs). Separate accounts give a hard blast-radius boundary that VPCs inside one account cannot provide.
- Consolidated billing gives one invoice, and usage aggregates for volume discounts
- Reserved Instance and Savings Plans discounts can be shared across accounts
- Common OU layouts group by environment (Prod, Dev), business unit, or workload type
- Keep workloads out of the management account, which is not limited by SCPs
What Do Service Control Policies Do?
An SCP sets the maximum permissions available in the accounts it applies to, and it never grants permissions by itself. A principal can only use an action if the SCP at every level above it allows it, and an identity or resource policy also allows it. Even an administrator in a member account is limited by the SCPs.
- SCPs attach to the root, to OUs and to individual accounts, and they inherit down the tree
- SCPs never affect the management account, so a breach there is unrestricted
- SCPs do affect the root user of member accounts, but they do not affect service-linked roles
- By default AWS attaches a policy named FullAWSAccess at each level. Replace it only when you use an allowlist
- Resource control policies (RCPs) are the companion that limit permissions on resources, so check which services they support
RememberThe management account is exempt from every SCP. Keep it empty except for organization management tasks.
Should You Use a Blocklist or an Allowlist SCP Strategy?
Use a blocklist for most OUs and an allowlist only for tightly locked environments. A blocklist keeps FullAWSAccess and adds Deny statements for things you must prevent. An allowlist removes FullAWSAccess and allows only named services, which is stricter but needs more maintenance as you adopt new services.
| Strategy | Statements | Use when |
|---|---|---|
| Blocklist | Allow all, then Deny chosen actions | Most OUs |
| Allowlist | Allow only named services | Sandboxes, restricted environments |
Example inheritance: a Deny on S3 at the Sandbox OU blocks S3 for every account inside it, and an extra Deny on EC2 at one account blocks EC2 there as well. In an allowlist OU that allows only EC2, an account can use only EC2, whatever its own policies say.
SecurityTest SCPs in a sandbox OU before attaching them to the root or production OUs. A wrong Deny can silently break services for every team, and SCP denials do not always explain themselves clearly.
Which Advanced IAM Conditions Matter Most?
Conditions narrow a statement beyond service and action, and a handful solve most real needs. Combine them with Deny statements for guardrails and with Allow statements for scoped access.
| Condition key | What it controls |
|---|---|
| aws:SourceIp | The caller's IP address, where the call comes from |
| aws:RequestedRegion | The Region the call goes to |
| aws:PrincipalTag and resource tags | Tag-based access control |
| aws:MultiFactorAuthPresent | Whether MFA was used in the session |
| aws:PrincipalOrgID | Whether the caller belongs to your organization |
- Source IP: Deny everything unless the request comes from the office or VPN ranges. It does not work as expected for requests made through VPC endpoints or by AWS services on your behalf, so use VPC conditions there.
- Region: Deny actions outside approved Regions, such as ap-south-1 and ap-southeast-1. Exclude global services, which are served from us-east-1, or you will break IAM and similar services.
- Tags (ABAC): Allow start and stop on EC2 only when the instance tag Project equals the caller's tag Project, so access follows tags and policies stay short.
- MFA: Allow EC2 actions but deny stop and terminate when MFA is not present. Use the BoolIfExists form so sessions with no MFA value are caught too.
- Organization ID: Allow a bucket policy for any principal in your organization, which automatically covers new accounts.
Common MistakeConfusing aws:SourceIp with aws:RequestedRegion. One is where the caller is, and the other is which Region the API call targets. They control different things.
How Do You Give Cross-Account Access: Role or Resource Policy?
Both work, but they behave differently. With a role, you switch identity: you assume a role in the other account and your original permissions are set aside for that session. With a resource-based policy, the resource lets your identity in directly, so you keep your own permissions while using it.
| Role assumption | Resource-based policy | |
|---|---|---|
| Identity during access | The role in the other account | Your original identity |
| Original permissions | Not available in the session | Still available |
| Works for | Any service the role can use | Services that support resource policies |
Choose a resource-based policy when you must use both accounts at once, for example reading DynamoDB in account A while writing to an S3 bucket in account B. For a role, the target account's trust policy must name the caller, and the caller needs permission to call sts:AssumeRole. For a resource-based policy across accounts, both the resource policy and the caller's own identity policy must allow the action.
aws sts assume-role \ --role-arn arn:aws:iam::210987654321:role/audit-readonly \ --role-session-name rahul-audit \ --external-id devops-audit-2026An external ID protects against the confused deputy problem when a third party assumes roles in many customers' accounts. Chaining roles from a role session limits the new session to one hour.
What Are IAM Permission Boundaries?
A permission boundary is a policy that caps the maximum permissions an IAM user or role can have, even if its identity policies allow more. Boundaries apply to users and roles, not groups, and they never grant anything on their own. Effective permissions are the overlap of what the identity policy allows and what the boundary allows, and an SCP narrows that further.
Boundary allows: s3:*, cloudwatch:*, ec2:Describe*Policy allows: AdministratorAccessResult: only s3:*, cloudwatch:* and ec2:Describe*Boundaries are most useful for safe delegation. A team lead can create roles and users for a team, but only if each new identity carries the boundary, so nobody can mint more power than the boundary permits. Enforce that with a policy that allows user and role creation only when the iam:PermissionsBoundary condition equals your boundary ARN, and that denies removing the boundary.
| Statement | Effect | Key detail |
|---|---|---|
| Create identities | Allow | iam:CreateUser and iam:CreateRole only when iam:PermissionsBoundary equals the boundary ARN |
| Keep the boundary | Deny | iam:DeleteUserPermissionsBoundary and iam:DeleteRolePermissionsBoundary |
| Protect the boundary policy | Deny | Changing or deleting the boundary policy itself |
A resource-based policy in the same account that names a user or role directly can still grant access that the boundary does not cover, so keep that in mind when you design resource policies.
How Does IAM Evaluate a Request?
AWS checks several layers in a fixed order, and any explicit Deny or missing Allow stops the request. A request is allowed only when nothing denies it, every applicable layer permits it, and something grants it.
The layers, in order, are:
- Explicit Deny in any policy
- Organizations SCPs (and RCPs) must allow
- Resource-based policies, which can grant access directly in the same account
- Identity-based policies must grant it, unless a resource policy already did
- Permission boundary must allow
- Session policy must allow
- Otherwise, implicit deny
Practice with this policy of two statements:
| Statement | Effect | Action |
|---|---|---|
| One | Deny | sqs:* |
| Two | Allow | sqs:DeleteQueue |
- sqs:CreateQueue is denied, because of the explicit Deny
- sqs:DeleteQueue is also denied, because a Deny beats an Allow and statement order does not matter
- ec2:DescribeInstances is denied, because nothing allows it and the default is implicit deny
How Does OIDC Federation Replace Access Keys in CI/CD?
With OIDC federation, your pipeline presents a short-lived identity token from its provider and AWS exchanges it for temporary credentials, so no access key is stored anywhere. You register the provider as an IAM OIDC identity provider, and create a role whose trust policy accepts tokens only from your repository and branch. The same pattern works for other OIDC providers and for EKS workloads.
| Trust policy element | Value for GitHub Actions |
|---|---|
| Principal | The OIDC provider ARN for token.actions.githubusercontent.com |
| Action | sts:AssumeRoleWithWebIdentity |
| Condition on aud | sts.amazonaws.com |
| Condition on sub | Your repository and branch, for example repo:devops-network/deploy-app:ref:refs/heads/main |
The workflow needs permission to request the token and then uses the official action:
name: deployon: push: branches: [main]permissions: id-token: write contents: readjobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::123456789012:role/github-deploy-role aws-region: ap-south-1 - run: aws sts get-caller-identitySecurityAlways constrain the sub claim. A trust policy that only checks the audience would let any repository that uses the provider assume the role.
What Is AWS IAM Identity Center?
Identity Center, the successor to AWS Single Sign-On, gives people one sign-in to all accounts in the organization and to supported business applications. Users come from the built-in directory, from Active Directory, or from an external identity provider through SAML and SCIM. It removes the need for IAM users in each account and gives short-lived credentials.
- Permission sets: Collections of policies that you assign to users or groups for chosen accounts. Developers might get full access in Dev accounts and read-only in Prod from one definition.
- ABAC: Access based on user attributes such as department or cost center, so permissions follow attribute changes.
- Application assignments: Single sign-on to SAML 2.0 applications.
- CLI use:
aws configure ssoandaws sso logingive developers temporary credentials with no stored keys.
Which Active Directory Option Should You Use on AWS?
Pick by where your users live and what you need to join. AWS Managed Microsoft AD runs a real AD in AWS and can trust your on-premises AD. AD Connector proxies requests to your on-premises AD without storing identities in AWS. Simple AD is a basic, legacy option, so check its current availability before using it in new designs.
| Option | Where users live | Use when |
|---|---|---|
| AWS Managed Microsoft AD | In AWS, with optional trust to on-premises | You need a full AD in AWS |
| AD Connector | On-premises | You keep identities on-premises |
| Simple AD | In AWS only | A very basic standalone directory |
What Is AWS Control Tower?
Control Tower sets up and governs a secure multi-account environment, called a landing zone, using Organizations, IAM Identity Center and AWS Config. It creates the log archive and audit accounts, an account factory for new accounts, and controls (formerly called guardrails) that apply across accounts.
| Control type | How it works | Example |
|---|---|---|
| Preventive | SCP blocks the action | Block use of unapproved Regions |
| Detective | AWS Config flags it after the fact | Find untagged resources |
| Proactive | CloudFormation hook blocks bad templates | Refuse unencrypted resources at deploy time |
Detailed Step-by-Step Practical Lab
Run this in a test organization. Policy files are generated with Python so no hand-written JSON is needed. Attaching an SCP to an empty OU affects nothing, and the management account is never restricted.
Step 1: Create the organization and an OU
aws organizations create-organization --feature-set ALL ROOT_ID=$(aws organizations list-roots --query 'Roots[0].Id' --output text) aws organizations enable-policy-type --root-id $ROOT_ID \ --policy-type SERVICE_CONTROL_POLICY OU_ID=$(aws organizations create-organizational-unit \ --parent-id $ROOT_ID --name Sandbox \ --query 'OrganizationalUnit.Id' --output text)Step 2: Create and attach a region-restricting SCP
python3 - <<'EOF'import jsonscp = dict( Version='2012-10-17', Statement=[dict( Sid='DenyOutsideMumbai', Effect='Deny', Action=['ec2:*', 'rds:*', 's3:CreateBucket'], Resource='*', Condition=dict( StringNotEquals=dict([('aws:RequestedRegion', 'ap-south-1')]) ), )],)json.dump(scp, open('scp.json', 'w'), indent=2)EOF POLICY_ID=$(aws organizations create-policy \ --type SERVICE_CONTROL_POLICY \ --name RestrictToMumbaiOnly \ --description "Deny EC2, RDS and S3 bucket creation outside ap-south-1" \ --content file://scp.json \ --query 'Policy.PolicySummary.Id' --output text) aws organizations attach-policy --policy-id $POLICY_ID --target-id $OU_IDaws organizations list-policies-for-target --target-id $OU_ID \ --filter SERVICE_CONTROL_POLICYAny member account placed in Sandbox can now use those services only in ap-south-1.
Step 3: Create a permission boundary and cap a user
python3 - <<'EOF'import jsonboundary = dict( Version='2012-10-17', Statement=[dict( Effect='Allow', Action=['s3:*', 'cloudwatch:*', 'ec2:Describe*'], Resource='*', )],)json.dump(boundary, open('boundary.json', 'w'), indent=2)EOF BOUNDARY_ARN=$(aws iam create-policy --policy-name DevEngineerBoundary \ --policy-document file://boundary.json \ --query 'Policy.Arn' --output text) aws iam create-user --user-name arjun-dev --permissions-boundary $BOUNDARY_ARNaws iam attach-user-policy --user-name arjun-dev \ --policy-arn arn:aws:iam::aws:policy/AdministratorAccessStep 4: Verify the boundary with the policy simulator
USER_ARN=$(aws iam get-user --user-name arjun-dev --query User.Arn --output text) aws iam simulate-principal-policy \ --policy-source-arn $USER_ARN \ --action-names s3:ListAllMyBuckets ec2:RunInstances iam:CreateUser \ --query 'EvaluationResults[].[EvalActionName,EvalDecision]' --output tableS3 is allowed, while EC2 RunInstances and iam:CreateUser are denied, even though the user has AdministratorAccess, because the boundary is the ceiling.
Step 5: Create a GitHub OIDC provider and role
export ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) # If the CLI asks for a thumbprint, use the value from the AWS or GitHub documentationaws iam create-open-id-connect-provider \ --url https://token.actions.githubusercontent.com \ --client-id-list sts.amazonaws.com python3 - <<'EOF'import json, osprovider = 'arn:aws:iam::' + os.environ['ACCOUNT_ID'] + ':oidc-provider/token.actions.githubusercontent.com'trust = dict( Version='2012-10-17', Statement=[dict( Effect='Allow', Principal=dict(Federated=provider), Action='sts:AssumeRoleWithWebIdentity', Condition=dict( StringEquals=dict([ ('token.actions.githubusercontent.com:aud', 'sts.amazonaws.com'), ('token.actions.githubusercontent.com:sub', 'repo:devops-network/deploy-app:ref:refs/heads/main'), ]) ), )],)json.dump(trust, open('github-trust.json', 'w'), indent=2)EOF aws iam create-role --role-name github-deploy-role \ --assume-role-policy-document file://github-trust.jsonaws iam attach-role-policy --role-name github-deploy-role \ --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccessUse the role ARN in the workflow shown earlier. No access key is stored in GitHub.
Step 6: Clean up
aws iam detach-role-policy --role-name github-deploy-role \ --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccessaws iam delete-role --role-name github-deploy-roleaws iam delete-open-id-connect-provider \ --open-id-connect-provider-arn arn:aws:iam::$ACCOUNT_ID:oidc-provider/token.actions.githubusercontent.com aws iam detach-user-policy --user-name arjun-dev \ --policy-arn arn:aws:iam::aws:policy/AdministratorAccessaws iam delete-user-permissions-boundary --user-name arjun-devaws iam delete-user --user-name arjun-devaws iam delete-policy --policy-arn $BOUNDARY_ARN aws organizations detach-policy --policy-id $POLICY_ID --target-id $OU_IDaws organizations delete-policy --policy-id $POLICY_IDaws organizations delete-organizational-unit --organizational-unit-id $OU_IDDo not delete the organization if you use it for anything else.
Production Best Practices & Common Pitfalls
- Keep the management account empty: SCPs cannot restrict it.
- Prefer blocklist SCPs: They are easier to maintain than allowlists.
- Test SCPs in a sandbox OU first: Roll them out gradually.
- Use Identity Center for people: Avoid IAM users in every account.
- Use OIDC for pipelines: No stored keys, and a narrow trust condition.
- Use boundaries for delegation: Let team leads create roles only within a cap.
- Use aws:PrincipalOrgID in resource policies: New accounts are covered automatically.
- Exclude global services in region restrictions: Or you will block IAM and similar services.
- Use external IDs for third-party roles: It prevents the confused deputy problem.
- Turn on AWS Config and Security Hub across accounts: Control Tower can do this from the start.
Common MistakeUsing role assumption when you need to use two accounts at once. The role session has only the role's permissions, so use a resource-based policy on the target resource instead.
Common MistakePutting workloads in the management account. A breach there is not limited by any SCP.
Quick Reference & Troubleshooting Commands
| Task | Command |
|---|---|
| Create organization | aws organizations create-organization --feature-set ALL |
| List roots | aws organizations list-roots |
| Create OU | aws organizations create-organizational-unit --parent-id <root-id> --name <name> |
| List accounts | aws organizations list-accounts |
| Move an account | aws organizations move-account --account-id <id> --source-parent-id <p> --destination-parent-id <ou> |
| Create SCP | aws organizations create-policy --type SERVICE_CONTROL_POLICY --name <n> --description <d> --content file://scp.json |
| Attach SCP | aws organizations attach-policy --policy-id <p-id> --target-id <ou-id> |
| SCPs on a target | aws organizations list-policies-for-target --target-id <id> --filter SERVICE_CONTROL_POLICY |
| Assume a role | aws sts assume-role --role-arn <arn> --role-session-name <name> |
| Problem | Likely cause and fix |
|---|---|
| Denied in a member account despite admin rights | An SCP on the account, an OU above it, or the root. Check every level. |
| Management account seems unaffected by an SCP | By design. SCPs never apply to it. |
| Needs two accounts at once | Role assumption drops original permissions. Use a resource-based policy. |
| Cross-account access still denied | Both sides must allow it. Check trust or resource policy and the caller's policy. |
| User cannot do something their policy allows | A permission boundary or session policy caps it. |
| OIDC role cannot be assumed | The sub or aud condition does not match the token claims. |
| Identity Center user sees no account | No permission set assigned to that user or group for that account. |