Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

GitHub Engineering 5 min read Case study mediumAdept

Why and how GitHub encrypts sensitive database columns using ActiveRecord::Encryption

GitHub 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.

Related posts

  • How GitHub converts previously encrypted and unencrypted columns to ActiveRecord encrypted columns

    GitHub Engineering mediumAdept

    GitHub migrated plaintext columns and columns encrypted with a deprecated internal library to ActiveRecord::Encryption. It used per-model previous encryptors instead of the global support_unencrypted_data option, and a custom ActiveModel type gated by an inverted, long-lived feature flag that acts as an on/off switch for each column. A changed_in_place? bug compared decrypted plaintext to stored ciphertext, which raised false 2FA recovery-code alerts in customer security logs; delegating the check to EncryptedAttributeType fixed it. A simplified recipe using a previous encryptor plus the MaintenanceTasks gem backfills existing records, and the same flow handles key rotation by adding a new key and re-running the task.

  • Why we chose Turso to secure AI credentials

    Turso mediumAdept

    Eden, a gateway and control plane for database, API and AI traffic, uses Turso's in-process SQLite-compatible storage with AES-256-GCM whole-database encryption so a single Rust binary can run beside the workloads it governs without a separate Postgres. Whole-database encryption was chosen over column-level encryption, which is fragile across migrations and still leaks schema and row counts. To avoid forking the product, a compatibility layer (TursoPool, TursoConnection) mimics the tokio_postgres client surface and rewrites Postgres SQL at the connection boundary: bind parameters, NOW(), row locks, INTERVAL arithmetic, casts, JSON aggregation and ON CONFLICT predicates. File-backed deployments refuse to start without a 64-hex-character key and run with WAL and synchronous=NORMAL, and tests assert the on-disk file has no plaintext SQLite header.

  • Supabase Vault is now in Beta

    Supabase mediumAdept

    Supabase Vault is a Postgres extension and dashboard UI for storing encrypted secrets and encrypting columns, built on pgsodium's Transparent Column Encryption. Secrets are stored on disk with libsodium-based authenticated encryption with associated data (AEAD), so backups and replication streams stay encrypted and unforgeable. Decrypted values are exposed through auto-generated views such as decrypted_<table>. Only key IDs live in the database, while root keys are managed outside SQL by Supabase. Planned extensions include end-to-end encryption, group encryption via signcryption, and public key management.

  • Upgrading 3 Million Variables to Envelope Encryption

    Railway mediumAdept

    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.

  • Supabase Vault

    Supabase mediumAdept

    Supabase Vault is a Postgres extension, built as a thin layer over pgsodium and libsodium, that stores secrets such as API keys and access tokens encrypted on disk and in backups. Unlike pgcrypto, which requires passing raw keys through SQL where they can leak into logs, replication streams and clients, Vault references keys by ID and derives them from a per-database root key held outside SQL by pgsodium's Server Key Management. Secrets go into the vault.secrets table and are decrypted on the fly through the vault.decrypted_secrets view. Encryption uses AEAD, so the associated-data column is authenticated alongside the secret, and custom keys can be created with pgsodium.create_key().

The quest for software engineering knowledge.

Look:
Layout: