Skip to content
Closed
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Added
- **`google:*@<domain>` 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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<id>` and `--mcp-static-client-redirect-uris=<uri>[,<uri>]`; the redirect URI must match exactly. Enter that ID, with no secret, in the client's settings.

With any sign-in provider, `--access-users=<principal>[,…]` and `--access-admins=<principal>[,…]` (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:<address>` (in `--google-domain`), `github:<numeric user id>` or `azure:<Entra object id>`; 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=<principal>[,…]` and `--access-admins=<principal>[,…]` (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:<address>` (in `--google-domain`; `google:*@<domain>` in `--access-users` admits the whole domain, sign-in only), `github:<numeric user id>` or `azure:<Entra object id>`; 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.

Expand Down
5 changes: 4 additions & 1 deletion docs/adr/066-access-grants.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:*@<domain>` 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:<numeric user id>`: 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:<id>`.
- `azure:<object id>`: the Entra object id, a GUID, lower-cased. A UPN can be changed or reused;
Expand Down
2 changes: 1 addition & 1 deletion docs/spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ <h3>How a recall shows up</h3>
<tr><td class="k">GitHub sign-in</td><td><code>--github-client-id</code>, <code>--github-client-secret</code>; <code>--github-org</code> restricts access to an organisation and <code>--github-team</code> to a team</td></tr>
<tr><td class="k">Microsoft Entra sign-in</td><td><code>--azure-client-id</code>, <code>--azure-client-secret</code>, <code>--azure-tenant-id</code></td></tr>
<tr><td class="k">Google sign-in</td><td><code>--google-client-id</code>, <code>--google-client-secret</code>, <code>--google-domain</code> (Workspace domain, matched on the ID token <code>hd</code> claim)</td></tr>
<tr><td class="k">Access by principal</td><td><code>--access-users</code> and <code>--access-admins</code> (or <code>ACCESS_USERS</code>, <code>ACCESS_ADMINS</code>) take <code>google:&lt;address&gt;</code>, <code>github:&lt;numeric user id&gt;</code> or <code>azure:&lt;object id&gt;</code>. With either list set, only listed principals sign in, checked at sign-in, on every session use and at <code>/authorize</code>; an admin also gets the write scope. An invalid list stops the server at start (ADR-066)</td></tr>
<tr><td class="k">Access by principal</td><td><code>--access-users</code> and <code>--access-admins</code> (or <code>ACCESS_USERS</code>, <code>ACCESS_ADMINS</code>) take <code>google:&lt;address&gt;</code>, <code>github:&lt;numeric user id&gt;</code> or <code>azure:&lt;object id&gt;</code>; <code>google:*@&lt;domain&gt;</code> in the users list admits the whole <code>--google-domain</code> (sign-in only, never admin). With either list set, only listed principals sign in, checked at sign-in, on every session use and at <code>/authorize</code>; an admin also gets the write scope. An invalid list stops the server at start (ADR-066)</td></tr>
<tr><td class="k">Session</td><td>A 24-hour <code>xray_session</code> cookie. The same token is accepted as <code>Authorization: Bearer</code>, and on a WebSocket upgrade as a subprotocol, because a browser cannot set headers on that handshake</td></tr>
<tr><td class="k">Session to another origin</td><td>A login may hand its token to a UI on a different host through <code>?ui=&lt;origin&gt;</code>, only for origins in <code>--ui-callback-origins</code>. Empty by default</td></tr>
<tr><td class="k">MCP, shared secret</td><td>A Secret named by <code>--mcp-token-secret</code>, key <code>token</code>. Full scope</td></tr>
Expand Down
2 changes: 1 addition & 1 deletion docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:<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) |
| 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=<origin>`, only for origins in `--ui-callback-origins`. Empty by default |
| MCP, shared secret | A Secret named by `--mcp-token-secret`, key `token`. Full scope |
Expand Down
38 changes: 32 additions & 6 deletions internal/xray/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func SetAccessGrants(g AccessGrants) { grants = g }

const principalForms = "google:<address>, github:<numeric user id>, azure:<object id>"

// domainWildcard is the local part that stands for every address in the Workspace
// domain: google:*@<domain>. 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
Expand All @@ -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
}
Expand All @@ -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)
}
Expand All @@ -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")
}
Expand Down Expand Up @@ -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:*@<domain>).
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.
Expand Down
38 changes: 38 additions & 0 deletions internal/xray/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:*@<domain> 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")
}
Loading