Reconstruct the authorization chain
At a fictional bank, an APS role in the application account needs a symmetric key from the security account. Having kms:Decrypt in the role’s IAM policy is insufficient if the key does not authorize that access. In a cross-account policy design, check authorization at the key and delegation at the identity, without ignoring explicit denies, conditions, and applicable boundaries.
Permission for the service storing the object is a separate check. Identify the effective session principal, operation, full key ARN, and Region. Within an account, a key policy can directly authorize a principal or enable IAM delegation; do not turn the cross-account pattern into a universal two-independent-permission rule for every request.
Constrain use without confusing context with a secret
kms:ViaService can restrict key use to requests made by an integrated service on the principal’s behalf through forward access sessions. A direct KMS call does not establish that the service path is authorized, nor does it automatically satisfy the condition.
For symmetric operations, encryption context adds authenticated pairs that must be reproduced for decryption. It is not a secret store: it can appear in plaintext in logs. Use nonsensitive operational identifiers, never customer names or secrets.
In the original exercise, Workload=nav-batch and Stage=prod identify the context. Changing prod to Prod or losing a pair can invalidate the request. Record required context alongside process metadata, protecting integrity and compatibility across application versions.
Give each grant a purpose and an exit
A grant allows specified operations on one key; it does not introduce a deny. It has one grantee and one-key scope. Creation, revocation, and retirement are eventually consistent; a grant token can allow newly granted permission to be used before normal propagation.
This does not make revocation instantaneous or replace other access rules. For context, Equals requires an exact pair match; Subset allows additional pairs while retaining every required pair. Pair order does not matter, but capitalization and values do.
This lesson’s Python model checks only those comparisons, not IAM or cryptography. In automation, a stable name with identical parameters helps avoid duplicate grants on retries. Define an owner, purpose, constraints, and retirement procedure when work ends.
Distinguish rotation from data migration
Rotating material in an eligible key retains the logical key identity and allows older data to remain decryptable. It does not rewrite objects or rotate data keys already used. If a plaintext data key was compromised, rotating the KMS key alone does not resolve that exposure.
Envelope encryption uses a data key for the data and protects that data key with KMS. GenerateDataKey can return plaintext and encrypted copies of the data key; the application should avoid persisting the plaintext copy and remove it from memory when no longer needed.
GenerateDataKeyWithoutPlaintext does not provide the plaintext copy for immediate encryption. Retargeting an alias changes future resolutions of that alias but does not automatically migrate historical ciphertext to the new key.
Rehearse recovery using the Region’s own policies
Related multi-Region keys share material and key identity, but policies, grants, aliases, and enabled/disabled state are independent. Copying architecture into another Region without reviewing these properties can leave the application unable to decrypt during recovery.
The rehearsal should use the actual destination role and correct regional ARN. Do not assume every service exploits multi-Region interoperability: S3 treats these keys as regional in its server-side encryption mechanism. A private endpoint policy does not itself grant KMS authorization either.
Collect evidence by operation and path. For cross-account calls, CloudTrail records in both caller and key-owner accounts help correlate who requested access, which key was used, and the result.
Treat key retirement as a recovery dependency
A PendingDeletion key stops accepting cryptographic operations, although an application might continue temporarily using cached data keys. No immediate incident does not prove disuse. Retirement review must cover historical copies, object versions, rare cycles, and restores, with identified owners.
Canceling scheduled deletion leaves the key Disabled; an authorized re-enablement decision and service validation are needed. After a KMS-generated key is deleted, recreating an alias with the same name does not recover the old material. Keep planning separate from execution and use read/restore tests before approving exit.
The decision should explain which data still depends on the key and for how long, rather than relying only on recent traffic.
Diagnose a cross-account request
Record the effective identity, operation, key ARN, Region and intermediary service. Compare each element with applicable policies in both accounts. In this exercise, the key accepts the principal but requires a service in another Region; the identity has the operation but names another resource.
Fixing one side alone preserves the block. Before expanding permissions, write down requests that must remain forbidden, including direct calls and other keys. The repair must preserve those limits.
A direct diagnostic call can legitimately fail when S3 is the only authorized path. Then validate the intended path and rejection cases, retaining records from both accounts.
Two context comparisons
Build two columns for each request: does it match authorization, and does it match the context authenticated with the data? A Subset can permit several sets while one ciphertext remains bound to its original set. Thus every candidate in a list can satisfy the grant while only one can decrypt.
Retain enough metadata to reconstruct each version’s context; do not substitute current application values. If the schema changes, treat data migration separately from policy changes. Test changed values, omitted pairs and additional pairs as distinct cases.
These pairs are not secrets: audit identifiers must respect that property from the time data is created.
Delegation as a set decision
Enumerate the approved operation set and every set automation can request. The intended rule is full inclusion: all requested operations must be approved. A rule requiring just one match accepts mixed requests with additional operations.
Add negative cases combining an allowed operation with a forbidden one; testing only wholly allowed or wholly forbidden requests misses that defect. Also record the key, grantee and context constraints. Do not infer delegation power from operations the role can execute directly.
The source of CreateGrant authority matters because a policy and a parent grant have different delegation rules.
Define what recovery can recover
Separate the inventory into controlled data, retained versions and potentially extracted copies. Identify the key protecting each layer: changing the key wrapping a data key does not change files encrypted by that data key. For an authorized replacement, plan new data keys, re-encryption, functional validation, consumer transition and handling of previous versions.
Avoid deleting evidence or violating retention to simplify the change. Record future-access containment separately from confidentiality already lost. A recovery report should identify replaced copies and continuing consequences without claiming that rotation made data unreadable to a party that already copied it with its key.
Prepare a replica for the actual consumer
Build a matrix per Region containing ARN, state, available material, identity, operation and request context. Mark properties shared across Regions and those requiring local management. Creating a replica does not establish that the recovery consumer can use it.
In this scenario, retaining ciphertext is possible, but only after repairing state and authorized identity. Check the application path separately: a direct KMS call and an integration managed by another service are not equivalent trials. Record the test identity because an administrative account can hide a production-role failure.
Also retain a negative case for the previous identity when its revocation is part of the change.
Validate identity and path together
Draw a table with identities as rows and private and public paths as columns. Record required outcomes before changing policies. An endpoint policy governs traversal of that endpoint; it is not by itself a global rule on the KMS key.
When the requirement also limits the path, place that condition in service-side controls and retain identity selection at the endpoint. Test a missing context key as well as incorrect values. Confirm that the permitted case remains permitted: a broad denial can produce apparent security at the cost of availability.
Treat service-mediated application calls as distinct paths before applying the same condition.
Separate key inventory from key use
Define the effective identity and account for each task. A consumer that knows a key ARN can have usage authorization without being able to inventory every key owned by that account. For cross-account inventory, assuming an owner-account role creates a different identity context; its trust and permissions need their own scope.
Do not add Decrypt for convenience to a function that only enumerates. Also record Region and pagination because a partial response does not represent the full inventory. Associate results with collection identity and time.
This design permits checking existence and management without confusing listing capability with access to protected data.
Save intent before requesting a grant
Before calling, retain an immutable representation of the approved request: key, grantee, operations, constraints, name and remaining properties. After a lost response, reconstruct the attempt from that record rather than configuration that has since changed.
Compare the request with its approval before sending it. On receiving a response, associate GrantId with the intent; the name supports deduplication and does not replace the management identifier. A change in operations or recipient requires a new decision and an explicit plan to retain or remove the earlier grant.
Observe effective state and propagation limits before declaring replacement complete. Include no secrets in names or context.
required = {'Workload': 'nav-batch', 'Stage': 'prod'}
request = {'Stage': 'prod', 'Workload': 'nav-batch', 'Run': 'r14'}
exact_match = request == required # False: additional pair
subset_match = all(request.get(k) == v for k, v in required.items()) # True
wrong_case = {**request, 'Stage': 'Prod'}
wrong_case_matches = all(wrong_case.get(k) == v for k, v in required.items()) # False
# Local pair-comparison model only; not KMS encryption or IAM evaluation.In a fictional recovery rehearsal, the related multi-Region identifier exists at the destination, but the recovery role is not authorized in its regional policy. APS identifies the call and missing condition before proposing a scoped change.
Common pitfalls
Confusing IAM Allow with effective access; treating context as secret; expecting instant revocation; treating rotation as re-encryption; deleting keys because recent traffic is absent.
Related topics: S3: access, encryption, and retention
Access and recovery depend on the correct key, identity, context, operation, Region, and lifecycle together.
References
- KMS key policies · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- Creating a key policy · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- Cross-account KMS access · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- KMS condition keys · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- Encryption context · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- KMS grants · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- Creating grants and constraints · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- KMS rotation · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- Automatic rotation and key identity · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- Multi-Region KMS keys · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- KMS key deletion · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- CancelKeyDeletion · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- GenerateDataKey · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- GenerateDataKeyWithoutPlaintext · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- IAM policies, permission boundaries and endpoint policies · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- KMS aliases · AWS documentation inspected 2026-10-05; SAP-C02 security mapping
- SAP-C02 domain 1 tasks · AWS documentation inspected 2026-10-05; SAP-C02 security mapping