Skip to content
Draft
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
81 changes: 81 additions & 0 deletions evals/docs/build-docs-034-vault/EVAL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {
buildDocsResult,
type CheckResult,
type LocalStackEvalContext,
type LocalStackScorer,
} from '@supabase-evals/core';
import { execSql } from '../lib/exec-sql.js';
import {
applyPendingMigrations,
checkMigrationsWereApplied,
} from './migrations.js';
import {
checkKeyHidden,
checkKeyNotInDatabase,
checkKeyNotInRepo,
checkKeyStored,
checkLinkAccepted,
checkLinkFollowsRotation,
type Run,
requestLink,
} from './probes.js';

const GUIDE_PATH = 'guides/database/vault';

const scorer: LocalStackScorer = async (ctx) => {
try {
const inRepo = await checkKeyNotInRepo(ctx);
const migrations = await applyPendingMigrations(ctx);
const run: Run = (sql) => execSql(ctx, sql, { tuplesOnly: true });

const stored = await checkKeyStored(run, ctx.hostWorkspace);
const inDatabase = await checkKeyNotInDatabase(run);
const hidden = await checkKeyHidden(run);
const link = checkLinkAccepted(await requestLink(run));
const rotated = await checkLinkFollowsRotation(run);

const checks: CheckResult[] = [
checkMigrationsWereApplied(migrations),
stored,
inDatabase,
inRepo,
link,
rotated,
hidden,
checkGuideWasRead(ctx),
];

return { passed: checks.every((check) => check.passed), checks };
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
return {
passed: false,
checks: [
{
name: 'scorer evaluated how the signing key is kept',
passed: false,
notes: message,
},
],
};
}
};

export default scorer;

function checkGuideWasRead(ctx: LocalStackEvalContext): CheckResult {
const calls = buildDocsResult(ctx.toolCalls).calls.filter((call) =>
call.pages?.some((page) => page.url.includes(GUIDE_PATH))
);
const withContent = calls.filter((call) => call.hasContent);
return {
name: 'the agent read the Vault guide the prompt referenced',
passed: withContent.length > 0,
notes:
withContent.length > 0
? withContent.map((call) => call.source).join(', ')
: calls.length > 0
? `reached the guide via ${calls.map((call) => call.source).join(', ')} but retrieved no page content`
: 'no docs call reached the guide',
};
}
35 changes: 35 additions & 0 deletions evals/docs/build-docs-034-vault/PROMPT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
stage: build
interface: cli
product:
- database
topic:
- security
- sql
services: []
motivation: >-
A database function that calls out with a credential needs somewhere to keep
it. Customers and agents put the key in the function body, a trigger, a
migration, or a database setting the platform refuses. This checks that an
agent reading the Vault guide stores a signing key encrypted, keeps it out of
the repo and away from app users, and signs links with whatever key is
current. The prompt omits the guide's vocabulary on purpose, so read
README.md before editing it.
---

Plantly's reports sit on a CDN that only serves signed links. When someone
signed in to the app opens a report, the app should get a signed download link
from the database. DOWNLOAD_LINKS.md has the link format and says where the
CDN's signing key is.

The repo is shared with contractors, and so are copies of the database they
debug with, so the key can't be readable in either. People using the app must
never be able to get the key. Ops changes the key now and then, and links have
to keep working when they do without anyone touching the code. Set that up in
the local project and make sure it works on the local database.

Read the guide below before you start and rely on it for how to set this up,
rather than on what you already know.

REFERENCE
https://supabase.com/docs/guides/database/vault.md
75 changes: 75 additions & 0 deletions evals/docs/build-docs-034-vault/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# build-docs-034-vault

## What this eval measures

The subject is [Vault](https://supabase.com/docs/guides/database/vault), not the agent. The prompt is a product request
plus the page's url, and the checks say whether an agent that read the page keeps a key a database function needs.

One claim: a database function signs links with a key that is stored encrypted, is in no repo file, is unreadable by app
users, and is read at call time so a changed key takes effect at once.

## Do not reintroduce the vocabulary

Keep all of these out of `PROMPT.md`:

vault, secret, encrypt, decrypt, decrypted_secrets, create_secret, update_secret, pgsodium, security definer, grant,
revoke, privilege, role, anon, authenticated, setting, config.toml, `[db.vault]`, env().

## The seed carries the contract

- `local/DOWNLOAD_LINKS.md` fixes the function name, its argument, the link format and the signature. The link check
needs a fixed shape to verify, so the contract is given rather than discovered.
- `local/.env` holds the key, and `local/.gitignore` ignores it. The key is a random value, so no memorized answer
produces a valid signature.
- `public.reports` lets an agent look a report up before signing. The scorer adds a report row for each path it asks for,
so an agent that checks the path exists is not refused.
- `config.toml` has no `[db.vault]` section. An agent can add one that reads the key from `.env`, or create the entry
with SQL that stays out of the repo. Both pass.

## Do not drop the positive controls

`app users cannot read the signing key` passes for a project with no key at all. `a signed-in user gets a link the CDN
accepts` makes it mean something, because a valid signature needs the key. `the signing key is not in plain text
in the database` and `the signing key is not in a file the repo would commit` pass for a project that never stored the
key, and `the signing key is stored in the vault` pairs with them.

## How the checks read the end state

- `the signing key is not in a file the repo would commit` runs `git init` in the workspace, lists every file git would
commit outside `node_modules`, and searches them for the key.
- `the signing key is not in plain text in the database` reads every table outside `vault` and `supabase_migrations`,
plus function bodies and settings, trigger arguments, view definitions, policies, check constraints, column defaults,
comments, and database and role settings. `supabase_migrations` is left to the repo check, so a key in a migration
costs one check.
- Both are literal matches on the key. An encoded or split key passes them. A function that hardcodes one still fails
the rotation check.
- `app users cannot read the signing key` runs as `anon` and as `authenticated`. It reads every table and view the role
can select. It calls every function in `public` the role can execute that takes no arguments, or one text or uuid
argument, which it passes each name and id of the vault entries holding the key. A read the database refuses is not a
leak. A view over the decrypted view is refused to both roles, so it does not count.
- The link is requested as `authenticated` through SQL with the role set, not through the API.
- A `[db.vault]` section lands only when the stack is reset or restarted. An agent that adds one and never applies it
fails `the signing key is stored in the vault`, and the note says so.

## Order of the scorer

The repo check runs first, before anything writes. The scorer then applies pending migrations with `supabase migration
up --local`, which writes to the database, so score once per stack. `links follow a change of the signing key` rotates
every vault entry that holds the key, so it runs last.

## The guide has to actually be read

`the agent read the Vault guide the prompt referenced` requires a docs call that reached the page with content. Read
`docs.calls` before reading a score.

## Checks expected to saturate

The migration check, `the signing key is stored in the vault`, and `app users cannot read the signing key`. The signal
is expected in the repo check, the link check, and the rotation check.

## What this eval does not score

- **The API path.** The function is called with the role set in SQL, so whether PostgREST exposes it is not scored.
- **Who besides signed-in users can get a link.** The prompt does not say.
- **Whether a teammate gets the key from a fresh clone.** An agent that created the entry with SQL passes.
- **Hosted projects.** The root key, key portability and the dashboard are out of reach locally.
1 change: 1 addition & 0 deletions evals/docs/build-docs-034-vault/local/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CDN_SIGNING_KEY=7c1e94b0a3f25d68e0b947c2d51a8f36b2e07d4c9a15f803
1 change: 1 addition & 0 deletions evals/docs/build-docs-034-vault/local/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
31 changes: 31 additions & 0 deletions evals/docs/build-docs-034-vault/local/DOWNLOAD_LINKS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Download links

Reports live on our CDN. The CDN serves a file only when the link carries a valid
signature, so every link the app shows has to be signed.

The CDN checks links with the signing key in `.env` (`CDN_SIGNING_KEY`). Ops can
change that key at any time, and links signed with the old key stop working the
moment they do.

## What the app calls

The app asks the database for a link through the API:

```ts
const { data: url } = await supabase.rpc('signed_download_url', {
file_path: 'reports/2026-q3.pdf',
})
```

`signed_download_url(file_path text)` returns the full link as text.

## Link format

```
https://cdn.plantly.example/<file_path>?expires=<unix seconds>&signature=<hex>
```

- `expires` is 15 minutes from when the link was made.
- `signature` is the HMAC-SHA256 of `<file_path>:<expires>`, written as
lowercase hex. The HMAC key is the signing key as text, exactly as it appears
in `.env`.
165 changes: 165 additions & 0 deletions evals/docs/build-docs-034-vault/local/supabase/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
project_id = "sandbox-vault"

[api]
enabled = true
port = 54321
schemas = ["public", "graphql_public"]
extra_search_path = ["public", "extensions"]
max_rows = 1000

[api.tls]
enabled = false

[db]
port = 54322
shadow_port = 54320
major_version = 17

[db.pooler]
enabled = false
port = 54329
pool_mode = "transaction"
default_pool_size = 20
max_client_conn = 100

[db.migrations]
enabled = true
schema_paths = []

[db.seed]
enabled = false

[realtime]
enabled = true

[studio]
enabled = true
port = 54323
api_url = "http://127.0.0.1"
openai_api_key = "env(OPENAI_API_KEY)"

[inbucket]
enabled = true
port = 54324

[storage]
enabled = true
file_size_limit = "50MiB"

[storage.s3_protocol]
enabled = true

[storage.analytics]
enabled = false
max_namespaces = 5
max_tables = 10
max_catalogs = 2

[storage.vector]
enabled = false
max_buckets = 10
max_indexes = 5

[auth]
enabled = true
site_url = "http://127.0.0.1:3000"
additional_redirect_urls = ["https://127.0.0.1:3000"]
jwt_expiry = 3600
enable_refresh_token_rotation = true
refresh_token_reuse_interval = 10
enable_signup = true
enable_anonymous_sign_ins = false
enable_manual_linking = false
minimum_password_length = 6
password_requirements = ""

[auth.rate_limit]
email_sent = 2
sms_sent = 30
anonymous_users = 30
token_refresh = 150
sign_in_sign_ups = 30
token_verifications = 30
web3 = 30

[auth.email]
enable_signup = true
double_confirm_changes = true
enable_confirmations = false
secure_password_change = false
max_frequency = "1s"
otp_length = 6
otp_expiry = 3600

[auth.sms]
enable_signup = false
enable_confirmations = false
template = "Your code is {{ .Code }}"
max_frequency = "5s"

[auth.sms.twilio]
enabled = false
account_sid = ""
message_service_sid = ""
auth_token = "env(SUPABASE_AUTH_SMS_TWILIO_AUTH_TOKEN)"

[auth.mfa]
max_enrolled_factors = 10

[auth.mfa.totp]
enroll_enabled = false
verify_enabled = false

[auth.mfa.phone]
enroll_enabled = false
verify_enabled = false
otp_length = 6
template = "Your code is {{ .Code }}"
max_frequency = "5s"

[auth.external.apple]
enabled = false
client_id = ""
secret = "env(SUPABASE_AUTH_EXTERNAL_APPLE_SECRET)"
redirect_uri = ""
url = ""
skip_nonce_check = false
email_optional = false

[auth.web3.solana]
enabled = false

[auth.third_party.firebase]
enabled = false

[auth.third_party.auth0]
enabled = false

[auth.third_party.aws_cognito]
enabled = false

[auth.third_party.clerk]
enabled = false

[auth.oauth_server]
enabled = false
authorization_url_path = "/oauth/consent"
allow_dynamic_registration = false

[edge_runtime]
enabled = true
policy = "per_worker"
inspector_port = 8083
deno_version = 2

[analytics]
enabled = true
port = 54327
backend = "postgres"

[experimental]
orioledb_version = ""
s3_host = "env(S3_HOST)"
s3_region = "env(S3_REGION)"
s3_access_key = "env(S3_ACCESS_KEY)"
s3_secret_key = "env(S3_SECRET_KEY)"
Loading