SECURITY ENGINEERING · PART 10 · CLOUD SECURITY · DATA · 142 OF 229

Cloud KMS Explained: Keys, Grants and Rotation

The cloud makes encryption easy; the hard part is managing the keys, and that is what decides whether it protects anything. This episode covers cloud KMS: provider-managed versus customer-managed keys, envelope encryption in the cloud, key policies and who can decrypt, automatic rotation, why access to a key is the real control, and the attacks on KMS such as ransom via key deletion.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 10

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Envelope encryption, every decrypt logged
  • customer-managed keys for control
  • the key policy is the control

Notes

Envelope encryption

Cloud encryption uses envelope encryption, the pattern from Part four. The key management service holds master keys that never leave it. A data key encrypts the actual data locally and fast, and is wrapped by the master key and stored alongside the ciphertext. To read the data, the service unwraps the data key, and every unwrap checks the key policy and logs it. So every decryption is access-controlled and logged, the whole security value. The provider does this behind the encryption checkbox.

How cloud encryption works
  • KMS holds master keys; they never leave it
  • a data key encrypts the data (fast, local)
  • the data key is wrapped by the master key, stored with the data
  • to read: ask KMS to unwrap, which checks policy and logs
  • exactly the Part 4 pattern

Managed vs customer keys

You choose between two kinds of key. A provider-managed key is the default and easiest, but you have little control or visibility over it. A customer-managed key is one you create, where you set the policy and rotation and, crucially, can disable it. That last power matters: disabling the key instantly revokes the ability to decrypt all data it protects, a strong containment tool in an incident. For anything sensitive, use customer-managed keys, because control over the key is control over the data.

Two kinds of key
  • provider-managed key: easy, but you have little control or visibility
  • customer-managed key (CMK): you set the policy, rotation, and can disable it
  • CMK lets you revoke access to data by disabling the key
  • use CMKs for anything sensitive

Access is the control

The core lesson: the key policy, not the cryptography, is what protects the data. Nobody breaks AES; they get the permission to decrypt. Separate key administrators, who manage the key, from key users, who decrypt with it, so no single role does both. Grant decrypt with least privilege, to specific roles on specific keys, never on everything. And use encryption context, which is associated data, to bind a decryption to a particular resource or tenant. Access to the key is the real security boundary.

The key policy decides
  • the algorithm is unbreakable; the policy is the target
  • who can use the key to decrypt?
  • separate key admins from key users
  • least privilege on kms:Decrypt; not on "*"
  • encryption context binds a decrypt to a resource/tenant

Rotation

Rotation in the cloud is mostly automatic, but know its limits. Turn on automatic rotation and the service creates new key material on a schedule; the key identifier stays the same, and old material is retained so old data still decrypts, so your code changes nothing. But it does not re-encrypt existing data. That is fine for routine rotation. After an actual compromise it is not enough: you need a new key and must re-encrypt the data the old one protected. Routine rotation and incident response are different.

Key rotation in the cloud
  • turn on automatic rotation: new key material yearly (or faster)
  • the key id stays the same; old material is kept to decrypt old data
  • it does NOT re-encrypt existing data
  • after a compromise: new key AND re-encrypt
  • as in Part 4

What to encrypt

A practical approach to what you encrypt. Encrypt everything at rest, because it is nearly free and usually on by default. Reserve the stronger controls, customer-managed keys and tight policies, for the sensitive data: personal information, secrets, regulated records. Use separate keys per data classification and environment, so one key is never a single point of exposure. Encrypt in transit with TLS, and for the most sensitive fields consider field-level encryption in the app.

A practical approach
  • encrypt everything at rest; nearly free, on by default
  • customer-managed keys for sensitive data (PII, secrets, regulated)
  • separate keys per data class and environment
  • encrypt in transit too (TLS)
  • field-level encryption for the most sensitive columns

Attacks on KMS

Attackers do not steal keys from the hardware; they abuse access. A compromised role with decrypt permission on every key is as good as holding the keys. In cloud ransom attacks, they schedule your key for deletion or re-encrypt data under a key they control, so you lose access entirely. The defences are least privilege on key use, the mandatory deletion waiting period so a scheduled deletion can be reversed, and alerts on key events like disable, delete and policy change.

How KMS is abused
  • a compromised role with kms:Decrypt on * is as good as the keys
  • ransom: schedule your key for deletion, or re-encrypt data under an attacker key
  • disabling your key denies all access to that data
  • defence: least privilege, deletion waiting period, alerts on key events

Common mistakes

Mistakes. Declaring data encrypted while nearly every role can decrypt it, so the encryption protects nothing. Using provider-managed keys for sensitive data, giving up control and the ability to revoke. Granting decrypt on all keys in a role. Not separating key admins from key users. No alerts on key deletion or policy changes, so a ransom attack is invisible until too late. And believing encryption stops a public-bucket leak, when an authorised read returns the decrypted data.

Avoid these
  • "data is encrypted" but everyone can decrypt it
  • provider-managed keys for sensitive data (no control)
  • kms:Decrypt on * in a role
  • key admins and users not separated
  • no alerts on key deletion or policy changes
  • thinking encryption stops a public bucket leak

Say it like this

In the interview: cloud encryption uses envelope encryption, where KMS master keys wrap data keys and every decryption is access-checked and logged. Encrypting data is easy, so the real question is who can decrypt. For sensitive data I use customer-managed keys, so I control policy and rotation and can disable the key to revoke access in an incident. The key policy, not the algorithm, is the control: separate key admins from users, grant decrypt with least privilege, and alert on key events.

In the interview
  • "Envelope encryption: KMS
  • master keys wrap data keys, every decrypt checked and logged. For sensitive data I
  • use customer-managed keys so I
  • control policy, rotation and can disable them. The key
  • policy, not the cipher, is the control: least privilege on decrypt, and alert on key events."

Interview questions

Q1How does encryption at rest work in the cloud?

Through envelope encryption: a KMS master key wraps data keys that encrypt the actual data locally, and the wrapped data key is stored with the ciphertext. Every decryption requires the KMS to unwrap the data key, which enforces the key policy and is logged.

Q2What is the difference between provider-managed and customer-managed keys?

Provider-managed keys are the easy default but give the customer little control or visibility. Customer-managed keys (CMKs) let the customer set the key policy and rotation and disable the key, which instantly revokes the ability to decrypt all data it protects.

Q3Why is the key policy more important than the encryption algorithm?

Because the algorithm is effectively unbreakable, so attackers target the permission to decrypt instead. The key policy decides who can use the key, making it the real security boundary; least privilege on decrypt and separating key admins from users are essential.

Q4What does cloud KMS automatic key rotation do?

It generates new key material on a schedule under the same key ID, retaining old material so existing data still decrypts, so applications need no change. It does not re-encrypt existing data, so after a compromise a new key and explicit re-encryption are required.

Q5How is cloud KMS abused by attackers?

By compromising an identity with broad kms:Decrypt permissions, which is equivalent to holding the keys, or in ransom attacks by scheduling keys for deletion or re-encrypting data under an attacker-controlled key. Least privilege, deletion waiting periods and alerts on key events defend against this.

Q6What is encryption context in KMS?

Additional authenticated data supplied on encrypt that must be supplied identically on decrypt, binding a ciphertext to a specific resource, tenant or purpose. It can be required by key policy and appears in audit logs, strengthening access control.

Q7Does encryption at rest prevent a public bucket leak?

No. Encryption at rest protects against storage-layer access, but an authorised read returns decrypted data. If a bucket is public or over-permissioned, the data is exposed despite encryption. Access control and block-public-access are what prevent exposure.

Q8Why separate key administrators from key users?

So that no single role can both manage a key (change its policy, delete it) and use it to decrypt data. Separation of duties limits the damage from a single compromised identity and is a core principle of KMS access design.