Highlights

Contents

Part VI
06

Encryption and secrets

We protect data and capabilities at rest and in motion. Encryption without key control merely moves the secret into another file. We will trace TLS identity, encrypted storage, envelope keys, and secret rotation with counted overhead boundaries.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Authentication vsauthorization2Sessions and cookies3JWT and API keys4OAuth 2.0 and PKCE5RBAC, ACLs, and resourcepolicy6Encryption and secrets7Password hashing andsigned URLs8CORS, CSRF and abuseprevention9Case study: securing oneoperation

#Section 21TLS protects a named connection

A browser sends a private session over the network. Transport Layer Security, or TLS, protects a connection’s confidentiality and integrity and supports peer authentication under its protocol and certificate validation rules. Encryption in transit applies such protection while data moves between defined endpoints.

The browser validates the server’s certificate chain, identity name, and other required conditions, then derives session protection under the negotiated protocol. It must not accept any certificate merely because bytes became encrypted. Encryption with an attacker can still hide traffic from observers while giving the attacker the plaintext.

CHECK WHO IS ON THE OTHER END BEFORE SENDING THE CREDENTIAL OVER THE ENCRYPTED LINKCHECK WHO IS ON THE OTHER END BEFORE SENDING THE CREDENTIAL OVER THE ENCRYPTED LINKconnectexpected hostvalidate identitychain + namederive keyssession protectionsend credentialnow safeencryption to the wrong server protects nothing
Figure 18.21Illustrative TLS responsibilities. Detailed protocol messages depend on the configured TLS version and are covered in the networking chapter.

TLS termination defines where plaintext becomes available. If the edge terminates TLS, the next hop needs its own protection and identity assumptions. Internal network placement does not automatically provide confidentiality or integrity. A mutually authenticated service connection can verify both peers where required, but application authorization remains another layer.

#Section 22Encryption at rest depends on the threat

Heron stores private clips on disk or object storage. Encryption at rest protects stored bytes under an encryption and key-management scheme. It can protect against stolen media or an unauthorized storage-layer read, depending on where keys and decryption authority live. It does not prevent an authorized compromised application from asking to decrypt its permitted data.

An encryption boundary can exist at disk, database, object storage, or application fields. Each protects against different access paths and imposes different operational costs. Define the attacker and data exposure being reduced before saying a checkbox makes data secure. Backups and replicas need matching protection and key-recovery policies.

A STOLEN DISK SHOWS CIPHERTEXT; THE APP WITH DECRYPT RIGHTS STILL SEES PLAINTEXTA STOLEN DISK SHOWS CIPHERTEXT; THE APP WITH DECRYPT RIGHTS STILL SEES PLAINTEXTstorage copy9f3a…c1e0useless without the keyauthorized application{score: 121}a compromised app is a separate risk
Figure 18.22Illustrative encryption-at-rest boundary. A compromised authorized decryptor remains a separate risk.

Encryption also needs integrity protection appropriate to the format. A ciphertext changed by an attacker should not become accepted unauthenticated plaintext. Use a reviewed authenticated-encryption construction and verify before interpreting data. Nonce uniqueness or other algorithm-specific conditions are operational requirements, so a storage writer must follow the library protocol rather than choose values casually.

For a chosen authenticated-encryption format in the sizing exercise, a million-byte plaintext plus a twelve-byte nonce and sixteen-byte tag produces 1,000,028 stored bytes before other framing. This arithmetic describes the stated format, not every cipher. Use reviewed libraries and safe nonce handling; do not implement a new cipher or substitute an ordinary hash for encryption.

#Section 23Envelope encryption separates data and key protection

A large clip is encrypted with a data encryption key, a key used for that data’s encryption. A separate key encryption key protects or wraps the data key. Envelope encryption stores ciphertext and the protected data key while a key-management service controls the wrapping authority.

The application obtains or unwraps the data key under policy, decrypts the authorized data, and avoids retaining plaintext keys longer than necessary. Rotating a wrapping key can sometimes rewrap data keys without rewriting all large payloads, under the system’s protocol. Rotation of the actual data key requires a different data transition.

ENVELOPE ENCRYPTION PROTECTS THE DATA AND ITS DATA KEY SEPARATELYENVELOPE ENCRYPTION PROTECTS THE DATA AND ITS DATA KEY SEPARATELYmanaged wrapping keywrappeddata keyciphertextdata-key authority and data access both need policy and audit
Figure 18.23Illustrative envelope-encryption responsibilities. Stored metadata connects the data to the appropriate key version.

A wrapped key record should bind to its intended data and key version under the supported format. Losing that association can make a valid ciphertext impossible to decrypt or cause the wrong key to be selected. Audit key retrieval without recording plaintext keys. Restore tests must use the same identity and access path expected during an actual incident.

Availability and recovery depend on key access. Deleting a required key can make valid backups unreadable. Restrict destructive key operations, audit their use, and test restore with the actual retained key versions. Key separation helps only if identities permitted to unwrap keys are controlled and monitored.

#Section 24Secrets need retrieval and rotation rules

An application needs a database credential and a signing capability. Secrets management controls how such confidential capabilities are created, stored, distributed, rotated, and revoked. A secret embedded in source or a container image can remain in many copies after its visible file is changed.

Prefer a managed retrieval or workload-identity mechanism appropriate to the environment. Grant the application only the secret or action it needs, bound access, and avoid ordinary logs or traces carrying secret values. Separate development and production credentials. A configuration loader should fail clearly when required secret context is unavailable rather than select a public default password.

A SECRET HAS A LIFE: ISSUE SCOPED, FETCH BY IDENTITY, NEVER LOG, ROTATE AND REVOKEA SECRET HAS A LIFE: ISSUE SCOPED, FETCH BY IDENTITY, NEVER LOG, ROTATE AND REVOKEissuescopedretrieveby workload idusenever loggedrotate + revokeon schedule or leaka hidden file is not a lifecycle
Figure 18.24Illustrative secrets lifecycle. Retrieval authority and emergency invalidation are part of the design.

Rotation needs a compatibility window or an atomic switch appropriate to the credential type. Deploy readers that accept new material, change issuance or use, then revoke old authority after its permitted overlap. Emergency compromise can shorten that transition and disrupt clients. Test the procedure rather than assuming changing one environment variable updates every running process.