Skip to content

feat(auth): let a signed scheduler request name the node it is for - #1307

Merged
odesenfans merged 4 commits into
mainfrom
od/node-bound-allocation-auth
Oct 22, 2026
Merged

odesenfans merged 4 commits into
mainfrom
od/node-bound-allocation-auth

Conversation

@odesenfans

Copy link
Copy Markdown
Contributor

The Aleph-EIP191-V1 payload gains an optional node_hash. A node that receives one checks it against its own hash and refuses any other, including when it has not resolved its own hash yet. A payload without the field is accepted as before, so the scheduler side (aleph-im/aleph-vm-scheduler#223) can roll out in either order; requiring the field is a follow-up once every scheduler sends it.

scripts/sign_allocation_request.py takes --node-hash for callers that want the same binding. Tests cover match, case-insensitive match, mismatch, unresolved own hash, missing node identity, non-string value, absent field, and a payload whose node was rewritten after signing.

🤖 Generated with Claude Code

@foxpatch-aleph foxpatch-aleph left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The verifier logic is correct and thoughtfully fail-closed (absent field accepted for rollout, non-string rejected, unresolved own hash refuses, case-insensitive hex match, no response-shape oracle, and node_hash is inside the signed bytes so signature and replay cache both cover it). The blocking issue is that all 8 new tests are missing @pytest.mark.asyncio: no asyncio_mode=auto exists in pyproject, any conftest, or CI, so pytest skips them all (verified: '71 passed, 8 skipped' with PytestUnhandledCoroutineWarning), meaning the PR's claimed coverage for the new security behavior never executes and CI cannot catch it. The assertions are correct (all pass under --asyncio-mode=auto); adding the marker to each test, matching the convention of the 50 existing marked tests, resolves this. One minor nit on the signing script's empty-string handling.

tests/supervisor/views/test_allocation_auth.py (line 1047): All 8 new node-binding tests (lines 1047-1088) are missing @pytest.mark.asyncio. This repo runs pytest-asyncio in strict mode (no asyncio_mode = auto in pyproject, any conftest, or the CI invocation), so these tests are silently skipped — I confirmed: 71 passed, 8 skipped with PytestUnhandledCoroutineWarning: async def functions are not natively supported and have been skipped. Since skips don't fail CI, the new security behavior ships with zero executing assertions. Every one of the 50 pre-existing async tests in this file carries the marker; please add it to each new test. They all pass once actually run (--asyncio-mode=auto gives 9 passed), so this is purely the missing decorators.

scripts/sign_allocation_request.py (line 41): Minor: if node_hash: makes --node-hash "" silently sign an unbound payload, which every node accepts — the opposite of what the caller asked for. if node_hash is not None: would emit "node_hash": "" instead, which every node rejects, turning the typo into a loud failure rather than a quiet drop of the binding.

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.63%. Comparing base (cfb6fe5) to head (40e5ce9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1307      +/-   ##
==========================================
+ Coverage   88.61%   88.63%   +0.02%     
==========================================
  Files         201      201              
  Lines       28821    28878      +57     
  Branches     1697     1699       +2     
==========================================
+ Hits        25539    25596      +57     
  Misses       2963     2963              
  Partials      319      319              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The Aleph-EIP191-V1 payload gains an optional node_hash. A node that
receives one checks it against its own hash and refuses any other; a
payload without it is accepted as before, so schedulers can start
sending it at their own pace. The signing script takes --node-hash for
callers that want the same.
@odesenfans
odesenfans force-pushed the od/node-bound-allocation-auth branch from ce29e26 to 1fc883a Compare October 22, 2026 13:23
pytest-asyncio runs in strict mode here, so the eight new tests were
collected and skipped; CI passed on no assertions.
…bound one

if node_hash: dropped the field on an empty string, so the caller who
asked for a binding got a payload every node accepts.

@foxpatch-aleph foxpatch-aleph left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct, fail-closed implementation of optional node binding for the Aleph-EIP191-V1 payload, with thorough test coverage and accurate docs. I verified all eight binding behaviors by executing the verifier directly (the new async tests are skipped only in this sandbox for lack of pytest-asyncio); the check is correctly ordered before the replay-cache write, uses the same node-identity access pattern as existing views, and rejects non-string values and unresolved own hashes. The opt-in nature of the field is the acknowledged rollout plan; until it is required, an authorized signer can still send unbound payloads to any node. Two non-blocking nits: the hex comparison is exact modulo case and would silently fail on a 0x-prefix asymmetry, and the scheduler-facing doc omits that a node with an unresolved own hash refuses all bound payloads.

src/aleph/vm/agent/views/allocation_auth.py (line 139): The comparison is exact modulo case, so a 0x prefix on either side — an operator setting NODE_HASH=0x..., or a scheduler quoting the hash that way — silently fails the binding with a uniform 401 that is hard to distinguish from a bad signature. Consider normalizing both sides (e.g. .removeprefix("0x").lower()) or documenting that the field must be the bare hex item_hash.

doc/scheduler-allocations.md (line 14): The new sentence covers the happy path only. Consider adding half a sentence noting that a node which has not resolved its own hash yet (no NODE_HASH, empty cache, discovery pending) refuses every bound payload until it does, so a freshly provisioned node answers 401 to bound requests. The docstring in allocation_auth.py states this, but this is the scheduler-facing doc where an operator debugging those 401s will look first.

@foxpatch-aleph foxpatch-aleph left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct, fail-closed implementation of optional node-bound allocation auth. The payload field is signature-covered, checked before crypto and before the replay cache records the payload (so a refusal during hash resolution does not burn a retry), and every ambiguous case (missing identity, unresolved own hash, non-string value) refuses. I verified the riskiest interaction — reading request.app on a request the decorator cloned — against aiohttp 3.10.11 (clone propagates _match_info, which backs .app) and via the already-shipped allocations_v2 handler doing the same read on the cloned path; end-to-end script-to-verifier interop also behaves as documented. All 79 tests pass. Only non-blocking nits remain: the wrong-node refusal is unlogged (an operator cannot distinguish it from a bad key once the field becomes mandatory), the new case-insensitive comparison diverges from the case-sensitive per-message binding in views/init.py:931, and --node-hash could hint that the value must be the bare hash.

src/aleph/vm/agent/views/allocation_auth.py (line 214): A wrong-node refusal is completely silent, while every other rejection here is either logged or self-evident. Once the follow-up makes node_hash mandatory, a node whose hash never resolves (no NODE_HASH, empty cache, discovery failing with multiple matches) will 401 every scheduler request with the generic invalid-token body and nothing in the log to distinguish it from a key problem — contrast the message-level binding at views/init.py:930, which answers an explicit 503 for exactly this state. Consider a logger.info/debug when _node_binding_ok fails, especially on the own is None branch.

src/aleph/vm/agent/views/allocation_auth.py (line 139): Minor consistency observation: this binding is case-insensitive while the pre-existing per-message node binding at views/init.py:931 (str(required_node_hash) != node_hash) is case-sensitive. Harmless for lowercase hex item hashes from the aggregate, but the codebase now has two notions of same-node; if the case-insensitive one is the intended semantics, the message-level check may deserve the same treatment (or a comment tying them together).

scripts/sign_allocation_request.py (line 57): The value is passed through verbatim, and anything that is not the bare hash (e.g. a 0x prefix or stray whitespace) fails closed at the node with the generic 401, which is confusing from a shell. A hint like bare item hash, as the corechannel aggregate lists it in the help text would match the doc and save an operator a debugging round-trip.

@odesenfans
odesenfans merged commit 5baf4be into main Oct 22, 2026
19 of 20 checks passed
@odesenfans
odesenfans deleted the od/node-bound-allocation-auth branch October 22, 2026 15:17
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