@pagopa/dx-cli 0.21.5 → 0.21.6
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.
|
@@ -285,7 +285,7 @@ describe("initialize", () => {
|
|
|
285
285
|
principalType: "ServicePrincipal",
|
|
286
286
|
roleDefinitionId: "/subscriptions/sub-1/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe",
|
|
287
287
|
}));
|
|
288
|
-
expect(mockCreateFederatedIdentityCredential).toHaveBeenCalledWith("dx-d-itn-common-rg-01", "dx-d-itn-bootstrap-id-01", "bootstrapper-dev-cd", {
|
|
288
|
+
expect(mockCreateFederatedIdentityCredential).toHaveBeenCalledWith("dx-d-itn-common-rg-01", "dx-d-itn-bootstrap-id-01", "dx-bootstrapper-dev-cd", {
|
|
289
289
|
audiences: ["api://AzureADTokenExchange"],
|
|
290
290
|
issuer: "https://token.actions.githubusercontent.com",
|
|
291
291
|
subject: "repo:pagopa/dx:environment:bootstrapper-dev-cd",
|
|
@@ -341,4 +341,38 @@ describe("initialize", () => {
|
|
|
341
341
|
secretValue: "private-key",
|
|
342
342
|
});
|
|
343
343
|
});
|
|
344
|
+
test("uses a repository-specific federated credential name", async ({ cloudAccountService, }) => {
|
|
345
|
+
const createOrUpdateEnvironmentSecret = vi
|
|
346
|
+
.fn()
|
|
347
|
+
.mockResolvedValue(undefined);
|
|
348
|
+
await cloudAccountService.initialize({
|
|
349
|
+
csp: "azure",
|
|
350
|
+
defaultLocation: "italynorth",
|
|
351
|
+
displayName: "Test subscription",
|
|
352
|
+
id: "sub-1",
|
|
353
|
+
}, {
|
|
354
|
+
name: "dev",
|
|
355
|
+
prefix: "dx",
|
|
356
|
+
}, {
|
|
357
|
+
clientId: "app-client-id",
|
|
358
|
+
id: "app-id",
|
|
359
|
+
installationId: "installation-id",
|
|
360
|
+
key: "private-key\n",
|
|
361
|
+
}, {
|
|
362
|
+
owner: "pagopa",
|
|
363
|
+
repo: "dx-playground",
|
|
364
|
+
}, {
|
|
365
|
+
createBranch: vi.fn(),
|
|
366
|
+
createOrUpdateEnvironmentSecret,
|
|
367
|
+
createPullRequest: vi.fn(),
|
|
368
|
+
getFileContent: vi.fn(),
|
|
369
|
+
getRepository: vi.fn(),
|
|
370
|
+
updateFile: vi.fn(),
|
|
371
|
+
});
|
|
372
|
+
expect(mockCreateFederatedIdentityCredential).toHaveBeenCalledWith("dx-d-itn-common-rg-01", "dx-d-itn-bootstrap-id-01", "dx-playground-bootstrapper-dev-cd", {
|
|
373
|
+
audiences: ["api://AzureADTokenExchange"],
|
|
374
|
+
issuer: "https://token.actions.githubusercontent.com",
|
|
375
|
+
subject: "repo:pagopa/dx-playground:environment:bootstrapper-dev-cd",
|
|
376
|
+
});
|
|
377
|
+
});
|
|
344
378
|
});
|
|
@@ -199,14 +199,19 @@ export class AzureCloudAccountService {
|
|
|
199
199
|
})));
|
|
200
200
|
logger.debug("Assigned bootstrap roles to identity {identityName} in subscription {subscriptionId}", { identityName, subscriptionId: cloudAccount.id });
|
|
201
201
|
const githubEnvironmentName = `bootstrapper-${name}-cd`;
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
const federatedCredentialName = this.#createFederatedCredentialName({
|
|
203
|
+
github,
|
|
204
|
+
githubEnvironmentName,
|
|
205
|
+
});
|
|
206
|
+
// Include a repository-derived suffix so different repositories can share
|
|
207
|
+
// the same bootstrap identity without overwriting each other's OIDC trust.
|
|
208
|
+
await msiClient.federatedIdentityCredentials.createOrUpdate(resourceGroupName, identityName, federatedCredentialName, {
|
|
204
209
|
audiences: ["api://AzureADTokenExchange"],
|
|
205
210
|
issuer: "https://token.actions.githubusercontent.com",
|
|
206
211
|
subject: `repo:${github.owner}/${github.repo}:environment:${githubEnvironmentName}`,
|
|
207
212
|
});
|
|
208
213
|
logger.debug("Configured federated identity credential {credentialName} for identity {identityName} in subscription {subscriptionId}", {
|
|
209
|
-
credentialName:
|
|
214
|
+
credentialName: federatedCredentialName,
|
|
210
215
|
identityName,
|
|
211
216
|
subscriptionId: cloudAccount.id,
|
|
212
217
|
});
|
|
@@ -374,6 +379,10 @@ export class AzureCloudAccountService {
|
|
|
374
379
|
logger.debug("Created key vault {keyVaultName} in subscription {subscriptionId}", { keyVaultName, subscriptionId: cloudAccount.id });
|
|
375
380
|
return keyVaultName;
|
|
376
381
|
}
|
|
382
|
+
#createFederatedCredentialName({ github, githubEnvironmentName, }) {
|
|
383
|
+
const repoName = github.repo.replaceAll(/[^a-zA-Z0-9-]/g, "-");
|
|
384
|
+
return `${repoName}-${githubEnvironmentName}`;
|
|
385
|
+
}
|
|
377
386
|
#createRoleAssignmentName(scope, principalId, roleDefinitionId) {
|
|
378
387
|
const hash = createHash("sha256")
|
|
379
388
|
.update(`${scope}:${principalId}:${roleDefinitionId}`)
|