Skip to content

Ariadne credentials: several per reply, form and header values, --credential-env (cypkg) - #895

Merged
transfix merged 3 commits into
masterfrom
feat/ariadne-credentials-cypkg
Oct 30, 2026
Merged

transfix merged 3 commits into
masterfrom
feat/ariadne-credentials-cypkg

Conversation

@transfix

@transfix transfix commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

A follow-up to #888 (merged as 276887d), on master.

These are three generic additions to Ariadne's host-owned credentials that cypkg (cy-pca/cypkg, a terminal client for cvcpkg registries written as .ari documents) needs for cvcpkg's device sign-in. The asks are in #888 (comment). With them, a document signs in, refreshes and uses an API token without ever holding a token.

What it adds

1. Several credentials from one reply. capture_auth also takes a list:

(dict "capture_auth" (list (dict "name" "cvcpkg" "field" "access_token")
                           (dict "name" "cvcpkg.refresh" "field" "refresh_token")))
  • Each field becomes its own credential, captured from the URL's origin.
  • Every token is blanked wherever the reply carries it.
  • An "optional" #t field may be missing, since a refresh reply need not rotate the refresh token.
  • A name given twice is an error.

2. A stored credential as a form or header value. Writing (dict "credential" NAME) as a form or headers dict value makes the host fill in the token at send time:

  • percent-encoded in a form, as is in a header (X-Api-Key, say);
  • only for an origin NAME is bound to, like auth:; elsewhere the request isn't sent;
  • echoes of it are blanked, in both spellings;
  • query refuses one, since URLs are logged.

So an RFC 6749 §6 refresh shows the document neither token:

(http-request "POST" "https://cvcpkg.example/v1/auth/token"
  (dict "form" (dict "grant_type" "refresh_token"
                     "refresh_token" (dict "credential" "cvcpkg.refresh"))
        "capture_auth" (list (dict "name" "cvcpkg" "field" "access_token")
                             (dict "name" "cvcpkg.refresh" "field" "refresh_token" "optional" #t))))

3. --credential-env NAME=VAR. This is for API tokens and CI (cvcpkg's CVCPKG_TOKEN). It is repeatable, native only, and implies --net.

  • A policy credential NAME ORIGIN... line must bind NAME, so the launcher, not the document, decides where the token may go.
  • The token is held in memory for the run, ahead of the store file's token for NAME. It is never written to the file, and a capture of NAME replaces it.
  • An unset or empty variable supplies nothing, so a launcher can always pass the flag.
  • A malformed value stops the host, and the error never quotes it.
  • ari info and arigl info list the names it supplied.

The browser path, now in CI

Nothing tested a request from the single-threaded wasm ari, where the verbs run inline and the fetch backend spins on emscripten_sleep. The "ari terminal backend (wasm, node)" job now runs src/ari/tests/net_probe.ari against net_probe_server.py under node. It covers a device sign-in with two tokens, a refresh with a form credential, a fetch with the refreshed token, and a refused origin, and it fails if any token reaches the output.

xhr-shim.cjs is a small XMLHttpRequest over node's fetch, enough for emscripten's Fetch.js. The probe is embedded only with -DCVC_ARI_WASM_TEST_DOCS=ON, so the published page doesn't carry it. The job now also runs when src/cvc/net changes. The shim exercises the page's own cvc::net code and verbs, but not a browser's CORS.

Snapshots wait until the document is idle (from nicotina M0's notes)

  • arigl snapshot, in a window and with --terminal, now waits like ari snapshot. Before, one frame showed a document's first frame, and nicotina's tests passed --frames 60 to work around it.
  • The wait also no longer ends early. It used to stop after three drains with no request in flight, so a program working between two requests (parsing one reply before sending the next) looked idle, and the snapshot could miss the second reply.
  • AppRuntime::idle() now means no async call in flight and no program step waiting to run. AppRuntime::settle(step, max_seconds) runs the host's step until the document has been idle for three steps running, at most 10 s. ari snapshot and both of arigl snapshot's paths use it whenever the network is on.
  • A new ari_net_test case loops between two requests and fails with the old check; the whole suite still runs in about 3 s.
  • arigl builds here only through the wasm-mt tree (no native VTK), where it compiles and links. CI's cvcGL lanes build it natively.

Tests

  • net_policy_test: CredentialStore::provide. It works only for bound names, sits ahead of the file's token, is never written, and gives way to a capture.
  • ariadne_host_test: --credential-env parsing and its errors.
  • ariadne_runtime_test, against a localhost registry:
    • a device reply yields two credentials;
    • a refresh with a form credential sends the refresh token (percent-encoded, %2F checked) and keeps the new access token;
    • no token appears anywhere in the state tree;
    • credential values go only to bound origins and never into a query; a duplicate capture name is refused;
    • an environment token works as a Bearer header and as an X-Api-Key header, and is never in the store file;
    • an unbound name and a malformed value are refused; an unset variable is harmless.
  • ari_net_test: the same device sign-in, refresh and --credential-env, through the built ari, with no output carrying a token.

Local results, rebased on master 276887d (Linux RelWithDebInfo):

  • net_policy_test 23/23, ariadne_host_test 21/21, ariadne_runtime_test 203 passed (one unrelated locale skip), ari_net_test 8/8, state_exec_async_calls_test 47/47;
  • ariadne_loader_test, uri_http_cache_test and net_http_client_test pass unchanged;
  • the new CI step passes locally with the cvcpkg emsdk 5.0.7.

…r values, --credential-env

cypkg (cy-pca/cypkg), a terminal client for cvcpkg registries written as .ari documents, signs in
with cvcpkg's device pairing. Its token reply carries an access and a refresh token, a refresh is
an RFC 6749 section 6 form POST, and CI uses an API token from the environment. #888's credentials
covered one token per reply, sent as a Bearer header; these three generic additions cover the rest
without a token ever reaching the document
(#888 (comment)).

- capture_auth takes a list of {name, field, optional} dicts, one credential each, all captured
  from the URL's origin. Every field is taken first and each token blanked wherever the reply
  carries it, then each is kept. A missing optional field is no error: a refresh reply need not
  rotate the refresh token. A name given twice is an error. captured is true when every required
  field was kept; error names the ones that were not.
- A credential value, (dict "credential" NAME), as a form or headers dict value: the request is
  encoded with a random letters-and-digits placeholder in its place, and the host puts the token
  there as it is sent (percent-encoded in a form, as is in a header), only for an origin NAME is
  bound to, like auth; elsewhere the request is not sent. Echoes are blanked in both spellings. A
  query refuses one (URLs are logged). Any credential option turns off redirect following, and the
  origin is checked against the policy before any token is looked up.
- --credential-env NAME=VAR (repeatable, implies --net, native only): enable_net holds the token in
  VAR as credential NAME for the run, through the new CredentialStore::provide: in memory, ahead
  of the file's token for NAME, never written, replaced by a capture. A policy credential line must
  bind NAME, so the launcher decides where it goes. An unset or empty VAR supplies nothing, so a
  launcher can always pass the flag; a malformed value stops the host without being quoted.
  ari/arigl info list the names it supplied.
- ari and arigl --help, net_intrinsics.h and docs/ARIADNE.md 10.2 and 10.3 describe them.

Tests:
- net_policy_test: provide (bound names only, ahead of the file, never written, replaced by a
  capture, forgotten).
- ariadne_host_test: --credential-env parsing and its errors.
- ariadne_runtime_test, against a localhost registry: a device reply gives two credentials and a
  refresh with a form credential sends the refresh token (percent-encoded) and keeps the new access
  token, no token in the state tree; credential values only for bound origins, never in a query, a
  duplicate capture name refused; an environment token as a Bearer and as an X-Api-Key header,
  never in the store file, an unbound name and a malformed value refused, an unset variable
  harmless.
- ari_net_test: the same device sign-in and refresh, and --credential-env, through the built ari,
  no output carrying a token.
Nothing tested a request from the single-threaded browser build, where the verbs run inline and
the fetch backend spins on emscripten_sleep. The "ari terminal backend (wasm, node)" job now does:

- src/ari/tests/net_probe.ari signs in (two tokens from one reply), refreshes with the refresh token
  as a form credential, fetches with the refreshed token, and is refused another origin;
  net_probe_server.py stands in for the registry.
- xhr-shim.cjs: a small XMLHttpRequest over node's fetch, enough for emscripten's Fetch.js, so the
  page's cvc::net fetch backend runs under node (which has fetch but no XMLHttpRequest).
- CVC_ARI_WASM_TEST_DOCS (off by default) embeds src/ari/tests at /tests in the wasm ari; the job
  turns it on, runs the probe, checks the results and that no token reached the output.
- The job also runs when src/cvc/net or inc/cvc/net change.

Run locally with the cvcpkg emsdk 5.0.7: every check passes.
@transfix
transfix enabled auto-merge (squash) October 30, 2026 05:46
From nicotina M0's notes on #888:
- arigl snapshot (window and --terminal) did not wait for requests as ari snapshot does, so one
  frame showed a document's first frame; nicotina's tests passed --frames 60 instead.
- ari's wait ended after three drains with no async call in flight. A program working between two
  requests (parsing a reply is a sliced data step, not an async call) looked idle then, and the
  snapshot could miss the second reply.

AppRuntime::idle() is now "no async call in flight and no program step waiting to run"
(async_scheduler::has_runnable), and AppRuntime::settle(step, max_seconds) runs a host's step until
the document has been idle for three steps running, at most 10 s. ari snapshot, arigl's terminal
snapshot (a drain) and its window snapshot (a whole frame, the PNG written after) call it when the
network is on.

- ari_net_test SnapshotWaitsThroughWorkBetweenRequests: a document that loops between two requests
  shows both replies in a one-frame snapshot. With idle() back at "no call in flight" it fails
  (the second is empty); the whole suite still runs in about 3 s.
- arigl is built only through the wasm-mt tree here (no native VTK); it compiles and links. CI's
  cvcGL lanes build it natively.
- ari and arigl --help and docs/ARIADNE.md 10.3 say so.
@transfix
transfix merged commit 43f6890 into master Oct 30, 2026
20 of 27 checks passed
@transfix
transfix deleted the feat/ariadne-credentials-cypkg branch October 30, 2026 09:44
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.

1 participant