For the people who run ModelRiver, not for customers. Customer keys in Google Cloud KMS and Azure Key Vault are built and off. This runbook sets up the identities ModelRiver uses, runs a check against a real key, and then turns the option on for an organization that asked.
Commands marked (untested) were written from the clouds' documentation and not run against real accounts here; run them once in a test project and tenant first. Placeholders are in <angle brackets>: never paste a real id, tenant or secret into tickets or chat.
How it works
ModelRiver stores no cloud secret for a customer or for itself. Its AWS role (the one that runs the service, KMS_ROLE_ARN or the instance role) proves who it is to Google and to Microsoft:
- Google: the role signs an AWS
GetCallerIdentityrequest, Google STS exchanges it for a token through a workload identity pool, and that token impersonates one service account that customers grant on their key. - Azure: AWS issues a web identity token for the role (outbound identity federation,
sts:GetWebIdentityToken), and Microsoft Entra exchanges it, in the customer's tenant, for a Key Vault token through one multi-tenant application with a federated credential.
Tokens live only in memory and are refreshed five minutes before they expire.
One-time setup
Google Cloud (a project of ModelRiver's)
- Create a workload identity pool and an AWS provider that trusts ModelRiver's AWS account, and limit it to ModelRiver's role. (untested)
gcloud iam workload-identity-pools create <pool> --location global --project <project>gcloud iam workload-identity-pools providers create-aws <provider> \ --workload-identity-pool <pool> --location global --project <project> \ --account-id <modelriver aws account id> \ --attribute-condition 'attribute.aws_role == "arn:aws:sts::<modelriver aws account id>:assumed-role/<role name>"'- Create the one service account customers grant on their keys, and let the pool impersonate it. It needs no roles in this project. (untested)
gcloud iam service-accounts create <service account name> --project <project>gcloud iam service-accounts add-iam-policy-binding \ <service account name>@<project>.iam.gserviceaccount.com \ --role roles/iam.workloadIdentityUser \ --member 'principalSet://iam.googleapis.com/projects/<project number>/locations/global/workloadIdentityPools/<pool>/attribute.aws_role/arn:aws:sts::<modelriver aws account id>:assumed-role/<role name>'- Note the two values ModelRiver is configured with: the provider's audience,
//iam.googleapis.com/projects/<project number>/locations/global/workloadIdentityPools/<pool>/providers/<provider>, and the service account's email. The email is what customers see on the page and grant on their key.
Microsoft Entra (a tenant of ModelRiver's)
- Register a multi-tenant application, so customers can add it to their own tenants. (untested)
az ad app create --display-name ModelRiver --sign-in-audience AzureADMultipleOrgsNote its application (client) id: it is KMS_AZURE_CLIENT_ID, and customers run az ad sp create --id <client id> for it.
- Add a federated credential that trusts AWS's issuer for ModelRiver's account, with the audience
api://AzureADTokenExchangeand the role as subject. Get the issuer from AWS (below) and check the subject against a real token'ssubclaim. (untested)
az ad app federated-credential create --id <client id> --parameters '{ "name": "modelriver-aws", "issuer": "<aws outbound issuer url>", "subject": "<modelriver role arn>", "audiences": ["api://AzureADTokenExchange"]}'A federated credential belongs to the application in ModelRiver's tenant; a customer's tenant trusts it through the service principal they create.
AWS (ModelRiver's account)
- Turn on outbound web identity federation for the account, and read its issuer for the Entra credential above. (untested)
aws iam enable-outbound-web-identity-federationaws iam get-outbound-web-identity-federation-info- Let ModelRiver's role ask for tokens, for the Entra audience only. (untested)
1{2 "Effect": "Allow",3 "Action": "sts:GetWebIdentityToken",4 "Resource": "*",5 "Condition": {6 "ForAnyValue:StringEquals": { "sts:IdentityTokenAudience": "api://AzureADTokenExchange" }7 }8}- The role also signs STS requests for Google, which needs no extra permission.
Hosts to allow
ModelRiver's outbound network must reach these and nothing is called on any other host:
| Used for | Host |
|---|---|
| Google token exchange | sts.googleapis.com |
| Google service account token | iamcredentials.googleapis.com |
| Google keys | cloudkms.googleapis.com |
| AWS tokens and signed requests | sts.<region>.amazonaws.com |
| Microsoft Entra | login.microsoftonline.com |
| Customers' vaults | <vault>.vault.azure.net (one per customer vault) |
Government and China clouds are not supported. Because the vault host differs per customer, an egress allow list needs the pattern *.vault.azure.net or each vault added before its owner saves the key.
Settings
Set on the service, then restart. Each provider needs its switch and its identifiers; a malformed value stops the boot.
| Variable | Meaning |
|---|---|
KMS_BYOK_GCP_ENABLED | true turns Google on server-wide; halt stops it, existing keys included (see below) |
KMS_GCP_WIF_AUDIENCE | the provider audience from step 3 above |
KMS_GCP_SERVICE_ACCOUNT | the service account's email |
KMS_BYOK_AZURE_ENABLED | true turns Azure on server-wide; halt stops it, existing keys included (see below) |
KMS_AZURE_CLIENT_ID | the Entra application's client id |
KMS_KEY_ARN and KMS_ROLE_ARN stay as they are today. The switch alone shows nothing to customers: staff must also turn on the organization's kms_byok_gcp or kms_byok_azure override.
Run the live check
The check works with the switch off, as long as the identifiers are set. Run it from a machine of the release, with a real key you own, labelled or tagged modelriver-org-id=<organization id> for a UUID you choose (no database is read):
bin/modelriver eval 'ModelRiver.Release.kms_live_check("gcp", "projects/<project>/locations/<location>/keyRings/<key ring>/cryptoKeys/<key>", "<organization id>")'bin/modelriver eval 'ModelRiver.Release.kms_live_check("azure", "https://<vault>.vault.azure.net/keys/<name>/<version>", "<organization id>")'It prints one line per step, kms_live_check <provider> <step>: ok or a reason code, stops at the first failure and never prints a key, token, body or header. The steps are parse, organization, credentials (Google and Azure), describe, owner, usable, wrap, unwrap and compare. Run it for a key without the label too: it must stop at owner with access_denied.
Reason codes
| Code | Meaning, and what to check |
|---|---|
invalid_key_ref, invalid_organization_id, unknown_provider | The input: reference shape, a UUID, gcp or azure |
access_denied | The key is missing the ownership label or tag or carries another organization's id, ModelRiver's identity lacks the role or permission, or (Azure) the vault's tenant differs from the one saved. These look the same on purpose |
not_found | No such key or version |
disabled | The key or the pinned version is disabled, expired or not yet valid |
invalid_state | Pending destruction or otherwise unusable |
wrong_key_spec | Google: not a symmetric ENCRYPT_DECRYPT key. Azure: not RSA of 3072 bits or more, or missing wrapKey and unwrapKey |
kms_unreachable_credentials | The federation failed: the pool and provider condition, the service account binding, the Entra federated credential (issuer, subject, audience), or the AWS permission |
kms_unreachable_http_<status> | An unexpected status from the cloud |
kms_unreachable_unavailable, _timeout, _network | The cloud or the network: retry, then check the hosts above |
kms_unreachable_host_not_allowed, _unexpected_response, _unexpected_error | A host outside the fixed list, or an answer ModelRiver does not understand: report it, with the step |
mismatch | Unwrapping did not give back the data key: stop, do not turn the option on |
provider_halted | The provider's switch is halt: nothing was sent |
After a passing check
- Pass on a real key of each cloud, and the failing
ownercase above. - Set the switch for the provider and restart.
- For the organization that asked, turn on
kms_byok_gcporkms_byok_azurein the admin entitlements. Nothing else changes for it: the page offers the cloud next to AWS. - Ask the customer to follow KMS encryption.
Turning the switch or the override off hides the cloud and refuses new setups; keys already in use keep working, rotating and being checked.
Emergency stop: halt
Setting KMS_BYOK_GCP_ENABLED or KMS_BYOK_AZURE_ENABLED to halt stops that provider, for new and existing keys. Set it on every node and restart them all: the restart also drops the data keys each node holds in memory. Changing the switch on a running node (a live put_env from a remote console) is not a supported halt; restart every node. A value other than true, false or halt stops the boot, so a mistyped halt never reads as off.
While a provider is halted:
- Nothing is sent to it: no federation token, no Google or Azure KMS request.
- Its keys fail closed with
provider_halted. New request logs of those organizations are kept without content, and stored ones can't be read. Nothing falls back to ModelRiver's key or to plain text, and no row is rewritten. - New setups for it are refused, as with the switch off. Rotating one of its keys answers that ModelRiver has paused access, and changes nothing.
- The health check records it once per key: the key's last error, a
data.kms_key_haltedaudit event and a log line. It sends no email and does not mark the key unavailable. Retiring keys on it wait. - AWS keys, ModelRiver's key and the other provider are not affected.
To lift it, set the switch back to true (or false) and restart. Keys resume with no repair, since nothing was rewritten. A failure cached on a node clears within a minute, and the next health check clears the last error.
Warning: rotating CLOAK_KEY and Azure keys
For Azure, ModelRiver binds each wrapped data key to its organization with a MAC derived from CLOAK_KEY. If CLOAK_KEY is rotated while Azure keys are in use, their wrapped keys fail closed: they can't be unwrapped, new request logs are kept without content and stored ones can't be read until it is put right. Before rotating CLOAK_KEY, move every organization with an Azure key to AWS or ModelRiver's key (change key, then wait for the page to show nothing left to re-encrypt), or have an engineer re-wrap the Azure keys under the new CLOAK_KEY. Google and AWS keys are not affected.