JuliusBrussee/caveman · error
secretbox: production refuses plaintext
Error message
secretbox: production refuses plaintext %s; use %s
What it means
ResolveEnvironmentSecret enforces that in production (per runtimeenv.IsProduction) secrets are supplied only as encrypted values in the ciphertext env var; a non-empty plaintext env var is rejected outright to prevent secrets leaking through insecure channels. The error names both variables so the operator knows which pair to fix.
Solutions
- Remove the plaintext env var from the production environment and set only the ciphertext variable with a secretbox-encrypted, base64 value.
- If local testing is intended, run with the non-production runtime environment flag so plaintext is permitted.
- Audit your deployment manifest / IaC for legacy plaintext secret keys and delete them from production templates.
- Encrypt the value with secretbox.Encrypt, base64-encode it, and place it in the ciphertextEnv variable instead.
Example fix
// before (prod manifest) env: APP_TOKEN: "sk-live-abc123" # plaintext APP_TOKEN_CIPHERTEXT: "<base64>" // after env: # APP_TOKEN removed for production APP_TOKEN_CIPHERTEXT: "<base64 secretbox envelope>"
Defensive patterns
Strategy: validation
Validate before calling
if runtimeenv.IsProduction() && strings.TrimSpace(os.Getenv(plaintextEnv)) != "" {
return fmt.Errorf("%s must not be set in production; provide %s instead", plaintextEnv, ciphertextEnv)
} Try / catch
val, err := secretbox.ResolveEnvironmentSecret("APP_TOKEN", "APP_TOKEN_CIPHERTEXT")
if err != nil {
if strings.Contains(err.Error(), "production refuses plaintext") {
log.Fatalf("deployment misconfiguration: %v", err)
}
return err
} Prevention
- Keep plaintext secret vars only in dev-only .env files excluded from prod images/manifests.
- Lint IaC templates to forbid known plaintext secret keys in production.
- Encrypt every prod secret and set only the *_CIPHERTEXT variable.
- Run a startup config audit that fails fast when plaintext vars are present in prod.
When it happens
Trigger: Calling ResolveEnvironmentSecret(plaintextEnv, ciphertextEnv) while the process is in production mode and os.Getenv(plaintextEnv) is set to a non-empty, non-whitespace value — regardless of whether the ciphertext var is also set.
Common situations: Copying a docker-compose / dev .env file (which sets plain env vars) to a production deployment; a platform injecting legacy plaintext vars; someone setting the plaintext var as a 'fallback' during an incident.
Related errors
- secretbox: decrypted to an empty secret
- CAVEMAN_CCR_MAX_BYTES must be a positive integer
- ccr max storage bytes must be positive
- ccr storage budget is below minimum
- compat upstream name
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/0362c793d57a68f7.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/secretbox/secretbox.go:171
return plaintext, nil
}
return Decrypt(envelope)
}
func useKMS() bool {
return strings.EqualFold(strings.TrimSpace(os.Getenv("CAVE_KMS_PROVIDER")), kms.ProviderScaleway)
}
// ResolveEnvironmentSecret loads a boot-time secret. In production plaintext
// environment variables are rejected: operators must provide a base64-encoded
// secretbox/KMS envelope in ciphertextEnv. Local development may continue using
// plaintextEnv. An entirely absent optional secret returns an empty string.
func ResolveEnvironmentSecret(plaintextEnv, ciphertextEnv string) (string, error) {
plain := strings.TrimSpace(os.Getenv(plaintextEnv))
encoded := strings.TrimSpace(os.Getenv(ciphertextEnv))
production := runtimeenv.IsProduction()
if production && plain != "" {
return "", fmt.Errorf("secretbox: production refuses plaintext %s; use %s", plaintextEnv, ciphertextEnv)
}
if encoded == "" {
return plain, nil
}
wrapped, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
return "", fmt.Errorf("secretbox: %s is not valid base64", ciphertextEnv)
}
decrypted, err := Decrypt(wrapped)
if err != nil {
return "", fmt.Errorf("secretbox: decrypt %s: %w", ciphertextEnv, err)
}
if len(decrypted) == 0 {
return "", fmt.Errorf("secretbox: %s decrypted to an empty secret", ciphertextEnv)
}
return string(decrypted), nil
}
View on GitHub (pinned to 3ee70a1026)