@yadsh/dsh-qa-integrations 0.5.0 → 0.6.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.
- package/README.md +431 -18
- package/compatibility.json +1 -1
- package/lib/broker.js +456 -9
- package/lib/broker.js.map +1 -1
- package/lib/client/bitrix24.js +2 -1
- package/lib/client/bitrix24.js.map +1 -1
- package/lib/client/card.js +8 -1
- package/lib/client/card.js.map +1 -1
- package/lib/client/confluence.js +3 -2
- package/lib/client/confluence.js.map +1 -1
- package/lib/client/gitlab.js +40 -4
- package/lib/client/gitlab.js.map +1 -1
- package/lib/client/index.js +13 -11
- package/lib/client/index.js.map +1 -1
- package/lib/client/integrations.js +39 -2
- package/lib/client/integrations.js.map +1 -1
- package/lib/client/jira.js +3 -2
- package/lib/client/jira.js.map +1 -1
- package/lib/client/provider-card.js +138 -4
- package/lib/client/provider-card.js.map +1 -1
- package/lib/client/styles.js +8 -5
- package/lib/client/styles.js.map +1 -1
- package/lib/client/teamcity.js +31 -4
- package/lib/client/teamcity.js.map +1 -1
- package/lib/client/testit.js +65 -0
- package/lib/client/testit.js.map +1 -0
- package/lib/client/weblate.js +70 -0
- package/lib/client/weblate.js.map +1 -0
- package/lib/client.js +2600 -480
- package/lib/client.js.map +1 -1
- package/lib/coerce.js +16 -7
- package/lib/coerce.js.map +1 -1
- package/lib/config.js +12 -0
- package/lib/config.js.map +1 -1
- package/lib/errors.js.map +1 -1
- package/lib/index.js +274 -28
- package/lib/index.js.map +1 -1
- package/lib/providers/bitrix24/catalog.js +13 -0
- package/lib/providers/bitrix24/catalog.js.map +1 -1
- package/lib/providers/bitrix24/config.js +3 -0
- package/lib/providers/bitrix24/config.js.map +1 -1
- package/lib/providers/bitrix24/credential-help.js +24 -0
- package/lib/providers/bitrix24/credential-help.js.map +1 -0
- package/lib/providers/bitrix24/index.js +9 -0
- package/lib/providers/bitrix24/index.js.map +1 -1
- package/lib/providers/bitrix24/operations.js +60 -1
- package/lib/providers/bitrix24/operations.js.map +1 -1
- package/lib/providers/bitrix24/tools.js +95 -3
- package/lib/providers/bitrix24/tools.js.map +1 -1
- package/lib/providers/confluence/credential-help.js +29 -0
- package/lib/providers/confluence/credential-help.js.map +1 -0
- package/lib/providers/confluence/index.js +9 -0
- package/lib/providers/confluence/index.js.map +1 -1
- package/lib/providers/gitlab/catalog.js +108 -15
- package/lib/providers/gitlab/catalog.js.map +1 -1
- package/lib/providers/gitlab/config.js +11 -3
- package/lib/providers/gitlab/config.js.map +1 -1
- package/lib/providers/gitlab/credential-help.js +33 -0
- package/lib/providers/gitlab/credential-help.js.map +1 -0
- package/lib/providers/gitlab/index.js +337 -6
- package/lib/providers/gitlab/index.js.map +1 -1
- package/lib/providers/jira/credential-help.js +31 -0
- package/lib/providers/jira/credential-help.js.map +1 -0
- package/lib/providers/jira/index.js +9 -0
- package/lib/providers/jira/index.js.map +1 -1
- package/lib/providers/registry.js +4 -0
- package/lib/providers/registry.js.map +1 -1
- package/lib/providers/shared/credential-help.js +29 -0
- package/lib/providers/shared/credential-help.js.map +1 -0
- package/lib/providers/shared/service-boundary.js +44 -0
- package/lib/providers/shared/service-boundary.js.map +1 -0
- package/lib/providers/teamcity/catalog.js +56 -2
- package/lib/providers/teamcity/catalog.js.map +1 -1
- package/lib/providers/teamcity/credential-help.js +25 -0
- package/lib/providers/teamcity/credential-help.js.map +1 -0
- package/lib/providers/teamcity/index.js +254 -2
- package/lib/providers/teamcity/index.js.map +1 -1
- package/lib/providers/testit/attachments.js +131 -0
- package/lib/providers/testit/attachments.js.map +1 -0
- package/lib/providers/testit/catalog.js +225 -0
- package/lib/providers/testit/catalog.js.map +1 -0
- package/lib/providers/testit/config.js +175 -0
- package/lib/providers/testit/config.js.map +1 -0
- package/lib/providers/testit/credential-help.js +29 -0
- package/lib/providers/testit/credential-help.js.map +1 -0
- package/lib/providers/testit/index.js +184 -0
- package/lib/providers/testit/index.js.map +1 -0
- package/lib/providers/testit/operations.js +1070 -0
- package/lib/providers/testit/operations.js.map +1 -0
- package/lib/providers/testit/tools.js +717 -0
- package/lib/providers/testit/tools.js.map +1 -0
- package/lib/providers/testit/transport.js +158 -0
- package/lib/providers/testit/transport.js.map +1 -0
- package/lib/providers/weblate/catalog.js +185 -0
- package/lib/providers/weblate/catalog.js.map +1 -0
- package/lib/providers/weblate/config.js +147 -0
- package/lib/providers/weblate/config.js.map +1 -0
- package/lib/providers/weblate/credential-help.js +26 -0
- package/lib/providers/weblate/credential-help.js.map +1 -0
- package/lib/providers/weblate/index.js +181 -0
- package/lib/providers/weblate/index.js.map +1 -0
- package/lib/providers/weblate/operations.js +703 -0
- package/lib/providers/weblate/operations.js.map +1 -0
- package/lib/providers/weblate/query.js +80 -0
- package/lib/providers/weblate/query.js.map +1 -0
- package/lib/providers/weblate/tools.js +408 -0
- package/lib/providers/weblate/tools.js.map +1 -0
- package/lib/providers/weblate/transport.js +179 -0
- package/lib/providers/weblate/transport.js.map +1 -0
- package/lib/repository.js +197 -13
- package/lib/repository.js.map +1 -1
- package/lib/service-credentials/config.js +179 -0
- package/lib/service-credentials/config.js.map +1 -0
- package/lib/service-credentials/policy.js +92 -0
- package/lib/service-credentials/policy.js.map +1 -0
- package/lib/service-credentials/registry.js +142 -0
- package/lib/service-credentials/registry.js.map +1 -0
- package/lib/service-credentials/state.js +30 -0
- package/lib/service-credentials/state.js.map +1 -0
- package/lib/service-credentials/types.js +20 -0
- package/lib/service-credentials/types.js.map +1 -0
- package/lib/tools.js +27 -2
- package/lib/tools.js.map +1 -1
- package/lib/typert.host.js +1187 -39
- package/lib/typert.remote-client.d.ts +37 -5
- package/lib/typert.remote-client.js +1057 -33
- package/lib/types/broker.d.ts +70 -4
- package/lib/types/client/bitrix24.d.ts +1 -1
- package/lib/types/client/card.d.ts +3 -1
- package/lib/types/client/confluence.d.ts +2 -2
- package/lib/types/client/gitlab.d.ts +15 -2
- package/lib/types/client/index.d.ts +3 -2
- package/lib/types/client/integrations.d.ts +11 -2
- package/lib/types/client/jira.d.ts +2 -2
- package/lib/types/client/provider-card.d.ts +50 -8
- package/lib/types/client/styles.d.ts +4 -3
- package/lib/types/client/teamcity.d.ts +15 -2
- package/lib/types/client/testit.d.ts +15 -0
- package/lib/types/client/weblate.d.ts +15 -0
- package/lib/types/coerce.d.ts +2 -2
- package/lib/types/config.d.ts +21 -0
- package/lib/types/errors.d.ts +9 -1
- package/lib/types/index.d.ts +108 -11
- package/lib/types/providers/bitrix24/catalog.d.ts +1 -1
- package/lib/types/providers/bitrix24/config.d.ts +11 -1
- package/lib/types/providers/bitrix24/credential-help.d.ts +8 -0
- package/lib/types/providers/bitrix24/index.d.ts +5 -0
- package/lib/types/providers/bitrix24/tools.d.ts +4 -0
- package/lib/types/providers/confluence/credential-help.d.ts +9 -0
- package/lib/types/providers/confluence/index.d.ts +5 -0
- package/lib/types/providers/contract.d.ts +62 -1
- package/lib/types/providers/gitlab/catalog.d.ts +20 -5
- package/lib/types/providers/gitlab/config.d.ts +14 -3
- package/lib/types/providers/gitlab/credential-help.d.ts +9 -0
- package/lib/types/providers/gitlab/index.d.ts +51 -1
- package/lib/types/providers/jira/credential-help.d.ts +8 -0
- package/lib/types/providers/jira/index.d.ts +5 -0
- package/lib/types/providers/registry.d.ts +2 -0
- package/lib/types/providers/shared/credential-help.d.ts +17 -0
- package/lib/types/providers/shared/service-boundary.d.ts +25 -0
- package/lib/types/providers/teamcity/catalog.d.ts +18 -2
- package/lib/types/providers/teamcity/credential-help.d.ts +8 -0
- package/lib/types/providers/teamcity/index.d.ts +53 -2
- package/lib/types/providers/testit/attachments.d.ts +20 -0
- package/lib/types/providers/testit/catalog.d.ts +75 -0
- package/lib/types/providers/testit/config.d.ts +61 -0
- package/lib/types/providers/testit/credential-help.d.ts +8 -0
- package/lib/types/providers/testit/index.d.ts +60 -0
- package/lib/types/providers/testit/operations.d.ts +95 -0
- package/lib/types/providers/testit/tools.d.ts +15 -0
- package/lib/types/providers/testit/transport.d.ts +67 -0
- package/lib/types/providers/weblate/catalog.d.ts +43 -0
- package/lib/types/providers/weblate/config.d.ts +57 -0
- package/lib/types/providers/weblate/credential-help.d.ts +9 -0
- package/lib/types/providers/weblate/index.d.ts +50 -0
- package/lib/types/providers/weblate/operations.d.ts +77 -0
- package/lib/types/providers/weblate/query.d.ts +37 -0
- package/lib/types/providers/weblate/tools.d.ts +15 -0
- package/lib/types/providers/weblate/transport.d.ts +60 -0
- package/lib/types/repository.d.ts +38 -3
- package/lib/types/service-credentials/config.d.ts +73 -0
- package/lib/types/service-credentials/policy.d.ts +44 -0
- package/lib/types/service-credentials/registry.d.ts +43 -0
- package/lib/types/service-credentials/state.d.ts +14 -0
- package/lib/types/service-credentials/types.d.ts +97 -0
- package/lib/types/tools.d.ts +10 -1
- package/lib/types/types.d.ts +114 -10
- package/package.json +7 -7
- package/lib/shared/settings.js +0 -19
- package/lib/shared/settings.js.map +0 -1
- package/lib/types/shared/settings.d.ts +0 -19
package/compatibility.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"range": ">=0.1.5-rc.2 <0.2.0",
|
|
5
5
|
"testedReleases": ["0.1.5-rc.2"],
|
|
6
6
|
"requiredHostFeatures": ["tools", "qaSurface"],
|
|
7
|
-
"requiredClientFeatures": ["qaUserSettingsSections"]
|
|
7
|
+
"requiredClientFeatures": ["qaUserSettingsSections", "settings.plugins.tab"]
|
|
8
8
|
},
|
|
9
9
|
"node": ">=22"
|
|
10
10
|
}
|
package/lib/broker.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { IntegrationError } from "./errors.js";
|
|
2
|
+
import { evaluateServiceOperation, narrowBoundary, } from "./service-credentials/policy.js";
|
|
3
|
+
import { isCredentialSource, UNCLASSIFIED_OPERATION, } from "./service-credentials/types.js";
|
|
2
4
|
/** In-process broker boundary; no caller outside it receives decrypted secrets. */
|
|
3
5
|
export class IntegrationBroker {
|
|
4
6
|
repository;
|
|
5
7
|
secrets;
|
|
6
8
|
providers;
|
|
7
9
|
logger;
|
|
8
|
-
|
|
10
|
+
serviceCredentials;
|
|
11
|
+
defaultForNewConnections;
|
|
12
|
+
constructor(repository, secrets, providers, logger, options = {}) {
|
|
9
13
|
this.repository = repository;
|
|
10
14
|
this.secrets = secrets;
|
|
11
15
|
this.providers = providers;
|
|
12
16
|
this.logger = logger;
|
|
17
|
+
this.serviceCredentials = options.serviceCredentials;
|
|
18
|
+
this.defaultForNewConnections = options.defaultForNewConnections ?? true;
|
|
13
19
|
}
|
|
14
20
|
listProviders() {
|
|
15
21
|
return this.providers.list().map((provider) => ({
|
|
@@ -18,6 +24,7 @@ export class IntegrationBroker {
|
|
|
18
24
|
enabled: true,
|
|
19
25
|
authModes: ["token"],
|
|
20
26
|
capabilities: provider.capabilities,
|
|
27
|
+
credentialHelp: provider.credentialHelp,
|
|
21
28
|
}));
|
|
22
29
|
}
|
|
23
30
|
list(principal) {
|
|
@@ -28,6 +35,7 @@ export class IntegrationBroker {
|
|
|
28
35
|
summary(principal, providerId) {
|
|
29
36
|
const provider = this.providers.get(providerId);
|
|
30
37
|
const integration = this.repository.find(principal, providerId);
|
|
38
|
+
const service = this.serviceSummary(providerId, integration);
|
|
31
39
|
if (integration === undefined) {
|
|
32
40
|
return {
|
|
33
41
|
provider: providerId,
|
|
@@ -43,6 +51,8 @@ export class IntegrationBroker {
|
|
|
43
51
|
policy: [],
|
|
44
52
|
lastValidatedAt: null,
|
|
45
53
|
errorCode: null,
|
|
54
|
+
credentialSource: "personal",
|
|
55
|
+
service,
|
|
46
56
|
};
|
|
47
57
|
}
|
|
48
58
|
const policy = integration.capabilities.map((capability) => ({
|
|
@@ -63,14 +73,71 @@ export class IntegrationBroker {
|
|
|
63
73
|
policy,
|
|
64
74
|
lastValidatedAt: integration.lastValidatedAt,
|
|
65
75
|
errorCode: integration.lastErrorCode,
|
|
76
|
+
credentialSource: integration.credentialSource,
|
|
77
|
+
service,
|
|
66
78
|
};
|
|
67
79
|
}
|
|
68
|
-
/**
|
|
69
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Connect one provider for one principal. The credential source is decided
|
|
82
|
+
* here, server-side: the client may ask for service mode, and gets it only
|
|
83
|
+
* when this deployment really manages a credential for that provider
|
|
84
|
+
* instance. A new connection defaults to service mode when the deployment
|
|
85
|
+
* says so and a profile exists — an existing connection never moves on its
|
|
86
|
+
* own, because its source is already stored.
|
|
87
|
+
*/
|
|
88
|
+
async connect(principal, providerId, input, options = {}) {
|
|
70
89
|
const provider = this.providers.get(providerId);
|
|
90
|
+
const instanceId = String(input.options?.["instanceId"] ?? "").trim();
|
|
91
|
+
const profile = this.profileFor(providerId, instanceId);
|
|
92
|
+
const existing = this.repository.find(principal, providerId);
|
|
93
|
+
// The client may ask for either mode; when it does not, service mode is the
|
|
94
|
+
// default only for a *new* connection. An existing binding keeps the source
|
|
95
|
+
// it stored, which is what makes an upgrade unable to move a user silently.
|
|
96
|
+
const wantsService = options.useServiceCredential ??
|
|
97
|
+
(existing === undefined && this.defaultForNewConnections);
|
|
98
|
+
if (options.useServiceCredential === true &&
|
|
99
|
+
(profile === undefined || !profile.enabled)) {
|
|
100
|
+
// The client asked for the managed credential and this deployment cannot
|
|
101
|
+
// produce one: say so instead of falling through to a personal token the
|
|
102
|
+
// form never offered a field for.
|
|
103
|
+
throw new IntegrationError(profile === undefined
|
|
104
|
+
? "ServiceCredentialUnavailable"
|
|
105
|
+
: "ServiceCredentialDisabled", "The deployment manages no usable credential for this instance");
|
|
106
|
+
}
|
|
107
|
+
if (wantsService && profile !== undefined && profile.enabled) {
|
|
108
|
+
this.repository.connect({
|
|
109
|
+
principal,
|
|
110
|
+
provider: providerId,
|
|
111
|
+
// No personal secret is stored: this connection spends the deployment's
|
|
112
|
+
// credential until the user switches, and only the switch stores one.
|
|
113
|
+
secret: null,
|
|
114
|
+
tenantId: profile.portal,
|
|
115
|
+
externalUserId: `service:${profile.id}`,
|
|
116
|
+
displayName: profile.label,
|
|
117
|
+
capabilities: this.serviceCapabilities(providerId),
|
|
118
|
+
credentialSource: "service",
|
|
119
|
+
serviceProfileId: profile.id,
|
|
120
|
+
});
|
|
121
|
+
this.repository.audit({
|
|
122
|
+
ownerUserId: principal.userId,
|
|
123
|
+
provider: providerId,
|
|
124
|
+
operation: "credential.connect",
|
|
125
|
+
result: "success",
|
|
126
|
+
credentialSource: "service",
|
|
127
|
+
serviceProfileId: profile.id,
|
|
128
|
+
sourceSessionId: null,
|
|
129
|
+
});
|
|
130
|
+
this.logger.info("credential.connected", {
|
|
131
|
+
provider: providerId,
|
|
132
|
+
credentialSource: "service",
|
|
133
|
+
serviceProfile: profile.id,
|
|
134
|
+
});
|
|
135
|
+
return this.summary(principal, providerId);
|
|
136
|
+
}
|
|
71
137
|
const parsed = provider.parseCredential(String(input.token ?? ""), input.options);
|
|
72
138
|
const validation = await provider.validate({
|
|
73
139
|
credential: parsed.credential,
|
|
140
|
+
credentialSource: "personal",
|
|
74
141
|
});
|
|
75
142
|
const encrypted = await this.secrets.encrypt(parsed.credential, "token");
|
|
76
143
|
this.repository.connect({
|
|
@@ -81,24 +148,70 @@ export class IntegrationBroker {
|
|
|
81
148
|
externalUserId: validation.externalUserId,
|
|
82
149
|
displayName: validation.displayName,
|
|
83
150
|
capabilities: validation.capabilities,
|
|
151
|
+
credentialSource: "personal",
|
|
152
|
+
serviceProfileId: null,
|
|
84
153
|
});
|
|
85
154
|
this.repository.audit({
|
|
86
155
|
ownerUserId: principal.userId,
|
|
87
156
|
provider: providerId,
|
|
88
157
|
operation: "credential.connect",
|
|
89
158
|
result: "success",
|
|
159
|
+
credentialSource: "personal",
|
|
160
|
+
serviceProfileId: null,
|
|
90
161
|
sourceSessionId: null,
|
|
91
162
|
});
|
|
92
|
-
this.logger.info("credential.connected", {
|
|
163
|
+
this.logger.info("credential.connected", {
|
|
164
|
+
provider: providerId,
|
|
165
|
+
credentialSource: "personal",
|
|
166
|
+
});
|
|
93
167
|
return this.summary(principal, providerId);
|
|
94
168
|
}
|
|
95
169
|
async validate(principal, providerId) {
|
|
96
170
|
const integration = this.requireConnected(principal, providerId);
|
|
97
171
|
try {
|
|
172
|
+
if (integration.credentialSource === "service") {
|
|
173
|
+
const resolved = this.resolveService(principal, integration);
|
|
174
|
+
const health = await this.probeService(resolved);
|
|
175
|
+
const code = healthCode(health);
|
|
176
|
+
// A credential the probe rejects is a rejected credential, not a
|
|
177
|
+
// successful validation. `unsafe_scope` is the one verdict that does not
|
|
178
|
+
// refuse: the ceiling already bounds what the token can reach here, and
|
|
179
|
+
// the finding is recorded for the operator instead.
|
|
180
|
+
if (code !== undefined && health?.status !== "unsafe_scope") {
|
|
181
|
+
this.repository.updateValidation(principal, providerId, false, code);
|
|
182
|
+
this.repository.audit({
|
|
183
|
+
ownerUserId: principal.userId,
|
|
184
|
+
provider: providerId,
|
|
185
|
+
operation: "credential.validate",
|
|
186
|
+
result: "error",
|
|
187
|
+
credentialSource: "service",
|
|
188
|
+
serviceProfileId: resolved.profile.id,
|
|
189
|
+
sourceSessionId: null,
|
|
190
|
+
});
|
|
191
|
+
this.logger.warn("credential.validation-failed", {
|
|
192
|
+
provider: providerId,
|
|
193
|
+
integrationId: integration.id,
|
|
194
|
+
reason: code,
|
|
195
|
+
serviceProfile: resolved.profile.id,
|
|
196
|
+
});
|
|
197
|
+
throw new IntegrationError(code, "Service credential is unusable");
|
|
198
|
+
}
|
|
199
|
+
this.repository.updateValidation(principal, providerId, true, code ?? null);
|
|
200
|
+
this.repository.audit({
|
|
201
|
+
ownerUserId: principal.userId,
|
|
202
|
+
provider: providerId,
|
|
203
|
+
operation: "credential.validate",
|
|
204
|
+
result: "success",
|
|
205
|
+
credentialSource: "service",
|
|
206
|
+
serviceProfileId: resolved.profile.id,
|
|
207
|
+
sourceSessionId: null,
|
|
208
|
+
});
|
|
209
|
+
return this.summary(principal, providerId);
|
|
210
|
+
}
|
|
98
211
|
const credential = await this.decrypt(principal, providerId);
|
|
99
212
|
const validation = await this.providers
|
|
100
213
|
.get(providerId)
|
|
101
|
-
.validate({ credential });
|
|
214
|
+
.validate({ credential, credentialSource: "personal" });
|
|
102
215
|
// Re-probe capabilities: a scope granted later at the provider must show up
|
|
103
216
|
// here, and a revoked one must stop being offered. Policies are left
|
|
104
217
|
// untouched, so a newly detected capability starts denied until the user
|
|
@@ -109,6 +222,8 @@ export class IntegrationBroker {
|
|
|
109
222
|
provider: providerId,
|
|
110
223
|
operation: "credential.validate",
|
|
111
224
|
result: "success",
|
|
225
|
+
credentialSource: "personal",
|
|
226
|
+
serviceProfileId: null,
|
|
112
227
|
sourceSessionId: null,
|
|
113
228
|
});
|
|
114
229
|
return this.summary(principal, providerId);
|
|
@@ -121,6 +236,8 @@ export class IntegrationBroker {
|
|
|
121
236
|
provider: providerId,
|
|
122
237
|
operation: "credential.validate",
|
|
123
238
|
result: "error",
|
|
239
|
+
credentialSource: integration.credentialSource,
|
|
240
|
+
serviceProfileId: integration.serviceProfileId,
|
|
124
241
|
sourceSessionId: null,
|
|
125
242
|
});
|
|
126
243
|
this.logger.warn("credential.validation-failed", {
|
|
@@ -131,6 +248,130 @@ export class IntegrationBroker {
|
|
|
131
248
|
throw error;
|
|
132
249
|
}
|
|
133
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Probe the deployment's managed credential for one instance and report what
|
|
253
|
+
* state it is in. The probe never changes upstream state, and the answer is a
|
|
254
|
+
* health status plus operator warnings — never the secret, and never the
|
|
255
|
+
* upstream identity the credential carries.
|
|
256
|
+
*/
|
|
257
|
+
async serviceCredentialHealth(providerId, instanceId) {
|
|
258
|
+
const profile = this.profileFor(providerId, instanceId);
|
|
259
|
+
const registry = this.serviceCredentials;
|
|
260
|
+
if (profile === undefined || registry === undefined || !profile.enabled) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
const provider = this.providers.get(providerId);
|
|
264
|
+
if (provider.validateServiceCredential === undefined)
|
|
265
|
+
return null;
|
|
266
|
+
const resolved = registry.readSecret(profile);
|
|
267
|
+
const health = await provider.validateServiceCredential({
|
|
268
|
+
credential: this.buildServiceCredential(providerId, resolved),
|
|
269
|
+
credentialSource: "service",
|
|
270
|
+
resourceBoundary: profile.resources,
|
|
271
|
+
});
|
|
272
|
+
// The upstream identity the probe found stays server-side: it is for the
|
|
273
|
+
// audit trail, not for a card, which shows the administrator's alias.
|
|
274
|
+
return {
|
|
275
|
+
status: health.status,
|
|
276
|
+
...(health.warnings === undefined ? {} : { warnings: health.warnings }),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Move one binding between credential sources. Both directions invalidate
|
|
281
|
+
* everything derived from the previous identity by bumping the binding
|
|
282
|
+
* revision, and neither direction ever falls back on its own.
|
|
283
|
+
*/
|
|
284
|
+
async setCredentialSource(principal, providerId, source) {
|
|
285
|
+
if (!isCredentialSource(source)) {
|
|
286
|
+
throw new IntegrationError("InvalidRequest", "Unknown credential source");
|
|
287
|
+
}
|
|
288
|
+
const integration = this.requireConnected(principal, providerId);
|
|
289
|
+
const provider = this.providers.get(providerId);
|
|
290
|
+
if (integration.credentialSource === source) {
|
|
291
|
+
return this.summary(principal, providerId);
|
|
292
|
+
}
|
|
293
|
+
if (source === "service") {
|
|
294
|
+
const resolved = this.resolveService(principal, integration);
|
|
295
|
+
this.repository.setCredentialSource({
|
|
296
|
+
principal,
|
|
297
|
+
provider: providerId,
|
|
298
|
+
source: "service",
|
|
299
|
+
serviceProfileId: resolved.profile.id,
|
|
300
|
+
capabilities: this.serviceCapabilities(providerId),
|
|
301
|
+
tenantId: resolved.profile.portal,
|
|
302
|
+
externalUserId: `service:${resolved.profile.id}`,
|
|
303
|
+
displayName: resolved.profile.label,
|
|
304
|
+
});
|
|
305
|
+
this.repository.audit({
|
|
306
|
+
ownerUserId: principal.userId,
|
|
307
|
+
provider: providerId,
|
|
308
|
+
operation: "credential.switch",
|
|
309
|
+
result: "success",
|
|
310
|
+
credentialSource: "service",
|
|
311
|
+
serviceProfileId: resolved.profile.id,
|
|
312
|
+
sourceSessionId: null,
|
|
313
|
+
});
|
|
314
|
+
this.logger.info("credential.switched", {
|
|
315
|
+
provider: providerId,
|
|
316
|
+
credentialSource: "service",
|
|
317
|
+
serviceProfile: resolved.profile.id,
|
|
318
|
+
});
|
|
319
|
+
return this.summary(principal, providerId);
|
|
320
|
+
}
|
|
321
|
+
const secret = this.repository.secretFor(principal, providerId);
|
|
322
|
+
if (secret === undefined) {
|
|
323
|
+
throw new IntegrationError("PersonalCredentialRequired", "Connect a personal account before switching to it");
|
|
324
|
+
}
|
|
325
|
+
const validation = await provider.validate({
|
|
326
|
+
credential: await this.secrets.decrypt(secret),
|
|
327
|
+
credentialSource: "personal",
|
|
328
|
+
});
|
|
329
|
+
this.repository.setCredentialSource({
|
|
330
|
+
principal,
|
|
331
|
+
provider: providerId,
|
|
332
|
+
source: "personal",
|
|
333
|
+
serviceProfileId: null,
|
|
334
|
+
capabilities: validation.capabilities,
|
|
335
|
+
tenantId: validation.tenantId,
|
|
336
|
+
externalUserId: validation.externalUserId,
|
|
337
|
+
displayName: validation.displayName,
|
|
338
|
+
});
|
|
339
|
+
this.repository.audit({
|
|
340
|
+
ownerUserId: principal.userId,
|
|
341
|
+
provider: providerId,
|
|
342
|
+
operation: "credential.switch",
|
|
343
|
+
result: "success",
|
|
344
|
+
credentialSource: "personal",
|
|
345
|
+
serviceProfileId: null,
|
|
346
|
+
sourceSessionId: null,
|
|
347
|
+
});
|
|
348
|
+
this.logger.info("credential.switched", {
|
|
349
|
+
provider: providerId,
|
|
350
|
+
credentialSource: "personal",
|
|
351
|
+
});
|
|
352
|
+
return this.summary(principal, providerId);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Narrow what this binding may read inside the profile's allowlist. A user may
|
|
356
|
+
* only remove entries: anything outside the administrator's list is dropped
|
|
357
|
+
* rather than stored, so a forged request cannot widen the boundary.
|
|
358
|
+
*/
|
|
359
|
+
setServiceSelection(principal, providerId, selection) {
|
|
360
|
+
const integration = this.requireConnected(principal, providerId);
|
|
361
|
+
const resolved = this.resolveService(principal, integration);
|
|
362
|
+
const narrowed = narrowBoundary(resolved.profile.resources, selection ?? undefined);
|
|
363
|
+
this.repository.setServiceSelection(principal, providerId, narrowed);
|
|
364
|
+
this.repository.audit({
|
|
365
|
+
ownerUserId: principal.userId,
|
|
366
|
+
provider: providerId,
|
|
367
|
+
operation: "credential.boundary",
|
|
368
|
+
result: "success",
|
|
369
|
+
credentialSource: "service",
|
|
370
|
+
serviceProfileId: resolved.profile.id,
|
|
371
|
+
sourceSessionId: null,
|
|
372
|
+
});
|
|
373
|
+
return this.summary(principal, providerId);
|
|
374
|
+
}
|
|
134
375
|
patchPolicy(principal, providerId, patch) {
|
|
135
376
|
const integration = this.requireConnected(principal, providerId);
|
|
136
377
|
if (!integration.capabilities.includes(patch.operation)) {
|
|
@@ -150,6 +391,8 @@ export class IntegrationBroker {
|
|
|
150
391
|
provider: providerId,
|
|
151
392
|
operation: "credential.disconnect",
|
|
152
393
|
result: "success",
|
|
394
|
+
credentialSource: "personal",
|
|
395
|
+
serviceProfileId: null,
|
|
153
396
|
sourceSessionId: null,
|
|
154
397
|
});
|
|
155
398
|
this.logger.info("credential.disconnected", { provider: providerId });
|
|
@@ -163,6 +406,19 @@ export class IntegrationBroker {
|
|
|
163
406
|
if (capability === undefined) {
|
|
164
407
|
throw new IntegrationError("InvalidRequest", "Unsupported integration operation");
|
|
165
408
|
}
|
|
409
|
+
const metadata = provider.operationMetadata?.(request.operation) ?? UNCLASSIFIED_OPERATION;
|
|
410
|
+
// The service ceiling is checked before anything else, so a call that the
|
|
411
|
+
// managed credential may not make is refused for that reason even when the
|
|
412
|
+
// personal switch for the capability happens to be off too.
|
|
413
|
+
const resolved = integration.credentialSource === "service"
|
|
414
|
+
? this.assertServiceOperation(principal, integration, {
|
|
415
|
+
operation: request.operation,
|
|
416
|
+
capability,
|
|
417
|
+
metadata,
|
|
418
|
+
boundaryKind: provider.resourceBoundaryKind?.(request.operation),
|
|
419
|
+
sourceSessionId: request.sourceSessionId,
|
|
420
|
+
})
|
|
421
|
+
: undefined;
|
|
166
422
|
const mode = this.repository.policy(integration, capability);
|
|
167
423
|
if (mode !== "allow" || !integration.capabilities.includes(capability)) {
|
|
168
424
|
this.repository.audit({
|
|
@@ -170,15 +426,24 @@ export class IntegrationBroker {
|
|
|
170
426
|
provider: request.provider,
|
|
171
427
|
operation: request.operation,
|
|
172
428
|
result: "denied",
|
|
429
|
+
credentialSource: integration.credentialSource,
|
|
430
|
+
serviceProfileId: resolved?.profile.id ?? null,
|
|
173
431
|
sourceSessionId: request.sourceSessionId,
|
|
174
432
|
});
|
|
175
433
|
throw new IntegrationError("OperationDeniedByPolicy", "Integration operation is denied by policy");
|
|
176
434
|
}
|
|
177
435
|
try {
|
|
178
|
-
const credential =
|
|
436
|
+
const credential = resolved === undefined
|
|
437
|
+
? await this.decrypt(principal, request.provider)
|
|
438
|
+
: this.buildServiceCredential(request.provider, resolved);
|
|
439
|
+
const boundary = resolved === undefined
|
|
440
|
+
? undefined
|
|
441
|
+
: narrowBoundary(resolved.profile.resources, integration.serviceSelection ?? undefined);
|
|
179
442
|
const providerData = await provider.execute({
|
|
180
443
|
credential,
|
|
181
444
|
externalUserId: integration.externalUserId ?? undefined,
|
|
445
|
+
credentialSource: integration.credentialSource,
|
|
446
|
+
resourceBoundary: boundary,
|
|
182
447
|
}, request.operation, request.input);
|
|
183
448
|
const data = typeof providerData === "object" &&
|
|
184
449
|
providerData !== null &&
|
|
@@ -190,12 +455,21 @@ export class IntegrationBroker {
|
|
|
190
455
|
provider: request.provider,
|
|
191
456
|
operation: request.operation,
|
|
192
457
|
result: "success",
|
|
458
|
+
credentialSource: integration.credentialSource,
|
|
459
|
+
serviceProfileId: resolved?.profile.id ?? null,
|
|
193
460
|
sourceSessionId: request.sourceSessionId,
|
|
194
461
|
});
|
|
195
462
|
this.logger.debug("tool.call", {
|
|
196
463
|
provider: request.provider,
|
|
197
464
|
operation: request.operation,
|
|
198
465
|
status: "success",
|
|
466
|
+
credentialSource: integration.credentialSource,
|
|
467
|
+
...(resolved === undefined
|
|
468
|
+
? {}
|
|
469
|
+
: {
|
|
470
|
+
serviceProfile: resolved.profile.id,
|
|
471
|
+
servicePolicyRevision: resolved.profile.policyRevision,
|
|
472
|
+
}),
|
|
199
473
|
});
|
|
200
474
|
return { provider: request.provider, operation: request.operation, data };
|
|
201
475
|
}
|
|
@@ -204,17 +478,160 @@ export class IntegrationBroker {
|
|
|
204
478
|
ownerUserId: principal.userId,
|
|
205
479
|
provider: request.provider,
|
|
206
480
|
operation: request.operation,
|
|
207
|
-
|
|
481
|
+
// A boundary or ceiling refusal comes back from the provider, but it is
|
|
482
|
+
// a policy decision and the trail records it as one.
|
|
483
|
+
result: isPolicyDenial(error) ? "denied" : "error",
|
|
484
|
+
credentialSource: integration.credentialSource,
|
|
485
|
+
serviceProfileId: resolved?.profile.id ?? null,
|
|
208
486
|
sourceSessionId: request.sourceSessionId,
|
|
209
487
|
});
|
|
210
488
|
throw error;
|
|
211
489
|
}
|
|
212
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Decide one operation against the service ceiling. Every refusal is audited
|
|
493
|
+
* with the real principal: upstream will only ever show the service account,
|
|
494
|
+
* so this row is what answers who asked.
|
|
495
|
+
*/
|
|
496
|
+
assertServiceOperation(principal, integration, query) {
|
|
497
|
+
let resolved;
|
|
498
|
+
try {
|
|
499
|
+
resolved = this.resolveService(principal, integration);
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
// A deployment credential that vanished or was retired is a denial like
|
|
503
|
+
// any other, and the trail has to show it as one.
|
|
504
|
+
this.repository.audit({
|
|
505
|
+
ownerUserId: principal.userId,
|
|
506
|
+
provider: integration.provider,
|
|
507
|
+
operation: query.operation,
|
|
508
|
+
result: "denied",
|
|
509
|
+
credentialSource: "service",
|
|
510
|
+
serviceProfileId: integration.serviceProfileId,
|
|
511
|
+
sourceSessionId: query.sourceSessionId,
|
|
512
|
+
});
|
|
513
|
+
throw error;
|
|
514
|
+
}
|
|
515
|
+
const decision = evaluateServiceOperation({
|
|
516
|
+
metadata: query.metadata,
|
|
517
|
+
capability: query.capability,
|
|
518
|
+
profile: resolved.profile,
|
|
519
|
+
boundaryKind: query.boundaryKind,
|
|
520
|
+
});
|
|
521
|
+
if (!decision.allowed) {
|
|
522
|
+
this.repository.audit({
|
|
523
|
+
ownerUserId: principal.userId,
|
|
524
|
+
provider: integration.provider,
|
|
525
|
+
operation: query.operation,
|
|
526
|
+
result: "denied",
|
|
527
|
+
credentialSource: "service",
|
|
528
|
+
serviceProfileId: resolved.profile.id,
|
|
529
|
+
sourceSessionId: query.sourceSessionId,
|
|
530
|
+
});
|
|
531
|
+
throw new IntegrationError(decision.code, decision.message);
|
|
532
|
+
}
|
|
533
|
+
return resolved;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* The profile a binding resolves to. It is chosen by the deployment — provider
|
|
537
|
+
* and portal — and never by an argument the model or the user supplies, which
|
|
538
|
+
* is why a caller cannot point a session at somebody else's credential.
|
|
539
|
+
*/
|
|
540
|
+
profileFor(providerId, instanceId) {
|
|
541
|
+
const registry = this.serviceCredentials;
|
|
542
|
+
if (registry === undefined)
|
|
543
|
+
return undefined;
|
|
544
|
+
const portal = this.providers.get(providerId).instancePortal?.(instanceId);
|
|
545
|
+
if (portal === undefined || portal === "")
|
|
546
|
+
return undefined;
|
|
547
|
+
return registry.find(providerId, portal);
|
|
548
|
+
}
|
|
549
|
+
resolveService(principal, integration) {
|
|
550
|
+
const registry = this.serviceCredentials;
|
|
551
|
+
const portal = integration.externalTenantId ?? "";
|
|
552
|
+
const profile = registry?.find(integration.provider, portal);
|
|
553
|
+
if (registry === undefined || profile === undefined) {
|
|
554
|
+
throw new IntegrationError("ServiceCredentialUnavailable", "This deployment manages no credential for the connected instance");
|
|
555
|
+
}
|
|
556
|
+
if (!profile.enabled) {
|
|
557
|
+
throw new IntegrationError("ServiceCredentialDisabled", "The service credential is disabled");
|
|
558
|
+
}
|
|
559
|
+
if (integration.servicePolicyRevision !== profile.policyRevision) {
|
|
560
|
+
// A profile changed, or a secret was rotated: record which revision this
|
|
561
|
+
// binding now runs under, so the change is visible and nothing derived
|
|
562
|
+
// from the previous revision is treated as current.
|
|
563
|
+
this.repository.setServicePolicyRevision(principal, integration.provider, profile.policyRevision);
|
|
564
|
+
}
|
|
565
|
+
return registry.readSecret(profile);
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Turn the deployment's secret into the credential shape of this provider.
|
|
569
|
+
* The provider owns that shape, so a service secret can never be spent against
|
|
570
|
+
* an instance other than the profile's.
|
|
571
|
+
*/
|
|
572
|
+
buildServiceCredential(providerId, resolved) {
|
|
573
|
+
const provider = this.providers.get(providerId);
|
|
574
|
+
try {
|
|
575
|
+
return provider.parseCredential(resolved.secret, {
|
|
576
|
+
instanceId: resolved.profile.instance,
|
|
577
|
+
}).credential;
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
if (error instanceof IntegrationError) {
|
|
581
|
+
throw new IntegrationError("ServiceCredentialInvalid", "The service credential is not usable for this provider", { cause: error });
|
|
582
|
+
}
|
|
583
|
+
throw error;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
async probeService(resolved) {
|
|
587
|
+
const provider = this.providers.get(resolved.profile.provider);
|
|
588
|
+
const probe = provider.validateServiceCredential;
|
|
589
|
+
if (probe === undefined)
|
|
590
|
+
return undefined;
|
|
591
|
+
return await probe({
|
|
592
|
+
credential: this.buildServiceCredential(resolved.profile.provider, resolved),
|
|
593
|
+
credentialSource: "service",
|
|
594
|
+
resourceBoundary: resolved.profile.resources,
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
/** Capabilities the managed credential can reach through this provider. */
|
|
598
|
+
serviceCapabilities(providerId) {
|
|
599
|
+
const provider = this.providers.get(providerId);
|
|
600
|
+
if (provider.capabilityServiceState === undefined)
|
|
601
|
+
return [];
|
|
602
|
+
return provider.capabilities.filter((capability) => provider.capabilityServiceState?.(capability) === "available");
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Managed-credential state of one provider, as a client renders it. Null for a
|
|
606
|
+
* provider that supports no managed credential at all, so nothing about the
|
|
607
|
+
* feature appears where it does not apply.
|
|
608
|
+
*/
|
|
609
|
+
serviceSummary(providerId, integration) {
|
|
610
|
+
const provider = this.providers.get(providerId);
|
|
611
|
+
if (provider.capabilityServiceState === undefined)
|
|
612
|
+
return null;
|
|
613
|
+
const capabilities = {};
|
|
614
|
+
for (const capability of provider.capabilities) {
|
|
615
|
+
capabilities[capability] =
|
|
616
|
+
provider.capabilityServiceState(capability) ?? "unavailable";
|
|
617
|
+
}
|
|
618
|
+
const profile = integration === undefined
|
|
619
|
+
? undefined
|
|
620
|
+
: this.serviceCredentials?.find(providerId, integration.externalTenantId ?? "");
|
|
621
|
+
return {
|
|
622
|
+
available: profile?.enabled === true,
|
|
623
|
+
label: profile?.label ?? null,
|
|
624
|
+
resources: profile?.resources ?? null,
|
|
625
|
+
selection: integration?.serviceSelection ?? null,
|
|
626
|
+
capabilities: Object.freeze(capabilities),
|
|
627
|
+
};
|
|
628
|
+
}
|
|
213
629
|
requireConnected(principal, provider) {
|
|
214
630
|
const integration = this.repository.find(principal, provider);
|
|
215
631
|
if (integration === undefined ||
|
|
216
632
|
integration.status === "revoked" ||
|
|
217
|
-
integration.secretRef === null
|
|
633
|
+
(integration.secretRef === null &&
|
|
634
|
+
integration.credentialSource !== "service")) {
|
|
218
635
|
throw new IntegrationError("IntegrationNotConnected", "Integration is not connected");
|
|
219
636
|
}
|
|
220
637
|
return integration;
|
|
@@ -222,7 +639,7 @@ export class IntegrationBroker {
|
|
|
222
639
|
async decrypt(principal, provider) {
|
|
223
640
|
const record = this.repository.secretFor(principal, provider);
|
|
224
641
|
if (record === undefined) {
|
|
225
|
-
throw new IntegrationError("
|
|
642
|
+
throw new IntegrationError("PersonalCredentialRequired", "This operation needs a personal credential");
|
|
226
643
|
}
|
|
227
644
|
if (record.expiresAt !== null &&
|
|
228
645
|
Date.parse(record.expiresAt) <= Date.now()) {
|
|
@@ -236,4 +653,34 @@ export class IntegrationBroker {
|
|
|
236
653
|
}
|
|
237
654
|
}
|
|
238
655
|
}
|
|
656
|
+
/** What a probe verdict means for the stored binding, if anything. */
|
|
657
|
+
function healthCode(health) {
|
|
658
|
+
switch (health?.status) {
|
|
659
|
+
case undefined:
|
|
660
|
+
case "healthy":
|
|
661
|
+
return undefined;
|
|
662
|
+
case "expired":
|
|
663
|
+
return "CredentialExpired";
|
|
664
|
+
case "revoked":
|
|
665
|
+
return "CredentialRevoked";
|
|
666
|
+
case "unsafe_scope":
|
|
667
|
+
return "ServiceCredentialUnsafeScope";
|
|
668
|
+
default:
|
|
669
|
+
return "ProviderUnavailable";
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
/** Codes that mean "policy refused this", wherever the refusal was decided. */
|
|
673
|
+
const DENIAL_CODES = Object.freeze([
|
|
674
|
+
"OperationDeniedByPolicy",
|
|
675
|
+
"OperationNotAllowedWithServiceCredential",
|
|
676
|
+
"SensitiveReadRequiresPersonalCredential",
|
|
677
|
+
"ServiceResourceNotAllowed",
|
|
678
|
+
"ServiceCredentialUnavailable",
|
|
679
|
+
"ServiceCredentialDisabled",
|
|
680
|
+
"ServiceCredentialInvalid",
|
|
681
|
+
"PersonalCredentialRequired",
|
|
682
|
+
]);
|
|
683
|
+
function isPolicyDenial(error) {
|
|
684
|
+
return error instanceof IntegrationError && DENIAL_CODES.includes(error.code);
|
|
685
|
+
}
|
|
239
686
|
//# sourceMappingURL=broker.js.map
|