@fabrika/installation-init 0.9.0-dev.34 → 0.9.0-dev.36
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/package.json +6 -6
- package/src/index.ts +9 -1
- package/src/mcp.ts +51 -3
- package/types/src/index.d.ts +1 -1
- package/types/src/mcp.d.ts +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/installation-init",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"zod": "^3.25.76",
|
|
31
|
-
"@fabrika/app": "0.9.0-dev.
|
|
32
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
33
|
-
"@fabrika/email": "0.9.0-dev.
|
|
34
|
-
"@fabrika/iam-contract": "0.9.0-dev.
|
|
35
|
-
"@fabrika/proxy-core": "0.9.0-dev.
|
|
31
|
+
"@fabrika/app": "0.9.0-dev.36",
|
|
32
|
+
"@fabrika/auth-core": "0.9.0-dev.36",
|
|
33
|
+
"@fabrika/email": "0.9.0-dev.36",
|
|
34
|
+
"@fabrika/iam-contract": "0.9.0-dev.36",
|
|
35
|
+
"@fabrika/proxy-core": "0.9.0-dev.36"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/src/index.ts
CHANGED
|
@@ -36,7 +36,15 @@ export {
|
|
|
36
36
|
} from './environment'
|
|
37
37
|
export { ghRepoExists, hasGhCli } from './gh'
|
|
38
38
|
export { action, detail, fail, info, ok, step, url, warn } from './log'
|
|
39
|
-
export {
|
|
39
|
+
export {
|
|
40
|
+
type IamOAuthConfig,
|
|
41
|
+
type IdentityAppSchema,
|
|
42
|
+
identityAppSchemas,
|
|
43
|
+
mcpAuthoringOn,
|
|
44
|
+
type McpClient,
|
|
45
|
+
parseMcpClientsJson,
|
|
46
|
+
platformIamOAuthConfig,
|
|
47
|
+
} from './mcp'
|
|
40
48
|
export { type CommandEnv, describeArgument, readEnv, readFlag, requiredSetting, setting, shellWord } from './options'
|
|
41
49
|
export { assertPinnedTag } from './pin'
|
|
42
50
|
export { confirm } from './prompt'
|
package/src/mcp.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// is resolved from, so the two cannot disagree: each `oauth` row's registered resource in the manifest, and IAM's
|
|
6
6
|
// `FABRIKA_IAM_OAUTH_CONFIG`, which issues tokens for exactly those resources.
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import type { AppSchema, RoleDef } from '@fabrika/auth-core'
|
|
9
|
+
import { IAM_APP_ID, OAUTH_CLIENT_PROVIDERS, type OAuthManagedClient, type OAuthResourceDto, parseOAuthManagedClient } from '@fabrika/iam-contract'
|
|
9
10
|
import { platformOAuthResourceUris, platformOAuthServed, type PlatformProxyComposition, type PlatformProxyManifestTemplate } from './proxy-manifest'
|
|
10
11
|
|
|
11
12
|
/** One operator-registered MCP client: its CIMD identity, plus where IAM fetches it when that differs. */
|
|
@@ -19,7 +20,7 @@ export interface IamOAuthConfig {
|
|
|
19
20
|
readonly resources: readonly OAuthResourceDto[]
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
const CLIENT_KEYS = ['provider', 'clientId', 'redirectUris', 'metadataUrl']
|
|
23
|
+
const CLIENT_KEYS = ['provider', 'clientId', 'redirectUris', 'metadataUrl', 'identity']
|
|
23
24
|
/** IAM's own ceiling: it refuses to boot with more. */
|
|
24
25
|
const MAX_CLIENTS = 16
|
|
25
26
|
|
|
@@ -39,7 +40,10 @@ const isHttpsUrl = (value: string): boolean => {
|
|
|
39
40
|
const parseClient = (value: unknown, index: number): McpClient => {
|
|
40
41
|
const client = parseOAuthManagedClient(value)
|
|
41
42
|
if (client === null || !isObject(value) || !Object.keys(value).every((key) => CLIENT_KEYS.includes(key))) {
|
|
42
|
-
throw new Error(
|
|
43
|
+
throw new Error(
|
|
44
|
+
`MCP client ${index} must be { provider: ${PROVIDERS}, clientId: <https URL>, redirectUris: [...], metadataUrl?, identity? }; `
|
|
45
|
+
+ 'identity is { app: <app id>, resource: <https URL>, roles?: [{ key, name }] } and only on an external client',
|
|
46
|
+
)
|
|
43
47
|
}
|
|
44
48
|
const metadataUrl = value['metadataUrl']
|
|
45
49
|
if (metadataUrl === undefined) {
|
|
@@ -73,9 +77,43 @@ export const parseMcpClientsJson = (raw: string): readonly McpClient[] => {
|
|
|
73
77
|
if (ids.size !== clients.length) {
|
|
74
78
|
throw new Error('the MCP client list names one client id twice')
|
|
75
79
|
}
|
|
80
|
+
identityAppSchemas(clients)
|
|
76
81
|
return clients
|
|
77
82
|
}
|
|
78
83
|
|
|
84
|
+
/** An external application's vocabulary in IAM: its declared roles, each granting no action (ADR-0049). */
|
|
85
|
+
export interface IdentityAppSchema {
|
|
86
|
+
readonly app: string
|
|
87
|
+
readonly schema: AppSchema
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The vocabulary each external application that declares roles reconciles into IAM, once per app. The deploy writes it
|
|
92
|
+
* with the provisioning key it already holds, so the application needs no IAM credential to declare its roles. Two
|
|
93
|
+
* clients of one app must declare the same roles.
|
|
94
|
+
*/
|
|
95
|
+
export const identityAppSchemas = (clients: readonly McpClient[]): readonly IdentityAppSchema[] => {
|
|
96
|
+
const declared = new Map<string, string>()
|
|
97
|
+
const schemas: IdentityAppSchema[] = []
|
|
98
|
+
for (const { clientId, identity } of clients) {
|
|
99
|
+
if (identity === undefined) continue
|
|
100
|
+
const roles = JSON.stringify(identity.roles ?? null)
|
|
101
|
+
const known = declared.get(identity.app)
|
|
102
|
+
if (known !== undefined && known !== roles) {
|
|
103
|
+
throw new Error(`MCP client ${clientId}: another client of \`${identity.app}\` declares other roles`)
|
|
104
|
+
}
|
|
105
|
+
declared.set(identity.app, roles)
|
|
106
|
+
if (known !== undefined || identity.roles === undefined) continue
|
|
107
|
+
const entries = identity.roles.map((role): [string, RoleDef] => [role.key, { name: role.name, permissions: [] }])
|
|
108
|
+
schemas.push({ app: identity.app, schema: { scopes: [], actions: [], roles: Object.fromEntries(entries) } })
|
|
109
|
+
}
|
|
110
|
+
return schemas
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** MCP authoring is on when the operator registers a client that is not identity-only: those sign people in, nothing more. */
|
|
114
|
+
export const mcpAuthoringOn = (clients: readonly McpClient[] | undefined): boolean =>
|
|
115
|
+
clients?.some((client) => client.identity === undefined) ?? false
|
|
116
|
+
|
|
79
117
|
/**
|
|
80
118
|
* IAM's OAuth configuration for one placed installation: the MCP clients (none when MCP authoring is off; the
|
|
81
119
|
* command-line client is IAM's own and is never listed), and every resource the composition registers, each marked
|
|
@@ -108,5 +146,15 @@ export const platformIamOAuthConfig = (
|
|
|
108
146
|
if (resources.length === 0) {
|
|
109
147
|
throw new Error('the platform proxy manifest template declares no OAuth resource on this composition')
|
|
110
148
|
}
|
|
149
|
+
// An identity token must never be one a platform service accepts: not its app id, not a resource on its hosts.
|
|
150
|
+
const platformHosts = Object.values(composition.placement).flatMap((placement) => placement.hosts)
|
|
151
|
+
for (const { clientId, identity } of clients) {
|
|
152
|
+
if (identity === undefined) continue
|
|
153
|
+
// IAM's own id is no proxy app's: a roles reconcile under it would rewrite IAM's vocabulary.
|
|
154
|
+
const platformApps = [IAM_APP_ID, ...template.apps.map((app) => app.id)]
|
|
155
|
+
if (platformApps.includes(identity.app) || platformHosts.includes(new URL(identity.resource).hostname)) {
|
|
156
|
+
throw new Error(`MCP client ${clientId}: its identity resource names a platform service's app id or host`)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
111
159
|
return { clients, resources }
|
|
112
160
|
}
|
package/types/src/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { EMAIL_FLAGS, type InstallationEmail, readInstallationEmail } from './em
|
|
|
6
6
|
export { configureEnvironment, type EnvironmentConfig, type EnvironmentEffects, environmentVariables, type ExistingEnvironmentProtection, existingEnvironmentProtection, triggerPlatformWorkflow, } from './environment';
|
|
7
7
|
export { ghRepoExists, hasGhCli } from './gh';
|
|
8
8
|
export { action, detail, fail, info, ok, step, url, warn } from './log';
|
|
9
|
-
export { type IamOAuthConfig, type McpClient, parseMcpClientsJson, platformIamOAuthConfig } from './mcp';
|
|
9
|
+
export { type IamOAuthConfig, type IdentityAppSchema, identityAppSchemas, mcpAuthoringOn, type McpClient, parseMcpClientsJson, platformIamOAuthConfig, } from './mcp';
|
|
10
10
|
export { type CommandEnv, describeArgument, readEnv, readFlag, requiredSetting, setting, shellWord } from './options';
|
|
11
11
|
export { assertPinnedTag } from './pin';
|
|
12
12
|
export { confirm } from './prompt';
|
package/types/src/mcp.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AppSchema } from '@fabrika/auth-core';
|
|
1
2
|
import { type OAuthManagedClient, type OAuthResourceDto } from '@fabrika/iam-contract';
|
|
2
3
|
import { type PlatformProxyComposition, type PlatformProxyManifestTemplate } from './proxy-manifest';
|
|
3
4
|
/** One operator-registered MCP client: its CIMD identity, plus where IAM fetches it when that differs. */
|
|
@@ -14,6 +15,19 @@ export interface IamOAuthConfig {
|
|
|
14
15
|
* client id is refused here, before a deploy writes a value IAM would refuse to boot with.
|
|
15
16
|
*/
|
|
16
17
|
export declare const parseMcpClientsJson: (raw: string) => readonly McpClient[];
|
|
18
|
+
/** An external application's vocabulary in IAM: its declared roles, each granting no action (ADR-0049). */
|
|
19
|
+
export interface IdentityAppSchema {
|
|
20
|
+
readonly app: string;
|
|
21
|
+
readonly schema: AppSchema;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The vocabulary each external application that declares roles reconciles into IAM, once per app. The deploy writes it
|
|
25
|
+
* with the provisioning key it already holds, so the application needs no IAM credential to declare its roles. Two
|
|
26
|
+
* clients of one app must declare the same roles.
|
|
27
|
+
*/
|
|
28
|
+
export declare const identityAppSchemas: (clients: readonly McpClient[]) => readonly IdentityAppSchema[];
|
|
29
|
+
/** MCP authoring is on when the operator registers a client that is not identity-only: those sign people in, nothing more. */
|
|
30
|
+
export declare const mcpAuthoringOn: (clients: readonly McpClient[] | undefined) => boolean;
|
|
17
31
|
/**
|
|
18
32
|
* IAM's OAuth configuration for one placed installation: the MCP clients (none when MCP authoring is off; the
|
|
19
33
|
* command-line client is IAM's own and is never listed), and every resource the composition registers, each marked
|