From a63f7c0faabcd577771659c9a45fab959d80dd28 Mon Sep 17 00:00:00 2001
From: Matthew Daubney
Date: Tue, 20 Oct 2026 11:42:01 +0100
Subject: [PATCH] Hardening: session expiry and sealed handling, request
timeout, list states, a11y, tested admin policy, security headers, README
Co-Authored-By: Claude Sonnet 5.5
---
README.md | 116 +++++++++++++++-----
docs/PLAN.md | 2 +-
docs/envbao-admin.hcl | 29 +++++
nginx.conf | 8 ++
src/App.tsx | 2 +
src/Layout.tsx | 22 +++-
src/api/SessionGuard.test.tsx | 121 +++++++++++++++++++++
src/api/SessionGuard.tsx | 48 ++++++++
src/api/adminPolicy.integration.test.ts | 100 +++++++++++++++++
src/api/bao.test.ts | 17 +++
src/api/bao.ts | 15 ++-
src/api/session.tsx | 42 ++++++-
src/api/useSession.ts | 7 ++
src/docs.test.ts | 14 +++
src/features/access/AccessEditor.test.tsx | 8 +-
src/features/access/AccessEditor.tsx | 5 +-
src/features/connect/ConnectPage.test.tsx | 9 +-
src/features/connect/ConnectPage.tsx | 4 +-
src/features/identities/EntitiesTab.tsx | 12 +-
src/features/identities/GroupsTab.tsx | 12 +-
src/features/identities/IdentitiesPage.tsx | 4 +-
src/features/identities/TokensTab.test.tsx | 4 +-
src/features/identities/TokensTab.tsx | 8 +-
src/features/identities/UsersTab.test.tsx | 6 +-
src/features/identities/UsersTab.tsx | 12 +-
src/features/shared/ListState.tsx | 13 +++
src/index.css | 32 ++++++
src/routes.test.tsx | 17 ++-
src/test/providers.tsx | 7 ++
src/test/queryClient.ts | 3 +
30 files changed, 623 insertions(+), 76 deletions(-)
create mode 100644 docs/envbao-admin.hcl
create mode 100644 src/api/SessionGuard.test.tsx
create mode 100644 src/api/SessionGuard.tsx
create mode 100644 src/api/adminPolicy.integration.test.ts
create mode 100644 src/docs.test.ts
create mode 100644 src/features/shared/ListState.tsx
create mode 100644 src/test/providers.tsx
create mode 100644 src/test/queryClient.ts
diff --git a/README.md b/README.md
index b132abf..f51412e 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,23 @@ Licensed under the [BSD 3-Clause License](LICENSE).
The UI talks directly to the OpenBao HTTP API from the browser. There is no backend.
+## What it does
+
+- **Connect** with a token or a userpass login. Refuses sealed or uninitialised servers, and explains CORS and connection problems.
+- **Identities**: create, edit and delete userpass users, identity entities (with userpass aliases) and groups; create, list and revoke tokens. A new token's value is shown once.
+- **Secrets**: browse KV v2 mounts and paths (names only; secret values are never read) and see which identities can reach a secret, through which policy, with which capabilities.
+- **Access**: from an identity's **Access** button, grant it capabilities on a secret path (globs allowed) or revoke them, without writing policy HCL.
+- **Graph**: Identity → Policy → Path graph, filterable by identity and path. Click a policy→path edge to revoke that grant.
+
+## Using it
+
+1. **Connect**: enter the OpenBao URL and a token (or userpass credentials).
+2. **Identities → Users** (or Entities / Groups): create someone.
+3. Click **Access** on that row, pick a secrets engine, enter a secret path such as `app/*`, tick the capabilities and **Grant**. The path is a KV path *within the mount*; EnvBao writes the `data/` and `metadata/` policy paths for you.
+4. Check the result under **Secrets** (select the secret) or **Graph**.
+
+Your session lasts as long as the token. When it expires, is revoked, or OpenBao is sealed, you'll see a banner with a link to sign in again. Reloading the page signs you out: the token is only held in memory.
+
## Quick start with Docker
```sh
@@ -67,28 +84,52 @@ bao secrets enable -path=secret -version=2 kv # skip if already mounted
### Admin policy for the UI
-Least privilege for the account that uses the UI:
+Least privilege for the account that uses the UI. The same policy is kept in [`docs/envbao-admin.hcl`](docs/envbao-admin.hcl), and the integration tests run every UI operation with only this policy, so it is known to be sufficient:
```hcl
-path "sys/policies/acl/*" { capabilities = ["create", "read", "update", "delete", "list"] }
-path "sys/policies/acl" { capabilities = ["list"] }
-path "auth/userpass/users/*" { capabilities = ["create", "read", "update", "delete", "list"] }
-path "auth/userpass/users" { capabilities = ["list"] }
-path "auth/token/create" { capabilities = ["create", "update"] }
-path "auth/token/lookup" { capabilities = ["update"] }
-path "auth/token/accessors" { capabilities = ["list"] }
+# Least-privilege policy for the account that uses EnvBao Admin.
+# Adjust "secret" if your KV v2 mount has a different path.
+
+# Policies: list, read, create/update and delete (managed `envbao-*` and read-only viewing of the rest)
+path "sys/policies/acl" { capabilities = ["list"] }
+path "sys/policies/acl/*" { capabilities = ["create", "read", "update", "delete"] }
+
+# Userpass users
+path "auth/userpass/users" { capabilities = ["list"] }
+path "auth/userpass/users/*" { capabilities = ["create", "read", "update", "delete"] }
+
+# Identity entities, aliases and groups
+path "identity/entity/name" { capabilities = ["list"] }
+path "identity/entity/name/*" { capabilities = ["create", "read", "update", "delete"] }
+path "identity/entity-alias" { capabilities = ["create", "update"] }
+path "identity/entity-alias/id/*" { capabilities = ["read", "delete"] }
+path "identity/group/name" { capabilities = ["list"] }
+path "identity/group/name/*" { capabilities = ["create", "read", "update", "delete"] }
+
+# Tokens: create, list (needs sudo in OpenBao), inspect and revoke by accessor
+path "auth/token/create" { capabilities = ["create", "update"] }
+path "auth/token/accessors" { capabilities = ["list", "sudo"] }
+path "auth/token/lookup-accessor" { capabilities = ["update"] }
path "auth/token/revoke-accessor" { capabilities = ["update"] }
-path "identity/*" { capabilities = ["create", "read", "update", "delete", "list"] }
-path "sys/mounts" { capabilities = ["read"] }
-path "secret/metadata/*" { capabilities = ["list"] }
-path "sys/capabilities" { capabilities = ["update"] }
+
+# Discovery: mounted auth methods and secrets engines, and KV v2 metadata for the secret browser
+path "sys/auth" { capabilities = ["read"] }
+path "sys/mounts" { capabilities = ["read"] }
+path "secret/metadata/*" { capabilities = ["list"] }
```
+Notes:
+
+- Listing token accessors needs `sudo` in OpenBao, so the Tokens tab needs it on `auth/token/accessors`.
+- Creating **orphan** tokens (the "Orphan" checkbox) needs `sudo` on `auth/token/create`. It is deliberately not granted above; add `"sudo"` there if you want it.
+- If your KV v2 mount is not `secret/`, change `secret/metadata/*`.
+- The account can create policies and attach them to identities, which is effectively the power to grant access to anything. Treat it as an administrator.
+
### Admin login
```sh
-bao policy write envbao-admin envbao-admin.hcl
-bao write auth/userpass/users/admin password=... policies=envbao-admin
+bao policy write envbao-admin docs/envbao-admin.hcl
+bao write auth/userpass/users/admin password=... token_policies=envbao-admin
# or
bao token create -policy=envbao-admin
```
@@ -104,7 +145,7 @@ npm run build
This produces a static `dist/` directory. Serve it with any static host, with an SPA fallback to `index.html`. Use HTTPS: the OpenBao token is held in the browser, and browsers block mixed content from an HTTPS page to an HTTP OpenBao.
-nginx:
+nginx (the bundled [`nginx.conf`](nginx.conf), used by the Docker image, also sets security headers):
```nginx
server {
@@ -125,19 +166,40 @@ envbao.example.com {
}
```
-The OpenBao URL is entered on the Connect screen. Add the UI's origin to OpenBao's CORS allowed origins (see [CORS](#cors)).
+The OpenBao URL is entered on the Connect screen; there is no build-time or runtime configuration. Add the UI's origin to OpenBao's CORS allowed origins (see [CORS](#cors)).
-CI runs on Gitea Actions (`.gitea/workflows/`): lint, test, build.
+The bundled `nginx.conf` sends a Content-Security-Policy. Its `connect-src` allows any `http:`/`https:` origin because the OpenBao address is chosen at runtime; if you always use one OpenBao, tighten `connect-src` to that address.
+
+### Container image
+
+```sh
+docker build -t envbao-admin .
+docker run -p 8080:80 envbao-admin
+```
+
+## Development
+
+```sh
+npm install
+npm run dev # http://localhost:5173
+npm test # unit tests
+npm run lint
+npm run build
+BAO_ADDR=http://127.0.0.1:8200 BAO_TOKEN=root npm run test:integration # against a dev OpenBao
+```
+
+The integration tests need a dev server with userpass available (they enable it if missing) and a KV v2 mount at `secret/` (the dev-mode default). They create and delete their own uniquely named objects, but run them against a throwaway instance, not a real one.
+
+CI runs on Gitea Actions (`.gitea/workflows/ci.yml`): lint, test and build, plus an integration job against an OpenBao dev container.
## Limitations
-- Browser-direct access means CORS must be enabled on OpenBao, and the token lives in the browser (in memory; sessionStorage optional).
-- No server-side audit trail beyond OpenBao's own audit log.
-- KV v2 only.
-- Only userpass auth, tokens and identity entities/groups are supported.
-- Access is granted by writing one managed policy per user, entity or group, named `envbao--` (for example `envbao-user-alice`). A managed policy that is edited outside EnvBao becomes read-only in the UI. Other policies are always shown read-only.
-- Tokens cannot be granted access after creation (OpenBao fixes a token's policies when it is created), so choose their policies when creating them.
-- Grants are KV v2 only: they write `/data/...` rules for read/create/update/delete and `/metadata/...` for list.
-- The access model follows OpenBao's "most specific path wins" rule, so a broader rule never adds to or overrides a more specific one.
-- Glob and templated policy paths are approximated.
-- The graph is not paginated, so large instances may be slow.
+- **Browser-direct**: CORS must be enabled on OpenBao, and the token lives in the browser's memory (never written to storage). There is no server-side audit trail beyond OpenBao's own audit log.
+- **Scope**: KV v2 only, and only userpass auth, tokens and identity entities/groups are managed.
+- **Managed policies**: access is granted by writing one policy per user, entity or group, named `envbao--` (for example `envbao-user-alice`). If a managed policy is edited outside EnvBao (for example to add parameter constraints) it becomes read-only in the UI rather than being overwritten. All other policies are shown read-only. Policy names are lower-cased by OpenBao, so identities whose names differ only by case or punctuation would collide; EnvBao detects this and refuses to overwrite.
+- **Tokens**: cannot be granted access after creation (OpenBao fixes a token's policies when it is created), so choose their policies when creating them. Tokens created by a token die with it unless created as orphans.
+- **Grants** write `/data/...` rules for read/create/update/delete and `/metadata/...` for list. `patch`, `sudo` and the KV `delete`/`undelete`/`destroy` sub-paths are not offered.
+- **Access model**: follows OpenBao's "most specific path wins" rule. Parameter constraints, control groups, MFA and templated paths are not evaluated (templated paths are approximated), so the access views can over-report for policies that use them; such policies are flagged.
+- **Inheritance**: identity→policy edges and the Access panel show *effective* policies, including those a user inherits from an aliased entity and that entity's groups. Nested groups and non-userpass aliases are not followed.
+- **Scale**: the graph and Access panel read every user, entity, group, token and policy on each load, with no pagination, so large instances may be slow.
+- **Sessions**: tokens are not renewed automatically. When one expires you sign in again.
diff --git a/docs/PLAN.md b/docs/PLAN.md
index b7e27d8..01c1d04 100644
--- a/docs/PLAN.md
+++ b/docs/PLAN.md
@@ -11,7 +11,7 @@ EnvBao needs an admin UI over an OpenBao instance so users/tokens can be created
## Architecture
- `src/api/bao.ts`: typed fetch client (`X-Vault-Token`, base URL config, error mapping). Endpoints: `sys/policies/acl`, `auth/userpass/users`, `auth/token/create|lookup|accessors`, `identity/entity|group`, `sys/mounts`, `secret/metadata` (KV v2), `sys/capabilities`.
- `src/model/`: `buildAccessGraph()` — parses ACL policy HCL path rules into `{path, capabilities}`, joins with identities' attached policies → nodes/edges. Pure and unit-testable.
-- Managed-policy convention: UI generates one policy per (identity, secret path set) named `envbao-`, so grants are editable via a simple "secret path + capability checkboxes" form rather than raw HCL (raw HCL view available).
+- Managed-policy convention (as built): one policy per user/entity/group named `envbao--`, marked with an `# envbao-owner:` header; tokens cannot be granted to after creation. Originally planned as `envbao-`, so grants are editable via a simple "secret path + capability checkboxes" form rather than raw HCL (raw HCL view available).
- UI libs: React Router, TanStack Query (server state), `@xyflow/react` (React Flow) + dagre layout for graph, Vitest for tests.
## Screens
diff --git a/docs/envbao-admin.hcl b/docs/envbao-admin.hcl
new file mode 100644
index 0000000..dee01ab
--- /dev/null
+++ b/docs/envbao-admin.hcl
@@ -0,0 +1,29 @@
+# Least-privilege policy for the account that uses EnvBao Admin.
+# Adjust "secret" if your KV v2 mount has a different path.
+
+# Policies: list, read, create/update and delete (managed `envbao-*` and read-only viewing of the rest)
+path "sys/policies/acl" { capabilities = ["list"] }
+path "sys/policies/acl/*" { capabilities = ["create", "read", "update", "delete"] }
+
+# Userpass users
+path "auth/userpass/users" { capabilities = ["list"] }
+path "auth/userpass/users/*" { capabilities = ["create", "read", "update", "delete"] }
+
+# Identity entities, aliases and groups
+path "identity/entity/name" { capabilities = ["list"] }
+path "identity/entity/name/*" { capabilities = ["create", "read", "update", "delete"] }
+path "identity/entity-alias" { capabilities = ["create", "update"] }
+path "identity/entity-alias/id/*" { capabilities = ["read", "delete"] }
+path "identity/group/name" { capabilities = ["list"] }
+path "identity/group/name/*" { capabilities = ["create", "read", "update", "delete"] }
+
+# Tokens: create, list (needs sudo in OpenBao), inspect and revoke by accessor
+path "auth/token/create" { capabilities = ["create", "update"] }
+path "auth/token/accessors" { capabilities = ["list", "sudo"] }
+path "auth/token/lookup-accessor" { capabilities = ["update"] }
+path "auth/token/revoke-accessor" { capabilities = ["update"] }
+
+# Discovery: mounted auth methods and secrets engines, and KV v2 metadata for the secret browser
+path "sys/auth" { capabilities = ["read"] }
+path "sys/mounts" { capabilities = ["read"] }
+path "secret/metadata/*" { capabilities = ["list"] }
diff --git a/nginx.conf b/nginx.conf
index 9563e16..da41c20 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -3,9 +3,17 @@ server {
root /usr/share/nginx/html;
index index.html;
+ # The OpenBao address is chosen at runtime, so connect-src cannot be narrowed to one origin.
+ # Tighten it if you only ever talk to a single OpenBao.
+ add_header Content-Security-Policy "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' http: https:; frame-ancestors 'none'; base-uri 'none'; form-action 'self'" always;
+ add_header X-Content-Type-Options nosniff always;
+ add_header Referrer-Policy no-referrer always;
+ add_header X-Frame-Options DENY always;
+
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
+ add_header X-Content-Type-Options nosniff always;
}
location / {
diff --git a/src/App.tsx b/src/App.tsx
index d877c99..c5d2605 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,5 +1,6 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { createBrowserRouter, RouterProvider } from 'react-router'
+import { SessionGuard } from './api/SessionGuard'
import { SessionProvider } from './api/session'
import { routes } from './routes'
@@ -10,6 +11,7 @@ function App() {
return (
+
diff --git a/src/Layout.tsx b/src/Layout.tsx
index 4c15512..30023cb 100644
--- a/src/Layout.tsx
+++ b/src/Layout.tsx
@@ -1,4 +1,5 @@
-import { NavLink, Outlet } from 'react-router'
+import { Link, NavLink, Outlet } from 'react-router'
+import { useSession } from './api/useSession'
const links = [
{ to: '/identities', label: 'Identities' },
@@ -6,9 +7,18 @@ const links = [
{ to: '/graph', label: 'Graph' },
]
+const notices = {
+ expired: 'Your session has expired or the token was revoked.',
+ sealed: 'OpenBao has been sealed.',
+}
+
export function Layout() {
+ const { notice, client, tokenInfo } = useSession()
return (