Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 50 additions & 10 deletions compose.individual-services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ services:
- devnet
restart: "no"
secrets:
- database_connection
- source: database_connection
target: database_connection
uid: "102"
gid: "102"
mode: 0440
environment:
<<: *env

Expand All @@ -64,9 +68,17 @@ services:
ports:
- "10001:10001" # Supervisor
secrets:
- auth_mnemonic
- source: auth_mnemonic
target: auth_mnemonic
uid: "102"
gid: "102"
mode: 0400
- blockchain_http_endpoint
- database_connection
- source: database_connection
target: database_connection
uid: "102"
gid: "102"
mode: 0440
environment:
<<: *env

Expand All @@ -87,8 +99,16 @@ services:
- "10002:10002" # Supervisor
- "10012:10012" # Inspect Service
secrets:
- auth_mnemonic
- database_connection
- source: auth_mnemonic
target: auth_mnemonic
uid: "102"
gid: "102"
mode: 0400
- source: database_connection
target: database_connection
uid: "102"
gid: "102"
mode: 0440
environment:
<<: *env

Expand All @@ -103,7 +123,11 @@ services:
ports:
- "10003:10003" # Supervisor
secrets:
- database_connection
- source: database_connection
target: database_connection
uid: "102"
gid: "102"
mode: 0440
environment:
<<: *env

Expand All @@ -120,9 +144,17 @@ services:
ports:
- "10004:10004" # Supervisor
secrets:
- auth_mnemonic
- source: auth_mnemonic
target: auth_mnemonic
uid: "102"
gid: "102"
mode: 0400
- blockchain_http_endpoint
- database_connection
- source: database_connection
target: database_connection
uid: "102"
gid: "102"
mode: 0440
environment:
<<: *env

Expand All @@ -138,9 +170,17 @@ services:
- "10005:10005" # Supervisor
- "10011:10011" # Jsonrpc API service
secrets:
- auth_mnemonic
- source: auth_mnemonic
target: auth_mnemonic
uid: "102"
gid: "102"
mode: 0400
- blockchain_http_endpoint
- database_connection
- source: database_connection
target: database_connection
uid: "102"
gid: "102"
mode: 0440
environment:
<<: *env
volumes:
Expand Down
24 changes: 21 additions & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ services:
interval: 3s
timeout: 3s
retries: 5
secrets:
- source: database_connection
target: database_connection
uid: "102"
gid: "102"
mode: 0440
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: rollupsdb
Expand All @@ -46,7 +52,11 @@ services:
networks:
- devnet
secrets:
- database_connection
- source: database_connection
target: database_connection
uid: "102"
gid: "102"
mode: 0440
restart: "no"
environment:
<<: *env
Expand All @@ -69,9 +79,17 @@ services:
- "10011:10011" # Jsonrpc API service
- "10012:10012" # Inspect Service
secrets:
- auth_mnemonic
- source: auth_mnemonic
target: auth_mnemonic
uid: "102"
gid: "102"
mode: 0400
- blockchain_http_endpoint
- database_connection
- source: database_connection
target: database_connection
uid: "102"
gid: "102"
mode: 0440
environment:
<<: *env

Expand Down
117 changes: 117 additions & 0 deletions docs/secret-files.md
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 |

Check failure on line 14 in docs/secret-files.md

View workflow job for this annotation

GitHub Actions / basic-checks

Table column style

docs/secret-files.md:14:61 MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md060.md

Check failure on line 14 in docs/secret-files.md

View workflow job for this annotation

GitHub Actions / basic-checks

Table column style

docs/secret-files.md:14:48 MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md060.md
| `CARTESI_DATABASE_CONNECTION_FILE` | credential | database connection string (DSN) |
| `CARTESI_BLOCKCHAIN_HTTP_ENDPOINT_FILE` | regular-file | endpoint without embedded credentials |

Check failure on line 16 in docs/secret-files.md

View workflow job for this annotation

GitHub Actions / basic-checks

Table column style

docs/secret-files.md:16:101 MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md060.md

Check failure on line 16 in docs/secret-files.md

View workflow job for this annotation

GitHub Actions / basic-checks

Table column style

docs/secret-files.md:16:58 MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md060.md

Check failure on line 16 in docs/secret-files.md

View workflow job for this annotation

GitHub Actions / basic-checks

Table column style

docs/secret-files.md:16:43 MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md060.md

## 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`).

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:

```

Check failure on line 112 in docs/secret-files.md

View workflow job for this annotation

GitHub Actions / basic-checks

Fenced code blocks should have a language specified

docs/secret-files.md:112 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md040.md
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.
5 changes: 5 additions & 0 deletions internal/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,15 @@ used-by = ["evmreader", "claimer", "node", "prt"]

[blockchain.CARTESI_BLOCKCHAIN_HTTP_ENDPOINT]
file = true
file-policy = "regular-file"
go-type = "URL"
description = """
HTTP endpoint for the blockchain RPC provider."""
used-by = ["evmreader", "claimer", "node", "prt"]

[blockchain.CARTESI_BLOCKCHAIN_HTTP_AUTHORIZATION]
file = true
file-policy = "credential"
go-type = "RedactedString"
description = """
Additional security when interacting with providers.
Expand Down Expand Up @@ -334,6 +336,7 @@ used-by = ["claimer", "node", "cli", "prt"]

[auth.CARTESI_AUTH_PRIVATE_KEY]
file = true
file-policy = "strict-secret"
go-type = "RedactedString"
description = """
The node will use this private key to sign transactions."""
Expand All @@ -342,6 +345,7 @@ used-by = ["claimer", "node", "cli", "prt"]

[auth.CARTESI_AUTH_MNEMONIC]
file = true
file-policy = "strict-secret"
go-type = "RedactedString"
description = """
The node will use the private key generated from this mnemonic to sign transactions."""
Expand Down Expand Up @@ -382,6 +386,7 @@ used-by = ["claimer", "node", "cli", "prt"]
[database.CARTESI_DATABASE_CONNECTION]
default = ""
file = true
file-policy = "credential"
go-type = "URL"
description = """
Postgres endpoint in the 'postgres://user:password@hostname:port/database' format (URL).
Expand Down
17 changes: 15 additions & 2 deletions internal/config/generate/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ var funcMap = template.FuncMap{
// For example, "int" becomes "toInt", "Duration" becomes "toDuration".
return "to" + strings.ToUpper(goType[:1]) + goType[1:]
},
// toFilePolicyConst maps a Config.toml file-policy value to the
// corresponding SecretFilePolicy constant name emitted in generated code.
"toFilePolicyConst": func(policy string) string {
switch policy {
case filePolicyStrict:
return "SecretFilePolicyStrict"
case filePolicyCredential:
return "SecretFilePolicyCredential"
case "", filePolicyRegular:
return "SecretFilePolicyRegularFileOnly"
default:
panic("invalid file-policy: " + policy)
}
},
// splitLines splits a string into lines (by "\n").
"splitLines": func(s string) []string {
return strings.Split(s, "\n")
Expand Down Expand Up @@ -122,7 +136,6 @@ package config

import (
"fmt"
"os"
"strings"

"github.com/spf13/viper"
Expand Down Expand Up @@ -221,7 +234,7 @@ func Get{{ toFieldName .Name }}() ({{ .GoType }}, error) {
{{- if .File }}
if s == "" {
filename := viper.GetString({{toConstName .Name}}_FILE)
contents, err := os.ReadFile(filename)
contents, err := ReadConfigFileWithPolicy(filename, {{ toFilePolicyConst .FilePolicy }})
if err != nil {
return notDefined{{ .GoType }}(), fmt.Errorf("failed to parse %s: %w", {{ toConstName .Name }}_FILE, err)
}
Expand Down
15 changes: 15 additions & 0 deletions internal/config/generate/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ func generateDocsFile(path string, env []Env) {
"quote": func(s string) string {
return `"` + s + `"`
},
"filePolicyDesc": func(p string) string {
switch p {
case filePolicyStrict:
return "strict-secret (owner-only regular file; rejects group/world access)"
case filePolicyCredential:
return "credential (regular file; rejects world access)"
case "", filePolicyRegular:
return "regular-file (must be a regular file)"
default:
return p
}
},
}
tmpl := template.Must(template.New("docs").Funcs(funcMap).Parse(docsTemplate))

Expand Down Expand Up @@ -56,6 +68,9 @@ This file documents the configuration options.
{{.Description}}

* **Type:** {{backtick .GoType}}
{{- if .File}}
* **File policy:** {{filePolicyDesc .FilePolicy}}
{{- end}}
{{- if .Default}}
* **Default:** {{.Default | quote | backtick}}
{{- end}}
Expand Down
Loading
Loading