diff --git a/.github/workflows/nexjast-ci.yml b/.github/workflows/nexjast-ci.yml index 0cbdf861..20c9c0c0 100644 --- a/.github/workflows/nexjast-ci.yml +++ b/.github/workflows/nexjast-ci.yml @@ -61,6 +61,10 @@ jobs: shell: bash run: python3 tools/ci/verify_no_plaintext_runtime_secrets.py + - name: Verify runtime environment expansion declarations + shell: bash + run: python3 tools/ci/verify_environment_expansions.py + - name: Verify OSSL policy coverage shell: bash run: python3 tools/ci/verify_ossl_policy.py diff --git a/bin/Robust.HG.ini.example b/bin/Robust.HG.ini.example index 73115d21..505c6a91 100644 --- a/bin/Robust.HG.ini.example +++ b/bin/Robust.HG.ini.example @@ -22,6 +22,11 @@ ; * such use is providing a base path for setting locations that Robust ; * uses to write data. ; * +[Environment] + ; Runtime secrets are supplied through process environment, + ; /etc/nexverse/nexverse.env or bin/nexverse.local.env. + NEXVERSE_NATIVE_TOKEN_SIGNING_KEY = "" + [Const] ; The domain or IP of the Robust server. BaseHostname = "127.0.0.1" diff --git a/bin/config-include/GridCommon.ini b/bin/config-include/GridCommon.ini index daecdb8d..75e5ae67 100644 --- a/bin/config-include/GridCommon.ini +++ b/bin/config-include/GridCommon.ini @@ -1,7 +1,13 @@ [Environment] - ; Database credentials are loaded from process environment, /etc/nexverse/nexverse.env, + ; Runtime secrets are loaded from process environment, /etc/nexverse/nexverse.env, ; or bin/nexverse.local.env and must never be committed. + ; + ; Every ${Environment|...} reference used by the simulator must be declared + ; here so Nini can expand the configuration even while the related module is + ; disabled. The actual secret value remains outside version control. NEXVERSE_DB_PASSWORD = "" + NEXVERSE_ECONOMY_API_KEY = "" + NEXVERSE_EXPERIENCES_API_KEY = "" ; This is the main configuration file for an instance of OpenSim running in grid mode diff --git a/doc/NexVerse/SECRETS.md b/doc/NexVerse/SECRETS.md index 9ca9b442..6f8fb1dc 100644 --- a/doc/NexVerse/SECRETS.md +++ b/doc/NexVerse/SECRETS.md @@ -19,6 +19,13 @@ For the current grid configuration: - `NEXVERSE_ROBUST_CERT_PASSWORD` — password for the Robust TLS certificate container when that certificate is enabled. - `NEXVERSE_NATIVE_TOKEN_SIGNING_KEY` — HMAC signing key for NexVerse native access tokens; generate at least 32 random bytes (for example `openssl rand -hex 64`). +Simulator service variables are also declared in `bin/config-include/GridCommon.ini` so Nini can resolve every `${Environment|...}` expression during startup: + +- `NEXVERSE_ECONOMY_API_KEY` — required only when `[NexEconomyViewer] Enabled = true`; use a restricted machine key with `economy:read` and `economy:transfer`. +- `NEXVERSE_EXPERIENCES_API_KEY` — required only when `[NexExperiencesViewer] Enabled = true`; use a restricted machine key with `experiences:script`. + +The declarations themselves stay empty in the tracked INI. When the corresponding module is disabled, the empty declaration is sufficient for configuration expansion. When the module is enabled, provide the real value through a protected runtime secret source. + ## Recommended production setup Create the directory and file once: diff --git a/tools/ci/verify_environment_expansions.py b/tools/ci/verify_environment_expansions.py new file mode 100644 index 00000000..f290c6af --- /dev/null +++ b/tools/ci/verify_environment_expansions.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +"""Ensure runtime ${Environment|KEY} references are declared before Nini expansion.""" + +from pathlib import Path +import re + +ROOT = Path(__file__).resolve().parents[2] +REF = re.compile(r"\$\{Environment\|([A-Z][A-Z0-9_]*)\}") +SECTION = re.compile(r"^\s*\[([^]]+)\]\s*$") +ASSIGN = re.compile(r"^\s*([A-Z0-9_]+)\s*=") + + +def read(rel): + return (ROOT / rel).read_text(encoding="utf-8", errors="replace") + + +def refs(paths): + found = set() + for rel in paths: + found.update(REF.findall(read(rel))) + return found + + +def declarations(paths): + found = set() + for rel in paths: + section = "" + for raw in read(rel).splitlines(): + m = SECTION.match(raw) + if m: + section = m.group(1) + continue + if section != "Environment": + continue + m = ASSIGN.match(raw) + if m: + found.add(m.group(1)) + return found + + +profiles = [ + ( + "simulator", + ["bin/OpenSim.ini", "bin/config-include/GridCommon.ini"], + ["bin/OpenSim.ini", "bin/config-include/GridCommon.ini"], + ), + ( + "simulator-example", + ["bin/OpenSim.ini.example", "bin/config-include/GridCommon.ini"], + ["bin/OpenSim.ini.example", "bin/config-include/GridCommon.ini"], + ), + ( + "robust-hg", + ["bin/Robust.HG.ini"], + ["bin/Robust.HG.ini"], + ), + ( + "robust-hg-example", + ["bin/Robust.HG.ini.example"], + ["bin/Robust.HG.ini.example"], + ), +] + +violations = [] +for name, reference_paths, declaration_paths in profiles: + required = refs(reference_paths) + declared = declarations(declaration_paths) + missing = sorted(required - declared) + if missing: + violations.append((name, missing)) + +if violations: + print("[NX-SECRET-0002] Environment expansion declarations are incomplete:") + for profile, missing in violations: + print(f" - {profile}: missing {', '.join(missing)}") + raise SystemExit(1) + +print("NexVerse environment expansion declaration guard: OK")