@faable/faable 4.34.1 → 4.35.0
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.
|
@@ -2,12 +2,13 @@ import { withAuthHints, requireAuthAdmin } from '../../../api/auth_admin.js';
|
|
|
2
2
|
import { log } from '../../../log.js';
|
|
3
3
|
import { tenant_options } from '../options.js';
|
|
4
4
|
import { yes_no } from '../render.js';
|
|
5
|
+
import { api_setting_options, api_settings_patch } from './settings.js';
|
|
5
6
|
import { json_option, print_json } from '../../../lib/listing.js';
|
|
6
7
|
|
|
7
8
|
const apis_create = {
|
|
8
9
|
command: 'create <identifier>',
|
|
9
10
|
describe: 'Create an API (the audience tokens are issued for)',
|
|
10
|
-
builder: yargs => json_option(tenant_options(yargs))
|
|
11
|
+
builder: yargs => api_setting_options(json_option(tenant_options(yargs)))
|
|
11
12
|
.positional('identifier', {
|
|
12
13
|
type: 'string',
|
|
13
14
|
demandOption: true,
|
|
@@ -26,18 +27,22 @@ const apis_create = {
|
|
|
26
27
|
description: 'Turn on RBAC (and the access_token_authz dialect, which carries `permissions`)'
|
|
27
28
|
})
|
|
28
29
|
.example('$0 auth apis create https://api.example.com --permission tickets:read --permission tickets:write --rbac', 'An API whose user tokens carry the permissions their roles grant')
|
|
30
|
+
.example('$0 auth apis create https://api.example.com --token-lifetime 3600 --include-roles-in-access-token', 'Access tokens that last one hour and carry the `roles` claim')
|
|
29
31
|
.showHelpOnFail(false),
|
|
30
32
|
handler: withAuthHints(async (args) => {
|
|
33
|
+
// Before the login: a bad value fails without touching the network.
|
|
34
|
+
const settings = api_settings_patch(args);
|
|
31
35
|
const api = await requireAuthAdmin(args);
|
|
32
36
|
const a = (await api.apiCreate({
|
|
33
37
|
name: args.name ?? args.identifier,
|
|
34
38
|
identifier: args.identifier,
|
|
35
39
|
permissions: (args.permission ?? []).map(value => ({ value })),
|
|
36
|
-
...(args.rbac ? { rbac: true, token_dialect: 'access_token_authz' } : {})
|
|
40
|
+
...(args.rbac ? { rbac: true, token_dialect: 'access_token_authz' } : {}),
|
|
41
|
+
...settings
|
|
37
42
|
}));
|
|
38
43
|
if (args.json)
|
|
39
44
|
return print_json(a);
|
|
40
|
-
log.info(`✅ Created API ${a.name} (${a.id}) — ${a.identifier}, ${a.permissions?.length ?? 0} permission(s), RBAC ${yes_no(a.rbac)}.`);
|
|
45
|
+
log.info(`✅ Created API ${a.name} (${a.id}) — ${a.identifier}, ${a.permissions?.length ?? 0} permission(s), RBAC ${yes_no(a.rbac)}, tokens last ${a.token_lifetime} s.`);
|
|
41
46
|
})
|
|
42
47
|
};
|
|
43
48
|
|
|
@@ -24,7 +24,12 @@ const apis_get = {
|
|
|
24
24
|
log.info(` Identifier: ${a.identifier}`);
|
|
25
25
|
log.info(` Token dialect: ${a.token_dialect ?? '-'}`);
|
|
26
26
|
log.info(` RBAC: ${yes_no(a.rbac)}`);
|
|
27
|
+
log.info(` Token lifetime: ${a.token_lifetime ?? '-'} s`);
|
|
27
28
|
log.info(` Enforce policies: ${yes_no(a.enforce_policies)}`);
|
|
29
|
+
log.info(` Offline access: ${yes_no(a.allow_offline_access)}`);
|
|
30
|
+
log.info(` Skip consent: ${yes_no(a.skip_consent)}`);
|
|
31
|
+
log.info(` Roles claim: access token ${yes_no(a.include_roles_in_access_token)}, id_token ${yes_no(a.include_roles_in_id_token)}`);
|
|
32
|
+
log.info(` Teams claim: access token ${yes_no(a.include_teams_in_access_token)}, id_token ${yes_no(a.include_teams_in_id_token)}`);
|
|
28
33
|
log.info(` Permissions (${a.permissions?.length ?? 0}):`);
|
|
29
34
|
for (const p of a.permissions ?? []) {
|
|
30
35
|
log.info(` ${p.value}${p.description ? ` — ${p.description}` : ''}`);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CliError } from '../../../lib/errors.js';
|
|
2
|
+
|
|
3
|
+
// The range the Auth API accepts (auth ApiCreate / ApiUpdate schemas).
|
|
4
|
+
const TOKEN_LIFETIME_MIN = 60;
|
|
5
|
+
const TOKEN_LIFETIME_MAX = 60 * 60 * 24 * 30;
|
|
6
|
+
// Every boolean setting `apis get --json` shows, flag = the field in kebab case.
|
|
7
|
+
const API_BOOLEAN_SETTINGS = {
|
|
8
|
+
allow_offline_access: 'Clients may request `offline_access` and get a refresh_token for this API',
|
|
9
|
+
skip_consent: 'Skip the consent screen for first-party clients',
|
|
10
|
+
include_roles_in_access_token: "Access tokens carry a `roles` claim with the user's role names",
|
|
11
|
+
include_teams_in_access_token: "Access tokens carry a `teams` claim with the user's team slugs",
|
|
12
|
+
include_roles_in_id_token: 'id_tokens issued with an access token for this API carry `roles`',
|
|
13
|
+
include_teams_in_id_token: 'id_tokens issued with an access token for this API carry `teams`',
|
|
14
|
+
enforce_policies: 'Filter the requested scopes against the permission catalog at issuance'
|
|
15
|
+
};
|
|
16
|
+
const camel = (field) => field.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
17
|
+
const kebab = (field) => field.replace(/_/g, '-');
|
|
18
|
+
const api_setting_options = (yargs) => {
|
|
19
|
+
let y = yargs
|
|
20
|
+
.option('token-lifetime', {
|
|
21
|
+
// A string, so "3600.5" or "1h" are refused instead of rounded or NaN.
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: `Access token lifetime in seconds, ${TOKEN_LIFETIME_MIN}–${TOKEN_LIFETIME_MAX} (30 days); a new API gets 86400`
|
|
24
|
+
})
|
|
25
|
+
.option('description', {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'Description of the API'
|
|
28
|
+
});
|
|
29
|
+
for (const [field, description] of Object.entries(API_BOOLEAN_SETTINGS)) {
|
|
30
|
+
y = y.option(kebab(field), {
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
description
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return y;
|
|
36
|
+
};
|
|
37
|
+
const parse_token_lifetime = (raw) => {
|
|
38
|
+
const n = /^\d+$/.test(raw.trim()) ? Number(raw.trim()) : NaN;
|
|
39
|
+
if (!Number.isSafeInteger(n) ||
|
|
40
|
+
n < TOKEN_LIFETIME_MIN ||
|
|
41
|
+
n > TOKEN_LIFETIME_MAX) {
|
|
42
|
+
throw new CliError('usage', `--token-lifetime must be a whole number of seconds between ${TOKEN_LIFETIME_MIN} and ${TOKEN_LIFETIME_MAX} (30 days), got "${raw}".`);
|
|
43
|
+
}
|
|
44
|
+
return n;
|
|
45
|
+
};
|
|
46
|
+
// The fields of the body the flags ask for — only those passed.
|
|
47
|
+
const api_settings_patch = (args) => {
|
|
48
|
+
const patch = {};
|
|
49
|
+
if (args.tokenLifetime !== undefined) {
|
|
50
|
+
patch.token_lifetime = parse_token_lifetime(String(args.tokenLifetime));
|
|
51
|
+
}
|
|
52
|
+
if (args.description !== undefined)
|
|
53
|
+
patch.description = args.description;
|
|
54
|
+
for (const field of Object.keys(API_BOOLEAN_SETTINGS)) {
|
|
55
|
+
const value = args[camel(field)];
|
|
56
|
+
if (typeof value === 'boolean')
|
|
57
|
+
patch[field] = value;
|
|
58
|
+
}
|
|
59
|
+
return patch;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { API_BOOLEAN_SETTINGS, TOKEN_LIFETIME_MAX, TOKEN_LIFETIME_MIN, api_setting_options, api_settings_patch, parse_token_lifetime };
|
|
@@ -4,12 +4,13 @@ import { log } from '../../../log.js';
|
|
|
4
4
|
import { tenant_options } from '../options.js';
|
|
5
5
|
import { yes_no } from '../render.js';
|
|
6
6
|
import { resolve_api_ref } from '../roles/shared.js';
|
|
7
|
+
import { api_setting_options, api_settings_patch } from './settings.js';
|
|
7
8
|
import { json_option, print_json } from '../../../lib/listing.js';
|
|
8
9
|
|
|
9
10
|
const apis_update = {
|
|
10
11
|
command: 'update <api>',
|
|
11
|
-
describe: "Change an API's
|
|
12
|
-
builder: yargs => json_option(tenant_options(yargs))
|
|
12
|
+
describe: "Change an API's token settings and permission catalog (its identifier cannot change)",
|
|
13
|
+
builder: yargs => api_setting_options(json_option(tenant_options(yargs)))
|
|
13
14
|
.positional('api', {
|
|
14
15
|
type: 'string',
|
|
15
16
|
demandOption: true,
|
|
@@ -35,16 +36,19 @@ const apis_update = {
|
|
|
35
36
|
description: 'Remove a permission from the catalog — repeatable. Roles that grant it stop granting it'
|
|
36
37
|
})
|
|
37
38
|
.example('$0 auth apis update https://api.example.com --rbac --token-dialect access_token_authz', 'Turn on RBAC for an API')
|
|
39
|
+
.example('$0 auth apis update https://api.example.com --token-lifetime 3600', 'Access tokens issued from now on last one hour')
|
|
40
|
+
.epilog('Turn a yes/no setting off with --no-<flag>, e.g. --no-skip-consent. Changes apply to tokens issued from now on; tokens already issued keep theirs until they expire. The identifier (audience) cannot be changed: create a new API.')
|
|
38
41
|
.showHelpOnFail(false),
|
|
39
42
|
handler: withAuthHints(async (args) => {
|
|
40
43
|
const add = args.addPermission ?? [];
|
|
41
44
|
const rm = new Set(args.rmPermission ?? []);
|
|
42
45
|
const patch = {
|
|
43
46
|
...(args.rbac !== undefined ? { rbac: args.rbac } : {}),
|
|
44
|
-
...(args.tokenDialect ? { token_dialect: args.tokenDialect } : {})
|
|
47
|
+
...(args.tokenDialect ? { token_dialect: args.tokenDialect } : {}),
|
|
48
|
+
...api_settings_patch(args)
|
|
45
49
|
};
|
|
46
50
|
if (Object.keys(patch).length === 0 && !add.length && !rm.size) {
|
|
47
|
-
throw new CliError('usage', 'Nothing to update — pass
|
|
51
|
+
throw new CliError('usage', 'Nothing to update — pass a setting (--token-lifetime, --rbac, --token-dialect, --include-roles-in-access-token…), --add-permission or --rm-permission. See --help.');
|
|
48
52
|
}
|
|
49
53
|
const admin = await requireAuthAdmin(args);
|
|
50
54
|
const target = await resolve_api_ref(admin, args.api);
|
|
@@ -60,7 +64,7 @@ const apis_update = {
|
|
|
60
64
|
const a = (await admin.apiUpdate(target.id, patch));
|
|
61
65
|
if (args.json)
|
|
62
66
|
return print_json(a);
|
|
63
|
-
log.info(`✅ ${a.name}: RBAC ${yes_no(a.rbac)}, dialect ${a.token_dialect}. Applies to tokens issued from now on.`);
|
|
67
|
+
log.info(`✅ ${a.name}: RBAC ${yes_no(a.rbac)}, dialect ${a.token_dialect}, tokens last ${a.token_lifetime} s. Applies to tokens issued from now on.`);
|
|
64
68
|
if (a.rbac && a.token_dialect !== 'access_token_authz') {
|
|
65
69
|
log.warn('⚠️ RBAC is on but the dialect is not access_token_authz: tokens carry no `permissions` claim.');
|
|
66
70
|
}
|
package/dist/mcp/tools.js
CHANGED
|
@@ -99,6 +99,80 @@ const log_user = (l) => typeof l.user === 'string'
|
|
|
99
99
|
? { user_id: l.user.id, email: l.user.email, name: l.user.name }
|
|
100
100
|
: {};
|
|
101
101
|
const AUTH_READ = { ...READ };
|
|
102
|
+
// ── Auth APIs: the settings create_auth_api and update_auth_api take ────────
|
|
103
|
+
// Same names as the API fields; the CLI flag is the field in kebab case
|
|
104
|
+
// (src/commands/auth/apis/settings.ts).
|
|
105
|
+
const API_BOOLEANS = [
|
|
106
|
+
'allow_offline_access',
|
|
107
|
+
'skip_consent',
|
|
108
|
+
'include_roles_in_access_token',
|
|
109
|
+
'include_teams_in_access_token',
|
|
110
|
+
'include_roles_in_id_token',
|
|
111
|
+
'include_teams_in_id_token',
|
|
112
|
+
'enforce_policies'
|
|
113
|
+
];
|
|
114
|
+
const api_settings_input = {
|
|
115
|
+
token_lifetime: z
|
|
116
|
+
.number()
|
|
117
|
+
.int()
|
|
118
|
+
.min(60)
|
|
119
|
+
.max(60 * 60 * 24 * 30)
|
|
120
|
+
.optional()
|
|
121
|
+
.describe('Access token lifetime in seconds, 60–2592000 (30 days). A new API gets 86400'),
|
|
122
|
+
description: z.string().max(512).optional(),
|
|
123
|
+
rbac: z
|
|
124
|
+
.boolean()
|
|
125
|
+
.optional()
|
|
126
|
+
.describe('User tokens carry only the requested permissions their roles grant. On create it also sets the access_token_authz dialect'),
|
|
127
|
+
allow_offline_access: z
|
|
128
|
+
.boolean()
|
|
129
|
+
.optional()
|
|
130
|
+
.describe('Clients may request offline_access and get a refresh_token'),
|
|
131
|
+
skip_consent: z
|
|
132
|
+
.boolean()
|
|
133
|
+
.optional()
|
|
134
|
+
.describe('Skip the consent screen for first-party clients'),
|
|
135
|
+
include_roles_in_access_token: z
|
|
136
|
+
.boolean()
|
|
137
|
+
.optional()
|
|
138
|
+
.describe("Access tokens carry a `roles` claim with the user's role names"),
|
|
139
|
+
include_teams_in_access_token: z
|
|
140
|
+
.boolean()
|
|
141
|
+
.optional()
|
|
142
|
+
.describe("Access tokens carry a `teams` claim with the user's team slugs"),
|
|
143
|
+
include_roles_in_id_token: z
|
|
144
|
+
.boolean()
|
|
145
|
+
.optional()
|
|
146
|
+
.describe('id_tokens issued with an access token for this API carry `roles`'),
|
|
147
|
+
include_teams_in_id_token: z
|
|
148
|
+
.boolean()
|
|
149
|
+
.optional()
|
|
150
|
+
.describe('id_tokens issued with an access token for this API carry `teams`'),
|
|
151
|
+
enforce_policies: z
|
|
152
|
+
.boolean()
|
|
153
|
+
.optional()
|
|
154
|
+
.describe('Filter requested scopes against the permission catalog at issuance')
|
|
155
|
+
};
|
|
156
|
+
const api_settings_flags = (a) => [
|
|
157
|
+
...opt('--token-lifetime', a.token_lifetime),
|
|
158
|
+
...optText('--description', a.description),
|
|
159
|
+
...(a.rbac === undefined ? [] : [a.rbac ? '--rbac' : '--no-rbac']),
|
|
160
|
+
...API_BOOLEANS.flatMap(f => {
|
|
161
|
+
const flag = f.replace(/_/g, '-');
|
|
162
|
+
return a[f] === undefined ? [] : [a[f] ? `--${flag}` : `--no-${flag}`];
|
|
163
|
+
})
|
|
164
|
+
];
|
|
165
|
+
const api_detail = (a) => ({
|
|
166
|
+
id: a.id,
|
|
167
|
+
name: a.name,
|
|
168
|
+
identifier: a.identifier,
|
|
169
|
+
description: a.description,
|
|
170
|
+
token_lifetime: a.token_lifetime,
|
|
171
|
+
token_dialect: a.token_dialect,
|
|
172
|
+
rbac: !!a.rbac,
|
|
173
|
+
...Object.fromEntries(API_BOOLEANS.map(f => [f, !!a[f]])),
|
|
174
|
+
permissions: (a.permissions ?? []).map((p) => p.value)
|
|
175
|
+
});
|
|
102
176
|
// Which product a tool works on — /tools.json and the landing group by it.
|
|
103
177
|
const product_of = (tool) => tool.command[0] === 'auth' ? 'auth' : 'deploy';
|
|
104
178
|
const AUTH_WRITE = {
|
|
@@ -1096,6 +1170,72 @@ const TOOLS = [
|
|
|
1096
1170
|
remove: ['tickets:admin']
|
|
1097
1171
|
}
|
|
1098
1172
|
},
|
|
1173
|
+
{
|
|
1174
|
+
name: 'create_auth_api',
|
|
1175
|
+
title: 'Create an API',
|
|
1176
|
+
description: 'Create an API (resource server) in the Auth tenant: the audience clients request tokens for. The identifier becomes the `aud` claim and cannot change later. Settings left out take the defaults (tokens last 86400 s, no roles or teams claims).',
|
|
1177
|
+
input: {
|
|
1178
|
+
identifier: z
|
|
1179
|
+
.string()
|
|
1180
|
+
.regex(/^[^-]/, 'cannot start with "-"')
|
|
1181
|
+
.describe('Audience URL, e.g. https://api.example.com (cannot change later)'),
|
|
1182
|
+
name: z
|
|
1183
|
+
.string()
|
|
1184
|
+
.max(120)
|
|
1185
|
+
.optional()
|
|
1186
|
+
.describe('Display name (defaults to the identifier)'),
|
|
1187
|
+
permissions: z
|
|
1188
|
+
.array(z.string())
|
|
1189
|
+
.optional()
|
|
1190
|
+
.describe('Its permission catalog, e.g. tickets:read'),
|
|
1191
|
+
...api_settings_input,
|
|
1192
|
+
tenant,
|
|
1193
|
+
project
|
|
1194
|
+
},
|
|
1195
|
+
command: ['auth', 'apis', 'create'],
|
|
1196
|
+
flags: a => [
|
|
1197
|
+
a.identifier,
|
|
1198
|
+
...optText('--name', a.name),
|
|
1199
|
+
...(a.permissions ?? []).flatMap((p) => [`--permission=${p}`]),
|
|
1200
|
+
...api_settings_flags(a),
|
|
1201
|
+
...auth_scope(a)
|
|
1202
|
+
],
|
|
1203
|
+
shape: api_detail,
|
|
1204
|
+
write: true,
|
|
1205
|
+
// API writes change what every token of the tenant carries: never on the
|
|
1206
|
+
// hosted server, whose token only reads APIs (api tenant_access.ts).
|
|
1207
|
+
local_only: true,
|
|
1208
|
+
annotations: { ...AUTH_WRITE, idempotentHint: false },
|
|
1209
|
+
example: {
|
|
1210
|
+
identifier: 'https://api.example.com',
|
|
1211
|
+
permissions: ['tickets:read'],
|
|
1212
|
+
token_lifetime: 3600,
|
|
1213
|
+
include_roles_in_access_token: true
|
|
1214
|
+
}
|
|
1215
|
+
},
|
|
1216
|
+
{
|
|
1217
|
+
name: 'update_auth_api',
|
|
1218
|
+
title: "Change an API's settings",
|
|
1219
|
+
description: "Change an API's token settings: token lifetime, RBAC, the roles and teams claims, offline access, consent, description. Only the settings passed change. Applies to tokens issued from now on; tokens already issued keep theirs until they expire. The identifier cannot change. The permission catalog is not edited here.",
|
|
1220
|
+
input: {
|
|
1221
|
+
api: z.string().describe('API id (api_…) or identifier (audience URL)'),
|
|
1222
|
+
...api_settings_input,
|
|
1223
|
+
tenant,
|
|
1224
|
+
project
|
|
1225
|
+
},
|
|
1226
|
+
command: ['auth', 'apis', 'update'],
|
|
1227
|
+
flags: a => [a.api, ...api_settings_flags(a), ...auth_scope(a)],
|
|
1228
|
+
shape: api_detail,
|
|
1229
|
+
write: true,
|
|
1230
|
+
// See create_auth_api.
|
|
1231
|
+
local_only: true,
|
|
1232
|
+
annotations: AUTH_WRITE,
|
|
1233
|
+
example: {
|
|
1234
|
+
api: 'https://api.example.com',
|
|
1235
|
+
token_lifetime: 3600,
|
|
1236
|
+
include_teams_in_access_token: true
|
|
1237
|
+
}
|
|
1238
|
+
},
|
|
1099
1239
|
{
|
|
1100
1240
|
name: 'update_auth_user_roles',
|
|
1101
1241
|
title: "Change a user's roles",
|