Repository navigation
Add rserver --check-config and make --test-config a deprecated alias - #18020
Conversation
…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.
References #18020.
🍎 macOS Desktop E2E · ARM64✅ All tests passed!
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · macos-26 ARM64 · commit |
🪟 Windows Desktop E2E · Server 2025 x64✅ All tests passed!
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · Windows Server 2025 x64 · commit |
Code review findingsActionable items from an automated multi-agent review. Strengths, dismissed findings, and ratings are omitted. Critical
Important
Suggestions
|
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.
|
Thanks for the review. I've pushed Behavior: On the findings:
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. |
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 ...).
Sample outputBuilt in the `pro-jammy-arm64-golden-wattle` image (OSS build). No server started, no subsystems initialized. Clean config — exit 0 Config with unrecognized keys — exit 1
Admin subcommand works identically: |
|
@gtritchie tagged you for review since you provided the first one but feel free to delegate as you see fit. |
|
I'll let @kevinushey have a go at it this time. :-) |
kevinushey
left a comment
There was a problem hiding this comment.
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.
|
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. |
…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.
Summary
Adds
rserver --check-config(and a matchingrstudio-server check-configadmin 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-configbecomes 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; adddeferCheckConfigparam so callers can run extended checks before exiting; relaxed parse;collectUnrecognizedConfigKeys()reports all unrecognized keys in one pass;--test-configdeprecated 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 — validatessecure-cookie-key-file,server-data-dir,rsession-config-file,database-config-file, and R installation, then callsoverlay::checkConfigbefore exiting.src/cpp/server/ServerMainOverlay.cpp: no-op OSS stub foroverlay::checkConfig(extension point for downstream builds).src/cpp/server/ServerOptions.cpp: passesdeferCheckConfig=true.src/cpp/server/extras/admin/rstudio-server.inandrstudio-server.mac.in: add thecheck-configsubcommand 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-configdeprecation.Test plan
rserver --check-configon a clean config:[PASS]for all checks, exit 0.rserver --check-configon a config with unrecognized keys:[FAIL]listing every key in one pass, exit 1.rserver --test-configon the same config: deprecation warning + same whole-config result, same exit code.rserver --check-configwith no config file: error reported via logging path, exit 1.rstudio-core-tests --gtest_filter='*ProgramOptions*'(6/6) andrserver-tests --gtest_filter='*CheckConfig*'(8/8).