Upgrading 3 Million Variables to Envelope Encryption
Railway replaced direct per-variable calls to GCP KMS with envelope encryption: a locally generated AES-256-GCM data key per environment, encrypted once by KMS and serialized alongside each ciphertext. Storing the encrypted DEK next to the value enabled key rotation, decryption without passing environment context, and a gradual zero-downtime migration of over 3 million variables via fallback to legacy KMS decryption. KMS usage dropped 10x, worst-case batch decryption fell from ~10s to milliseconds, quota spikes disappeared, and per-environment keys limit the blast radius of a compromise.
Related posts
- Incident Report: Dec 13th, 2023
Railway easyNoviceAn upgrade of Railway's dashboard GKE cluster to v1.25 pulled in a metadata server version with a known high-load bug, slowing the encrypt/decrypt calls used for service environment variables. A user migration email sent at 20:57 UTC drove a load spike, and from 21:45 to 23:24 UTC new deployments shipped with stale variables and users could not update variables, while existing workloads kept running. Railway mitigated by switching to a statically assigned encryption key, temporarily disabling logging, and upgrading to a GKE version without the bug. Follow-ups include centralized incident coordination, slower migration messaging and accelerating the move off GKE to its in-house orchestrator.
- A few notes on AWS Nitro Enclaves: KMS integration
Trail of Bits hardMasterIntegrating AWS Nitro Enclaves with KMS through PCR-based key policies and attestation-encrypted responses still leaves a range of passive and active attacks on the enclave-KMS channel. Passive attackers can swap data-key ciphertexts, substitute CMKs, abuse key aliases or IAM credentials, and replay attestations within KMS's five-minute window. The countermeasures are attacker-resistant encryption context, hardcoded full CMK ARNs checked against response keyId, an attested IAM role verified via sts:GetCallerIdentity, and validation of algorithm identifiers. Active attackers require enclave-initiated TLS with a pinned, attested Amazon CA plus VPC restrictions, and key policies should use PCR0/PCR8, avoid root-principal pitfalls, and require MFA for critical operations.
- Incident Report: October 21st Security Attack
Railway mediumAdeptAn attacker partially escaped filesystem isolation in Railway's multi-tenant build infrastructure and stole a build credential. That credential was wrongly trusted by a self-hosted Temporal cluster, which exposed build histories and a copy of Railway's internal monorepo. Using the code, the attacker found a misconfigured OIDC binding in CI/CD, obtained cloud credentials, and SSHed into an orchestration machine. From there they read envelope-encrypted environment variables and decrypted them through the KMS, targeting AI provider keys for at most 1.85% (~100,000) of workspaces. Railway halted builds twice, revoked all credentials, rebuilt its PKI, reset 1,852 linked-account tokens, and coordinated key revocation with providers after an estimated ~$740,000 in unauthorized spend.
- Workflow SDK 5: built for production
Vercel mediumAdeptWorkflow SDK 5 reworks Vercel's durable async JavaScript workflow engine around security, regional placement and performance. Step payloads are now encrypted end to end with AES-256-GCM using per-run keys. On self-hosted Worlds, encryption works through a getEncryptionKeyForRun() hook. Runs are pinned to a home region chosen at start(). The engine executes multiple steps inline instead of taking a queue hop per step, replays incrementally, and streams over WebSockets. Benchmarks against v4 show p75 step-to-step overhead dropping from 618 ms to 109 ms, late-run overhead in a 1,020-step workflow falling from 1,748 ms to 70 ms, and stream delivery time improving 4.2×.
- Why and how GitHub encrypts sensitive database columns using ActiveRecord::Encryption
GitHub Engineering mediumAdeptGitHub replaced its internal Encrypted Attributes library with Rails' ActiveRecord::Encryption so developers can encrypt a sensitive column with a single familiar `encrypts` call, without hand-provisioning a key per column. The customizations are a custom key provider that pulls a single primary key from HashiCorp Vault and derives per-column keys with a KDF. The salt is table_attribute, and the current year goes in the info parameter so keys rotate yearly and limit AES-256-GCM nonce-reuse risk. An overridden `encrypts` helper makes this provider the default, and compression is disabled by default because compressing before encryption leaks plaintext entropy.