Repository navigation
feat(setup): discover the facts of the cardano node - #3716
turmelclem wants to merge 17 commits into
Conversation
Test Results 5 files ± 0 211 suites ±0 58m 16s ⏱️ - 1h 4m 50s Results for commit b4a45b9. ± Comparison against base commit e50bd4e. This pull request removes 61 and adds 105 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
The discovery ran with the privileges of the setup, which may run as root, so any local user could get their own binary executed as root by starting a process named with block producer credentials on its command line. The command now runs with the real uid/gid of the node process, read from status, so the binary gets no privilege the node does not already have. It is not run at all when that identity is unknown.
…e Cardano node - Read the shelley genesis file from configuration, and network from its magic - Read the peers of the pool from the topology file - Select a lone relay when no block producer is running - Each fact is best-effort: a missing of invalid file leaves it undiscovered
…macOS and Windows
- Install a tracing subscriber from the existing flags (verbosity, JSON format, output file) - Remove the logger from the command context, logs use the tracing macros directly - The JSON logs now use the tracing format instead of Bunyan
5852306 to
b4a45b9
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Two unresolved issues remain: credential-source precedence incorrectly rejects a valid KES pair with an agent socket, and the privilege drop leaves supplementary root groups on the spawned process.
2 open issues
What changed in this PR
Adds runtime-agnostic Cardano node discovery to mithril-setup, including Linux host probes, command-line and node-file parsing, node selection, and collection of signer-relevant facts. It also migrates setup logging from slog to tracing.
Changes:
- Adds Cardano discovery models, probe traits, selection rules, and fact collection.
- Adds Linux
/proc, cgroup, filesystem, and executable inspection with unit and manual tests. - Replaces
sloglogging and logger propagation with a globaltracingsubscriber.
| File | Description |
|---|---|
| mithril-setup/tests/cardano_discovery_on_host.rs | Adds an ignored manual host test for Cardano node discovery. |
| mithril-setup/src/test_tools/mod.rs | Registers shared test utilities. |
| mithril-setup/src/test_tools/logs.rs | Adds tracing log capture helpers and tests. |
| mithril-setup/src/main.rs | Configures tracing output and removes logger injection. |
| mithril-setup/src/lib.rs | Exposes discovery and test utility modules. |
| mithril-setup/src/discovery/mod.rs | Registers the environment discovery modules. |
| mithril-setup/src/discovery/cardano/probes.rs | Defines runtime-agnostic Cardano observation traits and process models. |
| mithril-setup/src/discovery/cardano/node_files/topology.rs | Parses P2P and legacy topology peer definitions. |
| mithril-setup/src/discovery/cardano/node_files/shelley_genesis.rs | Parses Shelley genesis network magic values. |
| mithril-setup/src/discovery/cardano/node_files/mod.rs | Registers and re-exports node-file parsers. |
| mithril-setup/src/discovery/cardano/node_files/configuration.rs | Parses node configuration and resolves Shelley genesis paths. |
| mithril-setup/src/discovery/cardano/mod.rs | Organizes and exports Cardano discovery components. |
| mithril-setup/src/discovery/cardano/host/tools.rs | Inspects node versions and locates cardano-cli. |
| mithril-setup/src/discovery/cardano/host/procfs.rs | Discovers Cardano processes and process identities from /proc. |
| mithril-setup/src/discovery/cardano/host/mod.rs | Registers Linux host probes and fixtures. |
| mithril-setup/src/discovery/cardano/host/files.rs | Reads Cardano node files from the host filesystem. |
| mithril-setup/src/discovery/cardano/host/cgroup.rs | Resolves systemd units from process cgroups. |
| mithril-setup/src/discovery/cardano/discovery.rs | Defines public discovered-facts and node-role models. |
| mithril-setup/src/discovery/cardano/discoverer.rs | Selects the node and aggregates command-line, process, tool, and file facts. |
| mithril-setup/src/discovery/cardano/command_line.rs | Parses cardano-node run options and credential modes. |
| mithril-setup/src/commands/signer.rs | Migrates signer command logging to tracing. |
| mithril-setup/src/command_context.rs | Removes the shared slog logger from command context. |
| mithril-setup/Cargo.toml | Adds discovery, serialization, error-handling, and tracing dependencies. |
| Cargo.lock | Updates the dependency lockfile for tracing and discovery support. |
Review effort: Lite
| // Dropping to the node identity also clears the supplementary groups when the setup | ||
| // runs as root, so that the node binary can't do more than the node itself | ||
| #[cfg(unix)] | ||
| command.uid(run_as.uid).gid(run_as.gid); |
| // One block producer | ||
| 1 => { | ||
| let node = block_producers.remove(0); | ||
| if node.command_line.is_using_kes_agent() { |


Content
This PR adds Cardano node discovery to
mithril-setup.The discovery is runtime-agnostic: it finds running
cardano-nodeprocesses and gathers facts through process, systemd, tool, and file probe traits. Linux host implementations inspect/proc, cgroups, node files, and the node executable.The discovery:
cardano-node runcommand-line options, including socket, database, configuration, topology, credentials, listening address, and non-producing-node flags.mainnet,preprod,preview,devnet, or a private network fromnetworkMagic.localRoots[].accessPoints[]and legacyProducers[].cardano-cliexecutable, resolving command-line paths against the node working directory.Discovery attribute provenance
node.pid/procprocess discovery for a runningcardano-nodenode.systemd_unitNonewhen no matching service is foundroleBlockProducerfor an eligible block producer;Relayonly for the sole non-block-producing nodesocket_path--socket-path, resolved against the node working directoryNoneif absent or not parseabledatabase_dir--database-path, resolved against the node working directoryNoneif absentconfig_file--config, resolved against the node working directoryNoneif absenttopology_file--topology, resolved against the node working directoryNoneif absentshelley_genesis_fileShelleyGenesisFile, resolved relative toconfig_fileNonewhen the configuration or file cannot be interpretednetworknetworkMagic, mapped to known Mithril signer names or a private networkNonewhen the genesis cannot be read or parsedpool_peerslocalRoots[].accessPoints[], or legacyProducers[]from the topology filekes_key_path--shelley-kes-key, resolved against the node working directoryNoneif absentoperational_certificate_path--shelley-operational-certificate, resolved against the node working directoryNoneif absentkes_agent_socket--shelley-kes-agent-socket, resolved against the node working directoryNoneif absentbulk_credentials_file--bulk-credentials-file, resolved against the node working directoryNoneif absentlistening_address.ipv4--host-addrfrom the node command lineNoneif absent or invalidlistening_address.ipv6--host-ipv6-addrfrom the node command lineNoneif absent or invalidlistening_address.port--portfrom the node command lineNoneif absent or invalidservice_userNoneif process ownership is unknownnode_versioncardano-node --version, executed with the node process identityNoneif the executable or process identity is unknown or the version output cannot be parsedcardano_cli_pathNoneif no executable is foundLogging
mithril-setup now writes its logs with tracing instead of slog. The tracing subscriber is set up from the existing flags (verbosity, JSON format, output file), so the command line works the same. The logger is no longer passed through the command context: the code calls the tracing macros (info!, debug!, warn!) directly. The JSON output now uses the tracing format instead of Bunyan.
Pre-submit checklist
Comments
The implementation includes a manual Linux host test in
mithril-setup/tests/cardano_discovery_on_host.rs.Issue(s)
Relates to #3677