feat(security): require the node password to grant Trusted
Demo images / Build & push demo images (push) Successful in 4m22s

Promotion to Trusted is a privilege escalation — a Trusted peer can read
node state, be deployed to, and is exempt from the `!= Untrusted` gates
federation/DWN/messaging use. It must therefore cost a fresh proof that
the person at the keyboard is the operator, not merely that a session
cookie exists. Same reasoning as node.rotate-identity and TOTP setup,
both of which already re-verify.

Both entry points are covered:

- `federation.invite` gates on the RESOLVED level, not on an explicit
  request for Trusted: "Link Your Nodes" sends no `trust_level` at all
  and falls through to the Trusted default. The invite is a bearer grant
  of Trusted to whoever redeems it, so minting it IS the escalation.
  Observer invites are untouched.
- `federation.set-trust` gates only when the peer is not already
  Trusted, so the dropdown re-emitting its own value doesn't demand a
  password for a no-op.

Demotion is deliberately NOT gated: making something less privileged
must never be harder than leaving it alone, or the safe action becomes
the inconvenient one.

The backend is the sole authority on what counts as an escalation — it
returns a `PASSWORD_REQUIRED:`-prefixed error and the UI prompts and
retries only on that, so the rule lives in exactly one place and the
frontend never pre-judges. TrustPasswordModal.vue (modelled on
RotateDidModal.vue) serves both flows. NodeDetailModal's select snaps
back to the node's real level on change, since a cancelled or failed
promotion would otherwise leave the dropdown displaying a level the node
never accepted.

The operator path stamps TrustSource::Manual; set_trust_level grew an
`Option<TrustSource>` so automatic adjustments (the discovery-handshake
demotion safety net) pass None and leave the recorded provenance alone
rather than laundering an uninvited-join peer into looking approved.

Follow-up, deliberately out of scope: `federation.join` also reaches
Trusted when redeeming someone else's Trusted invite, with no re-auth.

Tests: 44/44 federation, 79/79 rpc-client, vue-tsc clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
archipelago
2026-08-03 13:07:21 -04:00
co-authored by Claude Opus 5
parent f0b71f86aa
commit 24ce8b39e8
10 changed files with 587 additions and 32 deletions
@@ -486,6 +486,18 @@ describe('RPCClient convenience methods', () => {
expect(getLastMethod()).toBe('federation.invite')
})
it('federationInvite omits password when none is given', async () => {
mockSuccess({ code: 'ABC', did: 'did:key:z', onion: 'abc.onion' })
await rpcClient.federationInvite('observer')
expect(getLastParams()).not.toHaveProperty('password')
})
it('federationInvite forwards the password for a trusted invite', async () => {
mockSuccess({ code: 'ABC', did: 'did:key:z', onion: 'abc.onion' })
await rpcClient.federationInvite('trusted', 'hunter2')
expect(getLastParams()).toMatchObject({ trust_level: 'trusted', password: 'hunter2' })
})
it('federationJoin calls federation.join', async () => {
mockSuccess({ joined: true, node: {} })
await rpcClient.federationJoin('invite-code')
@@ -510,6 +522,22 @@ describe('RPCClient convenience methods', () => {
expect(getLastMethod()).toBe('federation.set-trust')
})
it('federationSetTrust omits password on demotion', async () => {
mockSuccess({ updated: true, did: 'did:key:z', trust_level: 'observer' })
await rpcClient.federationSetTrust('did:key:z', 'observer')
expect(getLastParams()).not.toHaveProperty('password')
})
it('federationSetTrust forwards the password when promoting', async () => {
mockSuccess({ updated: true, did: 'did:key:z', trust_level: 'trusted' })
await rpcClient.federationSetTrust('did:key:z', 'trusted', 'hunter2')
expect(getLastParams()).toMatchObject({
did: 'did:key:z',
trust_level: 'trusted',
password: 'hunter2',
})
})
it('federationSyncState calls federation.sync-state', async () => {
mockSuccess({ synced: 1, failed: 0, results: [] })
await rpcClient.federationSyncState()
+15 -3
View File
@@ -781,12 +781,18 @@ class RPCClient {
}
// Federation
/** Minting a `trusted` invite requires the node password — the backend
* rejects it with a `PASSWORD_REQUIRED` error until one is supplied.
* Observer invites never need one. */
async federationInvite(
trustLevel: 'trusted' | 'observer' = 'trusted'
trustLevel: 'trusted' | 'observer' = 'trusted',
password?: string,
): Promise<{ code: string; did: string; onion: string; trust_level: string }> {
const params: Record<string, unknown> = { trust_level: trustLevel }
if (password) params.password = password
return this.call({
method: 'federation.invite',
params: { trust_level: trustLevel },
params,
})
}
@@ -855,13 +861,19 @@ class RPCClient {
})
}
/** Promotion TO `trusted` requires the node password — the backend rejects
* it with a `PASSWORD_REQUIRED` error until one is supplied. Demotion is
* never gated: making a peer less privileged must stay easy. */
async federationSetTrust(
did: string,
trustLevel: 'trusted' | 'observer' | 'untrusted',
password?: string,
): Promise<{ updated: boolean; did: string; trust_level: string }> {
const params: Record<string, unknown> = { did, trust_level: trustLevel }
if (password) params.password = password
return this.call({
method: 'federation.set-trust',
params: { did, trust_level: trustLevel },
params,
})
}