0
0
Kubernetesdevops~10 mins

Secrets encryption at rest in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Secrets encryption at rest
Create Secret in Kubernetes
Secret stored in etcd (unencrypted)
Enable Encryption Configuration
Kubernetes API Server encrypts Secret data
Encrypted Secret stored in etcd
When Secret requested
API Server decrypts Secret before returning
User gets decrypted Secret
This flow shows how Kubernetes encrypts Secrets before saving them in etcd and decrypts them when accessed.
Execution Sample
Kubernetes
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
  - resources:
    - secrets
    providers:
    - aescbc:
        keys:
        - name: key1
          secret: <base64-encoded-key>
    - identity: {}
This config enables AES-CBC encryption for Secrets stored in etcd.
Process Table
StepActionSecret State in etcdAPI Server BehaviorResult
1Create Secret 'mysecret'Plaintext storedNo encryption configuredSecret saved unencrypted
2Apply EncryptionConfigurationNew secrets encrypted; existing unencryptedAPI Server encrypts Secrets before savingNew secrets stored encrypted
3Request Secret 'mysecret'Encrypted data in etcdAPI Server decrypts Secret before returningUser receives plaintext Secret
4Update Secret 'mysecret'Encrypted data updatedAPI Server encrypts updated SecretUpdated Secret stored encrypted
5Delete EncryptionConfigurationSecrets remain encryptedAPI Server stops encrypting new SecretsNew Secrets stored unencrypted
6Request Secret 'mysecret'Encrypted data in etcdAPI Server decrypts SecretUser receives decrypted Secret
7ExitN/AN/AProcess ends
💡 Process ends after Secret retrieval and encryption configuration changes
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6Final
Secret Data in etcdNonePlaintextEncryptedEncryptedEncryptedEncryptedEncryptedEncrypted
API Server Encryption EnabledFalseFalseTrueTrueTrueFalseFalseFalse
User ReceivesNonePlaintext SecretPlaintext SecretPlaintext SecretPlaintext SecretPlaintext SecretPlaintext SecretPlaintext Secret
Key Moments - 3 Insights
Why is the Secret stored unencrypted at first (Step 1) but new Secrets encrypted after applying EncryptionConfiguration (Step 2)?
Initially, Kubernetes stores Secrets as plaintext in etcd because encryption is not enabled. After applying EncryptionConfiguration, the API Server encrypts new Secrets before saving them, so etcd stores encrypted data (see execution_table rows 1 and 2).
If the EncryptionConfiguration is deleted (Step 5), are existing Secrets decrypted in etcd?
No, existing Secrets remain encrypted in etcd. Deleting the config stops encrypting new Secrets, but stored Secrets stay encrypted until manually decrypted or rotated (see execution_table row 5).
When a Secret is requested, why does the user always get the decrypted Secret even though etcd stores encrypted data?
The API Server decrypts Secrets on retrieval before returning them to the user, so users always see plaintext Secrets regardless of encryption at rest (see execution_table rows 3 and 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at Step 2. What changes in the API Server behavior?
AIt stops encrypting Secrets
BIt deletes Secrets from etcd
CIt starts encrypting Secrets before saving to etcd
DIt returns Secrets unencrypted to users
💡 Hint
Check the 'API Server Behavior' column at Step 2 in the execution_table
At which step does the user receive the Secret for the first time?
AStep 3
BStep 1
CStep 5
DStep 7
💡 Hint
Look at the 'User Receives' column in variable_tracker after Step 1 and Step 3
If EncryptionConfiguration is removed, what happens to new Secrets stored after Step 5?
AThey are stored unencrypted
BThey are deleted automatically
CThey are encrypted with the old key
DThey cause an error on save
💡 Hint
See 'API Server Encryption Enabled' variable_tracker value after Step 5 and execution_table Step 5
Concept Snapshot
Kubernetes Secrets encryption at rest:
- Secrets stored in etcd by default are unencrypted.
- Enable encryption via EncryptionConfiguration in API Server.
- API Server encrypts Secrets before saving to etcd.
- Secrets are decrypted by API Server when accessed.
- Removing encryption config stops encrypting new Secrets but existing remain encrypted.
- Protects sensitive data stored in cluster backend.
Full Transcript
This visual execution shows how Kubernetes handles Secrets encryption at rest. Initially, Secrets are stored in plaintext in etcd. When an EncryptionConfiguration is applied, the API Server encrypts Secrets before saving them, so etcd stores encrypted data. When a Secret is requested, the API Server decrypts it before returning it to the user, ensuring users always see plaintext Secrets. If the encryption config is removed, new Secrets are stored unencrypted, but existing encrypted Secrets remain encrypted in etcd. This process protects sensitive data stored in the cluster backend.