Skip to main content

Module agent_credentials

Module agent_credentials 

Source
Expand description

Per-agent M2M Cognito credential fetch/cache — the client side of per-agent credential binding (the relay side is designed in the private cloud repo).

Historically every agent under one AgentMux login shared the same account-level MUXBUS_TOKEN for every /reactive/* call. This module gets each agent its own bound Cognito client_credentials identity instead:

  1. provision_agent_client(): calls POST /agents/provision using the human’s own PKCE token, receiving a Cognito client_id/client_secret scoped to exactly this (account, agent_id) pair. One-time per agent (idempotent server-side; cached locally in db_agent_credentials).
  2. ensure_agent_credential(): returns a live access_token for that agent, provisioning on first use and re-fetching via client_credentials whenever the cached token has expired. A client the cloud no longer recognizes is dropped and re-provisioned (CredentialFailure::Unrecognized).

Callers (cloud_subscriber.rs) fall back to the shared MUXBUS_TOKEN whenever this returns None — provisioning failure must never block message delivery; that agent simply uses the account-level token.

Functions§

ensure_agent_credential
Get a live per-agent access token, provisioning the Cognito client on first use. Returns None (never an error) on any failure — provisioning being down or an agent not yet migrated must degrade to the caller’s shared-token fallback, not block delivery.
invalidate_binding_mismatched_credential
Same token invalidation as invalidate_cached_token, PLUS a CREDENTIAL_RETRY_COOLDOWN failure record — for a 403 (binding mismatch) specifically, not a plain 401 (expired token).
invalidate_cached_token
Clear a per-agent credential’s cached access token — called by cloud_subscriber when a request using it comes back 401 even though the credential looked locally valid (revoked/rotated server-side out-of-band). Without this, the next InjectAvailable round retries the exact same rejected token forever. Best-effort: a store error here just means the stale token survives until its local expiry, matching the pre-existing failure mode rather than introducing a new one. reagentx P1 on PR #2342.