@pattform/api-kit 2.6.0 → 2.6.2

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.
@@ -22,6 +22,6 @@ export interface GcpProjectComponentArgs {
22
22
  services?: string[];
23
23
  deployServiceAccountId?: string;
24
24
  deployRoles?: string[];
25
- workloadIdentityMembers?: pulumi.Input<string>[];
25
+ tokenCreatorMembers?: pulumi.Input<string>[];
26
26
  importProjectId?: string;
27
27
  }
@@ -38,13 +38,14 @@ class GcpProjectComponent extends pulumi.ComponentResource {
38
38
  member: pulumi.interpolate `serviceAccount:${deploySa.email}`,
39
39
  }, { parent: deploySa });
40
40
  }
41
- // Grant the ESC env subjects that may impersonate the deploy SA. Members
42
- // are WIF principals, e.g.
43
- // principal://iam.googleapis.com/<pool>/subject/pulumi:environments:org:Pattform:env:<Project>/<env>
44
- ((_e = args.workloadIdentityMembers) !== null && _e !== void 0 ? _e : []).forEach((member, i) => {
45
- new gcp.serviceaccount.IAMMember(`${name}-deploy-wif-${i}`, {
41
+ // Trust hop, mirroring OrganizationAccountAccessRole on AWS: the base
42
+ // automation identity (pattform-infra, opened via the shared Common
43
+ // gcp-login) may mint tokens for this project's deploy SA. Stacks then
44
+ // set gcp:impersonateServiceAccount to hop in, no per-client ESC auth.
45
+ ((_e = args.tokenCreatorMembers) !== null && _e !== void 0 ? _e : []).forEach((member, i) => {
46
+ new gcp.serviceaccount.IAMMember(`${name}-deploy-token-creator-${i}`, {
46
47
  serviceAccountId: deploySa.name,
47
- role: "roles/iam.workloadIdentityUser",
48
+ role: "roles/iam.serviceAccountTokenCreator",
48
49
  member: member,
49
50
  }, { parent: deploySa });
50
51
  });
package/dist/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export { AppComponent, AppComponentArgs, DnsRecordInstruction } from "./AppCompo
4
4
  export { ClientAccountComponent, ClientAccountComponentArgs } from "./ClientAccountComponent";
5
5
  export { GcpProjectComponent, GcpProjectComponentArgs } from "./GcpProjectComponent";
6
6
  export { FormComponent, FormComponentArgs, FormFieldSpec, FormDestination } from "./FormComponent";
7
- export { getClientRoleArn } from "./pattformHelper";
7
+ export { getClientRoleArn, getClientGcpDeploySa, getClientGcpProvider } from "./pattformHelper";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getClientRoleArn = exports.FormComponent = exports.GcpProjectComponent = exports.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
3
+ exports.getClientGcpProvider = exports.getClientGcpDeploySa = exports.getClientRoleArn = exports.FormComponent = exports.GcpProjectComponent = exports.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
4
4
  var ContainerComponent_1 = require("./ContainerComponent");
5
5
  Object.defineProperty(exports, "ContainerComponent", { enumerable: true, get: function () { return ContainerComponent_1.ContainerComponent; } });
6
6
  var ApiComponent_1 = require("./ApiComponent");
@@ -15,3 +15,5 @@ var FormComponent_1 = require("./FormComponent");
15
15
  Object.defineProperty(exports, "FormComponent", { enumerable: true, get: function () { return FormComponent_1.FormComponent; } });
16
16
  var pattformHelper_1 = require("./pattformHelper");
17
17
  Object.defineProperty(exports, "getClientRoleArn", { enumerable: true, get: function () { return pattformHelper_1.getClientRoleArn; } });
18
+ Object.defineProperty(exports, "getClientGcpDeploySa", { enumerable: true, get: function () { return pattformHelper_1.getClientGcpDeploySa; } });
19
+ Object.defineProperty(exports, "getClientGcpProvider", { enumerable: true, get: function () { return pattformHelper_1.getClientGcpProvider; } });
@@ -1,3 +1,6 @@
1
1
  import * as pulumi from "@pulumi/pulumi";
2
+ import * as gcp from "@pulumi/gcp";
2
3
  export declare function getClientRoleArn(client: string, infrastructureStack?: string): pulumi.Output<string>;
4
+ export declare function getClientGcpDeploySa(client: string, infrastructureStack?: string): pulumi.Output<string>;
5
+ export declare function getClientGcpProvider(client: string, infrastructureStack?: string): gcp.Provider;
3
6
  export declare function verifyRegion(awsRegion: string): any;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyRegion = exports.getClientRoleArn = void 0;
3
+ exports.verifyRegion = exports.getClientGcpProvider = exports.getClientGcpDeploySa = exports.getClientRoleArn = void 0;
4
4
  const pulumi = require("@pulumi/pulumi");
5
5
  const aws = require("@pulumi/aws");
6
+ const gcp = require("@pulumi/gcp");
6
7
  const DEFAULT_INFRASTRUCTURE_STACK = "Pattform/pattform-infrastructure/prod";
7
8
  // StackReferences are resources, so creating the same one twice in a program
8
9
  // would collide on its URN; memoise per stack name.
@@ -25,6 +26,48 @@ function getClientRoleArn(client, infrastructureStack = DEFAULT_INFRASTRUCTURE_S
25
26
  });
26
27
  }
27
28
  exports.getClientRoleArn = getClientRoleArn;
29
+ // Looks up a client's GCP deploy service account from the
30
+ // pattform-infrastructure stack (GCP analog of getClientRoleArn).
31
+ function getClientGcpDeploySa(client, infrastructureStack = DEFAULT_INFRASTRUCTURE_STACK) {
32
+ if (!stackReferences[infrastructureStack]) {
33
+ stackReferences[infrastructureStack] = new pulumi.StackReference(infrastructureStack);
34
+ }
35
+ return stackReferences[infrastructureStack].requireOutput("clientGcpDeploySas").apply(sas => {
36
+ const sa = sas[client];
37
+ if (!sa) {
38
+ const known = Object.keys(sas).join(", ") || "<none>";
39
+ throw new Error(`Client "${client}" has no GCP deploy service account in ${infrastructureStack} (known clients: ${known}). ` +
40
+ `Add a GcpProjectComponent for it in pattform-infrastructure and deploy that stack first.`);
41
+ }
42
+ return sa;
43
+ });
44
+ }
45
+ exports.getClientGcpDeploySa = getClientGcpDeploySa;
46
+ // Providers are resources; memoise so a program can call this repeatedly.
47
+ const gcpProviders = {};
48
+ // GCP provider that deploys as the client's deploy SA: the base identity from
49
+ // the shared Common gcp-login impersonates deploy@<project>, mirroring the
50
+ // assume-role hop AWS components make with getClientRoleArn. Pass it to GCP
51
+ // resources/components:
52
+ // const gcpProvider = getClientGcpProvider(client);
53
+ // new ContainerComponent(name, args, { providers: [gcpProvider] });
54
+ function getClientGcpProvider(client, infrastructureStack = DEFAULT_INFRASTRUCTURE_STACK) {
55
+ const key = `${infrastructureStack}/${client}`;
56
+ if (!gcpProviders[key]) {
57
+ const gcpConfig = new pulumi.Config("gcp");
58
+ gcpProviders[key] = new gcp.Provider(`pattform-gcp-${client}`, {
59
+ // Explicit providers do not inherit gcp:* stack config (same trap
60
+ // as aws:accessKey on explicit AWS providers), so the base token
61
+ // performing the impersonation must be passed through.
62
+ accessToken: gcpConfig.get("accessToken"),
63
+ project: gcpConfig.get("project"),
64
+ region: gcpConfig.get("region"),
65
+ impersonateServiceAccount: getClientGcpDeploySa(client, infrastructureStack),
66
+ });
67
+ }
68
+ return gcpProviders[key];
69
+ }
70
+ exports.getClientGcpProvider = getClientGcpProvider;
28
71
  function verifyRegion(awsRegion) {
29
72
  for (const [key, value] of Object.entries(aws.Region)) {
30
73
  if (value == awsRegion) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pattform/api-kit",
3
- "version": "2.6.0",
3
+ "version": "2.6.2",
4
4
  "description": "Pulumi infra library for building and deploying an API",
5
5
  "author": "Pattform <contact@pattform.io>",
6
6
  "license": "SEE LICENSE IN LICENSE",