# hkb-scp-baseline-protection

SCP-03 deny disabling logging and security services, and changes to hkb-baseline-* roles and stacks.

| Property | Value |
| --- | --- |
| Type | Service control policy |
| Attached to | the organization root |
| Source | `org/hkb-org-scp.yaml`, resource `BaselineProtectionPolicy` |

## `Scp03DenyDisablingSecurityServices`

```yaml
- Sid: Scp03DenyDisablingSecurityServices
  Effect: Deny
  Action:
    - cloudtrail:StopLogging
    - cloudtrail:DeleteTrail
    - cloudtrail:UpdateTrail
    - cloudtrail:PutEventSelectors
    - cloudtrail:PutInsightSelectors
    - config:DeleteConfigurationRecorder
    - config:StopConfigurationRecorder
    - config:DeleteDeliveryChannel
    - config:DeleteConfigurationAggregator
    - config:DeleteConfigRule
    - guardduty:DeleteDetector
    - guardduty:DisassociateFromAdministratorAccount
    - guardduty:DisassociateFromMasterAccount
    - securityhub:DisableSecurityHub
    - securityhub:DisassociateFromAdministratorAccount
    - securityhub:BatchDisableStandards
    - access-analyzer:DeleteAnalyzer
  Resource: "*"
  Condition:
    ArnNotLike:
      aws:PrincipalArn:
        - arn:aws:iam::*:role/AWSControlTowerExecution
        - arn:aws:iam::*:role/aws-controltower-*
        - arn:aws:iam::*:role/service-role/aws-controltower-*
        - arn:aws:iam::*:role/stacksets-exec-*
# Site floor (DQ-39): only the hkb-baseline-account custom resource sets EBS default
# encryption and the password policy; nothing may turn them off or swap the EBS key.
```

## `Scp03DenyWeakeningAccountBaseline`

```yaml
- Sid: Scp03DenyWeakeningAccountBaseline
  Effect: Deny
  Action:
    - ec2:DisableEbsEncryptionByDefault
    - ec2:ModifyEbsDefaultKmsKeyId
    - ec2:ResetEbsDefaultKmsKeyId
    - iam:DeleteAccountPasswordPolicy
    - iam:UpdateAccountPasswordPolicy
  Resource: "*"
  Condition:
    ArnNotLike:
      aws:PrincipalArn:
        - arn:aws:iam::*:role/AWSControlTowerExecution
        - arn:aws:iam::*:role/hkb-baseline-account-settings
```

## `Scp03DenyBaselineRoleChanges`

```yaml
- Sid: Scp03DenyBaselineRoleChanges
  Effect: Deny
  Action:
    - iam:AttachRolePolicy
    - iam:DeleteRole
    - iam:DeleteRolePermissionsBoundary
    - iam:DeleteRolePolicy
    - iam:DetachRolePolicy
    - iam:PutRolePermissionsBoundary
    - iam:PutRolePolicy
    - iam:UpdateAssumeRolePolicy
  Resource: arn:aws:iam::*:role/hkb-baseline-*
  Condition:
    ArnNotLike:
      aws:PrincipalArn:
        - arn:aws:iam::*:role/AWSControlTowerExecution
        - arn:aws:iam::*:role/aws-controltower-*
        - arn:aws:iam::*:role/service-role/aws-controltower-*
        - arn:aws:iam::*:role/stacksets-exec-*
```

## `Scp03DenyBaselineStackChanges`

```yaml
- Sid: Scp03DenyBaselineStackChanges
  Effect: Deny
  Action:
    - cloudformation:CreateChangeSet
    - cloudformation:DeleteChangeSet
    - cloudformation:DeleteStack
    - cloudformation:ExecuteChangeSet
    - cloudformation:SetStackPolicy
    - cloudformation:UpdateStack
  Resource: arn:aws:cloudformation:*:*:stack/hkb-baseline-*/*
  Condition:
    ArnNotLike:
      aws:PrincipalArn:
        - arn:aws:iam::*:role/AWSControlTowerExecution
        - arn:aws:iam::*:role/aws-controltower-*
        - arn:aws:iam::*:role/service-role/aws-controltower-*
        - arn:aws:iam::*:role/stacksets-exec-*
# Step 7.9. A launch that doesn't set HttpTokens has no value for the key, so it is denied too.
```

## `Scp03DenyLaunchWithoutImdsV2`

```yaml
- Sid: Scp03DenyLaunchWithoutImdsV2
  Effect: Deny
  Action: ec2:RunInstances
  Resource: arn:aws:ec2:*:*:instance/*
  Condition:
    StringNotEquals:
      ec2:MetadataHttpTokens: required
    ArnNotLike:
      aws:PrincipalArn:
        - arn:aws:iam::*:role/AWSControlTowerExecution
        - arn:aws:iam::*:role/aws-controltower-*
        - arn:aws:iam::*:role/service-role/aws-controltower-*
        - arn:aws:iam::*:role/stacksets-exec-*
# Without this, an instance launched with IMDSv2 could be switched back to allow IMDSv1.
```

## `Scp03DenyImdsV2OptOut`

```yaml
- Sid: Scp03DenyImdsV2OptOut
  Effect: Deny
  Action: ec2:ModifyInstanceMetadataOptions
  Resource: arn:aws:ec2:*:*:instance/*
  Condition:
    StringNotEquals:
      ec2:Attribute/HttpTokens: required
    "Null":
      ec2:Attribute/HttpTokens: "false"
    ArnNotLike:
      aws:PrincipalArn:
        - arn:aws:iam::*:role/AWSControlTowerExecution
        - arn:aws:iam::*:role/aws-controltower-*
        - arn:aws:iam::*:role/service-role/aws-controltower-*
        - arn:aws:iam::*:role/stacksets-exec-*
```
