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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ verbatim as the body of the matching GitHub release.

| Version | Date | Notes |
|---|---|---|
| v0.2.8 | 2026-11-24 | [changelog/v0.2.8.md](changelog/v0.2.8.md) |
| v0.2.7 | 2026-11-23 | [changelog/v0.2.7.md](changelog/v0.2.7.md) |
| v0.2.6 | 2026-11-23 | [changelog/v0.2.6.md](changelog/v0.2.6.md) |
| v0.2.5 | 2026-11-23 | [changelog/v0.2.5.md](changelog/v0.2.5.md) |
Expand Down
24 changes: 24 additions & 0 deletions changelog/v0.2.8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# v0.2.8

Per-identity SSO scopes.

## Added

- **Per-identity SSO scopes.** `GATEWAY_PROXY_AUTH_SCOPES_HEADER` lets an authenticating
reverse proxy send a scope header such as `X-Forwarded-Scopes` alongside the identity
header. One SSO user can be read-only while another gets `read,write`. When the scope
header is configured it is authoritative; a missing, empty or unsupported value fails
closed instead of inheriting the broader `GATEWAY_PROXY_AUTH_SCOPES` default.
- **Read-only admin access is visible in the console.** `/admin/settings` returns the
identity's scopes and `can_write`, so a read-only SSO user or `adm_...` token sees the
console with write actions disabled.

## Changed

- Proxy scope parsing accepts only `read` and `write`; unknown values are rejected with
`403 proxy_scope_invalid`.

## Notes

- Configure the proxy to send the scope header and strip any client-supplied
`X-Forwarded-*` headers. The gateway must remain unreachable except through the proxy.
2 changes: 1 addition & 1 deletion deploy/dokploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ database. The console is always a plain Application.
3. Compose path: `deploy/dokploy/compose.yml`.
4. **Trigger Type: On Tag**, with auto-deploy enabled. The gateway is a production
service; a pull request or a push to `Develop` must not restart it. A release tag
(`v0.2.7`) is the only thing that deploys — see "When it deploys" below.
(`v0.2.8`) is the only thing that deploys — see "When it deploys" below.
5. **Environment** (the compose file references all of these):

```bash
Expand Down
2 changes: 1 addition & 1 deletion docs/SPRING-AI.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on Spring AI; the gateway never depends on it.
<dependency>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-spring-ai</artifactId>
<version>0.2.7</version>
<version>0.2.8</version>
</dependency>
```

Expand Down
36 changes: 36 additions & 0 deletions docs/SSO.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,42 @@ skip its token screen — a signed-in browser lands straight on the dashboard.
Every admin write is audited against the identity the proxy supplied, so
`GET /admin/audit` answers "who changed this" with an email, not "shared-admin".

## Per-user read-only roles

By default every proxy-authenticated identity gets the same scopes. To make one
SSO user read-only while another can write, have the proxy send scopes per
identity as well:

```yaml
GATEWAY_PROXY_AUTH: "true"
GATEWAY_PROXY_AUTH_HEADER: X-Forwarded-User
GATEWAY_PROXY_AUTH_SCOPES_HEADER: X-Forwarded-Scopes
# Fallback only when SCOPES_HEADER is not configured:
GATEWAY_PROXY_AUTH_SCOPES: "read,write"
```

The proxy must then send both headers on every `/admin/**` request:

```text
X-Forwarded-User: viewer@example.com
X-Forwarded-Scopes: read
```

`X-Forwarded-Scopes: read,write` grants writes. When `SCOPES_HEADER` is
configured it is **authoritative**: a missing, empty or unsupported scope header
fails closed (`401 proxy_scope_missing` / `403 proxy_scope_invalid`) instead of
falling back to the broader `GATEWAY_PROXY_AUTH_SCOPES` default.

The admin console reflects this automatically: `/admin/settings` returns the
per-identity scopes and `can_write`, so a read-only user sees the console but
every mutation button is disabled.

Configure the header mapping in your IdP/proxy. For Authentik, a property mapping
on the proxy provider can emit `X-Forwarded-Scopes` from group membership; for
oauth2-proxy/Keycloak, map a group or realm role to the same header. The gateway
does not read groups or roles itself — it trusts the header, exactly like the
identity header.

## Authentik (recommended, self-hosted with Dokploy)

1. Authentik → **Providers → Create → Proxy**, mode *Forward auth (single application)*.
Expand Down
2 changes: 1 addition & 1 deletion path-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.7</version>
<version>0.2.8</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public static ApiException forbidden(String message) {
return new ApiException(403, "permission_error", "forbidden", message);
}

public static ApiException forbidden(String message, String code) {
return new ApiException(403, "permission_error", code, message);
}

public static ApiException notFound(String message, String code) {
return new ApiException(404, "invalid_request_error", code, message);
}
Expand Down
29 changes: 27 additions & 2 deletions path-gateway/src/main/java/com/anindra/path/config/AuthFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,16 @@ private void requireProxyIdentity(HttpServletRequest request) {
"proxy_identity_missing");
}
java.util.Set<String> scopes = java.util.Arrays.stream(
props.getProxyAuth().getScopes().split(","))
scopeSource(request).split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(String::toLowerCase)
.filter(s -> s.equals("read") || s.equals("write"))
.collect(java.util.stream.Collectors.toSet());
if (scopes.isEmpty()) {
throw ApiException.forbidden(
"The proxy supplied no supported admin scope (read/write).",
"proxy_scope_invalid");
}
request.setAttribute(ADMIN_PRINCIPAL_ATTR,
new com.anindra.path.admin.TenancyService.Principal(identity.trim(), scopes));
boolean mutating = !"GET".equalsIgnoreCase(request.getMethod())
Expand All @@ -135,6 +141,25 @@ private void requireProxyIdentity(HttpServletRequest request) {
}
}

/**
* The global scope default, or the per-identity header when {@code scopes-header} is
* configured. When the header is configured it is authoritative: a missing value fails
* closed instead of silently inheriting a broader default.
*/
private String scopeSource(HttpServletRequest request) {
String scopesHeader = props.getProxyAuth().getScopesHeader();
if (scopesHeader != null && !scopesHeader.isBlank()) {
String provided = request.getHeader(scopesHeader);
if (provided == null || provided.isBlank()) {
throw ApiException.unauthorized(
"Admin access requires the proxy to send " + scopesHeader + ".",
"proxy_scope_missing");
}
return provided;
}
return props.getProxyAuth().getScopes();
}

private boolean isPublicModelsRequest(HttpServletRequest request) {
return props.isPublicModels()
&& "GET".equalsIgnoreCase(request.getMethod())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ public static class ProxyAuth {
private String header = "X-Forwarded-User";
/** Scopes granted to a proxy-authenticated identity. */
private String scopes = "read,write";
/**
* Optional header carrying per-identity scopes. When set, the proxy must send it for
* every admin request; a missing/empty header fails closed instead of inheriting
* the broader {@link #scopes} default. Use it to give one SSO user read-only access
* while another can write.
*/
private String scopesHeader = "";
}

@Getter
Expand Down
1 change: 1 addition & 0 deletions path-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ gateway:
enabled: ${GATEWAY_PROXY_AUTH:false}
header: ${GATEWAY_PROXY_AUTH_HEADER:X-Forwarded-User}
scopes: ${GATEWAY_PROXY_AUTH_SCOPES:read,write}
scopes-header: ${GATEWAY_PROXY_AUTH_SCOPES_HEADER:}
admin-auth:
max-failures: ${GATEWAY_ADMIN_AUTH_FAILURES:10}
window: ${GATEWAY_ADMIN_AUTH_WINDOW:5m}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.anindra.path;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
* Per-identity SSO scopes: the proxy sends both the user and a scope header. The header
* is authoritative, so a viewer can read and an admin can write without sharing one
* global scope set.
*/
@SpringBootTest(properties = {
"spring.datasource.url=jdbc:h2:mem:proxyauthscopes;MODE=PostgreSQL;DB_CLOSE_DELAY=-1",
"spring.jpa.hibernate.ddl-auto=validate",
"gateway.admin-token=test-admin",
"gateway.bootstrap-demo-key=false",
"gateway.master-key-path=./target/test-master.key",
"gateway.proxy-auth.enabled=true",
"gateway.proxy-auth.header=X-Forwarded-User",
"gateway.proxy-auth.scopes=read,write",
"gateway.proxy-auth.scopes-header=X-Forwarded-Scopes"
})
@AutoConfigureMockMvc
class ProxyAuthScopesHeaderTest {

@Autowired
private MockMvc mvc;

@Test
void missingScopeHeaderFailsClosed() throws Exception {
mvc.perform(get("/admin/providers").header("X-Forwarded-User", "viewer@example.com"))
.andExpect(status().isUnauthorized())
.andExpect(jsonPath("$.error.code").value("proxy_scope_missing"));
}

@Test
void readScopeCanReadButCannotWrite() throws Exception {
mvc.perform(get("/admin/settings")
.header("X-Forwarded-User", "viewer@example.com")
.header("X-Forwarded-Scopes", "read"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.scopes[0]").value("read"))
.andExpect(jsonPath("$.can_write").value(false));

mvc.perform(get("/admin/providers")
.header("X-Forwarded-User", "viewer@example.com")
.header("X-Forwarded-Scopes", "read"))
.andExpect(status().isOk());

mvc.perform(post("/admin/providers")
.header("X-Forwarded-User", "viewer@example.com")
.header("X-Forwarded-Scopes", "read")
.contentType("application/json")
.content("{\"slug\":\"viewer-nope\",\"type\":\"openai\",\"base_url\":\"https://example.test/v1\"}"))
.andExpect(status().isForbidden());
}

@Test
void writeScopeCanWrite() throws Exception {
mvc.perform(get("/admin/settings")
.header("X-Forwarded-User", "admin@example.com")
.header("X-Forwarded-Scopes", "read,write"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.can_write").value(true));

mvc.perform(post("/admin/providers")
.header("X-Forwarded-User", "admin@example.com")
.header("X-Forwarded-Scopes", "read,write")
.contentType("application/json")
.content("{\"slug\":\"admin-ok\",\"type\":\"openai\",\"base_url\":\"https://example.test/v1\"}"))
.andExpect(status().isOk());
}

@Test
void unsupportedScopeHeaderFailsClosed() throws Exception {
mvc.perform(get("/admin/providers")
.header("X-Forwarded-User", "viewer@example.com")
.header("X-Forwarded-Scopes", "admin"))
.andExpect(status().isForbidden())
.andExpect(jsonPath("$.error.code").value("proxy_scope_invalid"));
}
}
2 changes: 1 addition & 1 deletion path-spring-ai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.7</version>
<version>0.2.8</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.7</version>
<version>0.2.8</version>
<packaging>pom</packaging>
<name>path-parent</name>
<description>Build parent for Path, the provider-agnostic LLM gateway, and its Spring AI adapter</description>
Expand Down
Loading