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