Skip to content

Allow secrets to be provided from a file or environment variable#5177

Open
sisuresh wants to merge 3 commits intostellar:masterfrom
sisuresh:secrets
Open

Allow secrets to be provided from a file or environment variable#5177
sisuresh wants to merge 3 commits intostellar:masterfrom
sisuresh:secrets

Conversation

@sisuresh
Copy link
Contributor

Description

Resolves #1316

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

@sisuresh sisuresh requested a review from jacekn March 12, 2026 20:05
@@ -333,6 +333,13 @@ KNOWN_PEERS=[
# This example also adds a common name to NODE_NAMES list named `self` with the
# public key associated to this seed
NODE_SEED="SBI3CZU7XZEWVXU7OZLW5MMUQAP334JFOPXSLTPOH43IRTEQ2QYXU5RG self"
#
# You can also load the seed from an environment variable:
# NODE_SEED="$ENV:STELLAR_NODE_SEED"
Copy link
Contributor Author

@sisuresh sisuresh Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could remove this and only introduce the file based approach if there are any security concerns.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that env variables are a bit less secure. But at the same time I think they can be adequate for non-production environments and it would be convenient to allow their use.
Perhaps we can support them but call out files on disk as best practice in the docs or in the config comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up simplifying this PR for your use case. We can expand it later if needed.

sisuresh and others added 3 commits March 13, 2026 11:23
Introduce SecretManager utility that resolves config values from
external file references using the $FILE:/path prefix convention.
Files are read with trailing whitespace trimming. Values without a
prefix are returned unchanged (backward compatible).

Apply secret resolution to NODE_SEED parsing in Config.cpp so that
operators can keep seeds out of the config file.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add checkFilePermissions() using std::filesystem::perms to reject
secret files that are readable by group or others. This follows the
SSH model of requiring restrictive permissions (0600 or stricter)
without platform-specific preprocessor guards.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a post-parse check that rejects $FILE: secret references when
NETWORK_PASSPHRASE matches the public network. This restricts the
feature to testnets and private networks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sisuresh sisuresh marked this pull request as ready for review March 14, 2026 00:19
Copilot AI review requested due to automatic review settings March 14, 2026 00:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for resolving sensitive config values (currently NODE_SEED) from external secret sources, primarily via $FILE: references, and documents / tests the behavior.

Changes:

  • Introduce util/SecretManager for resolving $FILE:-prefixed config values with permission checks and whitespace trimming.
  • Update config parsing to allow NODE_SEED to be read from a $FILE: reference and reject such references on public network config.
  • Add unit tests and update the example config documentation for $FILE: usage.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/util/SecretManager.h New API for resolving config secrets (e.g., $FILE:).
src/util/SecretManager.cpp Implements file-based secret resolution and permission validation.
src/main/Config.cpp Uses SecretManager when parsing NODE_SEED; rejects external secrets on pubnet.
src/main/test/ConfigTests.cpp Adds tests for secret resolution and config integration.
docs/stellar-core_example.cfg Documents $FILE: usage for NODE_SEED.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move secrets out of the config file

3 participants