#19538: security: migrate sensitive Docker env vars to Docker secrets
docker
size: S
## Summary
- Use Docker secrets for sensitive credentials (session keys, tokens, cookies)
- Add `docker-entrypoint.sh` that reads from `/run/secrets/` and exports as env vars
- Update `docker-compose.yml` with secrets section pointing to local files
- Update `Dockerfile` with entrypoint
- Backward compatible: direct env vars still override Docker secrets
## Security Impact
Prevents credential exposure in `docker-compose.yml`, `docker inspect` output, and `/proc/<pid>/environ`.
## Migration
1. Create a `./secrets/` directory (chmod 700)
2. Write each credential to its own file: `echo "your-token" > ./secrets/openclaw_gateway_token`
3. Set file permissions: `chmod 600 ./secrets/*`
4. Optionally set `OPENCLAW_SECRETS_DIR` to customize the secrets directory
## Test plan
- [ ] Test Docker secrets flow with sample secrets files
- [ ] Verify backward compatibility with direct env vars
- [ ] Test container startup with both approaches
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR migrates sensitive Docker environment variables to Docker secrets, improving security by preventing credential exposure in `docker inspect` output and process environments. The implementation adds a shell entrypoint that loads secrets from `/run/secrets/` and falls back to environment variables for backward compatibility.
**Key changes:**
- Added `docker-entrypoint.sh` to load 8 secrets into env vars with fallback logic
- Updated `docker-compose.yml` to use Docker secrets (but only defines 4 of the 8 secrets the entrypoint expects)
- Modified `Dockerfile` to set the entrypoint
**Issues found:**
- **Critical mismatch**: entrypoint loads 8 secrets but compose only defines 4 (`openclaw_gateway_password`, `openai_api_key`, `anthropic_api_key`, `gemini_api_key` are missing)
- **Security gap**: `secrets/` directory not in `.gitignore` - users following migration instructions could accidentally commit credentials
- **Shell compatibility**: script uses `local` keyword (bash-specific) but has `#!/bin/sh` shebang
- **Code injection risk**: `eval` usage in the entrypoint could be replaced with safer `printenv`
<h3>Confidence Score: 2/5</h3>
- This PR has critical issues that will cause runtime failures and potential security gaps
- The mismatch between secrets defined in docker-compose.yml (4 secrets) and secrets loaded in the entrypoint (8 secrets) will cause container startup failures. The missing .gitignore entry creates a risk of accidental credential exposure. The eval usage and shell compatibility issues need fixing before merge.
- All three files need attention: docker-compose.yml needs 4 additional secret definitions, .gitignore needs the secrets/ directory pattern, and docker-entrypoint.sh needs safer variable checking and correct shebang
<sub>Last reviewed commit: 3a446be</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#10174: fix(docker): exclude .env files from Docker build context
by coygeek · 2026-02-06
78.5%
#7133: feat: Automated Docker setup with environment-based configuration
by synetalsolutions · 2026-02-02
78.1%
#21305: Fix/proxy-ip-allow-list
by janaka · 2026-02-19
76.1%
#8478: Security: remove --allow-unconfigured from default Dockerfile CMD
by uttej-badwane · 2026-02-04
75.3%
#9999: Docker: fix token mismatch and add dev setup workflow
by benclarkeio · 2026-02-06
74.9%
#23000: Secrets: add migrate rollback and skill ref support
by joshavant · 2026-02-21
74.9%
#8050: fix: docker hardening
by christopherbarnett96 · 2026-02-03
74.8%
#13953: feat(docker): add .env template and improve Dockerfile
by n24q02m · 2026-02-11
74.7%
#4238: Fix/docker migration atomicity
by ricardotrevisan · 2026-01-29
74.7%
#9190: feat(docker): Add autonomous container self-restart and runtime pac...
by alexdredmon · 2026-02-05
73.9%