Skip to content

Send miner auth token in Ready handshake. - #78

Merged
illuzen merged 14 commits into
mainfrom
illuzen/auth
Aug 13, 2026
Merged

illuzen merged 14 commits into
mainfrom
illuzen/auth

Conversation

@illuzen

@illuzen illuzen commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Require a shared auth token when connecting to a node's miner QUIC endpoint (--auth-token / MINER_AUTH_TOKEN or --auth-token-file / MINER_AUTH_TOKEN_FILE).
  • Send Ready { token } in the initial handshake (matches quantus-miner-api 0.3.0).
  • Wire the same auth into pool-service when --node-addr is set (POOL_AUTH_TOKEN / POOL_AUTH_TOKEN_FILE).

Companion PR

Depends on the chain PR that introduces miner auth and bumps quantus-miner-api to 0.3.0.

Note: this branch temporarily uses path = "../chain2/miner-api" for local development. Before merge, switch the dependency to the published/git tag or branch once the chain change is available.

Test plan

  • cargo check -p miner-cli -p pool-service -p quic-transport -p miner-service
  • Start a node with miner listen port enabled; copy token from logs or miner-auth-token file.
  • quantus-miner serve --node-addr … --auth-token <TOKEN> connects and mines.
  • --auth-token-file <path> works against the node's token file.
  • Missing/wrong token fails to authenticate (node rejects; miner reconnects).
  • (Optional) pool-service with --node-addr requires auth token flags.

illuzen and others added 4 commits August 11, 2026 15:58
Require --auth-token or --auth-token-file when connecting to a node so the
miner matches the node's shared-secret QUIC auth.

Co-authored-by: Cursor <[email protected]>
Require --tls-cert-sha256 or --tls-cert-sha256-file so miners reject
MITM certs instead of accepting any self-signed server certificate.

Co-authored-by: Cursor <[email protected]>
@n13

n13 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Ok the desired architecture for this is:

The node prints an API key on the command line on start, persists it in file - so on restart, node as the same API key

QUIC miners are started with the API key as a parameter to be able to authenticate with the node, it's only used in the initial handshake to set up the secure connection

This protects the node from griefing attacks - example I could make thousands of fake miners, connect to nodes, and feed them bad results, meanwhile I am mining real blocks...

illuzen and others added 3 commits August 12, 2026 15:09
A node/miner protocol mismatch now fails cleanly at the TLS handshake with
"no application protocol" instead of an opaque auth error.

Co-authored-by: Cursor <[email protected]>
The temporary git branch pin is no longer needed now that 0.3.0 is published.

Co-authored-by: Cursor <[email protected]>
@illuzen
illuzen requested a review from n13 August 12, 2026 12:10

@n13 n13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewer model: GPT Sol

Verdict: REQUEST_CHANGES — permanent auth configuration failures currently become endless reconnect loops, and the operator guidance is inconsistent with the shipped node behavior.

Findings:

  1. [P1] Validate permanent auth/TLS configuration before starting long-lived services (crates/miner-cli/src/main.rs:164-178, crates/pool-service/src/main.rs:135-146, crates/quic-transport/src/lib.rs:27-29, crates/miner-service/src/quic.rs:45-63). The CLI/pool resolvers accept any non-empty fingerprint, but parsing happens only inside connect(), whose callers classify every error as transient. On this head, quantus-miner serve --auth-token token --tls-cert-sha256 nope --cpu-workers 1 --gpu-devices 0 starts metrics and a worker, then retries the deterministic parse error forever; pool-service also starts and exposes its HTTP API before retrying forever. Rejected tokens have an additional issue: connect() returns immediately after writing Ready, so both callers reset the delay to one second before Chain PR #662 validates the token and closes with auth failed, causing a permanently misconfigured miner to reconnect every second. Parse/validate the pin and enforce the API's serialized Ready frame limit once at startup, before spawning workers/HTTP; treat explicit auth rejection as fatal or do not reset backoff until authentication is known to have succeeded.

  2. [P2] Make every auth instruction and runnable example match the new required inputs (crates/miner-cli/src/main.rs:24,242-244, crates/pool-service/src/main.rs:35,179-181, README.md:20-48,83-130). The merged node intentionally does not log the auth token, yet the CLI help, pool help, configuration table, and errors still tell operators to copy it from logs. The README's Examples and Docker commands also omit both newly required credentials, so those documented serve commands now exit immediately. Point token guidance only at miner-auth-token, and add the file mounts/flags (or environment variables) to every affected native and container example.

Validation:

  • cargo fmt --all -- --check — passed
  • taplo fmt --check — passed
  • cargo clippy --locked -p quic-transport -p miner-service -p miner-cli -p pool-service --all-targets -- -D warnings — passed
  • cargo test --locked -p quic-transport -p miner-service -p miner-cli -p pool-service — passed (9 existing pool tests; the changed CLI, miner-service, and QUIC transport paths have 0 tests)
  • Manual malformed-pin startup checks reproduced the miner retry loop and pool HTTP-serving behavior above
  • All four GitHub CI checks are green at 227da2464d02ed8497282e1f543cf4ad82d8c71b

illuzen and others added 3 commits August 12, 2026 21:16
…ing.

Validate the fingerprint and Ready frame size at miner/pool startup before
metrics, workers, or HTTP come up. Treat node auth rejection and pin mismatch
as PermanentConnectError (no retry), and only reset reconnect backoff after
the first NewJob proves auth succeeded.

Co-authored-by: Cursor <[email protected]>
The node never logs the auth token; CLI/pool help and every serve/Docker
example now require the chain config files (or env vars) instead of implying
credentials can be copied from logs.

Co-authored-by: Cursor <[email protected]>
@illuzen
illuzen requested a review from n13 August 12, 2026 13:21

@n13 n13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewer model: GPT Sol

Verdict: REQUEST_CHANGES — the earlier auth/TLS startup and reconnect blockers are fixed, but the newly documented Docker commands cannot be parsed by the miner CLI.

Findings:

  1. [P2] Use a node address that the Docker examples can actually pass (README.md:161, README.md:168, README.md:182, crates/miner-cli/src/main.rs:21). All three Docker examples set --node-addr / MINER_NODE_ADDR to host.docker.internal:9833, but the option is a std::net::SocketAddr, which only accepts a numeric IP address. Running the documented value exits immediately with invalid value 'host.docker.internal:9833' ... invalid socket address syntax, before auth or QUIC setup; localhost:9833 fails identically. This leaves every Docker command added by the fix unusable. Either resolve hostnames in the CLI (for example, accept a host/port value and use async address resolution) or document a numeric address/routing setup that is actually reachable from the container, then exercise the published commands.

The previous permanent-misconfiguration findings are otherwise resolved: malformed pins and oversized Ready frames are validated before miner workers, metrics, or pool HTTP start; explicit auth failed closes are treated as permanent; reconnect backoff is not reset before the first NewJob; and the token/fingerprint guidance now matches the merged node behavior.

Validation:

  • cargo fmt --all -- --check — passed
  • taplo fmt --check — passed
  • cargo clippy --locked -p quic-transport -p miner-service -p miner-cli -p pool-service --all-targets -- -D warnings — passed
  • cargo test --locked -p quic-transport -p miner-service -p miner-cli -p pool-service — passed (12 tests)
  • Manual malformed-pin startup checks — miner and pool both exit before starting services
  • Manual README address checks — reproduced immediate parse failures for host.docker.internal:9833 and localhost:9833
  • Companion Chain PR #662 cross-check — quantus-miner/2, DER SHA-256 pin format, Ready { token }, and auth failed close reason match
  • All four GitHub CI checks are green at 361463645d82dd50183a4cb627654d9c9a1dd4fc

Container GPU access is a poor fit for this miner, and the Docker examples
were unusable with SocketAddr (hostnames rejected). Run the native binary
instead.

Co-authored-by: Cursor <[email protected]>
@illuzen
illuzen requested a review from n13 August 12, 2026 13:38

@n13 n13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewer model: GPT Sol

Verdict: REQUEST_CHANGES — the previous Docker-address blocker is resolved, but permanent upstream-auth failure still leaves pool-service running with no/live-stale work, and the checked-in protocol specification now directs clients to an incompatible insecure protocol.

Findings:

  1. [P1] Propagate a permanent upstream failure to the pool process (crates/pool-service/src/main.rs:153-178, crates/pool-service/src/upstream.rs:62-69,109-115). run_node_client returns when the node closes with auth failed or connect() returns PermanentConnectError, but main discards the spawned task's JoinHandle and awaits the HTTP server forever. At startup this leaves /api/session returning no_job_available while the service/container still appears alive; after a previously authenticated connection loses auth, PoolState retains the last job and the HTTP side can keep issuing captcha challenges and tokens against that stale header after the upstream task is dead. The process also cannot pick up a corrected/rotated credential without a manual restart. Supervise the upstream task alongside HTTP and make a permanent error terminate main (or explicitly recover while invalidating the current job and surfacing unhealthy state).

  2. [P2] Update or remove the obsolete top-level protocol specification (EXTERNAL_MINER_PROTOCOL.md:53-85,118-172,199-212,233). The document still specifies only NewJob/JobResult, omits the initial authenticated Ready { token }, gives a serve command without either required credential, says the miner skips certificate verification, advertises the old quantus-miner ALPN, and elsewhere claims a 16 MB frame limit instead of 1 KB. A client implemented from this repository's named protocol specification cannot negotiate quantus-miner/2 or authenticate, and the TLS guidance contradicts the new mandatory pinning. Bring the document fully in line with quantus-miner-api 0.3.0, or replace it with an explicit pointer to the node's maintained MINING.md.

The latest commit otherwise resolves the prior Docker finding by removing the unsupported container path, and the earlier startup-validation/backoff fixes remain intact.

Validation:

  • cargo fmt --all -- --check — passed
  • taplo fmt --check — passed
  • cargo clippy --locked -p quic-transport -p miner-service -p miner-cli -p pool-service --all-targets -- -D warnings — passed
  • cargo test --locked -p quic-transport -p miner-service -p miner-cli -p pool-service — passed (12 tests; the changed miner-service and pool upstream control paths have no direct tests)
  • cargo build --locked -p miner-cli -p pool-service — passed
  • Manual startup checks — the command currently documented in EXTERNAL_MINER_PROTOCOL.md exits 1 for missing auth; malformed pins make both miner and pool exit before long-lived services start
  • Companion Chain PR #662 is merged; ALPN quantus-miner/2, DER SHA-256 pinning, Ready { token }, auth failed, and published quantus-miner-api 0.3.0 match this head
  • All four GitHub CI checks are green at aac3a141332b55ca9d328406f43f20681be11c27

illuzen and others added 3 commits August 12, 2026 21:52
…ing otherwise.

Supervise run_node_client alongside HTTP so a bad token/pin ends the process
instead of leaving a live API on a dead upstream. Node restarts still reconnect
with backoff; the current job is cleared while disconnected so captchas are not
issued against a stale header.

Co-authored-by: Cursor <[email protected]>
The local copy still described the pre-auth protocol (no Ready token, no pin,
old ALPN, 16 MB frames). Canonical docs live in quantus-miner-api and the
node's MINING.md.

Co-authored-by: Cursor <[email protected]>
@illuzen
illuzen requested a review from n13 August 12, 2026 14:00

@n13 n13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewer model: GPT Sol

Verdict: APPROVE — the authenticated, certificate-pinned miner handshake matches the published API and merged node implementation, and no blocking findings remain.

No blocking findings.

The latest commits resolve the prior blockers: pool-service now propagates permanent upstream auth/TLS failures to the process, clears the current job across transient disconnects, and continues reconnecting only for recoverable failures. The obsolete local protocol specification is removed, while the README points operators to the node's maintained MINING.md. Startup validation, DER SHA-256 certificate pinning, quantus-miner/2 ALPN, Ready { token }, auth-rejection handling, and reconnect backoff are consistent across the miner and pool paths.

Validation at 6085dc1696f358f763cac99753f4fb56aa8d41f5:

  • cargo fmt --all -- --check — passed
  • taplo fmt --check — passed
  • git diff --check 2eb0341a7054c41559f51518eed5c41a0575a4f8...6085dc1696f358f763cac99753f4fb56aa8d41f5 — passed
  • cargo clippy --locked -p quic-transport -p miner-service -p miner-cli -p pool-service --all-targets -- -D warnings — passed
  • cargo test --locked -p quic-transport -p miner-service -p miner-cli -p pool-service — passed (12 tests)
  • cargo build --locked -p miner-cli -p pool-service — passed
  • Manual malformed-pin startup checks — miner and pool both exited with status 1 before starting metrics/workers or HTTP
  • Published quantus-miner-api 0.3.0 and merged Chain PR #662 cross-check — message schema, 1 KiB frame cap, ALPN, certificate fingerprint format, auth close reason, and keep-alive requirements match
  • All four GitHub CI checks are green on the reviewed head

@illuzen
illuzen merged commit 2c8d530 into main Aug 13, 2026
4 checks passed
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.

2 participants