Implement and configure Docker secrets for private key management - #7
Implement and configure Docker secrets for private key management#7dlt-green wants to merge 8 commits into
Conversation
Added function to prepare Docker secrets from .env file.
Updated docker-compose.yml to include Docker secrets for private key and removed volume mapping for keys.
Implement Docker secrets preparation for private key
Removed comments about private key handling and healthcheck.
Removed comments and adjusted fallback logic for private key retrieval.
Removed Docker Secrets preparation section and related comments.
|
The PR is a good direction, but in its current form it does not fully remove the private key from the environment. update.sh creates node/privatekey.txt from NODE_1_PRIVATEKEY in node/.env, then Docker mounts that file as a secret at /run/secrets/node_privatekey. However, the script does not delete or clear NODE_1_PRIVATEKEY from node/.env. In addition in the .evn file we have other secrets for LLM and IPFS. Because node/docker-compose.yml still includes:
the private key will still be injected into the container environment if it remains in .env. The application will prefer reading the key from the Docker Secret file, but the same secret may still be present as an environment variable. So the security improvement is only partial. It becomes significantly safer only if update.sh also removes NODE_1_PRIVATEKEY from node/.env after writing privatekey.txt, or if the private key is moved out of .env manually before running Docker. In short: Docker Secrets are a safer mechanism, but this PR does not yet complete the migration away from environment-based private key exposure. |
|
Current State & Limitations update.sh extracts NODE_1_PRIVATEKEY from node/.env and creates privatekey.txt, which is then mounted as a Docker Secret at /run/secrets/node_privatekey. We fully agree that this is not the final state. Our Design Rationale Several other validators are currently running older versions of the deployment scripts and prefer a single, simple configuration file (.env). At the same time, we share your view that the long-term direction should be: Use .env only for management, but never mount it 1:1 into production containers. Instead, extract sensitive values and inject them via Docker Secrets (or a proper secrets manager). This principle should ideally apply not only to the private key, but also to other secrets such as LLM_API_KEY and IPFS_BEARER_TOKEN. Introduce the split into config.env + secrets.env + individual secret files. Proposed Next Steps Automatic cleanup in update.sh |
This pull request introduces support for securely loading the node's private key from a Docker Secret file instead of only from environment variables or local files. It updates the Docker Compose configuration and the key loading logic to handle secret files, and enhances the update script to automatically prepare the Docker Secret from the
.envfile if present. Minor cleanups and improvements are also included.Secure private key management:
node/docker-compose.yml: Configures the node service to use a Docker Secret (node_privatekey) for the private key, removing the previous volume mount for keys. The secret is sourced fromprivatekey.txt.node/src/keys.ts: Adds logic to load the node's private key from a file specified by theNODE_1_PRIVATEKEY_FILEenvironment variable (set by Docker Secrets), falling back to the previous environment variable or generating a new key if not found. Includes logging for key loading and generation.Update script enhancements:
update.sh: Adds aprepare_docker_secretsfunction that extractsNODE_1_PRIVATEKEYfrom.envand writes it toprivatekey.txtfor Docker Secrets, with appropriate permissions. This function is called before starting Docker services. [1] [2]update.sh: Minor cleanups, such as removing unnecessary blank lines and ensuring required commands are checked before use. [1] [2] [3] [4]These changes improve the security and automation of private key handling for the node service in Docker environments.
✅ Complete Final Summary – Secure Private Key Handling with Docker Secrets
Here’s a clear overview of all the changes needed to fully solve the private key security issue.
1. docker-compose.yml (in the node/ folder)
Goal: Pass the private key as a Docker Secret (mounted as a file in RAM) instead of an environment variable.
Key changes:
2. update.sh
Changes made:
Benefit: You can keep using .env as your single source of truth. The script converts the key into a secure Docker Secret automatically.
3. src/keys.ts
Main improvement:
The loadOrCreateNodeIdentity() function now follows this priority order:
Final Workflow After Changes