Skip to content

Commit 2d61799

Browse files
feat(validate): flag a credentialIds list that hides one of the org's keys
A credentialIds list is the full set of keys a call may use, pooled across every squad member. A provider left off it runs on Vapi's own key with no error. validate now reports a list that leaves out a key the org has saved for something the call uses: a model, voice or transcriber (and fallbacks), a key a tool or server names, the storage bucket and Langfuse. A provider the org has no key of its own for is left alone. The finding is a warning. It is an error in an org whose resources/<org>/.vapi-policy.yml sets customerKeysOnly: true. Pull now records each credential's provider in resources/<org>/.vapi-credential-providers.json, since the state file only maps names to UUIDs, and warns when two credentials collide on one name. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
1 parent c451ede commit 2d61799

16 files changed

Lines changed: 1627 additions & 2 deletions

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ default-exports the object (safety rule 5).
223223
| Simulation | `personalityId`, `scenarioId` | Personality and scenario files | `scenarioId: books-cleaning` |
224224
| Suite | `simulationIds[]` | Simulation files | `- books-cleaning-calm` |
225225
| Any server block | `credentialId` | A credential **name** in the org | `credentialId: my-api-credential` |
226+
| Assistant, or squad overrides | `credentialIds[]` | Credential **names**. The list is every key the call may use, not one provider's: [credential pins](docs/guides/credential-pins.md) | `- azure-south` |
226227

227228
The engine resolves IDs and credential names to each org's UUIDs on push.
228229

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ when run without arguments. Full flags and examples:
236236
| [Writing system prompts](docs/guides/writing-prompts.md) | Structure a voice agent's prompt |
237237
| [PR checks](docs/guides/pr-checks.md) | Test every pull request with simulations |
238238
| [Promotion](docs/guides/promotion.md) | Move resources from dev to staging to production |
239+
| [Credential pins](docs/guides/credential-pins.md) | Pin a call to specific keys with `credentialIds`, and mark an org customer-keys-only |
239240
| [How the engine works](docs/guides/how-it-works.md) | Understand sync, references, credentials and state |
240241
| [Configuration](docs/guides/configuration.md) | Environment variables and secrets |
241242
| [Troubleshooting](docs/guides/troubleshooting.md) | Fix common errors |

‎docs/guides/configuration.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Set these in GitHub under **Settings → Secrets and variables → Actions**.
4949
| --- | --- |
5050
| `promotion.yml` | Promotion pipelines between orgs. Start from `promotion.example.yml`. |
5151
| `vapi-checks.yml` | PR checks. Start from `vapi-checks.example.yml`. |
52+
| `resources/<org>/.vapi-policy.yml` | Rules the org must hold, written by hand. `customerKeysOnly: true` makes a `credentialIds` list that hides one of the org's keys an error instead of a warning. See [Credential pins](credential-pins.md). |
5253
| `resources/<org>/.vapi-ignore` | Platform resources this repo shouldn't manage, as glob patterns. See `resources/.vapi-ignore.example` and [YAML conventions](../learnings/yaml-conventions.md). |
5354

5455
These are hand-written. The files the engine writes live apart from them, in
@@ -58,6 +59,7 @@ These are hand-written. The files the engine writes live apart from them, in
5859
| --- | --- |
5960
| `state/<org>/state.json` | Which platform resource (UUID) each file under `resources/<org>/` is. |
6061
| `state/<org>/org.json` | The Vapi org ID the folder belongs to. Written by the first command that can see the key's org, then checked by every command before any request: a key for another org stops the command. If a folder genuinely moves to another org, delete the file in a reviewed commit. |
62+
| `state/<org>/credential-providers.json` | The provider of each saved credential, by name. Written by every pull and committed with the state file. It holds no secret. The credential-pin check reads it. |
6163

6264
## Other environment variables
6365

‎docs/guides/credential-pins.md‎

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Credential pins: `credentialIds` lists
2+
3+
An assistant, a squad member's `assistantOverrides` and a squad's
4+
`membersOverrides` can each carry a `credentialIds` list. It pins a call to
5+
specific keys, for example one site's Azure OpenAI key in an org that holds a
6+
key per site. This page explains what the list does on a call and what
7+
`npm run validate` checks about it.
8+
9+
## What a list does
10+
11+
A `credentialIds` list is not a choice for one provider. It is the full set
12+
of keys the call may use:
13+
14+
- As soon as any assistant on the call has a list, the call can use only the
15+
listed keys. Every squad member's list is pooled into one list for the
16+
whole call, so a list on one member narrows the other members too.
17+
- A provider whose key is not on the list does not fail. The model, voice or
18+
transcriber runs on Vapi's own key, a tool or server request goes out
19+
without its key, and the recording does not go to your storage bucket.
20+
- The phone number's own credential stays usable whatever the list says.
21+
22+
So a list has to name every key the call needs: the model key, the voice
23+
key, the transcriber key, each key a tool or server names in `credentialId`,
24+
the storage bucket key and the Langfuse key if the org has them.
25+
26+
Lists combine like this:
27+
28+
| Where the list is | What happens |
29+
| --- | --- |
30+
| On the assistant | Kept. Lists from overrides are added to it. |
31+
| In a member's `assistantOverrides` | Used, unless the squad's `membersOverrides` also has a list, which replaces it. |
32+
| In the squad's `membersOverrides` | Applies to every member. |
33+
34+
One list per squad, in `membersOverrides`, is the simplest layout: shared
35+
assistants carry no list, and each squad names its own keys.
36+
37+
```yaml
38+
# resources/<org>/squads/south-front-desk.yml
39+
name: South Front Desk
40+
members:
41+
- assistantId: triage
42+
- assistantId: pharmacy
43+
membersOverrides:
44+
credentialIds:
45+
- azure-south # this site's Azure OpenAI key
46+
- elevenlabs # voice
47+
- deepgram # transcriber
48+
- crm-webhook # the key the lookup tool names
49+
- recordings # storage bucket
50+
```
51+
52+
## What validate checks
53+
54+
`npm run validate -- <org>` (and `apply`, which runs it first) reports a list
55+
that leaves out a key **the org has saved** for something the call uses:
56+
57+
| The call uses | Reported when |
58+
| --- | --- |
59+
| A model, voice or transcriber, or a fallback voice or transcriber | The org has a key for that provider and the list has none. An OpenAI model can run on an `openai` key or an `azure-openai` key, so either on the list is enough. Every other provider takes a key saved under its own name. |
60+
| A tool, server or model that names a key in `credentialId` | That key is not on the list. |
61+
| Storage | The org has a storage bucket key and the list has none. |
62+
| Langfuse | The org has a Langfuse key and the list leaves it out. |
63+
64+
It does not report a provider the org has no key of its own for. Running
65+
that provider on Vapi's key is a normal setup, with or without a list.
66+
67+
A different key for the same provider counts as a key for it. A squad pinned
68+
to one site's Azure OpenAI key is not told about the other sites' keys.
69+
70+
For a squad, the check looks at the call as a whole: the pooled list, and
71+
what every member uses after its overrides are applied. An assistant with a
72+
list of its own is also checked on its own, since it can be called outside a
73+
squad.
74+
75+
The finding is `credential-pin-hides-key`:
76+
77+
```text
78+
⚠️ [credential-pin-hides-key] squads/south-front-desk (credentialIds): the voice of member "triage" and the voice of member "pharmacy" use 11labs, and this org has "elevenlabs" saved for it, but the call's credentialIds list ("azure-south", "deepgram") has no key for 11labs. A call that has a credentialIds list can use only the keys on it, so 11labs would run on Vapi's own key, not yours. Add the key to the list
79+
```
80+
81+
### Limits
82+
83+
- The check reads files. A squad member that is not a file in the org's
84+
folder (a dashboard-owned assistant) adds nothing to it.
85+
- It knows each key's provider, not which models or regions the key covers.
86+
A list with an Azure OpenAI key that does not serve the assistant's model
87+
passes.
88+
- A tool or server with no `credentialId` is not checked.
89+
- Lists added at call time (`assistantOverrides` on a call or a phone
90+
number) are outside the repo and are not seen.
91+
92+
## Orgs that must only use their own keys
93+
94+
By default the finding is a warning. For an org whose calls must never run
95+
on Vapi's keys, add a policy file and commit it:
96+
97+
```yaml
98+
# resources/<org>/.vapi-policy.yml
99+
customerKeysOnly: true
100+
```
101+
102+
In that org the finding is an error: `validate` fails, `apply` stops before
103+
it pulls or pushes, and the **Validate resources** check fails on the pull
104+
request. `npm run push` on its own only blocks on errors with `--strict`,
105+
like every other validation error.
106+
107+
The policy belongs to one org. Promotion does not copy it, so set it in each
108+
org that needs it. An unknown key in the file stops `validate`, so a typo
109+
can't switch the rule off.
110+
111+
The policy makes a hidden key an error. It does not require the org to have
112+
a key for every provider it uses.
113+
114+
## How the check knows what each key is for
115+
116+
The state file maps a credential's name to its UUID and nothing else. Pull
117+
also records each key's provider in
118+
`resources/<org>/.vapi-credential-providers.json`:
119+
120+
```json
121+
{
122+
"azure-south": { "provider": "azure-openai" },
123+
"elevenlabs": { "provider": "11labs" },
124+
"recordings": { "bucket": true, "provider": "azure" }
125+
}
126+
```
127+
128+
Commit it with the state file. It holds no secret. Every pull rewrites it,
129+
including `npm run pull -- <org> --bootstrap`, which changes no resource
130+
file. If the file is missing or older than the state file, the check reports
131+
`credential-pin-unchecked` and asks for that pull.
132+
133+
Give every key a name in Vapi before the first pull. Two keys with no name
134+
and the same provider get the same name here, and only one is kept. Pull
135+
warns when that happens.
136+
137+
## Promotion
138+
139+
A credential with the binding policy `omit` is dropped from a promoted file.
140+
For a single `credentialId` that is the point. For an entry in a
141+
`credentialIds` list it narrows what calls in the destination may use, so
142+
the plan says so:
143+
144+
```text
145+
release: dev → prod
146+
update squads/south-front-desk.yml
147+
⚠️ squads/south-front-desk.yml: credentialIds entry "elevenlabs" is left out in prod (binding policy "omit"). Calls there can use only the keys still on the list, so that provider would run on Vapi's own key.
148+
```
149+
150+
See [Promotion](promotion.md) for bindings.

‎docs/guides/how-it-works.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ Credentials are managed automatically through the state file. No secrets in reso
115115
2. Resource files use human-readable credential names
116116
3. **Push** resolves names back to UUIDs before sending to the API
117117

118+
Pull also records each credential's provider in
119+
`resources/<org>/.vapi-credential-providers.json`, so `validate` can check a
120+
`credentialIds` list against the keys the org has: see
121+
[Credential pins](credential-pins.md).
122+
118123
Setup and pull also refresh a marked block in the gitignored `.env.<org>` file:
119124

120125
```dotenv

‎docs/learnings/squads.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ The final assistant configuration is built by merging these layers in order:
165165

166166
Later layers win on conflicts. `variableValues` from all layers are merged separately.
167167

168+
`credentialIds` follows the same order with one difference: a list on the base assistant is kept and the override's list is added to it, while `squad.membersOverrides.credentialIds` replaces `member.assistantOverrides.credentialIds`.
169+
170+
**Gotcha:** a `credentialIds` list anywhere in the squad narrows the whole call to the listed keys, for every member and every provider. A provider left off runs on Vapi's own key with no error. List every key the call needs, and let `npm run validate` check it: see [Credential pins](../guides/credential-pins.md).
171+
168172
**Gotcha:** Liquid template substitution replaces undefined variables with **empty strings**, not errors. If a variable isn't in the merged `variableValues`, any `{{ myVar }}` reference silently becomes `""`.
169173

170174
---

‎improvements.md‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,62 @@ run's hand-off to the workflow, and an older workflow reads it there.
21512151

21522152
---
21532153

2154+
## 40. Nothing checked a `credentialIds` list against the keys an org has saved
2155+
2156+
**[RESOLVED 2026-11-17] (#PR_NUMBER)**
2157+
2158+
**Discovered:** 2026-11-17, while planning one squad per site in an org that
2159+
holds an Azure OpenAI key per site.
2160+
2161+
### Problem
2162+
2163+
A `credentialIds` list is the full set of keys a call may use, and every
2164+
squad member's list is pooled into one. A provider left off the list does
2165+
not fail the call: it runs on Vapi's own key. The engine could not tell a
2166+
complete list from one that hides the org's own voice, transcriber or
2167+
storage key.
2168+
2169+
### Current behavior (Verified)
2170+
2171+
- The state file records `name → uuid` for a credential and nothing else,
2172+
so the engine did not know which provider a saved key is for.
2173+
- `validate` only checked that each name on a list exists in the state file.
2174+
- Promotion dropped a `credentialIds` entry whose binding policy is `omit`
2175+
without saying so.
2176+
- Two credentials with no name and the same provider get the same slug on
2177+
pull, and the second silently replaces the first in the state file.
2178+
2179+
### Risk
2180+
2181+
An org that must run only on its own keys sends audio or prompts to Vapi's
2182+
provider accounts when one entry is missed in one squad file, with nothing
2183+
in the push output or the call to show it.
2184+
2185+
### Current mitigation
2186+
2187+
None before this change, other than reading every list by hand.
2188+
2189+
### Possible fix
2190+
2191+
Record each credential's provider on pull, report a list that leaves out a
2192+
key the org has saved for something the call uses, and let an org mark
2193+
itself customer-keys-only so the report is an error there.
2194+
2195+
### Status
2196+
2197+
**RESOLVED 2026-11-17.** Pull writes
2198+
`resources/<org>/.vapi-credential-providers.json` and warns when two
2199+
credentials collide on one name. `validate` has the
2200+
`credential-pin-hides-key` rule, an error in an org whose
2201+
`.vapi-policy.yml` sets `customerKeysOnly: true`. The promotion plan warns
2202+
when `omit` drops a `credentialIds` entry. See
2203+
[Credential pins](docs/guides/credential-pins.md).
2204+
2205+
Still open: the slug collision itself is only warned about, and the check
2206+
does not know which models or regions a key covers.
2207+
2208+
---
2209+
21542210
## Out of scope (intentionally not improvements)
21552211

21562212
- **State file is identity-only and not git-ignored.** It's intentionally

‎src/credential-kinds.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// What each saved credential is a key for.
2+
//
3+
// The state file maps a credential's name to its UUID and nothing else. A
4+
// `credentialIds` list can only be checked against the org's keys when the
5+
// provider of each key is known too, and pull already fetches that. Pull
6+
// records it in resources/<org>/.vapi-credential-providers.json, which is
7+
// committed with the folder. It holds no secret: a provider name per key,
8+
// and whether a storage bucket is set on it.
9+
//
10+
// Config-free so validate, push and tests can read any org.
11+
12+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
13+
import { join } from "node:path";
14+
import { sortedKeysReplacer } from "./state-serialize.ts";
15+
16+
export const CREDENTIAL_KINDS_FILE = ".vapi-credential-providers.json";
17+
18+
export interface CredentialKind {
19+
provider: string;
20+
// The key has a storage bucket configured. A gcp, azure or supabase key
21+
// only receives recordings when it does.
22+
bucket?: true;
23+
}
24+
25+
// Credential name (as resource files write it) → what it is a key for.
26+
export type CredentialKinds = Record<string, CredentialKind>;
27+
28+
function record(value: unknown): Record<string, unknown> | undefined {
29+
return value && typeof value === "object" && !Array.isArray(value)
30+
? (value as Record<string, unknown>)
31+
: undefined;
32+
}
33+
34+
/** What one credential from GET /credential is a key for. */
35+
export function credentialKindOf(
36+
credential: Record<string, unknown>,
37+
): CredentialKind | undefined {
38+
if (typeof credential.provider !== "string" || !credential.provider)
39+
return undefined;
40+
const plan = record(credential.bucketPlan);
41+
const bucket = plan?.name || plan?.containerName;
42+
return typeof bucket === "string" && bucket
43+
? { provider: credential.provider, bucket: true }
44+
: { provider: credential.provider };
45+
}
46+
47+
/** The org's recorded credential kinds, or undefined before its first pull. */
48+
export function credentialKindsRead(
49+
resourcesDir: string,
50+
): CredentialKinds | undefined {
51+
const path = join(resourcesDir, CREDENTIAL_KINDS_FILE);
52+
if (!existsSync(path)) return undefined;
53+
const raw = record(JSON.parse(readFileSync(path, "utf-8")));
54+
if (!raw) throw new Error(`${path} must hold a JSON object`);
55+
const kinds: CredentialKinds = {};
56+
for (const [name, value] of Object.entries(raw)) {
57+
const entry = record(value);
58+
if (typeof entry?.provider !== "string") continue;
59+
kinds[name] =
60+
entry.bucket === true
61+
? { provider: entry.provider, bucket: true }
62+
: { provider: entry.provider };
63+
}
64+
return kinds;
65+
}
66+
67+
/** Write the org's credential kinds. Returns false when nothing changed. */
68+
export function credentialKindsWrite(
69+
resourcesDir: string,
70+
kinds: CredentialKinds,
71+
): boolean {
72+
const path = join(resourcesDir, CREDENTIAL_KINDS_FILE);
73+
const content = `${JSON.stringify(kinds, sortedKeysReplacer, 2)}\n`;
74+
if (existsSync(path) && readFileSync(path, "utf-8") === content) return false;
75+
mkdirSync(resourcesDir, { recursive: true });
76+
writeFileSync(path, content);
77+
return true;
78+
}

‎src/org-policy.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Rules an org's folder must hold, set by hand in
2+
// resources/<org>/.vapi-policy.yml and committed with the folder.
3+
//
4+
// customerKeysOnly: true
5+
//
6+
// marks an org whose calls must never run on Vapi's own provider keys. The
7+
// credential-pin check is an error there and a warning everywhere else.
8+
// Promotion skips dotfiles, so a policy never travels to another org.
9+
//
10+
// Config-free so validate, push and tests can read any org.
11+
12+
import { existsSync, readFileSync } from "node:fs";
13+
import { join } from "node:path";
14+
import { parse as parseYaml } from "yaml";
15+
16+
export const ORG_POLICY_FILE = ".vapi-policy.yml";
17+
18+
export interface OrgPolicy {
19+
customerKeysOnly: boolean;
20+
}
21+
22+
const ORG_POLICY_KEYS = ["customerKeysOnly"];
23+
24+
export function orgPolicyParse(content: string): OrgPolicy {
25+
const raw: unknown = parseYaml(content) ?? {};
26+
if (typeof raw !== "object" || Array.isArray(raw))
27+
throw new Error(`${ORG_POLICY_FILE} must be a mapping`);
28+
const policy = raw as Record<string, unknown>;
29+
// A typo (`customerKeyOnly:`) must not quietly turn a safety rule off.
30+
for (const key of Object.keys(policy))
31+
if (!ORG_POLICY_KEYS.includes(key))
32+
throw new Error(
33+
`${ORG_POLICY_FILE}: unknown key "${key}" (known: ${ORG_POLICY_KEYS.join(", ")})`,
34+
);
35+
const { customerKeysOnly = false } = policy;
36+
if (typeof customerKeysOnly !== "boolean")
37+
throw new Error(
38+
`${ORG_POLICY_FILE}: customerKeysOnly must be true or false`,
39+
);
40+
return { customerKeysOnly };
41+
}
42+
43+
/** The org's policy; every rule is off when the file doesn't exist. */
44+
export function orgPolicyRead(resourcesDir: string): OrgPolicy {
45+
const path = join(resourcesDir, ORG_POLICY_FILE);
46+
return orgPolicyParse(existsSync(path) ? readFileSync(path, "utf-8") : "");
47+
}

0 commit comments

Comments
 (0)