Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,68 @@
Notable changes, newest first. Release notes on GitHub list every commit;
this file collects what users and scripts need to know.

## 0.26.0 (2026-11-07)

### New

- `norcube login` signs in through OAuth 2.0: the browser approves the
sign-in and hands the CLI a one-time code over `127.0.0.1`, which the CLI
exchanges with PKCE. The session's tokens no longer pass through the
dashboard page. `login --device` uses the same OAuth server.
- `norcube login --scopes backup.read,langsync.sync` limits a login to the
given scopes (the scopes CI tokens use; the default is `full`). The
login prints the scopes Norcube granted. Commands outside them exit with
code 5 (`insufficient_scope`) and the hint "This login is limited to …;
run `norcube login` for full access". A scope this release doesn't
know yet is still sent; Norcube Auth decides on it.
- `auth sessions list` has a SCOPES column (and `scopes` in JSON);
`whoami` and `auth status` show the login's scopes; `doctor` shows the
credential format and scopes and warns about the older format.
- `norcube logout` revokes the login's refresh token on Norcube (RFC 7009),
which ends its CLI session and removes it from Connected apps. A failure
on the server is reported, and the local sign-out happens anyway.
- `norcube login --force` ends the session it replaces on Norcube (the way
`logout` does) before storing the new one. If that fails, it warns and
signs in anyway.
- An account without an organization can sign in and use `whoami`, `org
list` and `org create`: Norcube Auth tokens are minted without an
organization. Product commands still need one.
- Fewer refreshes: a login refreshes one short-lived CLI token and
exchanges it per service and organization without the profile lock, so
parallel commands no longer queue behind each other.

### Changes

- `norcube upgrade` no longer links the deprecated `x/crypto/openpgp`
package (go-selfupdate 1.7.0).

### Upgrading

- A session from an older version moves to the new sign-in on its first
command, once, without signing in again (`auth status` and `doctor` only
describe the session and leave it as it is). A session made before
Norcube recorded CLI sessions can't be moved: the CLI asks for one
`norcube login`.
- After that move, an **older `norcube` binary** on the same machine must
sign in again: the session it knew was used up by the move.
- An older binary that keeps **its own copy** of the session's refresh
token (for example a copied credentials file) and presents it after the
move counts as a replayed token: Norcube then ends the session, which
signs the upgraded CLI out as well. Upgrade every `norcube` that shares a
session, or sign each in separately.
- Against a Norcube Auth that doesn't offer the OAuth sign-in yet, the CLI
keeps using the older sign-in for this release. CI tokens
(`NORCUBE_TOKEN`) are unchanged.

### Changes for scripts

- The credentials item of a profile has a new format (2): refresh token,
cached CLI access token, granted scopes and a format marker. Tokens per
service are no longer stored between commands.
- `login -o json` has `scopes`; `whoami -o json` and `auth status -o json`
have `scopes`, and `auth status` has `credentialFormat`. The `auth status`
and `auth sessions list` tables have a SCOPES column.

## 0.25.0 (2026-11-06)

### New
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,37 @@ and the Linux packages create it). Add `-o json` and `--query` to any command fo
scripting, and `--org <slug>` to target another organization for one
command.

## Signing in

`norcube login` opens the Norcube sign-in page in your browser. After you
approve the sign-in there, the browser hands the CLI a one-time code over
`127.0.0.1`, which the CLI exchanges for its session (OAuth 2.0 with PKCE:
the session's tokens never pass through the browser). The session is kept
in your OS keyring, per profile.

```bash
norcube login # full access: everything you can do in the dashboard
norcube login --scopes backup.read,langsync.sync # only these scopes (the ones CI tokens use)
norcube login --device # approve on your phone or laptop (SSH, containers)
norcube auth sessions list # every login of your account, with its scopes
norcube logout # revoke the session on Norcube, then forget it here
```

- A login limited with `--scopes` refuses commands outside its scopes with
exit code 5 and says which login would allow them. Your own permissions
in each organization apply either way.
- Every login shows up under Account › CLI sessions and Account ›
Connected apps in the dashboard. Revoking it there, or with
`norcube auth sessions revoke`, stops it at once.
- `norcube login --force` signs in again and ends the previous session on
Norcube.
- `norcube logout` revokes the login's refresh token on Norcube (RFC 7009),
so the session ends everywhere, and then removes it from this machine. If
Norcube can't be reached, it says so and signs out locally anyway.
- A session from an older `norcube` version moves to the new sign-in on its
first command, without signing in again. An older `norcube` binary on the
same machine then has to sign in again; see the [changelog](CHANGELOG.md).

## In CI and on servers

Create a CI token for the organization (scopes limit what it can do, and it
Expand Down
56 changes: 54 additions & 2 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ maps them to stable codes and exit codes.
| `internal/registry` | The service manifest (`services.yaml`, embedded): config key, product name, command name and aliases, OAuth audience, production endpoint, spec location, generated package. |
| `internal/service` | `service.New[T]` resolves the target organization (explicit, `--org`/`NORCUBE_ORG`, a command default such as `.langsync.json`, then the profile), the endpoint, a token source and the shared transport, and returns the typed client. |
| `internal/config`, `internal/resolve` | The config file (profiles, schema v2, migration) and which profile, endpoints, organization, credentials and output a command uses, each with its source. |
| `internal/auth`, `internal/credstore` | Browser login, the per-profile session (OS keyring or a 0600 file), the per-(audience, organization) access-token cache, and the refresh lock that keeps parallel commands from racing. |
| `internal/auth`, `internal/credstore` | Sign-in (OAuth browser and device flows, and the older flows for servers without them), the per-profile session (OS keyring or a 0600 file), the per-(audience, organization) token cache, and the refresh lock that keeps parallel commands from racing. See [Sign-in and tokens](#sign-in-and-tokens). |
| `internal/transport` | The one HTTP client: connect and read timeouts, retries with backoff and `Retry-After`, proxy and CA bundle, User-Agent, and the redacting `--debug` trace. |
| `internal/cmdutil`, `internal/output` | The result path: `--query` (JMESPath), the four output formats, pagination flags, `--wait` polling and `JobFailed`, `Confirm` and `Cancelled`, text and item input from files or stdin, safe file saves, renamed-command notes, and the command annotations (`annotations.go`: effect, flag enums, service) that `nrc commands` reads. |
| `internal/clierr` | Error codes, exit codes and the JSON error shape. |
Expand All @@ -47,6 +47,54 @@ prints the machine-readable command tree (schema in
It reads only the tree, the annotations and the registry, never the
network.

## Sign-in and tokens

The CLI is a public, first-party OAuth 2.0 client of Norcube Auth
(`client_id` `norcube-cli`). Everything it needs is discovered from the
auth URL's RFC 8414 metadata (`/.well-known/oauth-authorization-server`),
cached for a day in the user cache directory.

- **Browser sign-in** (`internal/auth/oauth.go`): authorization code with
PKCE (S256) and a random `state`, redirected to a loopback listener on
`127.0.0.1` and a random port (RFC 8252). The callback must carry the
`state` and the server's issuer (`iss`, RFC 9207) before the code is
exchanged. The authorization request names the scopes, the device's
hostname (`device_name`) and the CLI's User-Agent (`client_user_agent`)
for the consent screen and the session.
- **Device sign-in** (`internal/auth/device.go`): RFC 8628 against the
metadata's `device_authorization_endpoint`, polled at the token endpoint
(`authorization_pending`, `slow_down` adds five seconds, `access_denied`,
`expired_token`).
- **Tokens** (`internal/auth/oauthsession.go`): a sign-in gives a refresh
token and a 5-minute CLI access token, which no product accepts. Every
command exchanges it (RFC 8693) for a token per (audience,
organization; Norcube Auth's own `auth` audience also without one, for
an account that has none yet); exchanges use nothing up, run in parallel without any
lock and are cached in memory only. Refreshing rotates the refresh token,
so it runs under an in-process mutex plus a per-profile lock file, and
the rotated token is stored before the new access token is used. A
refused refresh re-reads the stored token once in case another process
rotated it meanwhile.
- **Credentials** (`internal/auth/keyring.go`): one item per profile.
Format 2 holds the refresh token, the cached CLI access token, the
granted scopes and a format marker; it fits the 2.5 KB Windows Credential
Manager limit, and a store that refuses it gets the blob without the
access token. Format 1 is the older sign-in (a refresh JWT that is
refreshed straight into per-service tokens, cached in the item too). It
is moved to format 2 once, under the lock, by a token exchange of the
refresh JWT; a token Norcube Auth won't move asks for one `norcube login`.
- **Errors**: a dead refresh token is `login_required` (exit 4),
`org_access_denied` is `permission_denied` (exit 5), and
`insufficient_scope` is `insufficient_scope` (exit 5) with a hint naming
the login's scopes.
- **Sign-out**: `logout` revokes the refresh token (RFC 7009); a format 1
session uses the older sign-out endpoint. `login --force` ends the
session it replaces the same way, best effort.
- **Older servers**: when the metadata is missing or doesn't list the token
exchange grant, `login` uses the older sign-in (the web app's
`/cli-login` page and `/auth/cli/device/*`) and sessions refresh the
older way. CI tokens (`NORCUBE_TOKEN`) work as before.

## Adding a service

1. **Manifest.** Add an entry to `internal/registry/services.yaml`: `key`
Expand Down Expand Up @@ -120,7 +168,11 @@ secrets and the one-time setup.

- `internal/cli` runs the real command tree in-process against a fake
backend (`cli_test.go`) with a temporary config, cache and mocked
keyring. Golden files under `internal/cli/testdata/golden` pin every
keyring. `internal/auth/authtest` is a fake Norcube Auth OAuth server
(metadata, authorization redirect, code exchange, refresh with rotation
and reuse detection, token exchange, device flow, session upgrade,
revocation) for sign-in and token tests; a test "browser" follows the
authorization redirect to the CLI's loopback callback. Golden files under `internal/cli/testdata/golden` pin every
output format; update them with `go test ./internal/cli -run TestGolden -update`.
- Contract tests walk the tree: every command has an example, complete
help text and an effect, nothing writes to stdout outside the result
Expand Down
24 changes: 11 additions & 13 deletions docs/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,18 @@ themselves ([README, Verify a release](../README.md#verify-a-release)).
### P12. Authentication security model

**Commitment.**
- **People sign in in the browser.** `nrc login` opens the dashboard,
the person approves while signed in, and the CLI receives its own CLI
session on a loopback listener bound to `127.0.0.1` with a random
`state`; only the dashboard's origin may call back. `--no-browser`
prints the URL; `--device` uses the device authorization flow (a short
code approved on any device). Nothing is pasted.
- **People sign in in the browser.** `nrc login` is a first-party OAuth
2.0 client: the browser approves the sign-in and hands a one-time code
to a loopback listener on `127.0.0.1`, and the CLI exchanges it with
PKCE. The callback checks `state` and `iss`; a request with another
`state` is refused and the login keeps waiting. Metadata endpoints must
share the issuer's origin. `--no-browser` prints the URL; `--device`
uses the device authorization flow (a short code approved on any
device). `--scopes` limits a login. Nothing is pasted.
- **Sessions are visible and revocable.** Each login is a named CLI
session (`nrc auth sessions list | revoke`, and in the dashboard);
`logout` ends it on Norcube Auth, `logout --all` for every profile.
session (`nrc auth sessions list | revoke`, and under Connected apps in
the dashboard); `logout` revokes it on Norcube Auth, `logout --all` for
every profile.
- **One refresh token per profile, short-lived access tokens per
(audience, organization).** Access tokens are minted per service and
cached with an expiry computed from `expires_in` at receipt (immune to
Expand Down Expand Up @@ -504,11 +507,6 @@ server that revokes on reuse), `keyring_concurrency_test.go`,
`citoken_test.go`, `device_test.go`, `browser_test.go`,
`session_check_test.go`, `logout_test.go`.

A first-party OAuth client design (authorization code with PKCE, scoped
logins with `--scopes`, sessions listed under Connected apps, RFC 7009
revocation) was chosen on 2026-10-29 and is in development; until it
ships, the model above is the contract.

### P13. One way to do each thing

**Commitment.** Cross-cutting behaviour has exactly one implementation,
Expand Down
26 changes: 14 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.26.10
require (
github.com/charmbracelet/huh v1.0.0
github.com/charmbracelet/lipgloss v1.1.0
github.com/creativeprojects/go-selfupdate v1.5.2
github.com/creativeprojects/go-selfupdate v1.7.0
github.com/getkin/kin-openapi v0.148.0
github.com/gofrs/flock v0.13.0
github.com/google/uuid v1.6.0
Expand All @@ -25,9 +25,10 @@ require (
)

require (
code.gitea.io/sdk/gitea v0.22.1 // indirect
github.com/42wim/httpsig v1.2.3 // indirect
github.com/Masterminds/semver/v3 v3.4.0 // indirect
code.gitea.io/sdk/gitea v0.25.1 // indirect
github.com/42wim/httpsig v1.2.4 // indirect
github.com/Masterminds/semver/v3 v3.5.0 // indirect
github.com/ProtonMail/go-crypto v1.5.2 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand All @@ -39,6 +40,7 @@ require (
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/cloudflare/circl v1.6.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/danieljoos/wincred v1.2.3 // indirect
github.com/davidmz/go-pageant v1.0.2 // indirect
Expand All @@ -48,11 +50,11 @@ require (
github.com/go-openapi/jsonpointer v0.22.5 // indirect
github.com/go-openapi/swag/jsonname v0.25.5 // indirect
github.com/godbus/dbus/v5 v5.2.2 // indirect
github.com/google/go-github/v74 v74.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/go-github/v86 v86.0.0 // indirect
github.com/google/go-querystring v1.2.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
github.com/hashicorp/go-version v1.8.0 // indirect
github.com/hashicorp/go-version v1.9.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -68,14 +70,14 @@ require (
github.com/rogpeppe/go-internal v1.16.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect
github.com/ulikunitz/xz v0.5.15 // indirect
github.com/ulikunitz/xz v0.5.17 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
gitlab.com/gitlab-org/api/client-go v1.9.1 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
gitlab.com/gitlab-org/api/client-go v1.46.0 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/crypto v0.58.0 // indirect
golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sys v0.49.0 // indirect
golang.org/x/text v0.43.0 // indirect
golang.org/x/time v0.14.0 // indirect
golang.org/x/time v0.15.0 // indirect
)
Loading
Loading