---
title: "Why and how GitHub encrypts sensitive database columns using ActiveRecord::Encryption"
description: "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."
url: "https://swe.quest/articles/why-and-how-github-encrypts-sensitive-database-columns-using-activerecord-4abc36e2a491f04c"
canonical: "https://github.blog/engineering/infrastructure/why-and-how-github-encrypts-sensitive-database-columns-using-activerecordencryption/"
source: "GitHub Engineering"
published: "2022-10-26"
difficulty: "medium"
kind: "Case study"
reading_minutes: 5
tags: ["cryptography","ruby","databases","security"]
---

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

A post on [GitHub Engineering](https://swe.quest/sources/github.md), published 2022-10-26, 5 min read, Case study. Original: [https://github.blog/engineering/infrastructure/why-and-how-github-encrypts-sensitive-database-columns-using-activerecordencryption/](https://github.blog/engineering/infrastructure/why-and-how-github-encrypts-sensitive-database-columns-using-activerecordencryption/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Cryptography](https://swe.quest/tags/cryptography.md) (Security)
- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)
- [Security](https://swe.quest/tags/security.md) (Security)

## Prerequisites

- Ruby on Rails ActiveRecord ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))
- symmetric encryption basics ([easy posts on Cryptography](https://swe.quest/tags/cryptography.md?difficulty=easy))

## Keywords

ActiveRecord::Encryption, Ruby on Rails, HashiCorp Vault, AES-256-GCM, KDF, GitHub

## Related posts

- [How GitHub converts previously encrypted and unencrypted columns to ActiveRecord encrypted columns](https://swe.quest/articles/how-github-converts-previously-encrypted-and-unencrypted-columns-to-7a6a32eb2ff23c82.md): GitHub Engineering · 2022-11-03 · Medium · 7 min read · Ruby, Cryptography, Schema migrations, Security, Deployment
  GitHub migrated plaintext columns and columns encrypted with a deprecated internal library to ActiveRecord::Encryption.
- [Why we chose Turso to secure AI credentials](https://swe.quest/articles/why-we-chose-turso-to-secure-ai-credentials-d8af40123ec1f1e5.md): Turso · 2026-06-16 · Medium · 11 min read · SQLite, Rust, Cryptography, PostgreSQL, AI agents
  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.
- [Supabase Vault is now in Beta](https://swe.quest/articles/supabase-vault-is-now-in-beta-56d546a7bcadd895.md): Supabase · 2022-12-16 · Medium · 6 min read · PostgreSQL, Cryptography, Security, Privacy
  Supabase Vault is a Postgres extension and dashboard UI for storing encrypted secrets and encrypting columns, built on pgsodium's Transparent Column Encryption.
- [Upgrading 3 Million Variables to Envelope Encryption](https://swe.quest/articles/upgrading-3-million-variables-to-envelope-encryption-eb068fd9d30969a4.md): Railway · 2024-04-16 · Medium · 6 min read · Cryptography, Schema migrations, Cloud platforms, Security
  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.
- [Supabase Vault](https://swe.quest/articles/supabase-vault-3db5f31fada1a63f.md): Supabase · 2022-08-19 · Medium · 5 min read · PostgreSQL, Cryptography, Security
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
