did-btcr2-js

ADR 128: HTTP Basic Credentials for the IPFS RPC Endpoint

Context

IpfsRpcCasExecutor reads and writes CAS data through the IPFS HTTP RPC API (block/get and block/put). It sent no credentials.

The RPC API of a Kubo node also has administration calls, for example config, shutdown, pin/rm, and repo/gc. So a node on a public network puts the RPC API behind a reverse proxy that requires authentication, usually HTTP Basic auth. The CLI could not use such a node:

  1. --cas-rpc-url https://<node> failed with HTTP 401 for block/put.
  2. Reads failed too. The RPC endpoint wins over the gateway, so each read used block/get, and a failed read returned no content.
  3. A URL with credentials (https://user:pass@<node>) also failed. fetch refuses it: Request cannot be constructed from a URL that includes credentials.

Only a local node with no authentication worked. The test-vector script packages/api/lib/publish-scenarios.ts wrote to an authenticated node with its own request code.

Decision

The api sends HTTP Basic credentials to the IPFS RPC endpoint.

The CLI takes the credentials with the rules of the Bitcoin Core RPC credentials.

Layer User Password
Flag --cas-rpc-user <user> none
Environment BTCR2_CAS_RPC_USER BTCR2_CAS_RPC_PASS
Profile cas.rpcUser cas.rpcPass
Fallback below all layers none the file that BTCR2_CAS_RPC_PASS_FILE names

Alternatives

Consequences

Positive. The CLI publishes to, and reads from, an IPFS node that requires HTTP Basic auth. The CAS credentials follow the rules and the names of the Bitcoin Core RPC credentials, so one explanation covers both.

Negative. The CLI has six new names: one flag, three environment variables, and two profile keys. Incomplete credentials stop each command that resolves a connection for the network, also a resolve that reads no CAS data.

Tests. The api tests cover the header on block/get, block/put, and the probe, no header without credentials, and CasConfig.rpcAuth. The cli tests cover the environment variables, the profile keys, an env: reference, the environment layer, a flag URL without the profile credentials, a flag URL and user with BTCR2_CAS_RPC_PASS_FILE, a user without a password, a password without a user, credentials without a URL, the header of a request through defaultApiFactory, config effective with redaction, config set of the two keys, and the header of the config doctor probe.