Skip to main content

Encryption

Loch S3 encrypts objects with AES-256-GCM. Two modes:

ModeKeyServer setup
SSE-S3A master key on the server; one key derived per objectS3_ENCRYPTION_KEY_FILE or S3_ENCRYPTION_KEY
SSE-CSent by the client with every request, never storedNone

Set the master key​

The key is 32 random bytes, base64-encoded:

openssl rand -base64 32 > master.key
sudo chown 100:101 master.key # the container user
chmod 0400 master.key

Mount the file and set S3_ENCRYPTION_KEY_FILE to its path. Prefer the file to S3_ENCRYPTION_KEY: environment variables show up in docker inspect.

warning

Without the master key, SSE-S3 objects cannot be read. Back it up apart from the data, see Backup and restore.

Choose what gets encrypted​

ScopeHow
One requestHeader x-amz-server-side-encryption: AES256 (--sse AES256 in aws s3 cp)
One bucketBucket default encryption (below)
Every writeS3_ENCRYPT_BY_DEFAULT=true

Bucket default encryption (only the owner or root can set it):

aws s3api put-bucket-encryption --bucket my-bucket --server-side-encryption-configuration \
'{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'

Downloads are decrypted transparently.

SSE-C​

KEY=$(openssl rand -base64 32)
KEY_MD5=$(echo -n "$KEY" | base64 -d | openssl dgst -md5 -binary | base64)
SSE_C="--sse-customer-algorithm AES256 --sse-customer-key $KEY --sse-customer-key-md5 $KEY_MD5"

aws s3api put-object --bucket my-bucket --key secret.txt --body secret.txt $SSE_C
aws s3api get-object --bucket my-bucket --key secret.txt secret.txt $SSE_C

Keep the key: the server does not store it, and the object cannot be read without it.

Without the key, a GET fails with MissingSecurityHeader; with a wrong key, with AccessDenied.

Good to know​

  • Objects written before encryption was turned on stay in clear text. Copy an object onto itself to encrypt it.
  • SSE-C headers win over default encryption. SSE-S3 and SSE-C headers cannot be combined.
  • Multipart parts stay in clear text in .uploads/ until the upload is completed.
  • Without HTTPS, SSE-C keys travel in clear text: keep a TLS proxy in front.