Compare commits
8
Commits
d5f5faf2df
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b7071a318 | ||
|
|
15e71e0e70 | ||
|
|
8c36460dea | ||
|
|
49f3d4b6a5 | ||
|
|
42ea9d6531 | ||
|
|
06366cd106 | ||
|
|
c6bb5b132a | ||
|
|
c29b0cfd63 |
No files matched your search
@@ -16,7 +16,7 @@ jobs:
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
- run: npm run lint
|
||||
- run: npm audit --audit-level=high
|
||||
- run: npm audit --omit=dev --audit-level=high
|
||||
- run: npm test
|
||||
- run: npm run build
|
||||
- uses: actions/upload-artifact@v3
|
||||
|
||||
@@ -20,7 +20,7 @@ jobs:
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
- run: npm run lint
|
||||
- run: npm audit --audit-level=high
|
||||
- run: npm audit --omit=dev --audit-level=high
|
||||
- run: npm test
|
||||
- run: npm run build
|
||||
|
||||
@@ -66,7 +66,8 @@ jobs:
|
||||
- name: Build and push
|
||||
run: |
|
||||
VERSION="${GITHUB_REF_NAME#v}"
|
||||
docker build -t "$IMAGE:$VERSION" -t "$IMAGE:latest" .
|
||||
# The runner may be arm64 (a Mac); the deploy host is amd64, so always build for it.
|
||||
docker build --platform linux/amd64 -t "$IMAGE:$VERSION" -t "$IMAGE:latest" .
|
||||
docker push "$IMAGE:$VERSION"
|
||||
docker push "$IMAGE:latest"
|
||||
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
FROM node:22-alpine AS build
|
||||
# The build stage only emits static files, so it runs on the builder's own architecture; only the nginx stage
|
||||
# takes the target platform (linux/amd64, set in the release workflow). No emulation needed.
|
||||
FROM --platform=$BUILDPLATFORM node:22-alpine AS build
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
@@ -28,7 +28,7 @@ Taken from the [demo stack](#quick-start-with-docker).
|
||||
|
||||
- **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; KV secret values are never read) and see which identities can reach a secret, through which policy, with which capabilities.
|
||||
- **Secrets**: browse KV v2 mounts and paths and add new secrets (values are write-only: existing values are never read, shown or overwritten) and see which identities can reach a secret, through which policy, with which capabilities.
|
||||
- **Secrets engines**: create (KV v2, database, AWS, SSH), change the settings of, and delete secrets engine mounts, including KV v2 settings such as max versions. Deleting asks you to type the mount path, and says what will be lost and which policies still refer to it.
|
||||
- **Dynamic secrets**: for database (Postgres, ...), AWS and SSH engines, and a raw-JSON editor for any other engine type: create, edit and delete roles; configure the engine (database connections with rotate and reset, AWS root and lease, the SSH signing CA); generate credentials, sign SSH keys or issue OTPs; and browse, renew and revoke leases. Issued credentials are shown once and are never stored or cached by the UI. Passwords and private keys you type into config forms are write-only: they are never shown again.
|
||||
- **Access**: from an identity's **Access** button, grant it capabilities on a secret path (globs allowed) or access to a dynamic-engine role (generate credentials, manage the role), or revoke them, without writing policy HCL. A role's **Access** button shows who can already use it.
|
||||
@@ -161,6 +161,8 @@ path "sys/mounts/*" { capabilities = ["create", "read", "update", "delete
|
||||
# KV v2 settings (max versions, check-and-set) of the KV mount
|
||||
path "secret/config" { capabilities = ["read", "update"] }
|
||||
path "secret/metadata/*" { capabilities = ["list"] }
|
||||
# Creating a new KV v2 secret. Create only: values can't be read back and existing secrets can't be overwritten
|
||||
path "secret/data/*" { capabilities = ["create"] }
|
||||
|
||||
# Dynamic secrets engines: roles, config, credentials and leases. The paths use the default mount
|
||||
# names (database/, aws/, ssh/); repeat a block with your own mount path for each engine you manage.
|
||||
@@ -209,7 +211,7 @@ Notes:
|
||||
- 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.
|
||||
- The `sys/mounts/*` rule lets this account create, change and **delete any secrets engine**, which destroys its data and revokes its leases. Remove it (and the New / Settings / Delete buttons will report permission denied) if mounts are managed elsewhere. Mounting, tuning and deleting do not need `sudo`.
|
||||
- KV v2 settings (max versions, check-and-set) are stored by the engine at `<mount>/config`, so the policy only covers them on `secret/`. Creating another KV store with settings mounts it and then fails to save them; EnvBao tells you the store exists, and you can add `<mount>/config` to the policy and use **Settings**.
|
||||
- If your KV v2 mount is not `secret/`, change `secret/metadata/*` and `secret/config`. The dynamic-engine rules name the default mounts (`database/`, `aws/`, `ssh/`), so change those too, or repeat a block for each mount. They deliberately avoid a `+/roles/*` wildcard, which would also match system paths such as `sys/config/cors`.
|
||||
- If your KV v2 mount is not `secret/`, change `secret/metadata/*`, `secret/data/*` and `secret/config`. The dynamic-engine rules name the default mounts (`database/`, `aws/`, `ssh/`), so change those too, or repeat a block for each mount. They deliberately avoid a `+/roles/*` wildcard, which would also match system paths such as `sys/config/cors`.
|
||||
- Listing leases and revoking by prefix need `sudo` in OpenBao (looking up, renewing and revoking a single lease do not). Without it the Leases tab shows a permission error.
|
||||
- The `creds`, `sign` and `static-creds` lines let this account issue live database logins, AWS keys and SSH certificates. Remove them if the account should manage roles without being able to use them.
|
||||
- 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.
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ Required secrets: in `envbao-admin`, `PKGS_USER`, `PKGS_PASSWORD` and `DEPLOY_DI
|
||||
|
||||
- **Token handling.** The token lives in memory only and is sent only to the OpenBao URL you entered. Anyone who can run script in the page (an XSS bug, a malicious browser extension) could use it, so keep the CSP and serve the UI from a dedicated origin.
|
||||
- **Credentials shown once.** Tokens and dynamic credentials appear when created and are never stored or cached by the UI. Password and private-key fields in configuration forms are write-only.
|
||||
- **Secret values are never read.** The Secrets page lists names and metadata only. It cannot display KV secret values.
|
||||
- **Secret values are write-only.** The Secrets page lists names and metadata only and cannot display KV secret values. **New secret** creates a secret (with `cas: 0`, so it can never overwrite one) and needs only `create` on `<mount>/data/*`.
|
||||
- **Audit.** The UI has no audit trail of its own. Turn on an OpenBao audit device; every UI action appears there under the signed-in account.
|
||||
- **Session length.** Sessions last as long as the token. Give the admin account a short TTL if you want people to sign in more often.
|
||||
- **Managed policies.** Grants are stored as policies named `envbao-<kind>-<name>` with an `# envbao-owner:` header. If someone edits one outside EnvBao, the UI treats it as read-only rather than overwrite it. Other policies are shown read-only.
|
||||
|
||||
@@ -33,6 +33,8 @@ path "sys/mounts/*" { capabilities = ["create", "read", "update", "delete
|
||||
# KV v2 settings (max versions, check-and-set) of the KV mount
|
||||
path "secret/config" { capabilities = ["read", "update"] }
|
||||
path "secret/metadata/*" { capabilities = ["list"] }
|
||||
# Creating a new KV v2 secret. Create only: values can't be read back and existing secrets can't be overwritten
|
||||
path "secret/data/*" { capabilities = ["create"] }
|
||||
|
||||
# Dynamic secrets engines: roles, config, credentials and leases. The paths use the default mount
|
||||
# names (database/, aws/, ssh/); repeat a block with your own mount path for each engine you manage.
|
||||
|
||||
+3
-3
@@ -86,13 +86,13 @@ For each identity, EnvBao keeps one policy named `envbao-<kind>-<name>` (for exa
|
||||
**Secrets** is where you browse and manage secrets engines. At the top:
|
||||
|
||||
- **New secrets engine** adds a mount (see [Managing secrets engines](#managing-secrets-engines)).
|
||||
- The **Secrets engine** drop-down chooses which engine to work with, with **Settings** and **Delete** for that engine beside it.
|
||||
- The **Secrets engine** drop-down chooses which engine to work with, with **Settings**, **Delete** and (for KV) **New secret** for that engine beside it.
|
||||
|
||||
For a **KV** engine you browse folders and secrets with the breadcrumb under the toolbar. Select a secret to see **who can reach it**: every identity with access, through which policy, and with which capabilities. **Grant access** on that panel opens the grant form for the secret.
|
||||
|
||||

|
||||
|
||||
EnvBao shows secret **names only**. It never reads or displays a secret's value. OpenBao applies the most specific matching policy path, and the table follows the same rule. It does not evaluate parameter constraints, control groups, MFA or templated paths (templated paths are approximated), so a policy using those may be over-reported and is flagged.
|
||||
**New secret** (KV engines) adds a secret under the current folder: type a name such as `expo` and one or more key/value pairs. Values are write-only. EnvBao never reads or displays a secret's value, and it refuses to overwrite an existing secret. OpenBao applies the most specific matching policy path, and the table follows the same rule. It does not evaluate parameter constraints, control groups, MFA or templated paths (templated paths are approximated), so a policy using those may be over-reported and is flagged.
|
||||
|
||||
## Dynamic secrets engines
|
||||
|
||||
@@ -162,7 +162,7 @@ If creating a KV engine succeeds but saving its KV settings fails, the page says
|
||||
## Good to know
|
||||
|
||||
- **Copy it now.** Tokens and generated credentials are shown once only.
|
||||
- **Names, not values.** Secret values are never shown.
|
||||
- **Write-only values.** Secret values can be created but are never shown, and existing secrets can't be changed here.
|
||||
- **Whole-instance reads.** The graph and Access panels read every user, entity, group, token and policy each time they load, which can be slow on very large instances.
|
||||
- **Not everything is managed here.** Auth methods other than userpass, nested groups and non-userpass aliases are not followed, and KV v1 mounts are not shown. See the README's limitations for the full list.
|
||||
- **Policies you did not create are read-only.** Change those with the OpenBao CLI.
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "envbao-admin",
|
||||
"version": "0.2.4",
|
||||
"version": "0.3.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "envbao-admin",
|
||||
"version": "0.2.4",
|
||||
"version": "0.3.3",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.104.5",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "envbao-admin",
|
||||
"private": true,
|
||||
"version": "0.2.4",
|
||||
"version": "0.3.3",
|
||||
"license": "BSD-3-Clause",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -71,3 +71,13 @@ describe('access model vs sys/capabilities-self', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('writeSecret', () => {
|
||||
test('creates a secret once and refuses to overwrite it', async () => {
|
||||
const path = `it-${sfx}/new/expo`
|
||||
await secrets.writeSecret(client, 'secret/', path, { TOKEN: 'v1' })
|
||||
await expect(secrets.writeSecret(client, 'secret/', path, { TOKEN: 'v2' })).rejects.toThrow()
|
||||
const res = await client.request<{ data: { data: Record<string, string> } }>('GET', `secret/data/${path}`)
|
||||
expect(res.data.data).toEqual({ TOKEN: 'v1' })
|
||||
})
|
||||
})
|
||||
@@ -72,6 +72,14 @@ export async function listSecrets(c: BaoClient, mount: string, prefix: string):
|
||||
/** API path of a secret's data, which is what ACL policies are written against. */
|
||||
export const dataPath = (mount: string, secret: string) => `${mount}data/${secret}`
|
||||
|
||||
/**
|
||||
* Creates a new KV v2 secret. `cas: 0` makes OpenBao refuse if the secret already exists, so this can never
|
||||
* overwrite a value (and only needs the `create` capability).
|
||||
*/
|
||||
export async function writeSecret(c: BaoClient, mount: string, path: string, data: Record<string, string>): Promise<void> {
|
||||
await c.request('POST', dataPath(mount, enc(path)), { data, options: { cas: 0 } })
|
||||
}
|
||||
|
||||
export async function readPolicyHcl(c: BaoClient, name: string): Promise<string | null> {
|
||||
try {
|
||||
const res = await c.request<{ data: { policy: string } }>('GET', `sys/policies/acl/${encodeURIComponent(name)}`)
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useState } from 'react'
|
||||
import type { BaoClient } from '../../api/bao'
|
||||
import { writeSecret } from '../../api/secrets'
|
||||
import { validateSecretPath } from '../../model/mounts'
|
||||
|
||||
interface Row {
|
||||
key: string
|
||||
value: string
|
||||
}
|
||||
|
||||
/** Create a new KV v2 secret under the current path. Values are write-only and existing secrets are never overwritten. */
|
||||
export function NewSecretDialog({ client, mount, prefix, onClose, onDone }: {
|
||||
client: BaoClient
|
||||
mount: string
|
||||
prefix: string
|
||||
onClose: () => void
|
||||
onDone: (path: string) => void
|
||||
}) {
|
||||
const qc = useQueryClient()
|
||||
const [name, setName] = useState('')
|
||||
const [rows, setRows] = useState<Row[]>([{ key: '', value: '' }])
|
||||
const [formError, setFormError] = useState<string | null>(null)
|
||||
|
||||
const create = useMutation({
|
||||
mutationFn: async () => {
|
||||
const path = prefix + name.trim()
|
||||
const data: Record<string, string> = {}
|
||||
for (const r of rows) data[r.key.trim()] = r.value
|
||||
await writeSecret(client, mount, path, data)
|
||||
await qc.invalidateQueries({ queryKey: ['kv-list'] })
|
||||
return path
|
||||
},
|
||||
onSuccess: (path) => onDone(path),
|
||||
})
|
||||
|
||||
const setRow = (i: number, patch: Partial<Row>) => setRows(rows.map((r, j) => (j === i ? { ...r, ...patch } : r)))
|
||||
|
||||
function submit(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
setFormError(null)
|
||||
const nameError = validateSecretPath(name.trim())
|
||||
if (nameError) return setFormError(nameError)
|
||||
const keys = rows.map((r) => r.key.trim())
|
||||
if (keys.some((k) => !k)) return setFormError('Every key needs a name.')
|
||||
if (new Set(keys).size !== keys.length) return setFormError('Keys must be unique.')
|
||||
create.mutate()
|
||||
}
|
||||
|
||||
return (
|
||||
<section aria-label="New secret" className="mount-dialog">
|
||||
<form aria-label="New secret form" onSubmit={submit}>
|
||||
<label>
|
||||
Name
|
||||
<span className="hint"> in {mount}{prefix}</span>
|
||||
<input value={name} onChange={(e) => setName(e.target.value)} placeholder="expo" autoComplete="off" />
|
||||
</label>
|
||||
<div className="kv-rows">
|
||||
{rows.map((r, i) => (
|
||||
<div className="kv-row" key={i}>
|
||||
<input aria-label={`Key ${i + 1}`} placeholder="key" value={r.key} autoComplete="off" onChange={(e) => setRow(i, { key: e.target.value })} />
|
||||
<input aria-label={`Value ${i + 1}`} type="password" placeholder="value" value={r.value} autoComplete="new-password" onChange={(e) => setRow(i, { value: e.target.value })} />
|
||||
<button type="button" disabled={rows.length === 1} onClick={() => setRows(rows.filter((_, j) => j !== i))}>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
<div>
|
||||
<button type="button" onClick={() => setRows([...rows, { key: '', value: '' }])}>
|
||||
Add key
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="hint">Values are write-only: they are never shown again, and an existing secret is never overwritten.</p>
|
||||
{(formError ?? create.error) && <p role="alert">{formError ?? create.error?.message}</p>}
|
||||
<button type="submit" disabled={create.isPending}>
|
||||
{create.isPending ? 'Saving…' : 'Create'}
|
||||
</button>
|
||||
<button type="button" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import { SecretsPage } from './SecretsPage'
|
||||
|
||||
vi.mock('../../api/grants')
|
||||
vi.mock('../../api/identities')
|
||||
vi.mock('../../api/secrets', async (orig) => ({ ...(await orig<typeof api>()), listMounts: vi.fn(), listSecrets: vi.fn(), readPolicyHcl: vi.fn() }))
|
||||
vi.mock('../../api/secrets', async (orig) => ({ ...(await orig<typeof api>()), listMounts: vi.fn(), listSecrets: vi.fn(), readPolicyHcl: vi.fn(), writeSecret: vi.fn() }))
|
||||
vi.mock('../../api/tokens')
|
||||
vi.mock('../../api/mounts', async (orig) => ({ ...(await orig<typeof mountsApi>()), createMount: vi.fn(), tuneMount: vi.fn(), readKvConfig: vi.fn(), deleteMount: vi.fn(), mountImpact: vi.fn() }))
|
||||
|
||||
@@ -292,3 +292,28 @@ test('asks to connect first', () => {
|
||||
)
|
||||
expect(screen.getByText(/Not connected/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('adds a new secret under the current folder', async () => {
|
||||
vi.mocked(api.writeSecret).mockResolvedValue()
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
|
||||
<SessionProvider>
|
||||
<MemoryRouter>
|
||||
<Connected />
|
||||
<SecretsPage />
|
||||
</MemoryRouter>
|
||||
</SessionProvider>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'go' }))
|
||||
await user.click(await screen.findByRole('button', { name: 'app/' }))
|
||||
await user.click(await screen.findByRole('button', { name: 'New secret' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Create' }))
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('Name is required.')
|
||||
await user.type(screen.getByLabelText(/^Name/), 'expo')
|
||||
await user.type(screen.getByLabelText('Key 1'), 'TOKEN')
|
||||
await user.type(screen.getByLabelText('Value 1'), 's3cret')
|
||||
await user.click(screen.getByRole('button', { name: 'Create' }))
|
||||
expect(api.writeSecret).toHaveBeenCalledWith(client, 'secret/', 'app/expo', { TOKEN: 's3cret' })
|
||||
})
|
||||
@@ -9,6 +9,7 @@ import { AccessPanel } from './AccessPanel'
|
||||
import { DeleteMountDialog } from './DeleteMountDialog'
|
||||
import { EngineView } from './EngineView'
|
||||
import { MountDialog } from './MountDialog'
|
||||
import { NewSecretDialog } from './NewSecretDialog'
|
||||
|
||||
function Browser({ client }: { client: BaoClient }) {
|
||||
const mounts = useMounts(client)
|
||||
@@ -16,7 +17,7 @@ function Browser({ client }: { client: BaoClient }) {
|
||||
const [mountChoice, setMount] = useState<string | null>(null)
|
||||
const [prefix, setPrefix] = useState('')
|
||||
const [selected, setSelected] = useState<string | null>(null)
|
||||
const [dialog, setDialog] = useState<'create' | 'edit' | 'delete' | null>(null)
|
||||
const [dialog, setDialog] = useState<'create' | 'edit' | 'delete' | 'secret' | null>(null)
|
||||
|
||||
const current = mounts.data?.find((m) => m.path === mountChoice) ?? mounts.data?.[0] ?? null
|
||||
const mount = current?.path ?? null
|
||||
@@ -58,7 +59,7 @@ function Browser({ client }: { client: BaoClient }) {
|
||||
go('')
|
||||
}}
|
||||
/>
|
||||
) : dialog && dialog !== 'delete' && (
|
||||
) : dialog && dialog !== 'delete' && dialog !== 'secret' && (
|
||||
<MountDialog
|
||||
// Remount per mount so one mount's settings are never shown (or saved) for another.
|
||||
key={dialog === 'edit' ? current?.path : 'create'}
|
||||
@@ -132,12 +133,32 @@ function Browser({ client }: { client: BaoClient }) {
|
||||
Settings
|
||||
</button>
|
||||
)}
|
||||
{isKv && (
|
||||
<button type="button" onClick={() => setDialog(dialog === 'secret' ? null : 'secret')} aria-expanded={dialog === 'secret'}>
|
||||
New secret
|
||||
</button>
|
||||
)}
|
||||
<button type="button" onClick={() => setDialog(dialog === 'delete' ? null : 'delete')} aria-expanded={dialog === 'delete'}>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{dialogs}
|
||||
{dialog === 'secret' && isKv && (
|
||||
<NewSecretDialog
|
||||
key={`${mount}${prefix}`}
|
||||
client={client}
|
||||
mount={mount}
|
||||
prefix={prefix}
|
||||
onClose={closeDialog}
|
||||
onDone={(path) => {
|
||||
closeDialog()
|
||||
const folder = path.includes('/') ? path.slice(0, path.lastIndexOf('/') + 1) : ''
|
||||
setPrefix(folder)
|
||||
setSelected(path)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
|
||||
|
||||
@@ -1573,3 +1573,16 @@ button.danger-solid:hover:not(:disabled) {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
/* New secret form: key/value rows. */
|
||||
.kv-rows {
|
||||
display: grid;
|
||||
gap: var(--s2);
|
||||
margin: var(--s3) 0;
|
||||
}
|
||||
|
||||
.kv-row {
|
||||
display: flex;
|
||||
gap: var(--s2);
|
||||
align-items: center;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from 'vitest'
|
||||
import { policiesReferencing, validateMountPath } from './mounts'
|
||||
import { policiesReferencing, validateMountPath, validateSecretPath } from './mounts'
|
||||
|
||||
const existing = ['secret/', 'database/', 'team/kv/']
|
||||
|
||||
@@ -38,3 +38,8 @@ test('finds policies with rules under a mount, however the mount is written', ()
|
||||
expect(policiesReferencing(policies, 'secret')).toEqual(['a-uses', 'b-uses'])
|
||||
expect(policiesReferencing(policies, 'nothing/')).toEqual([])
|
||||
})
|
||||
|
||||
test('validateSecretPath accepts plain and nested names and rejects bad ones', () => {
|
||||
for (const p of ['expo', 'shell/expo', 'a b']) expect(validateSecretPath(p), p).toBeNull()
|
||||
for (const p of ['', ' x', '/x', 'x/', 'a//b', 'a/../b', '.']) expect(validateSecretPath(p), p).not.toBeNull()
|
||||
})
|
||||
@@ -42,3 +42,14 @@ export function policiesReferencing(policies: PolicyText[], mount: string): stri
|
||||
.map((p) => p.name)
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
}
|
||||
|
||||
/** Error message for a secret name/path (relative to a KV mount) that can't be used, or null. */
|
||||
export function validateSecretPath(path: string): string | null {
|
||||
if (!path.trim()) return 'Name is required.'
|
||||
if (path !== path.trim()) return 'Name must not start or end with spaces.'
|
||||
if (path.startsWith('/') || path.endsWith('/')) return 'Name must not start or end with "/".'
|
||||
const parts = path.split('/')
|
||||
if (parts.some((p) => !p)) return 'Name must not contain empty parts ("//").'
|
||||
if (parts.some((p) => p === '.' || p === '..')) return 'Name must not contain "." or ".." parts.'
|
||||
return null
|
||||
}
|
||||
Reference in new issue
Block a user