diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ce36b4..57e2305 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased] +### Added +- **`google:*@` in `--access-users` admits the whole Workspace domain (ADR-066).** With `--access-admins` set and no users list, only the admins could sign in, so letting a domain in meant naming every address. The wildcard grants sign-in only; in `--access-admins`, or with a `*` anywhere else in an address, the server refuses to start with a message. Before, such an entry was read literally, matched no address and, with the list set, nobody could sign in. + ## [2.10.0] - 2026-11-19 ### Added diff --git a/README.md b/README.md index 835c0b1..28fcaf8 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ To give each MCP client a token of its own, which also makes its writes count as Clients that register themselves (Claude Code) need nothing more: open registration accepts loopback and custom-scheme redirect URIs. A client that is given a client ID and posts the code to its own https callback is pre-registered with `--mcp-static-client-id=` and `--mcp-static-client-redirect-uris=[,]`; the redirect URI must match exactly. Enter that ID, with no secret, in the client's settings. -With any sign-in provider, `--access-users=[,…]` and `--access-admins=[,…]` (or `ACCESS_USERS`, `ACCESS_ADMINS`) name who may sign in and who also gets the admin interface (an MCP token, voice writes), without editing `writeAllowedUsers`. A principal is `google:
` (in `--google-domain`), `github:` or `azure:`; ids rather than logins, because a login can be renamed and re-registered. Once either list is set, only listed principals sign in, whichever provider they use, and the server refuses to start with a principal for a provider that has no client id. +With any sign-in provider, `--access-users=[,…]` and `--access-admins=[,…]` (or `ACCESS_USERS`, `ACCESS_ADMINS`) name who may sign in and who also gets the admin interface (an MCP token, voice writes), without editing `writeAllowedUsers`. A principal is `google:
` (in `--google-domain`; `google:*@` in `--access-users` admits the whole domain, sign-in only), `github:` or `azure:`; ids rather than logins, because a login can be renamed and re-registered. Once either list is set, only listed principals sign in, whichever provider they use, and the server refuses to start with a principal for a provider that has no client id. **Replicas.** The chart runs one. Above one (`replicaCount: 3`) it turns on `--leader-elect`, so one replica runs the sweeps that delete expired memory, and a mutual-TLS mesh over which the replicas share their counters, each person's daily token spend, logins, OAuth client registrations and MCP authorization codes (ADR-068). Run X-Ray in a namespace of its own and limit the mesh port (8085) to the release's pods with a NetworkPolicy. Search-hit pulses, the voice session cap and rate limits are per pod. diff --git a/docs/adr/066-access-grants.md b/docs/adr/066-access-grants.md index ab99770..b23084e 100644 --- a/docs/adr/066-access-grants.md +++ b/docs/adr/066-access-grants.md @@ -26,7 +26,10 @@ configuration, never from code. They work for every sign-in provider: domain, so an address in a secondary domain cannot be listed. A non-ASCII address never matches a list (and signs in as before when no list is set). A Google session's name is the full address so the list can match it; reassigning an address inside Workspace - moves its access with it. + moves its access with it. `google:*@` in `--access-users` admits every address of + `--google-domain`, so a deployment can let the domain in and name its admins one by one. It + grants sign-in only: in `--access-admins`, or with a `*` anywhere else in the address, it fails + start-up. (A `*` read literally would match no address and, with a list set, lock everyone out.) - `github:`: digits only. A GitHub login can be renamed and the old one re-registered by someone else; the numeric id never is. The session id is `github:`. - `azure:`: the Entra object id, a GUID, lower-cased. A UPN can be changed or reused; diff --git a/docs/spec.html b/docs/spec.html index aab7236..ad577c7 100644 --- a/docs/spec.html +++ b/docs/spec.html @@ -495,7 +495,7 @@

How a recall shows up

GitHub sign-in--github-client-id, --github-client-secret; --github-org restricts access to an organisation and --github-team to a team Microsoft Entra sign-in--azure-client-id, --azure-client-secret, --azure-tenant-id Google sign-in--google-client-id, --google-client-secret, --google-domain (Workspace domain, matched on the ID token hd claim) - Access by principal--access-users and --access-admins (or ACCESS_USERS, ACCESS_ADMINS) take google:<address>, github:<numeric user id> or azure:<object id>. With either list set, only listed principals sign in, checked at sign-in, on every session use and at /authorize; an admin also gets the write scope. An invalid list stops the server at start (ADR-066) + Access by principal--access-users and --access-admins (or ACCESS_USERS, ACCESS_ADMINS) take google:<address>, github:<numeric user id> or azure:<object id>; google:*@<domain> in the users list admits the whole --google-domain (sign-in only, never admin). With either list set, only listed principals sign in, checked at sign-in, on every session use and at /authorize; an admin also gets the write scope. An invalid list stops the server at start (ADR-066) SessionA 24-hour xray_session cookie. The same token is accepted as Authorization: Bearer, and on a WebSocket upgrade as a subprotocol, because a browser cannot set headers on that handshake Session to another originA login may hand its token to a UI on a different host through ?ui=<origin>, only for origins in --ui-callback-origins. Empty by default MCP, shared secretA Secret named by --mcp-token-secret, key token. Full scope diff --git a/docs/spec.md b/docs/spec.md index 817f925..8d2e7a8 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -280,7 +280,7 @@ Every route under `/v1` needs a session except the sign-in routes, `/v1/version` | GitHub sign-in | `--github-client-id`, `--github-client-secret`; `--github-org` restricts access to an organisation and `--github-team` to a team | | Microsoft Entra sign-in | `--azure-client-id`, `--azure-client-secret`, `--azure-tenant-id` | | Google sign-in | `--google-client-id`, `--google-client-secret`, `--google-domain` (Workspace domain, matched on the ID token `hd` claim) | -| Access by principal | `--access-users` and `--access-admins` (or `ACCESS_USERS`, `ACCESS_ADMINS`) take `google:
`, `github:` or `azure:`. With either list set, only listed principals sign in, checked at sign-in, on every session use and at `/authorize`; an admin also gets the write scope. An invalid list stops the server at start (ADR-066) | +| Access by principal | `--access-users` and `--access-admins` (or `ACCESS_USERS`, `ACCESS_ADMINS`) take `google:
`, `github:` or `azure:`; `google:*@` in the users list admits the whole `--google-domain` (sign-in only, never admin). With either list set, only listed principals sign in, checked at sign-in, on every session use and at `/authorize`; an admin also gets the write scope. An invalid list stops the server at start (ADR-066) | | Session | A 24-hour `xray_session` cookie. The same token is accepted as `Authorization: Bearer`, and on a WebSocket upgrade as a subprotocol, because a browser cannot set headers on that handshake | | Session to another origin | A login may hand its token to a UI on a different host through `?ui=`, only for origins in `--ui-callback-origins`. Empty by default | | MCP, shared secret | A Secret named by `--mcp-token-secret`, key `token`. Full scope | diff --git a/internal/xray/grants.go b/internal/xray/grants.go index 8e5a6f4..b0583f7 100644 --- a/internal/xray/grants.go +++ b/internal/xray/grants.go @@ -28,6 +28,11 @@ func SetAccessGrants(g AccessGrants) { grants = g } const principalForms = "google:
, github:, azure:" +// domainWildcard is the local part that stands for every address in the Workspace +// domain: google:*@. It grants sign-in only, so --access-users can admit +// the domain while --access-admins names the people who get the admin interface. +const domainWildcard = "*" + var azureOID = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`) // NewAccessGrants parses comma-separated principal lists. A google address must @@ -38,25 +43,25 @@ var azureOID = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f] // same ids the session carries: a login or UPN can be renamed and re-registered. func NewAccessGrants(users, admins, domain string) (AccessGrants, error) { domain = strings.ToLower(strings.TrimSpace(domain)) - u, err := parsePrincipals(users, domain) + u, err := parsePrincipals(users, domain, true) if err != nil { return AccessGrants{}, fmt.Errorf("access users: %w", err) } - a, err := parsePrincipals(admins, domain) + a, err := parsePrincipals(admins, domain, false) if err != nil { return AccessGrants{}, fmt.Errorf("access admins: %w", err) } return AccessGrants{users: u, admins: a}, nil } -func parsePrincipals(list, domain string) ([]string, error) { +func parsePrincipals(list, domain string, wildcard bool) ([]string, error) { var out []string for _, e := range strings.Split(list, ",") { e = strings.TrimSpace(e) if e == "" { continue } - p, err := parsePrincipal(e, domain) + p, err := parsePrincipal(e, domain, wildcard) if err != nil { return nil, err } @@ -70,7 +75,7 @@ func parsePrincipals(list, domain string) ([]string, error) { return out, nil } -func parsePrincipal(e, domain string) (string, error) { +func parsePrincipal(e, domain string, wildcard bool) (string, error) { if !isASCII(e) { return "", fmt.Errorf("%q is not ASCII; use one of %s", e, principalForms) } @@ -85,6 +90,17 @@ func parsePrincipal(e, domain string) (string, error) { if !ok || local == "" { return "", fmt.Errorf("%q is not an address; use one of %s", e, principalForms) } + if strings.Contains(local, domainWildcard) { + // Only the whole-domain form, only where it grants sign-in alone. Any other + // use of * would be taken as a literal and match no address, which with a + // list set locks everyone out. + if local != domainWildcard { + return "", fmt.Errorf("%q: * stands only for the whole domain, google:*@%s", e, domain) + } + if !wildcard { + return "", fmt.Errorf("%q: a domain wildcard grants sign-in only; name each admin", e) + } + } if domain == "" { return "", fmt.Errorf("google principals need --google-domain") } @@ -144,7 +160,17 @@ func (g AccessGrants) allowsUser(userID, username string) bool { return true } p := principalOf(userID, username) - return slices.Contains(g.users, p) || slices.Contains(g.admins, p) + return slices.Contains(g.users, p) || slices.Contains(g.admins, p) || g.domainAdmits(p) +} + +// domainAdmits reports whether a Google principal's address is in a domain the +// users list admits whole (google:*@). +func (g AccessGrants) domainAdmits(p string) bool { + if !strings.HasPrefix(p, "google:") { + return false + } + _, host, ok := strings.Cut(strings.TrimPrefix(p, "google:"), "@") + return ok && slices.Contains(g.users, "google:"+domainWildcard+"@"+host) } // isAdmin reports whether a session gets the admin interface by principal. diff --git a/internal/xray/grants_test.go b/internal/xray/grants_test.go index 6e0bae5..4af1ce9 100644 --- a/internal/xray/grants_test.go +++ b/internal/xray/grants_test.go @@ -335,3 +335,41 @@ func TestNewAccessGrants_BlankListFailsClosed(t *testing.T) { _, err := NewAccessGrants("", " ", "example.com") assert.NoError(t, err, "an unset or whitespace-only value is an empty list") } + +// google:*@ admits the whole Workspace domain in --access-users, so a +// deployment can let the domain in and name its admins one by one. Before it was +// understood, the * was taken literally: it matched no address and, with a list +// set, nobody could sign in. +func TestAccessGrants_DomainWildcardAdmitsTheDomainNotItsAdmins(t *testing.T) { + g, err := NewAccessGrants("google:*@Example.com", "google:boss@example.com", "example.com") + require.NoError(t, err) + + assert.True(t, g.allowsUser("google:1", "alice@example.com"), "anyone in the domain signs in") + assert.True(t, g.allowsUser("google:2", "Bob@EXAMPLE.com"), "case does not matter") + assert.False(t, g.allowsUser("google:3", "mallory@other.test"), "another domain does not") + assert.False(t, g.allowsUser("google:4", "x@sub.example.com"), "a subdomain is not the domain") + assert.False(t, g.allowsUser("google:5", "kK@example.com"), "a non-ASCII address matches nothing") + assert.False(t, g.allowsUser("github:42", "alice@example.com"), "a GitHub session never matches a Google principal") + + assert.False(t, g.isAdmin("google:1", "alice@example.com"), "the wildcard grants sign-in, not the admin interface") + assert.True(t, g.isAdmin("google:9", "boss@example.com"), "an admin named one by one is") +} + +func TestAccessGrants_DomainWildcardIsRefusedWhereItWouldMisleadOrLockOut(t *testing.T) { + for name, tc := range map[string]struct{ users, admins string }{ + "as an admin": {"", "google:*@example.com"}, + "inside a name": {"google:a*@example.com", ""}, + "suffix of a name": {"google:*a@example.com", ""}, + "another domain": {"google:*@other.test", ""}, + "a subdomain": {"google:*@sub.example.com", ""}, + "two stars": {"google:**@example.com", ""}, + "for another provider": {"github:*", ""}, + } { + t.Run(name, func(t *testing.T) { + _, err := NewAccessGrants(tc.users, tc.admins, "example.com") + assert.Error(t, err, "refused at start, with a message, rather than matching nobody") + }) + } + _, err := NewAccessGrants("google:*@example.com", "", "") + assert.Error(t, err, "google principals still need --google-domain") +}