6: Security and Compliance

    Identity and Access Management at Scale

    Identity and access management at the Organization scale stops being a question of "which policy attaches to which user" and becomes a question of which guardrails the principal cannot step outside no matter how badly an attached policy is written. The professional surface tests four boundaries that intersect on every API call: the identity-based policy (what the principal has been granted), the resource-based policy (what the resource accepts), the permission boundary (a maximum-permissions ceiling on the principal), and the AWS Organizations service control policy that applies to the principal's account. An action succeeds only if every layer allows it, and the policy evaluation order from Chapter 2 sits underneath every decision in this chapter. The DevOps engineer's job is to compose those four layers so that a developer in a sandbox account can never assume a role in production, a CI/CD principal can never escalate beyond its bounded set of API calls, and a Lambda function can never reach the internet from a subnet it was not provisioned in.

    That intersection logic is the reason permission boundaries and attribute-based access control (ABAC) are tested together at this level. A permission boundary is itself a managed policy attached to a principal that caps the principal's effective permissions; granting iam:CreateRole to a developer is safe only when the developer's permission boundary forces them to attach a specified permission boundary to any role they create. ABAC moves the access logic from policy proliferation to tag matching: a single policy that allows actions on resources where aws:ResourceTag/Project equals aws:PrincipalTag/Project replaces dozens of project-specific policies, and the IAM Identity Center session token carries those principal tags automatically when sessions are issued with PrincipalTagAttributeMap mappings.

    The other lever that distinguishes professional content from associate content is the automated response loop. A security finding that lands in Amazon EventBridge becomes input to an AWS Systems Manager Automation runbook or an AWS Lambda function within seconds, and the response is logged through AWS Systems Manager OpsCenter so the entire chain (detection, decision, action, verification) is auditable. The same EventBridge bus that propagated AWS Health events in Chapter 4 also carries Security Hub findings, GuardDuty findings, AWS Config compliance changes, and IAM Access Analyzer findings. When the platform team owns the IAM perimeter and the response automation together, the time between detection and containment collapses from human-paced minutes to single-digit seconds.

    A common professional question gives a multi-account scenario where a privileged role exists in every account and asks how to prevent local administrators from creating new IAM users that bypass the IAM Identity Center identity plane. The answer is layered: a service control policy at the Organizations root or the workload organizational unit denies iam:CreateUser and iam:CreateAccessKey except for a narrowly scoped emergency role, a permission boundary on the IAM Identity Center permission set forbids iam:CreateUser even with administrator privileges, and an AWS Config managed rule (iam-user-no-policies-check) flags any user that does appear. The detective layer cannot remove the user, but the EventBridge response can, by invoking an Automation runbook that detaches the access key and opens an OpsItem for human review.

    Layering Permission Boundaries and Attribute-Based Access Control

    Permission boundaries are evaluated as an explicit ceiling, which means a principal needs both an allow in their identity-based policy and an allow in the boundary for the action to succeed. Building a development guardrail starts with a managed policy that lists the maximum API surface the team is permitted to use, then attaching that policy as the boundary on every role provisioned by the pipeline. When that pipeline also provisions roles for the developer's own work, the boundary must be re-attached recursively so the developer cannot escape it.

    {
     "Version": "2012-10-17",
     "Statement": [
     {
     "Sid": "ProductOpsCeiling",
     "Effect": "Allow",
     "Action": [
     "s3:*",
     "dynamodb:*",
     "logs:*",
     "cloudwatch:*",
     "xray:*",
     "lambda:*"
     ],
     "Resource": "*",
     "Condition": {
     "StringEquals": {"aws:RequestedRegion": ["us-east-1", "eu-west-1"]}
     }
     },
     {
     "Sid": "ForceBoundaryOnCreatedRoles",
     "Effect": "Deny",
     "Action": ["iam:CreateRole", "iam:PutRolePolicy"],
     "Resource": "*",
     "Condition": {
     "StringNotEquals": {
     "iam:PermissionsBoundary": "arn:aws:iam::123456789012:policy/dev-ceiling"
     }
     }
     }
     ]
    }
    

    Attribute-based access control replaces N policies per project with one policy keyed on tag equality. Tag-based policies pair best with IAM Identity Center because the identity provider can stamp the session with sts:TagSession attributes drawn from the external directory. Resource creators are forced to tag at creation through a parallel deny statement that rejects s3:CreateBucket or ec2:RunInstances when the request does not carry the required tag keys.

    {
     "Version": "2012-10-17",
     "Statement": [
     {
     "Sid": "ProjectMatchABAC",
     "Effect": "Allow",
     "Action": ["s3:GetObject", "s3:PutObject"],
     "Resource": "arn:aws:s3:::*/objects/*",
     "Condition": {
     "StringEquals": {
     "aws:ResourceTag/Project": "${aws:PrincipalTag/Project}",
     "aws:ResourceTag/Environment": "${aws:PrincipalTag/Environment}"
     }
     }
     }
     ]
    }
    

    💡 Exam Trap: A permission boundary does not grant permissions. A role with only a boundary attached has zero effective permissions. The boundary caps the union of identity policies; the role still needs an explicit allow in an inline or managed policy. The boundary is also evaluated against the actions made by the role, not actions made by another principal who assumes the role through sts:AssumeRole.

    Automated Response to Security Findings

    Closed-loop response is the highest-value pattern that distinguishes a Professional candidate from an Associate. The flow is: a detective service writes a finding to its native API, AWS Security Hub normalizes the finding into ASFF (AWS Security Finding Format), the finding is emitted as an EventBridge event from the aws.securityhub source, an EventBridge rule on a custom or default bus filters by finding type and severity, and the target is an AWS Systems Manager Automation runbook executed with an AutomationAssumeRole that has just enough permission to remediate. The Automation runbook is preferable to a raw Lambda function for two reasons: it ships with aws:approve change gates for high-impact actions, and every Automation execution is recorded as an OpsItem with structured OperationalData.

    Resources:
     ContainExposedKey:
     Type: AWS::Events::Rule
     Properties:
     EventBusName: default
     Description: Disables access keys flagged by IAM Access Analyzer
     EventPattern:
     source: ["aws.securityhub"]
     detail-type: ["Security Hub Findings - Imported"]
     detail:
     findings:
     ProductFields:
     aws/securityhub/ProductName: ["IAM Access Analyzer"]
     Severity:
     Label: ["HIGH", "CRITICAL"]
     Targets:
     - Id: AutomationRunbook
     Arn: !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/Custom-DisableExposedKey:$DEFAULT
     RoleArn: !GetAtt EventBridgeAutomationRole.Arn
     InputTransformer:
     InputPathsMap:
     accessKeyId: "$.detail.findings[0].Resources[0].Id"
     InputTemplate: |
     {"AccessKeyId": [<accessKeyId>]}
    

    The InputTransformer extracts the access-key ID from the ASFF document so the runbook receives a typed parameter. The runbook then calls iam:UpdateAccessKey with Status=Inactive and opens an OpsItem against the discovered principal for human follow-up. The same pattern reapplies for GuardDuty findings, Inspector findings, Macie findings, and AWS Config noncompliance events; only the EventBridge filter and the runbook body change.

    🎯 Scenario: A nightly Inspector scan reports a CVSS=9.8 finding on a containerized workload in production. The EventBridge rule routes the finding to the Custom-PatchCriticalCVE runbook, which calls Run Command across the affected EC2 instance set, applies the missing package, validates the patch, and only then closes the originating OpsItem. The pipeline alerts on-call only when the runbook fails or when aws:approve is required because the CVE is in a kernel module that requires a reboot.

    ⚠️ Anti-Pattern: Wiring EventBridge to a Lambda function that holds inline AdministratorAccess in order to "respond to anything." That violates least privilege and makes the response code itself the next attack target. The Automation runbook with its narrow AutomationAssumeRole is the auditable equivalent.

    Decision Anchor: Permission Boundary vs Service Control Policy

    Choose a permission boundary when the cap is per-principal and changes per team. Choose a service control policy when the cap is per-account and never changes regardless of who attaches what policy inside the account. SCPs cover root-user actions too; permission boundaries do not apply to the account root.

    📊 Limit: An IAM role can have at most one permissions boundary policy attached at any time. The boundary policy size limit is 6,144 characters for inline and 6,144 characters for managed. The Organizations SCP size limit is 5,120 characters per policy, and a single account can have at most five SCPs (one of which is FullAWSAccess) attached directly plus inherited policies from parent OUs.


    Continue with the interactive course

    Track your progress, jump into practice questions and use the Shark AI tutor inside the AWS - DevOps Engineer Professional learning hub.