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

Sources

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.

Knowledge check

  1. 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.
  2. 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.
  3. 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.
  4. 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.

Related