Protecting cloud data: keys, copies and backups
Unit 3 of 5 in Cloud identity, network and data protection.
You will be able to say who really controls a key, how a data key works, how a copy can leak and what makes a backup hard to destroy.
Lesson
Encrypted by default does not mean safe
Amazon says S3 now applies server-side encryption with S3-managed keys (SSE-S3) as the base level of encryption for every bucket, and that starting January 5, 2023 all new object uploads are automatically encrypted at no extra cost. If you want more control, such as managing key rotation and access policy grants, you can choose encryption with AWS KMS keys.
So the question has changed from whether the data is encrypted to who can read it. Encryption at rest protects against someone who gets the disk or the raw storage. It does not stop a principal who has permission to read the object, because the service decrypts for authorized requests. That is logic from how server-side encryption works, and it is why keys and permissions matter next.
Who controls a key: the key policy
AWS describes a key policy as a resource policy for a KMS key and as the primary way to control access to KMS keys. Every KMS key must have exactly one key policy. AWS says no principal, including the account root user or the key creator, has any permission to a KMS key unless explicitly allowed, and never denied, in a key policy, an IAM policy or a grant. IAM policies can allow access to a key only if the key policy enables it, and the default key policy does enable IAM policies. Key policies are Regional.
The KMS concepts page separates customer managed keys, which you control, from AWS managed keys, which exist in your account but can only be used in the context of one service by principals in the same account. It says you cannot share resources encrypted under an AWS managed key with other accounts.
The key-policy audit lab generates 20 synthetic policies and builds a linter that flags a wildcard principal with no account or organization restriction, unapproved cross-account principals, full key access given to a non-administrator, one principal holding both admin and use actions, and a permission to create grants with no restriction on them. It also teaches that the default statement allowing the account's IAM policies is not itself a finding, and that a clean key policy is not the same as least privilege.
Data keys and envelope encryption
AWS describes data keys as symmetric keys you can use to encrypt data, including large amounts of data. Unlike KMS keys, which cannot be downloaded, data keys are returned to you for use outside KMS. When KMS generates a data key it returns a plaintext copy for immediate use and an encrypted copy you can safely store with the data. To decrypt later, you ask KMS to decrypt the encrypted data key first. KMS does not store, manage or track your data keys or perform cryptographic operations with them.
That pattern is called envelope encryption: the data is encrypted with a data key, and the data key is encrypted under a KMS key. The envelope lab builds it on a local emulator: it generates a key, encrypts a file locally with AES-256-GCM, throws away the plaintext key, stores only the ciphertext and the wrapped key, and shows that a wrong encryption context makes the decrypt fail. It ends by saying that in real work you should use a vetted library rather than your own code.
Copies that leak: snapshots
A snapshot is a full copy of a disk or a database. AWS says an EBS snapshot can be shared publicly with all other AWS accounts, and Block public access for EBS snapshots can prevent it. For RDS, AWS says you can share a manual DB snapshot with up to 20 accounts, that an unencrypted snapshot can be set to Public so that all AWS accounts can restore a database from it, and warns not to share manual snapshots containing private information as Public. It also says encrypted snapshots cannot be shared as public.
Read together, those facts mean every publicly shared RDS snapshot is an unencrypted full copy of a database. The RDS snapshot lab audits a synthetic account for public and cross-account snapshots, measures the before state, switches sharing off and adds a preventive guard rail, because detecting a leak is not the same as stopping one.
Backups that survive a bad day
S3 Object Lock, AWS says, can prevent objects from being deleted or overwritten for a fixed time or indefinitely, using a write-once-read-many model. It works only in buckets with S3 Versioning. It offers retention periods and legal holds, and an object version can have either or both.
There are two retention modes. In compliance mode a protected version cannot be overwritten or deleted by any user, including the root user, its mode cannot be changed and its period cannot be shortened; AWS notes that the only way to delete such an object before its date is to delete the AWS account. In governance mode most users cannot delete it, but users with special permission, the s3:BypassGovernanceRetention permission, can alter it. Governance mode can also be used to test settings first.
That difference is why the Object Lock lab uses a short governance retention on your own free-tier bucket, tries to delete its own backup, and ends with how to clean up safely. A lock you cannot undo is a decision to make deliberately, with the people who own the data and the legal advice they need for any legal hold.
Key points
- Default encryption protects stored bytes; permissions decide who can read, so check keys and policies too.
- The key policy is the primary control of a KMS key; IAM policies work only if the key policy allows them.
- A data key encrypts the data; KMS keeps the key that wraps it. Store the wrapped key with the data and never the plaintext key.
- Snapshots are full copies; public sharing hands over everything, so block it and sweep for it.
- Immutable backups need versioning, a retention mode chosen on purpose and a clean-up plan.
Sources
- Amazon S3 User Guide: Setting default server-side encryption behavior for Amazon S3 buckets
- AWS KMS Developer Guide: Key policies in AWS KMS
- AWS KMS Developer Guide: AWS KMS keys (concepts)
- AWS KMS Developer Guide: Data keys
- Amazon EBS User Guide: Share an Amazon EBS snapshot with other AWS accounts
- Amazon RDS User Guide: Sharing a DB snapshot for Amazon RDS
- Amazon S3 User Guide: Locking objects with Object Lock
Practice in the labs
Audit key policies, build envelope encryption, find public database snapshots and lock a backup. The first three are offline or on a local emulator; the Object Lock lab uses your own free-tier account.
- Audit AWS KMS key policies for wildcard and cross-account access: You lint 20 synthetic key policies, see why searching for an asterisk fails and read the findings.
- Encrypt data with AWS KMS envelope encryption: You build envelope encryption on a local emulator, prove a wrong encryption context fails and lock the key down. It is an advanced lab.
- Find and lock down public RDS snapshots: You audit a synthetic account's snapshots for public and cross-account sharing and measure the account before and after the fix.
- Make your backups ransomware-proof with S3 Object Lock (WORM immutability): On your own bucket you lock a backup with a short retention and a legal hold, try to delete it and clean up safely.
Knowledge check
- Who has permission to use a KMS key by default, according to AWS? Answer: No principal, not even the key creator or the root user, unless allowed and never denied in a key policy, IAM policy or grant. AWS says no AWS principal, including the account root user or key creator, has any permissions to a KMS key unless explicitly allowed, and never denied, in a key policy, an IAM policy or a grant.
- In envelope encryption, what do you store beside the encrypted data? Answer: The encrypted copy of the data key. KMS returns a plaintext data key for immediate use and an encrypted copy that is safe to store with the data. KMS does not store your data keys, so you keep the encrypted copy and discard the plaintext.
- An RDS snapshot is shared as Public. What else must be true about it? Answer: It is not encrypted, because AWS says encrypted snapshots cannot be shared as public. AWS says that if the source is encrypted the visibility is Private because encrypted snapshots cannot be shared as public, so a public snapshot is an unencrypted copy of the whole database.
- What is the difference between S3 Object Lock compliance mode and governance mode? Answer: Compliance cannot be overridden by any user including root; governance can be overridden by users with a special permission. In compliance mode no user, including the root user, can overwrite or delete a protected version and the period cannot be shortened. In governance mode users with s3:BypassGovernanceRetention can alter or remove it.
Back to the syllabus or see all classes.