unbound-cli 1.26.0 → 1.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LOCAL_DEV.md CHANGED
@@ -147,7 +147,7 @@ node src/index.js policy model create --name "Sonnet Only" --allowed claude-3-5-
147
147
 
148
148
  # Security policies
149
149
  node src/index.js policy security create --name "Block PII" --sub-type guardrails \
150
- --guardrail PII:BLOCK --guardrail Secrets:REDACT
150
+ --guardrail PII:BLOCK --guardrail Secrets:AUDIT
151
151
  node src/index.js policy security create --name "Route 429s" --sub-type error-code-routing \
152
152
  --error-route 429:gpt-4:claude-3-5-sonnet
153
153
 
package/README.md CHANGED
@@ -173,9 +173,9 @@ unbound policy cost list
173
173
  Security policy examples:
174
174
 
175
175
  ```bash
176
- # Block PII, redact secrets, for the engg group
176
+ # Block PII and audit secrets for the engg group
177
177
  unbound policy security create --name "Block PII" --sub-type guardrails \
178
- --guardrail PII:BLOCK --guardrail Secrets:REDACT --group engg
178
+ --guardrail PII:BLOCK --guardrail Secrets:AUDIT --group engg
179
179
 
180
180
  # Default-route gpt-4 traffic to claude-3-5-sonnet
181
181
  unbound policy security create --name "Prefer Sonnet" --sub-type default-routing \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unbound-cli",
3
- "version": "1.26.0",
3
+ "version": "1.26.2",
4
4
  "description": "CLI tool for Unbound - AI Gateway management",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -520,6 +520,10 @@ Examples:
520
520
  }
521
521
  fs.mkdirSync(opts.out, { recursive: true });
522
522
  for (const name of [...packs.keys()].sort((a, b) => a.localeCompare(b))) {
523
+ if (!SLUG_RE.test(name)) {
524
+ output.warn(`pack "${name}": not a valid pack name, no file written.`);
525
+ continue;
526
+ }
523
527
  const { live, version, owner } = await fetchStablePack(name);
524
528
  for (const { row } of live.unsupported) output.warn(`${row.name}: unsupported policy type, not exported.`);
525
529
  if (!live.tool.length && !live.generic.length) {
@@ -15,7 +15,7 @@ const DOCS_SECURITY = 'https://docs.getunbound.ai/policies/security-policies';
15
15
  const DOCS_TOOL = 'https://docs.getunbound.ai/policies/tool-policies';
16
16
 
17
17
  const POLICY_TYPES = ['SECURITY', 'MODEL', 'COST'];
18
- const GUARDRAIL_ACTIONS = ['BLOCK', 'REDACT', 'ROUTE', 'AUDIT'];
18
+ const GUARDRAIL_ACTIONS = ['BLOCK', 'AUDIT'];
19
19
  const TOOL_ACTIONS = ['AUDIT', 'BLOCK', 'WARN', 'REQUIRE_SLACK_APPROVAL'];
20
20
  const SECURITY_SUB_TYPES = ['guardrails', 'default_routing', 'error_code_routing'];
21
21
  const MCP_ACTION_TYPES = ['read', 'write', 'destructive'];
@@ -229,7 +229,7 @@ function parseJsonOrThrow(str, flagName = '--config') {
229
229
  * {guardrail_id, action, threshold, route_model_id, entities, enabled} shape
230
230
  * the backend expects. Resolves the name and validates the action.
231
231
  */
232
- function parseGuardrailSpec(spec, allGuardrails, routeModelId) {
232
+ function parseGuardrailSpec(spec, allGuardrails) {
233
233
  const parts = spec.split(':');
234
234
  if (parts.length < 2 || parts.length > 3) {
235
235
  throw new Error(`Invalid --guardrail spec "${spec}". Expected format: <name>:<action>[:<threshold>]`);
@@ -254,10 +254,6 @@ function parseGuardrailSpec(spec, allGuardrails, routeModelId) {
254
254
  );
255
255
  }
256
256
 
257
- if (action === 'ROUTE' && !routeModelId) {
258
- throw new Error(`Guardrail "${guardrail.name}" uses ROUTE but --route-model was not provided.`);
259
- }
260
-
261
257
  const threshold = thresholdRaw != null ? Number(thresholdRaw) : 1;
262
258
  if (Number.isNaN(threshold) || threshold < 1 || threshold > 100) {
263
259
  throw new Error(`Invalid threshold "${thresholdRaw}" for guardrail "${guardrail.name}". Must be 1-100.`);
@@ -268,7 +264,7 @@ function parseGuardrailSpec(spec, allGuardrails, routeModelId) {
268
264
  enabled: true,
269
265
  action,
270
266
  threshold,
271
- route_model_id: action === 'ROUTE' ? routeModelId : null,
267
+ route_model_id: null,
272
268
  entities: (guardrail.entities || []).map((e) => ({ entity_id: e.id, enabled: true })),
273
269
  };
274
270
  }
@@ -1118,7 +1114,7 @@ function registerSecurity(policy) {
1118
1114
  .description('Manage Security policies. Guardrails for PII/secrets and model routing rules.')
1119
1115
  .addHelpText('after', `
1120
1116
  Security policies come in three sub-types:
1121
- guardrails Detect/block/redact sensitive content (PII, secrets, etc.)
1117
+ guardrails Detect sensitive content (PII, secrets, etc.) and block or audit it
1122
1118
  default-routing Route one model's traffic to another
1123
1119
  error-code-routing Re-route on specific HTTP error codes (e.g. 429 → fallback model)
1124
1120
 
@@ -1167,7 +1163,6 @@ Subcommands:
1167
1163
  .requiredOption('--name <name>', 'Policy name (required)')
1168
1164
  .option('--sub-type <type>', 'Sub-type: guardrails | default-routing | error-code-routing')
1169
1165
  .option('--guardrail <spec>', 'Guardrail spec: <name>:<action>[:<threshold>]. Repeatable. For guardrails sub-type.', (val, prev = []) => [...prev, val])
1170
- .option('--route-model <name>', 'Target model name for guardrail ROUTE actions')
1171
1166
  .option('--route <spec>', 'Default routing rule: <source-model>:<target-model>. Repeatable. For default-routing sub-type.', (val, prev = []) => [...prev, val])
1172
1167
  .option('--error-route <spec>', 'Error routing rule: <error-code>:<source-model>:<target-model>. Repeatable. For error-code-routing sub-type.', (val, prev = []) => [...prev, val])
1173
1168
  .option('--group <names|ids>', 'Comma-separated user group names or IDs to scope this policy to')
@@ -1179,10 +1174,7 @@ Subcommands:
1179
1174
  Examples:
1180
1175
  Guardrails sub-type:
1181
1176
  $ unbound policy security create --name "Block PII" --sub-type guardrails \\
1182
- --guardrail PII:BLOCK --guardrail Secrets:REDACT --group engg
1183
-
1184
- $ unbound policy security create --name "Route PII To Safe Model" --sub-type guardrails \\
1185
- --guardrail PII:ROUTE --route-model claude-3-5-sonnet
1177
+ --guardrail PII:BLOCK --guardrail Secrets:AUDIT --group engg
1186
1178
 
1187
1179
  Default routing sub-type:
1188
1180
  $ unbound policy security create --name "Prefer Sonnet" --sub-type default-routing \\
@@ -1220,15 +1212,7 @@ Learn more: ${DOCS_SECURITY}
1220
1212
  }
1221
1213
  const formData = await loadFormData();
1222
1214
  const guardrails = formData.guardrails || [];
1223
- const models = formData.ai_models || [];
1224
-
1225
- let routeModelId = null;
1226
- if (opts.routeModel) {
1227
- const m = resolveFull(models, opts.routeModel, { kind: 'model' })[0];
1228
- routeModelId = m.id;
1229
- }
1230
-
1231
- configObj.guardrails = opts.guardrail.map((spec) => parseGuardrailSpec(spec, guardrails, routeModelId));
1215
+ configObj.guardrails = opts.guardrail.map((spec) => parseGuardrailSpec(spec, guardrails));
1232
1216
  } else if (subType === 'default_routing') {
1233
1217
  if (!opts.route || opts.route.length === 0) {
1234
1218
  throw new Error('At least one --route is required for sub-type default-routing.');
@@ -85,8 +85,8 @@ function validateSecurityConfig(config, file) {
85
85
  if (item.enabled != null && typeof item.enabled !== 'boolean') {
86
86
  fail(`${path}.enabled`, 'must be a boolean');
87
87
  }
88
- if (item.action != null && !['AUDIT', 'BLOCK', 'REDACT', 'ROUTE'].includes(item.action)) {
89
- fail(`${path}.action`, 'must be one of: AUDIT, BLOCK, REDACT, ROUTE');
88
+ if (item.action != null && !['AUDIT', 'BLOCK'].includes(item.action)) {
89
+ fail(`${path}.action`, 'must be one of: AUDIT, BLOCK');
90
90
  }
91
91
  if (item.threshold != null && (!Number.isInteger(item.threshold) || item.threshold < 1 || item.threshold > 100)) {
92
92
  fail(`${path}.threshold`, 'must be an integer from 1 to 100');
@@ -94,9 +94,6 @@ function validateSecurityConfig(config, file) {
94
94
  if (item.route_model_id !== undefined && item.route_model_id !== null && item.route_model_id !== '' && !isPositiveInteger(item.route_model_id)) {
95
95
  fail(`${path}.route_model_id`, 'must be a positive integer ID');
96
96
  }
97
- if (item.action === 'ROUTE' && !item.route_model_id) {
98
- fail(`${path}.route_model_id`, 'is required when action is ROUTE');
99
- }
100
97
  if (item.priority != null && !Number.isInteger(item.priority)) {
101
98
  fail(`${path}.priority`, 'must be an integer');
102
99
  }
@@ -21,7 +21,7 @@ const POLICY_KINDS = ['tool', 'security', 'model', 'cost'];
21
21
  const GENERIC_KINDS = ['security', 'model', 'cost'];
22
22
  const TOOL_TYPES = ['TERMINAL_COMMAND', 'MCP_TOOL'];
23
23
  const TOOL_ACTIONS = ['AUDIT', 'BLOCK', 'WARN', 'REQUIRE_SLACK_APPROVAL'];
24
- const GUARDRAIL_ACTIONS = ['BLOCK', 'REDACT', 'ROUTE', 'AUDIT'];
24
+ const GUARDRAIL_ACTIONS = ['BLOCK', 'AUDIT'];
25
25
  const MCP_ACTION_TYPES = ['read', 'write', 'destructive'];
26
26
 
27
27
  const SLUG_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
@@ -203,7 +203,6 @@ function validateGuardrails(guardrails, where, file) {
203
203
  if (g.entities !== undefined && !isStringArray(g.entities)) throw new PackError(`${gw}.entities must be a list of entity names`, { file });
204
204
  if (g.routeModel !== undefined && typeof g.routeModel !== 'string') throw new PackError(`${gw}.routeModel must be a model name`, { file });
205
205
  if (g.enabled !== undefined && typeof g.enabled !== 'boolean') throw new PackError(`${gw}.enabled must be true or false`, { file });
206
- if (g.action === 'ROUTE' && !g.routeModel) throw new PackError(`${gw}.routeModel is required when action is ROUTE`, { file });
207
206
  });
208
207
  }
209
208
 
@@ -432,3 +432,31 @@ test('adopt keeps the stored owner in the apply and generated pack', async () =>
432
432
  fs.rmSync(home, { recursive: true, force: true });
433
433
  }
434
434
  });
435
+
436
+ test('pack export --all skips a pack name that would write outside the folder', async () => {
437
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'pack-export-'));
438
+ const out = path.join(home, 'out');
439
+ const server = http.createServer((req, res) => {
440
+ const send = (body) => {
441
+ res.writeHead(200, { 'Content-Type': 'application/json' });
442
+ res.end(JSON.stringify(body));
443
+ };
444
+ if (req.url.startsWith('/api/v1/policies/form_data/')) return send({ data: {} });
445
+ if (req.url.startsWith('/api/v1/labels/')) return send({ labels: [] });
446
+ if (req.url.startsWith('/api/v1/command-policies/')) {
447
+ return send({ policies: [{ id: '1', name: 'x', policy_type: 'MCP_TOOL', origin: 'CODE', code_pack: '../escape', code_slug: 'x' }], total_pages: 1 });
448
+ }
449
+ return send({ policies: [] });
450
+ });
451
+ try {
452
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
453
+ const result = await runCli(null, server.address().port, home, ['export', '--all', '-o', out]);
454
+ assert.equal(result.code, 0, result.stderr);
455
+ assert.match(result.stdout + result.stderr, /not a valid pack name/);
456
+ assert.equal(fs.existsSync(path.join(home, 'escape.yaml')), false);
457
+ assert.deepEqual(fs.readdirSync(out), []);
458
+ } finally {
459
+ server.close();
460
+ fs.rmSync(home, { recursive: true, force: true });
461
+ }
462
+ });
@@ -54,7 +54,8 @@ test('toDesired: builds write bodies with resolved ids', () => {
54
54
  test('toDesired: unresolved names fail before any write', () => {
55
55
  assert.throws(() => plan.toDesired(pack([{ ...TERMINAL, scope: { userGroups: ['Nope'] } }]), REF), /no user group named "Nope"/);
56
56
  assert.throws(() => plan.toDesired(pack([{ ...SECURITY, guardrails: [{ name: 'Secrets', action: 'BLOCK' }] }]), REF), /no guardrail named "Secrets"/);
57
- assert.throws(() => plan.toDesired(pack([{ ...SECURITY, guardrails: [{ name: 'PII', action: 'REDACT' }] }]), REF), /does not support REDACT/);
57
+ const blockOnly = { ...REF, guardrails: [{ ...REF.guardrails[0], supported_actions: ['BLOCK'] }] };
58
+ assert.throws(() => plan.toDesired(pack([{ ...SECURITY, guardrails: [{ name: 'PII', action: 'AUDIT' }] }]), blockOnly), /does not support AUDIT/);
58
59
  assert.throws(() => plan.toDesired(pack([{ ...MODEL, models: { allowed: ['llama'] } }]), REF), /no model named "llama"/);
59
60
  assert.throws(() => plan.toDesired(pack([{ ...COST, scope: { toolTypes: ['vim'] } }]), REF), /unknown tool type vim/);
60
61
  assert.throws(() => plan.toDesired(pack([{ ...SECURITY, labels: ['nope'] }]), REF), /no label named "nope"/);
@@ -109,7 +109,11 @@ test('validatePack: tool policy rules', () => {
109
109
 
110
110
  test('validatePack: generic policy rules', () => {
111
111
  assert.throws(() => load(BASE.replace(' threshold: 5', ' threshold: 500')), /threshold must be an integer from 1 to 100/);
112
- assert.throws(() => load(BASE.replace(' action: BLOCK\n threshold: 5', ' action: ROUTE\n')), /routeModel is required when action is ROUTE/);
112
+ for (const action of ['REDACT', 'ROUTE']) {
113
+ assert.throws(() => load(BASE.replace(' action: BLOCK', ` action: ${action}`)), /action must be one of: BLOCK, AUDIT/);
114
+ const rawConfig = BASE.replace(' guardrails:\n - name: PII\n action: BLOCK\n threshold: 5', ` config:\n guardrails:\n - guardrail_id: 1\n action: ${action}`);
115
+ assert.throws(() => load(rawConfig), /action: must be one of: AUDIT, BLOCK$/);
116
+ }
113
117
  assert.throws(() => load(BASE.replace(' config:\n monthly_budget: 5000', ' config: {}')), /cost policy needs a config/);
114
118
  assert.throws(() => load(BASE.replace(' priority: 10', ' priority: 10\n config:\n guardrails: []')), /either guardrails or config.guardrails/);
115
119
  const modelBad = BASE.replace(' kind: cost\n enabled: false\n config:\n monthly_budget: 5000', ' kind: model\n models:\n allowed: [a]\n allowAll: true');
@@ -0,0 +1,74 @@
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const { Command } = require('commander');
4
+ const config = require('../src/config');
5
+ const api = require('../src/api');
6
+ const output = require('../src/output');
7
+ const { register } = require('../src/commands/policy');
8
+
9
+ // Data policy guardrails take BLOCK or AUDIT, as the backend's form data lists them.
10
+
11
+ const ALL = ['BLOCK', 'REDACT', 'ROUTE', 'AUDIT'];
12
+ const FORM_DATA = {
13
+ guardrails: [
14
+ { id: 1, name: 'PII', supported_actions: ALL, entities: [] },
15
+ { id: 2, name: 'Secrets', supported_actions: ALL, entities: [] },
16
+ ],
17
+ ai_models: [],
18
+ };
19
+
20
+ function stub() {
21
+ const orig = {
22
+ isLoggedIn: config.isLoggedIn, get: api.get, post: api.post,
23
+ success: output.success, error: output.error, json: output.json,
24
+ exitCode: process.exitCode,
25
+ };
26
+ const seen = { postBody: null, errors: [] };
27
+ config.isLoggedIn = () => true;
28
+ api.get = async () => FORM_DATA;
29
+ api.post = async (_p, { body }) => { seen.postBody = body; return { policy: { id: 9, ...body } }; };
30
+ output.success = () => {};
31
+ output.error = (m) => { seen.errors.push(m); };
32
+ output.json = () => {};
33
+ return {
34
+ seen,
35
+ restore() {
36
+ config.isLoggedIn = orig.isLoggedIn; api.get = orig.get; api.post = orig.post;
37
+ output.success = orig.success; output.error = orig.error; output.json = orig.json;
38
+ process.exitCode = orig.exitCode;
39
+ },
40
+ };
41
+ }
42
+
43
+ async function create(...guardrails) {
44
+ const program = new Command();
45
+ register(program);
46
+ const flags = guardrails.flatMap((g) => ['--guardrail', g]);
47
+ await program.parseAsync(['node', 'x', 'policy', 'security', 'create', '--name', 'P', '--sub-type', 'guardrails', ...flags, '--json']);
48
+ }
49
+
50
+ for (const action of ['REDACT', 'ROUTE']) {
51
+ test(`a ${action} guardrail is refused before anything is sent`, async () => {
52
+ const { seen, restore } = stub();
53
+ try {
54
+ await create('PII:BLOCK', `Secrets:${action}`);
55
+ assert.equal(seen.postBody, null);
56
+ assert.equal(seen.errors.length, 1);
57
+ assert.match(seen.errors[0], new RegExp(`Invalid guardrail action "${action}"\\. Must be one of: BLOCK, AUDIT`));
58
+ assert.equal(process.exitCode, 1);
59
+ } finally {
60
+ restore();
61
+ }
62
+ });
63
+ }
64
+
65
+ test('the help example, BLOCK and AUDIT, is sent as given', async () => {
66
+ const { seen, restore } = stub();
67
+ try {
68
+ await create('PII:BLOCK', 'Secrets:AUDIT');
69
+ assert.deepEqual(seen.errors, []);
70
+ assert.deepEqual(seen.postBody.config.guardrails.map((g) => [g.guardrail_id, g.action]), [[1, 'BLOCK'], [2, 'AUDIT']]);
71
+ } finally {
72
+ restore();
73
+ }
74
+ });