Secrets are not encrypted by default in Kubernetes - Time & Space Complexity
We want to understand how the time to access Kubernetes Secrets changes as the number of Secrets grows.
How does the system behave when retrieving or managing many Secrets stored without encryption?
Analyze the time complexity of the following Kubernetes Secret retrieval snippet.
apiVersion: v1
kind: Secret
metadata:
name: my-secret
namespace: default
data:
password: cGFzc3dvcmQ= # base64 encoded
This snippet defines a Secret stored in Kubernetes without encryption, which is retrieved as plain data.
When the system retrieves Secrets, it may scan through stored Secrets to find the requested one.
- Primary operation: Searching through stored Secrets.
- How many times: Once per Secret retrieval request, scanning up to all Secrets.
As the number of Secrets increases, the time to find a specific Secret grows roughly in proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The time grows linearly as the number of Secrets grows.
Time Complexity: O(n)
This means the time to retrieve a Secret grows directly with the number of Secrets stored.
[X] Wrong: "Secrets are encrypted by default, so retrieval time is constant regardless of number."
[OK] Correct: By default, Kubernetes stores Secrets unencrypted at rest, so retrieval involves scanning which grows with the number of Secrets.
Understanding how data retrieval scales helps you design better systems and explain trade-offs clearly in real projects.
"What if Kubernetes encrypted Secrets at rest and used an index for retrieval? How would the time complexity change?"
Practice
Solution
Step 1: Understand Kubernetes default Secret storage
Kubernetes stores Secrets in etcd as base64 encoded strings, which is not encryption but simple encoding.Step 2: Confirm encryption is not enabled by default
Encryption at rest must be explicitly configured; by default, Secrets are not encrypted.Final Answer:
As base64 encoded plain text in etcd -> Option BQuick Check:
Default Secret storage = base64 plain text [OK]
- Confusing base64 encoding with encryption
- Assuming Secrets are encrypted by default
- Thinking Kubernetes uses external vault automatically
Solution
Step 1: Identify where encryption is configured
Encryption at rest is enabled by configuring the API server with an EncryptionConfiguration file and passing it via flags.Step 2: Verify other options are invalid
Kubelet does not handle encryption, Secret manifests do not have encryption fields, and kubectl has no encrypt command.Final Answer:
Configure EncryptionConfiguration file in API server flags -> Option AQuick Check:
Encryption enabled via API server config [OK]
- Trying to encrypt Secrets via kubectl commands
- Assuming kubelet manages encryption
- Adding encryption fields in Secret YAML
{
"kind": "EncryptionConfiguration",
"apiVersion": "apiserver.config.k8s.io/v1",
"resources": [
{
"resources": ["secrets"],
"providers": [
{"aescbc": {"keys": [{"name": "key1", "secret": "c2VjcmV0MTIzNDU2Nzg5MDEyMzQ1Njc4OTA="}]}},
{"identity": {}}
]
}
]
}
What does this configuration do?Solution
Step 1: Analyze the providers list for Secrets
The providers list has an AES-CBC encryption provider with a key named key1, followed by identity (no encryption) as fallback.Step 2: Understand the effect on Secrets
This means Secrets are encrypted with AES-CBC using key1; if decryption fails, identity provider returns plain data.Final Answer:
Encrypts Secrets using AES-CBC with key1, falling back to no encryption -> Option AQuick Check:
Encryption config with AES-CBC + identity fallback [OK]
- Thinking identity means encryption is disabled
- Assuming all resources are encrypted, not just Secrets
- Confusing provider order effect
Solution
Step 1: Check if API server reload is needed
EncryptionConfiguration changes require API server restart to take effect.Step 2: Verify other options are irrelevant
Secrets do not need annotations for encryption, kubectl version does not affect encryption, and key length would cause errors, not silent failure.Final Answer:
API server was not restarted after adding EncryptionConfiguration -> Option DQuick Check:
API server restart required for encryption config [OK]
- Forgetting to restart API server
- Adding encryption annotations to Secrets
- Blaming kubectl version for encryption issues
Solution
Step 1: Prepare EncryptionConfiguration file
Create a file defining encryption providers for Secrets, typically AES-CBC or AES-GCM.Step 2: Update API server flags and restart
Pass the EncryptionConfiguration file path to the API server via flags and restart it to apply changes.Step 3: Verify Secrets are encrypted in etcd
Check etcd data to confirm Secrets are stored encrypted, not just base64 encoded.Final Answer:
Create EncryptionConfiguration file, update API server flags, restart API server, verify etcd data -> Option CQuick Check:
Encryption setup = config file + API server restart + verify [OK]
- Trying to encrypt Secrets via manifest changes
- Restarting wrong components like kubelet or kube-proxy
- Using non-existent kubectl encrypt command
Ready to prove it?
Pass the test and this pattern moves unknown
