Repository navigation
fluree login / logout: sign a machine in to a fluree.ai account - #2205
Conversation
Sign a machine in to an account service once, without a project, over
the contract `fluree auth login` already uses for remotes: discovery,
the RFC 8628 device grant, and the token exchange.
- An account is not a remote. The sign-in lives in `account.toml` in the
global config dir (0600, replaced atomically), never in a project's
config.toml, and `remote add` refuses an account URL with a hint to
sign in instead.
- Discovery: an `account` object (api_base_url, dashboard_url) and no
top-level api_base_url mark an account service. Documented as "Account
services" in docs/design/auth-contract.md.
- `login` needs the device grant and a refresh token. It sends the host
name as `device_name` for the approval page and has a `--no-browser`
flag. Logging in again signs the previous sign-in out on the server.
- `logout` POSTs {api}/auth/disconnect, then deletes the file.
- `auth status` without --remote shows the sign-in, and works outside a
project.
- `account::session()` returns a fresh access token, refreshing it
through the exchange's refresh_token grant and saving the result.
- Reuses auth.rs's OIDC discovery, device flow and exchange (now
pub(crate)) rather than copying them.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016CjYmNEuWYTradVSiSAz2N
…d sign-in Found running `fluree login` against a deployed account service: - reqwest sends no User-Agent by default, and the AWS WAF common rule set in front of fluree.ai answers 403 to requests without one. Discovery read that as "no sign-in here". The discovery, OIDC-login and login clients now send `fluree/<version>` (`fluree_db_cli::USER_AGENT`), and the test server refuses requests without it. - `fluree logout` after the machine was disconnected from the dashboard said the server "did not confirm" and asked for a dashboard disconnect that had already happened. An `invalid_grant` refresh or an `invalid_state` disconnect now counts as already signed out. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CjYmNEuWYTradVSiSAz2N
|
A few things, none blocking:
|
bplatz
left a comment
There was a problem hiding this comment.
Approving. Keeping the account out of remotes reads right, the credential file handling (0600, atomic replace, no project needed) is careful, and the reuse of the existing device-grant and exchange code is clean.
Some feedback in the comment above — one small bug (logout can't clear an unreadable account.toml), a note for when session() gets callers, and a few smaller items. None blocking.
… take turns, config_stale renews - `fluree logout` removes an `account.toml` it can't read (and warns the server wasn't told); `auth status` reports it instead of failing, and the load error now names `fluree login`. - A refresh holds `account.toml.lock` and re-reads the file once it has it, so two processes near expiry spend the refresh token once (tested with two concurrent sessions; red without the lock). Temp files are named by pid, a per-process counter and the time. - `account::send` makes a call with the sign-in and, on 401 `config_stale` (the account's configuration changed after the token was issued), refreshes and sends it once more. `fluree auth token --account [--refresh]` prints the sign-in's token, renewing it on demand. The contract documents the code. - `auth status` with a sign-in and several remotes says how to see one; other remote-config errors are shown as a warning, not dropped. - The re-login test pins that the previous sign-in, by its own token, is the one signed out. - One `grant_type=refresh_token` call (`account::post_refresh`) serves the account and a remote's refresh. - `--url` must be https, except to localhost or a loopback address. - The auth contract's account example names the issuer under `/v1/oauth`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CjYmSfiNVsRZmcpMicDfq
|
Thanks for the review, @bplatz, all six were right. They're in cddff59 (on top of a merge of
Also: renewing a token after a configuration change. fluree.ai answers
Gate on the pushed head: |
Brings #2247, #2232, #2246, #2248, #2245, #2230, #2205, #2231, #2255, #2219, #2209, #2207, #2190, #2216, #2186, #2215, #2213, #2184, #2210, #2206, #2198, #2187, #2183, #2200, #2193, #2199, #2196 and #2145 into next. Resolutions: - Novelty: main's fact-state trim (a cutoff plus a bounded sweep) and the dictionary's coverage watermark sit on next's graph slots and per-graph OrdMaps. A commit's reification links count toward coverage. Planner stats from segment sums decline under annotations, whose link deltas only the walk counts, and otherwise carry the indexed link counts. - Stats-view identity: the index root's id reaches the snapshot through next's root decoder (`decode` takes the id, as `take_snapshot_metadata` does). `LedgerState::load_record` has a decoding-root form beside `load_decoding_root`. - Transact: #2184's parallel-relationship check runs in next's link cascade, counting the `rdf:reifies` links on the retracted edge that the transaction does not retract itself. Main's bundle `edge_reifiers` is dropped, and `subjects_with_prior_rows` and `enforce_single_target_reifiers` stay deleted. The upsert pre-check takes main's dictionary probe and bounded seek. - Query: geo search resolves the graph's POST tree once at open (pooled graphs keep their filter), an empty manifest when there is none. `branch_or_none` reads the dedicated branch, and the batched joins keep next's pooled lanes. The stats-view key hashes the root id. - Indexer: `apply_dict_novelty` and `compact_forward_streams` take the cycle's compaction budget, so the term dictionary keeps its reserved share. `Prefetched` holds `ContentBytes`. `relocalize_sorted_commit` rewrites next's 20-byte types records. - Disk cache: main's in-flight write registration, with an empty entry still read as crash debris that a write replaces. The process-wide eviction walk stays removed. - Graph import (#2232): fenced CAS and publishes, the seed carries the record's namespace and fence, 32-bit graph ids and next's loaders. An import into a graph of an existing ledger refuses triple terms and edge annotations: the splice merges no triple-term dictionary yet. - Iceberg: `create_iceberg_graph_source` goes with main (a source needs a mapping); the R2RML path keeps next's `model_instance`. - CLI: main's shared import flags without the leaflet flags; `graph import` routes through next's process-wide server routing, and `upload_source_import` serves next's `Destination`. Doc sources read a ledger through the command's open instance. - Tests: sibling ledger ids become distinct names, `genesis_ledger` is awaited, Cypher state dumps include each relationship's `rdf:reifies` link, and the graph-import arena test checks the refusal instead.
This adds
fluree login/fluree logout: signing a machine in to a fluree.ai account, so hosted services can be called from the CLI without a project or a pasted key. The server side lives in fluree.ai, not in this repo. It speaks the same discovery → device grant → token exchange contract thatfluree auth loginalready speaks to Solo stacks (docs/design/auth-contract.md), so most of this is reuse. The difference is where the result lives.The main design question was whether a fluree.ai account should just be a remote (
fluree remote add fluree-ai https://fluree.ai && fluree auth login --remote fluree-ai). I don't think it should. Remotes are Fluree data APIs, soremote addappends/fluree, andquery/list/trackall assume Fluree routes, which leaves a remote half the commands can't use. A remote also stores its tokens in the nearest.fluree/config.toml, which means afluree initfirst and a credential sitting in a project directory. So the account is its own thing:fluree login [--url URL] [--no-browser]reads<url>/.well-known/fluree.json, and requires the newaccountobject (an account service), the device grant, and a refresh token from the exchange. It stores the result inaccount.tomlin the global config dir ($FLUREE_HOME, else the platform dir), written 0600 and replaced atomically. Logging in again signs the previous one out on the server.fluree logoutdoesPOST {account api}/auth/disconnectwith the access token (refreshing it first if needed), then deletes the file. If the server can't be reached it still removes the local copy and says so.fluree auth statuswithout--remotenow shows the sign-in first, then the only remote as before. Outside any project it shows just the sign-in instead of failing on a missing.fluree/. It's still local only and never calls the server. With--remotenothing changes.fluree remote add <url>refuses a URL whose discovery describes an account service, and points atfluree login.account::session()is the piece the next commands will use: an access token with time left, refreshed through the exchange'srefresh_tokengrant and saved. Nothing calls it yet. I deliberately didn't hang it offdoc.remotehere, because that path fills the LLM slots withmodel = "auto", which a Solo stack's gateway resolves but fluree.ai's own/v1/responseswould treat as a literal model name. That needs its own change.On the discovery side (
auth-contract.mdgets an "Account services" section): an account service hasserviceplus anaccountobject (api_base_url,dashboard_url,status_url) and no top-levelapi_base_url, since that field means "Fluree data API" to every CLI. The device request also sends a non-standarddevice_nameform field (the host name) so the approval page can say which machine is asking. RFC 8628 servers ignore it, andfluree auth loginagainst a remote doesn't send it.Reused from
auth.rsrather than copied:discover_oidc_endpoints,run_device_code_flow(now takingdevice_nameandopen_browser),exchange_token(which also keeps the response body, for theaccountsummary), anddecode_token_summary.discover_remotelearned to readaccount.Docs: new
docs/cli/login.mdandlogout.md(README index,SUMMARY.md), plusauth.md,remote.mdand the contract section.Tests:
tests/account_login.rsruns the real binary against an in-process account service (axum). It covers login with no project (pending → grant → exchange,device_namesent, 0600 file, no.fluree/created);auth status; re-login signing the old one out; logout hitting disconnect;remote addrefusing an account URL; and a refresh that keeps an unrotated refresh token.account.rshas unit tests for the file round trip and permissions, the missing file,expparsing, and the hint text.cargo test -p fluree-db-cliandcargo clippy -p fluree-db-cli --all-targetsare clean.I've also run it against the fluree.ai side, deployed to a throwaway sandbox stack. That covered login from an empty directory,
auth status, the token accepted by the account's lanes, refresh,logoutrevoking both the refresh credential and the live token, and a machine disconnected from the dashboard. That run turned up two things, both fixed in the second commit:User-Agentby default, and the WAF in front of fluree.ai answers 403 to requests without one, so discovery saw "no sign-in here". The sign-in clients now sendfluree/<version>(fluree_db_cli::USER_AGENT), and the test server refuses requests without it. The data-plane client inremote_client.rsstill sends none; Solo stacks don't sit behind that WAF, so I've left it alone here.logoutafter a dashboard disconnect claimed the server "did not confirm" the sign-out. It now recognises an already-revoked sign-in.🤖 Generated with Claude Code
https://claude.ai/code/session_016CjYmNEuWYTradVSiSAz2N