-
Notifications
You must be signed in to change notification settings - Fork 76
secret file permissions #790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mpolitzer
wants to merge
2
commits into
next/2.0
Choose a base branch
from
feature/secret-file-permissions
base: next/2.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Secret File Permissions | ||
|
|
||
| The node reads several sensitive configuration values from files via the | ||
| `*_FILE` environment variables. To avoid silently accepting insecure secret | ||
| mounts, the node validates the file **type and permissions** before reading | ||
| the contents and rejects files that violate the policy. | ||
|
|
||
| This applies to the file-backed variants of: | ||
|
|
||
| | Variable | Policy | Sensitivity | | ||
| | ------------------------------------------- | ------------- | ---------------------------------------- | | ||
| | `CARTESI_AUTH_MNEMONIC_FILE` | strict-secret | signing material (mnemonic) | | ||
| | `CARTESI_AUTH_PRIVATE_KEY_FILE` | strict-secret | signing material (private key) | | ||
| | `CARTESI_BLOCKCHAIN_HTTP_AUTHORIZATION_FILE`| credential | outbound authorization header | | ||
| | `CARTESI_DATABASE_CONNECTION_FILE` | credential | database connection string (DSN) | | ||
| | `CARTESI_BLOCKCHAIN_HTTP_ENDPOINT_FILE` | regular-file | endpoint without embedded credentials | | ||
|
|
||
| ## Policy tiers | ||
|
|
||
| ### strict-secret (signing material) | ||
|
|
||
| Applies to the mnemonic and private-key files. | ||
|
|
||
| The file: | ||
|
|
||
| - **must be a regular file** (not a directory, device, pipe, etc.); | ||
| - **must not be readable, writable, or executable by group or world** | ||
| (`mode & 0o077` must be `0`, i.e. owner-only, such as `0400` or `0600`); | ||
| - **must be owned by the current effective user** on POSIX systems. | ||
|
|
||
| On violation the node refuses to start. This is a hard failure, not a warning. | ||
|
|
||
| ### credential (authorization headers, DSNs) | ||
|
|
||
| Applies to files carrying passwords or authorization tokens. | ||
|
|
||
| The file: | ||
|
|
||
| - **must be a regular file**; | ||
| - **must not be world-readable or world-writable** | ||
| (`mode & 0o007` must be `0`). | ||
|
mpolitzer marked this conversation as resolved.
|
||
|
|
||
| Group-readable files are accepted (e.g. `0640`), so a shared group can mount | ||
| credentials when needed. | ||
|
|
||
| ### regular-file (non-secret endpoint files) | ||
|
|
||
| Applies to endpoint files that do not carry credentials. | ||
|
|
||
| The file: | ||
|
|
||
| - **must be a regular file**. | ||
|
|
||
| No permission restrictions beyond that. This tier keeps URL convenience files | ||
| from being conflated with private key material. | ||
|
|
||
| ## Non-POSIX platforms | ||
|
|
||
| On Windows and other platforms that do not expose POSIX mode semantics, only the | ||
| regular-file check is enforced; mode and ownership checks are skipped. Treat | ||
| this as best-effort hardening, not cross-platform parity. | ||
|
|
||
| ## Required file modes | ||
|
|
||
| When mounting secrets into the container, use owner-only permissions for signing | ||
| material: | ||
|
|
||
| ```sh | ||
| chmod 600 /run/secrets/auth_mnemonic | ||
| chmod 600 /run/secrets/auth_private_key | ||
| ``` | ||
|
|
||
| and group-only or owner-only permissions for credential files: | ||
|
|
||
| ```sh | ||
| chmod 640 /run/secrets/blockchain_http_authorization | ||
| chmod 640 /run/secrets/database_connection | ||
| ``` | ||
|
|
||
| The node runs as a non-root user (`cartesi`, uid 102, gid 102). Secret files must | ||
| be readable by that user. | ||
|
|
||
| ## Docker Compose | ||
|
|
||
| Docker Compose mounts secrets into `/run/secrets/<name>`. By default they are | ||
| **owned by `root`** and **world-readable (`0444`)**, which the `strict-secret` | ||
| policy rejects. Mount signing secrets with an explicit mode and ownership so | ||
| they are readable only by the node user, for example: | ||
|
|
||
| ```yaml | ||
| services: | ||
| node: | ||
| secrets: | ||
| - source: auth_mnemonic | ||
| target: auth_mnemonic | ||
| uid: "102" | ||
| gid: "102" | ||
| mode: 0400 | ||
|
|
||
| secrets: | ||
| auth_mnemonic: | ||
| file: test/secrets/auth_mnemonic.txt | ||
| ``` | ||
|
|
||
| > Note: the `uid`, `gid`, and `mode` fields on service secrets require a recent | ||
| > Docker Compose version. Verify support in your environment; if they are | ||
| > unsupported, mount the secret as a bind volume with the host file owned by uid | ||
| > 102 and mode `0400` instead. | ||
|
|
||
| The node rejects insecure secret files at startup with a message such as: | ||
|
|
||
| ```text | ||
| failed to parse CARTESI_AUTH_MNEMONIC_FILE: file "/run/secrets/auth_mnemonic" | ||
| is accessible by group or others; expected owner-only permissions | ||
| ``` | ||
|
|
||
| Error messages never include the file contents. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.