Skip to content

Add rserver --check-config and make --test-config a deprecated alias - #18020

Merged
ian-flores merged 6 commits into
mainfrom
feature/engsct-134-check-config
Jun 26, 2026
Merged

ian-flores merged 6 commits into
mainfrom
feature/engsct-134-check-config

Conversation

@ian-flores

@ian-flores ian-flores commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds rserver --check-config (and a matching rstudio-server check-config admin subcommand) to validate the configuration file without starting the service. It reports every unrecognized option in a single pass and prints a [PASS]/[FAIL] summary on stdout; the exit code is the contract.

--test-config becomes a deprecated alias of --check-config. It now does the same work, validating the whole config rather than stopping at the first unrecognized key, and prints a deprecation warning. It will be removed in a future release. This aligns Workbench with Connect and Package Manager, which use --check-config.

Changes

  • src/cpp/core/ProgramOptions.cpp/.hpp: register --check-config; add deferCheckConfig param so callers can run extended checks before exiting; relaxed parse; collectUnrecognizedConfigKeys() reports all unrecognized keys in one pass; --test-config deprecated alias; missing/empty config → [FAIL].
  • src/cpp/server/ServerCheckConfig.{cpp,hpp} (new): helpers for file-path validation (checkConfigFilePath) and R installation detection (informational).
  • src/cpp/server/ServerMain.cpp: extended check block after config parse — validates secure-cookie-key-file, server-data-dir, rsession-config-file, database-config-file, and R installation, then calls overlay::checkConfig before exiting.
  • src/cpp/server/ServerMainOverlay.cpp: no-op OSS stub for overlay::checkConfig (extension point for downstream builds).
  • src/cpp/server/ServerOptions.cpp: passes deferCheckConfig=true.
  • src/cpp/server/extras/admin/rstudio-server.in and rstudio-server.mac.in: add the check-config subcommand and usage entry.
  • src/cpp/core/ProgramOptionsTests.cpp (new, 6 tests): missing config, unknown keys, deprecated alias, deferred check behaviour.
  • src/cpp/server/ServerCheckConfigTests.cpp (new, 8 tests): path check helpers.
  • NEWS.md: announce the --test-config deprecation.

Test plan

  • rserver --check-config on a clean config: [PASS] for all checks, exit 0.
  • rserver --check-config on a config with unrecognized keys: [FAIL] listing every key in one pass, exit 1.
  • rserver --test-config on the same config: deprecation warning + same whole-config result, same exit code.
  • rserver --check-config with no config file: error reported via logging path, exit 1.
  • Unit tests: rstudio-core-tests --gtest_filter='*ProgramOptions*' (6/6) and rserver-tests --gtest_filter='*CheckConfig*' (8/8).

…ized keys

Add a --check-config flag to rserver that validates the configuration file
without starting the service and reports all unrecognized option names in a
single pass, rather than stopping at the first unrecognized key the way
--test-config does. The existing --test-config flag is unchanged.

The flag is detected with an early argv scan so the config parse can run with
allow_unregistered=true; the config file is then re-parsed to collect every
unrecognized key name and print a [PASS]/[FAIL] summary. This mirrors the
syntax and unrecognized-key checking that Connect's check-config performs,
bringing the behavior to parity across products.

Also expose the flag through the rstudio-server admin script as the
check-config subcommand.
@ian-flores ian-flores added this to the 2026.07 (Pacific Dogwood) milestone Jun 18, 2026
@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

🍎 macOS Desktop E2E · ARM64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
402 0 18 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · macos-26 ARM64 · commit bc6191e3192326b116a765171b8994c3343d7226 · Run #183

@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

🪟 Windows Desktop E2E · Server 2025 x64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
408 0 13 1
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · Windows Server 2025 x64 · commit bc6191e3192326b116a765171b8994c3343d7226 · Run #183

@gtritchie

Copy link
Copy Markdown
Member

Code review findings

Actionable items from an automated multi-agent review. Strengths, dismissed findings, and ratings are omitted.

Critical

  1. src/cpp/core/ProgramOptions.cpp:330-332 — --check-config prints [PASS] Config file: no unrecognized options found and exits 0 when no config file exists at all. For rserver the default config path resolves to "" when /etc/rstudio/rserver.conf is absent (src/cpp/server/include/server/ServerOptions.gen.hpp:247), so collectUnrecognizedConfigKeys("") returns early empty (ProgramOptions.cpp:182) and that empty result is reported as success. An admin checking a typo'd path or a missing config gets a green PASS. Fix: handle configFile.empty() distinctly (FAIL or an explicit "no config file found"), and include the resolved path in the PASS/FAIL output.

  2. src/cpp/core/ProgramOptions.cpp:317 — when both --test-config and --check-config are passed, the test-config branch is checked first and returns exitSuccess() before the unrecognized-key scan runs. Because the early argv scan already forced allowUnregisteredConfigOptions = true (ProgramOptions.cpp:238-239), the test-config pass also won't fail on unknown keys, so the combined invocation reports success even on a config full of unrecognized options. Fix: evaluate checkConfigMode before test-config, or reject the two flags as mutually exclusive.

Important

  1. No automated tests. core::program_options::read() has no existing unit coverage and is the config entry point for rserver, rsession, and postback; the new branching logic ships untested. A new src/cpp/core/ProgramOptionsTests.cpp is auto-discovered by the *Tests.cpp glob (src/cpp/core/CMakeLists.txt:357), and ProgramStatus::exitCode() makes PASS/FAIL assertable. Cover: multi-key FAIL in one pass, clean PASS, "must not start the service", missing-config behavior (finding 1), dual-flag behavior (finding 2), and a malformed-syntax config.

  2. src/cpp/server/extras/admin/rstudio-server.mac.in — the macOS admin script has a test-config subcommand but was not given check-config, and its usage string is unchanged, while the Linux rstudio-server.in was updated. Fix: add the check-config subcommand and usage entry there too (confirm macOS server is in scope).

  3. src/cpp/core/ProgramOptions.cpp:205-208 — catch(const std::exception&) swallows all exceptions. Syntax errors are already handled by the main parse bailing earlier (ProgramOptions.cpp:290), but the catch also silently absorbs bad_alloc, locale/encoding conversion failures, and any other boost exception, each of which yields an empty vector and a false [PASS]. Fix: narrow to boost::program_options::invalid_config_file_syntax and let anything else propagate.

Suggestions

  1. src/cpp/core/ProgramOptions.cpp:332,337-339 — the [PASS]/[FAIL] verdict is written to stderr, so result=$(rserver --check-config) captures nothing. The exit code is the reliable contract; either move the verdict to stdout or document that exit status is the contract.

  2. src/cpp/core/ProgramOptions.cpp:324-325 — drop the "mirroring Connect's NamesChecker behavior" comment; it references an internal component of a separate closed-source product that no RStudio maintainer can verify, and the preceding clause already describes the intent. Move provenance to the commit message.

  3. src/cpp/core/ProgramOptions.cpp:186-188 — the openForRead error branch is effectively dead (the main parse already opened any non-empty config before the scan runs) and returns a PASS-shaped empty vector on error. If kept defensively, propagate the error instead.

  4. src/cpp/core/ProgramOptions.cpp:326-327 — in check-config mode the config file is opened and parsed twice; the first pass's results are discarded. Acceptable for a one-shot command, but the second parse could be avoided by threading the unrecognized keys out of the first pass.

Per cross-product alignment (Connect and Package Manager use --check-config),
unify the two flags: --check-config is canonical and --test-config is a
deprecated alias with identical behavior. Both now validate the whole config
and report every unrecognized option in a single pass (--test-config
previously stopped at the first), and --test-config prints a deprecation
warning.

Also address review findings:
- Report a missing or empty config file explicitly ([FAIL] with guidance)
  instead of a misleading [PASS].
- Write the [PASS]/[FAIL] verdict (with the config path) to stdout; the exit
  code remains the contract.
- Narrow the unrecognized-key scan's catch to invalid_config_file_syntax and
  propagate a read error rather than reporting a clean check.
- Add the check-config subcommand to the macOS admin script.
- Add ProgramOptionsTests.cpp covering clean, all-keys-fail-in-one-pass,
  missing-config, deprecated-alias, and no-service-start behavior.

Announce the --test-config deprecation in NEWS.
@ian-flores

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I've pushed 146f9b5d47, which also folds in the team's decision from the Slack thread: --test-config becomes a deprecated alias of --check-config.

Behavior: --check-config is now the canonical flag. --test-config does the same work, validates the whole config and lists every unrecognized option in one pass instead of stopping at the first, and prints a deprecation warning. NEWS records the deprecation; the blog post and admin-guide entry are a team follow-up.

On the findings:

  1. Missing config: an empty or absent path now reports [FAIL] No configuration file found to validate, with the path, instead of a silent [PASS].
  2. Both flags at once: moot now that they share one path.
  3. Tests: added ProgramOptionsTests.cpp covering a clean pass, several bad keys caught in one pass, a missing config, the deprecated alias (warning plus whole-config), and the guarantee that the service never starts.
  4. macOS script: added check-config and its usage line to rstudio-server.mac.in.
  5. Broad catch: narrowed to invalid_config_file_syntax; anything else propagates.
  6. Verdict on stderr: the [PASS]/[FAIL] line, with the config path, now goes to stdout. The exit code is still the contract.
  7. Dropped the NamesChecker comment.
  8. The openForRead branch returns the error now instead of an empty, pass-shaped result.
  9. Left the double parse alone, per your note that it's fine for a one-shot.

Built and ran it in a Linux image: clean and multi-bad-key configs, the deprecation warning, and the missing-config case all behaved, and the new tests pass.

@ian-flores ian-flores changed the title Add rserver --check-config to validate config and report all unrecognized keys Add rserver --check-config and make --test-config a deprecated alias Jun 18, 2026
Move the extended check-config orchestration into ServerMain, where the parsed
server options are available. ProgramOptions::read now defers finalization to
the caller for rserver (a new deferCheckConfig flag), so a clean syntax and
unrecognized-key parse returns control instead of exiting; other binaries are
unchanged.

The added checks:
- File paths: report whether configured paths (secure-cookie-key-file,
  rsession-config-file, database-config-file) exist. A missing server-data-dir
  is informational, since the server creates it on startup. Product binaries
  resolved against the install are left to --verify-installation.
- R installation: report the detected R version (informational).
- A new overlay::checkConfig hook lets Workbench builds add database and
  license checks; the open-source build is a no-op.

Extract the path check into ServerCheckConfig with unit tests, and update NEWS.
Eliminate duplicated argv scan: move check-config detection into
ServerOptions::read(), store the result as checkConfigMode_ with a public
accessor, and remove the redundant scan from ServerMain. ServerMain now
calls options.checkConfigMode() instead of re-scanning argv.

Add fileOnly parameter to checkConfigFilePath: when true, a directory
at a file-typed path is reported as [FAIL]. Apply it to
secure-cookie-key-file, rsession-config-file, and database-config-file
in ServerMain.

Add missing unit tests: DeferredCleanConfigReturnsRun (verifies
deferCheckConfig=true returns run() not exitSuccess()), and
FileOnlyRejectsDirectoryWithFail / FileOnlyAcceptsRegularFile for the
new fileOnly behaviour. Test counts: CheckConfig 10/10, ProgramOptions 7/7.

Replace non-ASCII em-dash and ellipsis in C++ comments with ASCII
equivalents (-- and ...).
@ian-flores

ian-flores commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Sample output

Built in the `pro-jammy-arm64-golden-wattle` image (OSS build). No server started, no subsystems initialized.

Clean config — exit 0

$ rserver --check-config --config-file /etc/rstudio/rserver.conf

-- Reading config file: /etc/rstudio/rserver.conf
[PASS] Config file /etc/rstudio/rserver.conf: no unrecognized options found
[PASS] server-data-dir: /var/run/rstudio-server not found (will be created on startup)
[PASS] R installation: found R 4.1.2

Config with unrecognized keys — exit 1

$ rserver --check-config --config-file /etc/rstudio/rserver.conf

-- Reading config file: /etc/rstudio/rserver.conf
[FAIL] Config file /etc/rstudio/rserver.conf: unrecognized option(s):
  - bad-key-one
  - bad-key-two

--test-config deprecated alias — exit 0

$ rserver --test-config --config-file /etc/rstudio/rserver.conf

Warning: --test-config is deprecated and will be removed in a future release; use --check-config instead.
-- Reading config file: /etc/rstudio/rserver.conf
[PASS] Config file /etc/rstudio/rserver.conf: no unrecognized options found
[PASS] server-data-dir: /var/run/rstudio-server not found (will be created on startup)
[PASS] R installation: found R 4.1.2

Admin subcommand works identically: rstudio-server check-config.

@ian-flores
ian-flores marked this pull request as ready for review June 23, 2026 21:54
@ian-flores
ian-flores requested a review from gtritchie June 23, 2026 21:54
@ian-flores

Copy link
Copy Markdown
Contributor Author

@gtritchie tagged you for review since you provided the first one but feel free to delegate as you see fit.

@gtritchie
gtritchie requested review from kevinushey and removed request for gtritchie June 23, 2026 22:27
@gtritchie

Copy link
Copy Markdown
Member

I'll let @kevinushey have a go at it this time. :-)

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The single-pass unrecognized-key collection, the deprecation alias, and the new test coverage all look correct. Two findings concern the deferred-flow design causing valid configs to report failure, plus one minor cleanup.

1. Deferred run() now routes check-config through the server-user privilege check (ServerOptions.cpp)

Previously --test-config returned exitSuccess() from program_options::read, so the if (status.exit()) return status; guard fired before the server-user existence/privilege block. With deferCheckConfig=true the read now returns run(), the guard no longer fires, and the server-user block executes.

Concrete failure: an admin runs rserver --check-config from their own shell (not root). serverUser_ defaults to rstudio-server, that account exists with a different uid, so the code hits "Attempt to run server as user 'rstudio-server'... without privilege" and returns exitFailure(). The extended check block in ServerMain is never reached. Output is a [PASS] config-parse line followed by an unrelated privilege error and exit 1 -- config validation reports failure for a perfectly valid config.

2. secure-cookie-key-file validated as a hard must-exist file, but the server auto-generates it (ServerMain.cpp)

The check uses fileOnly=true, non-informational. But SecureKeyFile.cpp generates and writes the key when the file does not exist. An admin who configures secure-cookie-key-file=/some/path (common in load-balanced setups, or any fresh install before first start) gets [FAIL] secure-cookie-key-file: /some/path not found and exit 1, even though the server would create the key on startup.

This is inconsistent with server-data-dir directly above it, which is correctly treated as informational for exactly this "created on startup" reason. Under load balancing the key may also live in the database, so on-disk existence isn't required at all. Suggest treating it as informational (or skipping it).

3. Duplicated check-config argv scan (minor cleanup)

The same raw for (int i = 1; i < argc; ++i) scan for --check-config/--test-config is implemented in both program_options::read and ServerOptions::read (to set checkConfigMode_). Since program_options::read already detects this, consider exposing the result rather than re-scanning argv in two places that must stay in sync.


Findings 1 and 2 are the actionable correctness issues -- both report a valid configuration as a failure, which undermines the feature's core contract (the exit code). Finding 1 is the more severe since it can fail before any extended check even runs.

Address review feedback on the deferred-flow design.

Skip the server-user existence/privilege block during --check-config.
With deferCheckConfig=true the parse returns run() rather than
exitSuccess(), so the guard no longer fired before the privilege
check; a non-root admin running --check-config hit the
"without privilege" error and exit 1 for a valid config. Config
validation does not need to resolve runtime privileges.

Treat secure-cookie-key-file as informational, matching server-data-dir.
The server auto-generates the key on startup when the file is absent
(and under load balancing it may live in the database), so a missing
file is not a fatal config error.

De-duplicate the --check-config/--test-config argv scan into a shared
program_options::detectCheckConfigMode() helper used by both
ProgramOptions::read and ServerOptions::read.
@ian-flores

Copy link
Copy Markdown
Contributor Author

Fixed in bc6191e, CI's green.

(1) Yep, that's the exact sequence. Once the parse returns run() instead of exitSuccess() the status.exit() guard stops firing, and a non-root admin running --check-config trips the uid comparison and exits 1 on a perfectly good config. Config validation has no business resolving runtime privileges, so I skip the whole server-user existence/privilege block when checkConfigMode_ is set. The path resolution and origin parsing after it don't read the server user, so ServerMain still gets to the extended checks.

(2) Agreed, and it was inconsistent with server-data-dir right below it. SecureKeyFile.cpp writes the key when the file's missing, and under load balancing it can live in the database instead, so requiring it on disk is just wrong. Made it informational.

(3) I took a different route than putting the result on read(). An out-param there has to thread through all four overloads for something the caller can work out in three lines, so I pulled the scan into program_options::detectCheckConfigMode() and call it from both spots.

@ian-flores
ian-flores requested a review from kevinushey June 26, 2026 17:50

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@ian-flores
ian-flores merged commit 4ac9ae7 into main Jun 26, 2026
15 checks passed
@ian-flores
ian-flores deleted the feature/engsct-134-check-config branch June 26, 2026 17:57
kevinushey pushed a commit that referenced this pull request Jun 26, 2026
…18083)

The testConfig() helper in the rstudio-server admin script wrapped `rserver --test-config` in backtick command substitution. That was harmless while --test-config reported only to stderr, but #18020 made --test-config a deprecated alias for --check-config, which writes its [PASS]/[FAIL] verdict to stdout. The backticks captured that stdout and then tried to execute the verdict text as a shell command, so `rstudio-server test-config` printed `[FAIL]: command not found`, hid the real verdict, and exited 127 instead of propagating the validator's exit code.

Run the binary directly, matching the checkConfig() helper added in #18020. Applied to both the Linux (rstudio-server.in) and macOS (rstudio-server.mac.in) templates.
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.

3 participants