Implementing Access Policies for Encryption Keys

Encryption keys play a critical role in securing data across AWS services. To ensure proper access control, organizations must define and enforce IAM policies, key policies, and permission boundaries for AWS Key Management Service (KMS) keys.

This study guide covers: βœ” Key Policy vs. IAM Policy for KMS βœ” Defining Access Controls for Encryption Keys βœ” Best Practices for Securing AWS KMS Keys βœ” Common Mistakes & How to Avoid Them βœ” SecureCart Use Case: Protecting Customer Payment Data


πŸ”Ή Understanding AWS KMS Access Control

AWS KMS does not rely solely on IAM policies. Instead, it uses a combination of IAM policies, Key Policies, and Grants to enforce access control.

Access Control Type

Purpose

KMS Key Policies

Controls access directly on the key itself (mandatory for all keys).

IAM Policies

Grants users, groups, or roles permission to use KMS keys.

Grants

Provides temporary permissions for specific AWS services (e.g., Lambda, S3).

Service Control Policies (SCPs)

Restricts KMS key usage across multiple AWS accounts.

πŸ“Œ Important: Key Policies override IAM policies in KMS. If an IAM user has KMS permissions but the Key Policy denies access, the user will not be able to use the key.


πŸ”Ή SecureCart Use Case: Protecting Customer Payment Data

SecureCart, an e-commerce platform, needs to encrypt customer credit card transactions stored in Amazon RDS and secure API keys used by third-party vendors.

βœ… SecureCart’s Requirements: βœ” Only authorized applications can decrypt credit card transactions. βœ” Developers should not have direct access to encryption keys. βœ” Auditors need read-only access to encryption logs. βœ” Key usage must be tracked and logged for compliance.


πŸ”Ή Step-by-Step: Implementing Access Policies for KMS Keys

1️⃣ Create a KMS Key for SecureCart’s Payment Transactions

βœ… Steps:

  1. Navigate to AWS KMS β†’ Create Key.

  2. Select Symmetric Key for encryption/decryption.

  3. Define Key Usage (Encrypt & Decrypt).

  4. Add an Alias (e.g., securecart-payment-key).

  5. Configure Key Policy (detailed below).

πŸ“Œ Why Use KMS? βœ” Meets PCI DSS compliance for securing payment data. βœ” Provides centralized key management with fine-grained access controls. βœ” Integrates with AWS services (S3, RDS, API Gateway).


2️⃣ Define Key Policies for Fine-Grained Access Control

βœ… KMS Key Policy for SecureCart:

User/Service

Permission

Justification

SecureCart Lambda Function

kms:Encrypt, kms:Decrypt

Encrypt/decrypt transactions.

Database Admins

kms:DescribeKey, kms:Decrypt

View key details but no modifications.

Auditors

kms:ListKeys, kms:GetKeyPolicy

Compliance reporting (read-only).

Developers

❌ No access

Prevent unauthorized key usage.

πŸ“Œ Key Policy JSON Excerpt:

jsonCopyEdit{
  "Id": "SecureCartKeyPolicy",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::123456789012:role/securecart-lambda" },
      "Action": ["kms:Encrypt", "kms:Decrypt"],
      "Resource": "*"
    },
    {
      "Effect": "Deny",
      "Principal": "*",
      "Action": ["kms:DeleteKey"],
      "Resource": "*"
    }
  ]
}

πŸ”Ή Why This Matters? βœ” Restricts key deletion. βœ” Allows only SecureCart Lambda to use the key. βœ” Blocks unauthorized access from developers.


3️⃣ Implement IAM Policies for Secure Access

IAM Policies help enforce role-based access control (RBAC) to KMS keys.

βœ… Example IAM Policy for SecureCart Auditors (Read-Only Access):

jsonCopyEdit{
  "Effect": "Allow",
  "Action": [
    "kms:ListKeys",
    "kms:GetKeyPolicy",
    "kms:DescribeKey"
  ],
  "Resource": "*"
}

πŸ”Ή Why Use IAM Policies? βœ” Assigns fine-grained permissions to IAM roles. βœ” Supports least privilege access control.


4️⃣ Use AWS KMS Grants for Temporary Access

Grants provide temporary permissions to AWS services (e.g., Lambda, RDS).

βœ… Example: SecureCart Lambda Needs Temporary Access

jsonCopyEdit{
  "Effect": "Allow",
  "Action": [
    "kms:CreateGrant",
    "kms:Decrypt"
  ],
  "Resource": "*",
  "Condition": {
    "StringEquals": { "kms:GrantConstraintType": "EncryptionContextEquals" }
  }
}

πŸ”Ή Why Use Grants? βœ” Limits access duration (reduces risk). βœ” Ideal for short-lived workloads (e.g., API calls).


5️⃣ Enforce Organization-Wide Key Restrictions with SCPs

SecureCart enforces global KMS security policies across all accounts.

βœ… Service Control Policy (SCP) Example: βœ” Prevents KMS key deletion across all accounts

jsonCopyEdit{
  "Effect": "Deny",
  "Action": ["kms:ScheduleKeyDeletion"],
  "Resource": "*",
  "Condition": {
    "StringEquals": { "aws:PrincipalOrgID": "o-abc12345" }
  }
}

πŸ”Ή Why Use SCPs? βœ” Enforces enterprise-wide security policies. βœ” Prevents accidental key deletion.


πŸ”Ή Best Practices for KMS Access Policies

βœ… Use IAM Roles Instead of IAM Users – Reduces risk of credential leakage. βœ… Enable Key Rotation – Reduces impact of compromised keys. βœ… Restrict Key Deletion – Prevents accidental data loss. βœ… Use Encryption Context – Ensures keys are used only for specific purposes. βœ… Log Key Usage with CloudTrail – Enables security audits.


πŸ”Ή Common Mistakes & How to Avoid Them

Mistake

Impact

Solution

Granting IAM Users Direct KMS Access

Increases security risk

Use IAM roles instead.

Not Configuring Key Policies Properly

Users may be locked out

Always test access policies.

Disabling Key Rotation

Increases risk of key compromise

Enable key rotation for compliance.

Not Logging KMS API Calls

Lack of visibility

Use AWS CloudTrail for tracking.


βœ… Summary

βœ” Use KMS Key Policies for direct key access control. βœ” Use IAM Policies for role-based access control. βœ” Use Grants for temporary, limited access. βœ” Use SCPs to enforce organization-wide security. βœ” Log all KMS activity with AWS CloudTrail for compliance.

Last updated