Loading content...
Not all data lives in databases. Production systems generate vast amounts of unstructured data: log files containing sensitive information, configuration files with credentials, uploaded documents, media files, machine learning models, exported reports, and temporary files that applications create during processing. If you only encrypt your database while leaving these files in plaintext, you have a significant security gap.
Consider what's typically stored outside databases in a modern application:
File system encryption ensures that all data at rest is protected, not just data you explicitly marked as sensitive.
By the end of this page, you will understand the full spectrum of file system encryption options—full-disk encryption, volume encryption, file-level encryption, and cloud storage encryption. You'll learn how each approach works internally, when to use each, and how to implement encryption for different operating systems and cloud environments.
File system encryption can be implemented at several layers of the storage stack. Each layer has different characteristics for performance, security, and operational complexity.
The encryption stack from top to bottom:
| Layer | What It Encrypts | Examples | Use Case |
|---|---|---|---|
| Application Layer | Specific files/content | GPG, OpenSSL, application code | Individual sensitive files |
| File System Layer | Files/directories transparently | eCryptfs, fscrypt, EFS | Home directories, specific folders |
| Block/Volume Layer | Entire disk partitions | LUKS, BitLocker, dm-crypt | Full system protection |
| Hardware Layer | All disk I/O | Self-Encrypting Drives (SED) | Maximum performance encryption |
Understanding the tradeoffs:
Higher layers (application, file system) offer:
Lower layers (block, hardware) offer:
The modern best practice: Use volume/block-level encryption as a baseline to catch everything, then add file or application-level encryption for the most sensitive data that needs protection beyond the storage boundary.
Unlike database TDE where the database process handles decryption, full-disk encryption typically unlocks at boot time. Once the system is running and unlocked, all processes can read files (subject to permissions). Block-level encryption primarily protects against offline attacks—stolen devices, decommissioned disks, physical access to powered-off systems. It does NOT protect against malware on a running system.
Full Disk Encryption (FDE) encrypts the entire contents of a storage device—operating system, applications, data, swap space, and temporary files. When the system boots, a passphrase or key (often from TPM or network key server) unlocks the disk, and all subsequent I/O is encrypted/decrypted transparently.
How FDE works:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
# LUKS (Linux Unified Key Setup) is the standard for Linux disk encryption # Step 1: Identify the device to encryptlsblk# Example: We'll encrypt /dev/sdb1 # Step 2: Create LUKS encrypted container# WARNING: This will destroy all data on the device!sudo cryptsetup luksFormat --type luks2 /dev/sdb1 # You'll be prompted for a passphrase# Use a strong, memorable passphrase or store in secrets management # Step 3: Open the encrypted containersudo cryptsetup luksOpen /dev/sdb1 encrypted_data# This creates /dev/mapper/encrypted_data # Step 4: Create a filesystem on the encrypted devicesudo mkfs.ext4 /dev/mapper/encrypted_data # Step 5: Mount and usesudo mount /dev/mapper/encrypted_data /mnt/secure_data # Step 6: Add to /etc/crypttab for automatic unlock at boot# Add line: encrypted_data /dev/sdb1 none luks # Step 7: Add to /etc/fstab for automatic mounting# Add line: /dev/mapper/encrypted_data /mnt/secure_data ext4 defaults 0 2 # === Key Management === # Add additional key (up to 8 key slots in LUKS2)sudo cryptsetup luksAddKey /dev/sdb1 # Use a key file instead of passphrasesudo dd if=/dev/urandom of=/root/luks_keyfile bs=4096 count=1sudo chmod 400 /root/luks_keyfilesudo cryptsetup luksAddKey /dev/sdb1 /root/luks_keyfile # Backup LUKS header (critical for recovery!)sudo cryptsetup luksHeaderBackup /dev/sdb1 \ --header-backup-file /secure-backup/sdb1-luks-header.img # Check encryption statussudo cryptsetup status encrypted_data # View LUKS header infosudo cryptsetup luksDump /dev/sdb1If you lose both the encryption passphrase AND the recovery key, your data is permanently inaccessible. For enterprise deployments, always escrow recovery keys to a centralized secrets manager, Active Directory, or MDM solution. Test key recovery procedures regularly. Many organizations have lost access to critical data due to lost encryption keys.
Volume encryption encrypts specific partitions or logical volumes rather than entire disks. This is common in server environments where the operating system might not need encryption, but data volumes containing sensitive information require protection.
Use cases for volume encryption vs. full disk:
Cloud block storage encryption:
Cloud providers offer native encryption for their block storage services. This is essentially volume-level encryption managed by the provider:
AWS EBS Encryption:
Google Cloud Persistent Disk:
Azure Managed Disks:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
# Create a customer-managed KMS key for EBS encryptionresource "aws_kms_key" "ebs_encryption" { description = "KMS key for EBS volume encryption" deletion_window_in_days = 30 enable_key_rotation = true policy = jsonencode({ Version = "2012-10-17" Statement = [ { Sid = "Enable IAM User Permissions" Effect = "Allow" Principal = { AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root" } Action = "kms:*" Resource = "*" }, { Sid = "Allow EBS to use the key" Effect = "Allow" Principal = { Service = "ec2.amazonaws.com" } Action = [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:DescribeKey" ] Resource = "*" } ] })} resource "aws_kms_alias" "ebs_encryption" { name = "alias/ebs-encryption-key" target_key_id = aws_kms_key.ebs_encryption.key_id} # Create encrypted EBS volumeresource "aws_ebs_volume" "encrypted_data" { availability_zone = "us-east-1a" size = 100 type = "gp3" iops = 3000 throughput = 125 encrypted = true kms_key_id = aws_kms_key.ebs_encryption.arn tags = { Name = "encrypted-data-volume" Environment = "production" Sensitive = "true" }} # Set account-level default encryption for all new EBS volumesresource "aws_ebs_encryption_by_default" "enabled" { enabled = true} resource "aws_ebs_default_kms_key" "default" { key_arn = aws_kms_key.ebs_encryption.arn}All major cloud providers support account-level or organization-level policies to require encryption for all new storage. Enable these policies early—it's much easier to enforce encryption by default than to retrofit it later. AWS has 'EBS encryption by default', GCP has organization policies for encryption requirements, and Azure has policies that can require encryption on all managed disks.
File-level encryption encrypts individual files or directories, allowing fine-grained control over what's protected. Unlike volume encryption, file-level encryption can travel with the file—if you copy an encrypted file to an unencrypted USB drive, the file remains encrypted.
When file-level encryption is appropriate:
123456789101112131415161718192021222324252627282930313233343536373839404142434445
# fscrypt is the native Linux file-level encryption system# Supported on ext4, f2fs, and UBIFS filesystems # Step 1: Enable encryption feature on filesystemsudo tune2fs -O encrypt /dev/sda1 # Step 2: Install fscrypt toolssudo apt install fscrypt libpam-fscrypt # Step 3: Set up fscrypt on the filesystemsudo fscrypt setupsudo fscrypt setup /mnt/data # Step 4: Create an encrypted directorymkdir /mnt/data/sensitivefscrypt encrypt /mnt/data/sensitive # Choose protector type:# 1 - Your login passphrase (pam_passphrase)# 2 - A custom passphrase (custom_passphrase)# 3 - A raw key in the keyring (raw_key) # Step 5: Access the encrypted directory# Files are only accessible when the directory is unlockedls /mnt/data/sensitive # Works - directory is unlocked # Step 6: Lock the directory when donefscrypt lock /mnt/data/sensitive # Now files appear as encrypted gibberishls /mnt/data/sensitive # Shows encrypted filenames # Step 7: Unlock directory againfscrypt unlock /mnt/data/sensitive # === For automated/service accounts === # Create a raw key protector (for services)head -c 32 /dev/urandom > /root/fscrypt.keyfscrypt encrypt /mnt/data/app_secrets --source=raw_key --key=/root/fscrypt.key # Store the key in secrets management (HashiCorp Vault, etc.) # Unlock using the key filefscrypt unlock /mnt/data/app_secrets --key=/root/fscrypt.keyFile-level encryption in cloud storage:
Cloud object storage services also offer file-level encryption options:
AWS S3:
Google Cloud Storage:
Azure Blob Storage:
With server-side encryption, the cloud provider performs encryption but technically has access to your data during processing. With client-side encryption, data leaves your systems already encrypted—the cloud provider never sees plaintext. Choose client-side for the highest security (e.g., regulated data), server-side for simplicity when you trust the provider.
Self-Encrypting Drives (SEDs) perform encryption in the drive controller hardware. Every write is encrypted, every read is decrypted, entirely in hardware—with no CPU overhead and no operating system involvement.
How SEDs work:
| Standard | Description | Use Case |
|---|---|---|
| TCG Opal | Trusted Computing Group specification for SEDs | Enterprise and consumer drives |
| TCG Enterprise | Extended Opal for data centers (e.g., multi-user) | Enterprise storage systems |
| ATA Security | Legacy password protection (avoid—weak) | Older systems only |
| IEEE 1667 | Interoperability standard for secure storage | USB and portable devices |
Managing SEDs:
SEDs require management software to enable authentication and manage keys:
Instant Secure Erase:
One of the most valuable SED features is instant secure erase. By rotating the DEK, all data becomes unreadable instantly—without the hours required to overwrite every sector. This is invaluable for:
In 2018, researchers discovered vulnerabilities in several SED implementations that allowed data recovery without the password. While many drives have been patched, this highlights that 'hardware encryption' doesn't automatically mean 'perfect security.' For the highest assurance, combine SEDs with software encryption (defense in depth), or use drives with FIPS 140-2+ certification that have undergone rigorous validation.
Even with encrypted storage for your primary data, sensitive information can leak through system areas often overlooked: swap space, temporary files, and logs. A comprehensive encryption strategy must address these.
Swap space risks:
Swap (virtual memory) contains process memory pages written to disk when RAM is exhausted. This can include:
If swap isn't encrypted, an attacker with disk access can recover sensitive memory contents.
1234567891011121314151617181920212223242526272829303132333435363738394041
# Method 1: Encrypted swap with random key (recommended)# Key regenerates each boot - swap contents lost on shutdown (good!) # Edit /etc/crypttab:# cryptswap /dev/sdX /dev/urandom swap,cipher=aes-xts-plain64,size=256 # Edit /etc/fstab:# /dev/mapper/cryptswap none swap sw 0 0 # Method 2: Encrypt existing swap partition with LUKS # Disable existing swapsudo swapoff -a # Create encrypted containersudo cryptsetup luksFormat /dev/sdX # Open the containersudo cryptsetup luksOpen /dev/sdX cryptswap # Create swap filesystemsudo mkswap /dev/mapper/cryptswap # Add to /etc/crypttab for automatic unlock at bootecho "cryptswap /dev/sdX none luks" | sudo tee -a /etc/crypttab # Add to /etc/fstabecho "/dev/mapper/cryptswap none swap sw 0 0" | sudo tee -a /etc/fstab # Enable swapsudo swapon /dev/mapper/cryptswap # Method 3: Use encrypted file-based swap (flexible) # Create encrypted swap filesudo dd if=/dev/zero of=/swapfile bs=1M count=4096sudo chmod 600 /swapfilesudo cryptsetup luksFormat /swapfilesudo cryptsetup luksOpen /swapfile cryptswapsudo mkswap /dev/mapper/cryptswapsudo swapon /dev/mapper/cryptswapFor full coverage: (1) Use full-disk encryption as a baseline, (2) Encrypt swap with a random key regenerated each boot, (3) Use tmpfs for /tmp so temporary files never hit disk, (4) Ensure logs are either on encrypted volumes or shipped encrypted to remote storage, and (5) Implement log scrubbing to avoid logging sensitive data in the first place.
Containerized environments present unique encryption challenges. Containers are ephemeral, scaled dynamically, and often scheduled across diverse infrastructure. Traditional volume encryption that requires unlock at boot doesn't fit this model well.
Container storage encryption strategies:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
# Example: AWS EBS CSI with encryption ---apiVersion: storage.k8s.io/v1kind: StorageClassmetadata: name: encrypted-ebsprovisioner: ebs.csi.aws.comparameters: type: gp3 encrypted: "true" # Optional: specific KMS key kmsKeyId: arn:aws:kms:us-east-1:123456789:key/abc123volumeBindingMode: WaitForFirstConsumerallowVolumeExpansion: true ---# StatefulSet with encrypted volumesapiVersion: apps/v1kind: StatefulSetmetadata: name: sensitive-appspec: serviceName: sensitive-app replicas: 3 selector: matchLabels: app: sensitive-app template: metadata: labels: app: sensitive-app spec: containers: - name: app image: myapp:latest volumeMounts: - name: data mountPath: /data volumeClaimTemplates: - metadata: name: data spec: accessModes: ["ReadWriteOnce"] storageClassName: encrypted-ebs # Uses encrypted storage class resources: requests: storage: 50GiContainer ephemeral storage (container filesystem, emptyDir volumes) typically lives on the host's disk. If hosts aren't encrypted, this data is unprotected. For sensitive workloads, either ensure hosts use full-disk encryption, use memory-backed emptyDir (medium: Memory), or only store sensitive data in encrypted persistent volumes.
We've covered the breadth of file system encryption options. Let's consolidate the key insights:
What's next:
We've now covered database encryption and file system encryption—the two major categories of data at rest. Next, we'll dive deep into key management: the critical infrastructure that makes all encryption possible. Without proper key management, even the strongest encryption is only as secure as how you protect your keys.
You now understand the full spectrum of file system encryption options—from full-disk encryption to file-level encryption, hardware encryption, and container storage encryption. You can design comprehensive encryption strategies that protect not just primary data but also system areas like swap, temp, and logs. Next, we'll explore the key management systems that underpin all of this encryption.