Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Permissions: applications and administration

Without a keyring, the principals that write values and the ones that only read them differ in their KMS rights, see With kms-aead alone. A keyring adds an administration side that builds with another feature, calls another handle and writes the keyring store, and the sections below give each side its checklist and its rights.

Two sides of a keyring

A keyring has two sides, each with its own handle and its own rights:

  • the application decrypts and runs sweeps on a Keyring, which KeyringRegistry::open returns in every build, and encrypts, computes beacons and re-encrypts on the Encryptor the Keyring hands out for each write;
  • the administration creates keyrings, rotates, promotes, retires and destroys versions, flags compromised ones, re-encrypts DEKs, exports keysets and shreds keyrings, on a KeyringAdmin, which KeyringRegistry::create, open_or_create and admin return with the admin feature.

The application builds without the admin feature and runs under a principal with the rights of its row only:

SideHandleKMSKeyring store
ApplicationKeyringdecryptread, and listen or watch
AdministrationKeyringAdminencrypt and decrypt, or under an asymmetric KEK decrypt and read of the public keyread, write and delete

Sweeps run on the application’s side: re-encrypting a value encrypts it under a DEK the record already holds, and never asks the KMS to encrypt a DEK. Every call that encrypts a DEK, writes or deletes the record is a KeyringAdmin call. The exact roles per KMS are in KMS rights, and the permissions per store in Store rights.

The admin feature keeps the administrative calls out of the application’s build, and the rights keep them out of its reach: without the KMS encrypt right and write access to the store, those calls fail in any build.

An application opens only keyrings that exist: open on a keyring the store holds no record of fails with KeyringError::RecordMissing. So the administration creates each keyring before an application opens it:

  • from infrastructure: a job, a CLI or a deployment step, built with the admin feature and run with the administrative rights, calls create or open_or_create;
  • or from an application that provisions lazily, such as one keyring per tenant on the tenant’s first request. Such an application enables admin and is given the administrative rights deliberately, and is then trusted as the administration is, see Keyring limits and Creating the keyrings.

An application’s own tests that create keyrings in MemoryKeyringStore enable admin for the tests only:

[dependencies]
kms-aead-keyring = { version = "0.34", features = ["ring", "firestore-tls-roots"] }

[dev-dependencies]
kms-aead-keyring = { version = "0.34", features = ["ring", "firestore-tls-roots", "admin"] }

The application

  • builds without the admin feature, with cargo build -p <application>: Cargo unifies the features of the packages one command builds, so a cargo build of a workspace with both the application and an administrative job gives the application admin too;
  • calls KeyringRegistry::open, and on the Keyring it returns encryptor, decrypt, the beacons and the probes, and runs the sweeps. None of its calls asks the KMS to encrypt;
  • runs as a principal with KMS decrypt on the KEK and read access to the keyring store, listen included, see KMS rights and Store rights;
  • where records are signed, opens its registry with RecordSignaturePolicy::Required and the public key of the record signer, from its configuration and never from the store, see Protect the keyring record;
  • awaits registry.shutdown(None) before it exits.

The administration

  • builds with the admin feature, and bigquery-export where it exports BigQuery keysets;
  • calls the registry’s create or open_or_create for each new keyring, and admin, and on the KeyringAdmin they return the lifecycle calls (rotate, promote, change_algorithm, mark_compromised, retire, reinstate, destroy and dangerously_destroy_all_versions), dangerously_shred, reencrypt_deks and the keyset exports export_bigquery_keyset and export_tink_keyset, see Key versions and lifecycle;
  • runs in a job or in infrastructure automation, never in a request handler, as the only principal with KMS encrypt and decrypt on the KEK, or under an asymmetric KEK decrypt and the read of the public key and no encrypt right, and with write access to the keyring store;
  • holds the record signer where records are signed: a Signer on a KMS signing key, with the right to sign and no other principal holding it, passed to create_signed, open_or_create_signed or with_record_signer, see Protect the keyring record;
  • logs every call it makes, since a version its log does not show is the start of A version the administrative job did not create;
  • opens its registry with the longest record_ttl in the fleet, which the promotion guard waits.

KMS rights

A keyring record is signed only where the administration holds a record signer, see Signing the keyring record and Keyring deployment, so a deployment splits the two sides above into two principals.

With kms-aead alone

An envelope that writes needs KMS encrypt on the KEK: one encryption per value with a per-call envelope, and one per renewed DEK with store-less DEK reuse. An envelope that reads needs KMS decrypt, on every DEK cache miss. A principal that does both needs both, and so does a re-encryption of stored DEKs, see Re-encrypt DEKs after a KEK rotation. The local KMS has no rights to grant.

KMSWriter: encryptReader: decrypt
GCPcloudkms.cryptoKeyVersions.useToEncryptcloudkms.cryptoKeyVersions.useToDecrypt, as in roles/cloudkms.cryptoKeyDecrypter
AWSkms:Encrypt on the keykms:Decrypt on the key
Azure Key Vaultkeys/wrap/action on the keykeys/unwrap/action on the key
Vault Transitupdate on <mount>/encrypt/<key>update on <mount>/decrypt/<key>

roles/cloudkms.cryptoKeyEncrypterDecrypter carries both GCP permissions. With the KMS random generator on, the writer also needs cloudkms.locations.generateRandomBytes on the location under GCP, and kms:GenerateRandom under AWS. See the page of each provider in KMS providers.

With a keyring

The rights of the two sides, per KMS:

KMSApplicationAdministration
GCProles/cloudkms.cryptoKeyDecrypterroles/cloudkms.cryptoKeyEncrypterDecrypter
AWSkms:Decrypt on the keykms:Encrypt and kms:Decrypt on the key, plus kms:GenerateRandom with the KMS random generator
Azure Key Vaulta role with keys/unwrap/action on the keya role with keys/wrap/action and keys/unwrap/action on the key
Vault Transitupdate on transit/decrypt/<key>update on transit/encrypt/<key> and transit/decrypt/<key>

Under an asymmetric KEK

Under an asymmetric KEK the public key encrypts new DEKs in the administration’s own process, so no side has the KMS encrypt right: Cloud KMS useToEncrypt, AWS kms:Encrypt, Key Vault keys/wrap/action and Transit transit/encrypt leave the administration’s grant. The administration needs the read of the public key beside the applications’ decrypt:

KMSApplicationAdministration
GCPcloudkms.cryptoKeyVersions.useToDecrypt, as in roles/cloudkms.cryptoKeyDecrypterdecrypt, and cloudkms.cryptoKeyVersions.viewPublicKey, as in roles/cloudkms.publicKeyViewer
AWSkms:Decrypt on the keykms:Decrypt and kms:GetPublicKey on the key
Azure Key Vaultkeys/unwrap/actionkeys/unwrap/action and keys/get
Vault Transitupdate on transit/decrypt/<key>update on transit/decrypt/<key>, and read on transit/keys/<key> or transit/export/public-key/<key>

Two built-in roles fall short of what the administration needs:

  • roles/cloudkms.cryptoKeyDecrypter does not carry viewPublicKey;
  • Azure’s “Key Vault Crypto Service Encryption User” carries read, wrap and unwrap and no decrypt.

The KMS audit log does not show who encrypted a DEK, since the encryption is local, and anyone holding the public key can encrypt one: a keyring under an asymmetric KEK runs with RecordSignaturePolicy::Required on every application, see Keyrings under an asymmetric KEK. The public_key call of each provider is in KMS providers.

The permissions of each store are below.

Store rights

The store’s access control is what the record’s integrity rests on, unless the record is signed: only the administration writes the record, and the applications read it and listen to its changes, see above:

StoreApplicationAdministration
Firestoreread of the keyring documents, which the listener uses too, such as roles/datastore.viewerread, write and delete of the keyring documents, such as roles/datastore.user
PostgreSQLSELECT on the table, and LISTEN, which needs no grantSELECT, INSERT, UPDATE and DELETE on the table; each write and delete also sends the NOTIFY
Cloud Storagestorage.objects.getstorage.objects.get, storage.objects.create and storage.objects.delete, since a write replaces the object
S3s3:GetObjects3:GetObject and s3:PutObject

dangerously_shred() needs more of the administration on the object stores:

StoreAlso needed
Cloud Storagestorage.objects.list, to find the object’s generations
S3s3:ListBucketVersions, s3:DeleteObject and s3:DeleteObjectVersion

What to alert on

Each side logs events an operator acts on, such as a refused record, a failed revalidation or a re-encryption that failed, and records metrics with the opentelemetry feature. The list, with the next step for each, is in Monitoring and alerts.