@microagi/alchemy-gcp 0.6.0 → 0.8.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/CHANGELOG.md +86 -0
- package/lib/Iam/ServiceAccount.d.ts +104 -0
- package/lib/Iam/ServiceAccount.d.ts.map +1 -0
- package/lib/Iam/ServiceAccount.js +236 -0
- package/lib/Iam/ServiceAccount.js.map +1 -0
- package/lib/Iam/ServiceAccountIamMember.d.ts +49 -0
- package/lib/Iam/ServiceAccountIamMember.d.ts.map +1 -0
- package/lib/Iam/ServiceAccountIamMember.js +50 -0
- package/lib/Iam/ServiceAccountIamMember.js.map +1 -0
- package/lib/Iam/index.d.ts +4 -0
- package/lib/Iam/index.d.ts.map +1 -0
- package/lib/Iam/index.js +3 -0
- package/lib/Iam/index.js.map +1 -0
- package/lib/Kubernetes/KubernetesManifest.d.ts +100 -0
- package/lib/Kubernetes/KubernetesManifest.d.ts.map +1 -0
- package/lib/Kubernetes/KubernetesManifest.js +131 -0
- package/lib/Kubernetes/KubernetesManifest.js.map +1 -0
- package/lib/Kubernetes/Secret.d.ts +25 -18
- package/lib/Kubernetes/Secret.d.ts.map +1 -1
- package/lib/Kubernetes/Secret.js +79 -45
- package/lib/Kubernetes/Secret.js.map +1 -1
- package/lib/Kubernetes/client.d.ts +27 -23
- package/lib/Kubernetes/client.d.ts.map +1 -1
- package/lib/Kubernetes/client.js +139 -37
- package/lib/Kubernetes/client.js.map +1 -1
- package/lib/Kubernetes/connection.d.ts +48 -0
- package/lib/Kubernetes/connection.d.ts.map +1 -0
- package/lib/Kubernetes/connection.js +93 -0
- package/lib/Kubernetes/connection.js.map +1 -0
- package/lib/Kubernetes/index.d.ts +1 -0
- package/lib/Kubernetes/index.d.ts.map +1 -1
- package/lib/Kubernetes/index.js +1 -0
- package/lib/Kubernetes/index.js.map +1 -1
- package/lib/Providers.d.ts.map +1 -1
- package/lib/Providers.js +5 -1
- package/lib/Providers.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +4 -2
- package/src/Iam/ServiceAccount.ts +431 -0
- package/src/Iam/ServiceAccountIamMember.ts +56 -0
- package/src/Iam/index.ts +3 -0
- package/src/Kubernetes/KubernetesManifest.ts +301 -0
- package/src/Kubernetes/Secret.ts +153 -79
- package/src/Kubernetes/client.ts +226 -59
- package/src/Kubernetes/connection.ts +180 -0
- package/src/Kubernetes/index.ts +1 -0
- package/src/Providers.ts +12 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,92 @@ All notable changes to `@microagi/alchemy-gcp`. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); this package
|
|
5
5
|
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 0.8.0 — 2026-06-17
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **`GCP.ServiceAccount`** — Alchemy resource for managing Google
|
|
12
|
+
Cloud service accounts (GSAs). Wraps the iam-v1 API
|
|
13
|
+
(`@distilled.cloud/gcp/unstable/iam-v1` — the `iamcredentials-v1`
|
|
14
|
+
surface was already in the stable index; `iam-v1` lives under
|
|
15
|
+
`unstable/` because the auto-generated codegen hasn't been manually
|
|
16
|
+
reviewed). Adoption gated on an alchemy marker embedded in the
|
|
17
|
+
GSA's `description` field (GSAs have no labels field, so the
|
|
18
|
+
label-based pattern used by `GCP.Project` doesn't apply — see
|
|
19
|
+
`Tags.descriptionHasAlchemyMarker`). Cold recovery (state loss)
|
|
20
|
+
falls back to a project-wide scan-by-marker when persisted
|
|
21
|
+
`output`/`olds` lack the `uniqueId`. Synchronous lifecycle — no LRO
|
|
22
|
+
polling required.
|
|
23
|
+
|
|
24
|
+
- **`GCP.serviceAccountIamMember`** — target-side binding helper, the
|
|
25
|
+
same shape as the existing `projectIamMember` and
|
|
26
|
+
`subnetworkIamMember`. Records a `(role, member)` grant onto the
|
|
27
|
+
GSA's binding bag; the ServiceAccount provider's `reconcile` merges
|
|
28
|
+
all bound entries by role into a single `setIamPolicy` call on the
|
|
29
|
+
GSA. Foreign bindings on the policy (non-alchemy roles, or members
|
|
30
|
+
we don't manage on the same role) are preserved verbatim. Etag
|
|
31
|
+
round-trip handles concurrent edits; `Conflict` triggers a
|
|
32
|
+
re-read + retry.
|
|
33
|
+
|
|
34
|
+
### Use cases
|
|
35
|
+
|
|
36
|
+
- Workload Identity bindings — `roles/iam.workloadIdentityUser` on a
|
|
37
|
+
GSA from a k8s SA. Replaces the manual `gcloud iam service-accounts
|
|
38
|
+
add-iam-policy-binding` dance that's been applied out-of-band for
|
|
39
|
+
the `research-ui` and `preview-builder` GSAs.
|
|
40
|
+
- Per-namespace `roles/artifactregistry.writer` on a GSA scoped to
|
|
41
|
+
a single research pod (instead of project-wide via
|
|
42
|
+
`projectIamMember`).
|
|
43
|
+
- Impersonation grants — `roles/iam.serviceAccountTokenCreator` /
|
|
44
|
+
`roles/iam.serviceAccountUser`.
|
|
45
|
+
|
|
46
|
+
## 0.7.0 — 2026-06-16
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- **`GCP.KubernetesManifest`** — generic Alchemy resource for *any*
|
|
51
|
+
Kubernetes Kind/CRD, server-side-applied via
|
|
52
|
+
`Content-Type: application/apply-patch+yaml` with `fieldManager=alchemy`
|
|
53
|
+
and `force=true`. Kind → REST resource (plural + scope) resolved through
|
|
54
|
+
the apiserver's discovery endpoint, so built-ins and CRDs work without a
|
|
55
|
+
hard-coded kind→plural table. Adoption gated on the standard
|
|
56
|
+
`alchemy_app`/`alchemy_stage`/`alchemy_id` label triple.
|
|
57
|
+
|
|
58
|
+
- **`clusterLayer` (`src/Kubernetes/connection.ts`)** — wires a GKE
|
|
59
|
+
cluster into the typed `@distilled.cloud/kubernetes` SDK: ADC bearer
|
|
60
|
+
token (`Credentials`) + an `HttpClient` whose `FetchHttpClient.Fetch` is
|
|
61
|
+
overridden with a `node:https` fetch that trusts the per-cluster CA.
|
|
62
|
+
The stock fetch can't verify the GKE cert (it's signed by the
|
|
63
|
+
cluster's own CA, not a public root), so the override is required.
|
|
64
|
+
|
|
65
|
+
### Changed
|
|
66
|
+
|
|
67
|
+
- **`GCP.KubernetesSecret` convergence** — moved off the hand-rolled
|
|
68
|
+
client onto typed `@distilled.cloud/kubernetes` core/v1 ops. Reconcile
|
|
69
|
+
is now **create + replace (PUT)** with the observed `resourceVersion`
|
|
70
|
+
for optimistic concurrency, bounded `Conflict` retry (recursive on the
|
|
71
|
+
whole observe→write flow, up to 3 re-attempts), and read-modify-write
|
|
72
|
+
metadata that preserves foreign annotations/owner references/finalizers
|
|
73
|
+
(a PUT replaces the whole object, so spreading `...observed.metadata`
|
|
74
|
+
first and overlaying only what we manage is essential — without it
|
|
75
|
+
every reconcile would strip an `ownerReference` and break garbage
|
|
76
|
+
collection). Validation scripts in `scripts/validate-k8s-{connection,
|
|
77
|
+
secret,manifest}.ts` cover live cluster runs against `research-cluster-a`.
|
|
78
|
+
|
|
79
|
+
## 0.6.0 — 2026-06-14
|
|
80
|
+
|
|
81
|
+
### Added
|
|
82
|
+
|
|
83
|
+
- **`GCP.KubernetesSecret`** — first Kubernetes resource in the
|
|
84
|
+
provider. Opaque Secret in a GKE cluster, driven via a hand-rolled
|
|
85
|
+
REST client with ADC bearer auth + per-cluster CA trust. Adoptable via
|
|
86
|
+
the standard alchemy-internal label triple.
|
|
87
|
+
|
|
88
|
+
### Changed
|
|
89
|
+
|
|
90
|
+
- **`Auth/Credentials.fromAuthProvider`** — same fix as `0.5.1`,
|
|
91
|
+
re-asserted against the freshly bumped workspace pins.
|
|
92
|
+
|
|
7
93
|
## 0.5.1 — 2026-06-08
|
|
8
94
|
|
|
9
95
|
### Fixed
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Resource } from "alchemy";
|
|
2
|
+
import * as Provider from "alchemy/Provider";
|
|
3
|
+
import type * as GCP from "../Providers.ts";
|
|
4
|
+
/**
|
|
5
|
+
* A GCP service account (GSA). Lives under a {@link import("../CloudResourceManager/Project.ts").Project}
|
|
6
|
+
* and serves as the federated identity target for Workload Identity
|
|
7
|
+
* (`iam.gke.io/gcp-service-account: <email>` on a k8s SA) and as the
|
|
8
|
+
* principal in any IAM grant that should out-live a human user.
|
|
9
|
+
*
|
|
10
|
+
* Adoption is gated on an alchemy marker embedded in the GSA's
|
|
11
|
+
* `description` field (see `gcpAlchemyDescription` /
|
|
12
|
+
* `descriptionHasAlchemyMarker`) — GSAs have no labels field, so the
|
|
13
|
+
* label-based adoption gate used by Project can't apply. The marker is
|
|
14
|
+
* only written on insert; `description` is mutable but we never *clear*
|
|
15
|
+
* it because doing so would orphan the adoption signal.
|
|
16
|
+
*
|
|
17
|
+
* All lifecycle operations (`createProjectsServiceAccounts`,
|
|
18
|
+
* `patchProjectsServiceAccounts`, `deleteProjectsServiceAccounts`) are
|
|
19
|
+
* synchronous — no LRO polling required.
|
|
20
|
+
*
|
|
21
|
+
* @section Creating a ServiceAccount
|
|
22
|
+
* @example Minimal GSA under a project
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const gsa = yield* GCP.ServiceAccount("Builder", {
|
|
25
|
+
* project: project.projectId,
|
|
26
|
+
* accountId: "research-builder",
|
|
27
|
+
* displayName: "Research pod build + push (BuildKit client)",
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example With explicit description and Workload Identity binding
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const gsa = yield* GCP.ServiceAccount("Builder", {
|
|
34
|
+
* project: project.projectId,
|
|
35
|
+
* accountId: "research-builder",
|
|
36
|
+
* displayName: "Research pod build + push",
|
|
37
|
+
* description: "Used by per-researcher BuildKit clients to push to AR.",
|
|
38
|
+
* });
|
|
39
|
+
* yield* GCP.serviceAccountIamMember(gsa, "ClusterA-WorkloadIdentity", {
|
|
40
|
+
* role: "roles/iam.workloadIdentityUser",
|
|
41
|
+
* member: `serviceAccount:${projectA.projectId}.svc.id.goog[researchers/build]`,
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export type ServiceAccountProps = {
|
|
46
|
+
/**
|
|
47
|
+
* GCP project id (e.g. `micro-research-shared`) the GSA lives under.
|
|
48
|
+
* Immutable — changing this orphans the GSA's unique id and any
|
|
49
|
+
* bindings, so `diff` triggers a replacement.
|
|
50
|
+
*/
|
|
51
|
+
project: string;
|
|
52
|
+
/**
|
|
53
|
+
* The account id segment of the service account's email. Must match
|
|
54
|
+
* `[a-z]([-a-z0-9]*[a-z0-9])`, 6-30 chars. Immutable — replaces.
|
|
55
|
+
*/
|
|
56
|
+
accountId: string;
|
|
57
|
+
/**
|
|
58
|
+
* User-visible display name. Max 100 UTF-8 bytes. Mutable.
|
|
59
|
+
*/
|
|
60
|
+
displayName?: string;
|
|
61
|
+
/**
|
|
62
|
+
* User-supplied description (max 256 UTF-8 bytes). The alchemy
|
|
63
|
+
* ownership marker is prepended automatically — see
|
|
64
|
+
* `gcpAlchemyDescription`. The user-supplied portion is preserved
|
|
65
|
+
* verbatim and surfaced back through `Attributes.description`.
|
|
66
|
+
*/
|
|
67
|
+
description?: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Single (role, members) entry on a GSA's IAM policy. Targets declare
|
|
71
|
+
* this contract so capabilities (e.g. Workload Identity) can `.bind`
|
|
72
|
+
* IAM grants onto the GSA — the provider's `reconcile` merges all
|
|
73
|
+
* bound entries by role into a single `setIamPolicy` call.
|
|
74
|
+
*/
|
|
75
|
+
export type ServiceAccountIamBinding = {
|
|
76
|
+
/** IAM role, e.g. `"roles/iam.workloadIdentityUser"`. */
|
|
77
|
+
role: string;
|
|
78
|
+
/** Principals, e.g. `["serviceAccount:foo.svc.id.goog[ns/ksa]"]`. */
|
|
79
|
+
members: ReadonlyArray<string>;
|
|
80
|
+
};
|
|
81
|
+
export type ServiceAccountBindingContract = {
|
|
82
|
+
iamBindings: ReadonlyArray<ServiceAccountIamBinding>;
|
|
83
|
+
};
|
|
84
|
+
export type ServiceAccount = Resource<"GCP.ServiceAccount", ServiceAccountProps, {
|
|
85
|
+
/** Full resource name, e.g. `projects/micro-research-shared/serviceAccounts/research-builder@micro-research-shared.iam.gserviceaccount.com`. */
|
|
86
|
+
name: string;
|
|
87
|
+
/** Email address derived from the account id, e.g. `research-builder@micro-research-shared.iam.gserviceaccount.com`. */
|
|
88
|
+
email: string;
|
|
89
|
+
/** Server-assigned stable numeric id. */
|
|
90
|
+
uniqueId: string;
|
|
91
|
+
/** Project the GSA lives under. */
|
|
92
|
+
projectId: string;
|
|
93
|
+
/** Account id (the part before `@`). */
|
|
94
|
+
accountId: string;
|
|
95
|
+
/** User-visible display name, or `undefined` if never set. */
|
|
96
|
+
displayName: string | undefined;
|
|
97
|
+
/** User-visible description (without the alchemy marker), or `undefined` if never set. */
|
|
98
|
+
description: string | undefined;
|
|
99
|
+
/** Whether the GSA is currently disabled. */
|
|
100
|
+
disabled: boolean;
|
|
101
|
+
}, ServiceAccountBindingContract, GCP.Providers>;
|
|
102
|
+
export declare const ServiceAccount: import("alchemy").ResourceClass<ServiceAccount>;
|
|
103
|
+
export declare const ServiceAccountProvider: () => import("effect/Layer").Layer<Provider.Provider<ServiceAccount>, never, import("alchemy").Stack | import("alchemy").Stage | import("@distilled.cloud/gcp").Credentials | import("effect/unstable/http/HttpClient").HttpClient>;
|
|
104
|
+
//# sourceMappingURL=ServiceAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceAccount.d.ts","sourceRoot":"","sources":["../../src/Iam/ServiceAccount.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAU7C,OAAO,KAA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Error } from "@distilled.cloud/gcp";
|
|
2
|
+
import * as iam from "@distilled.cloud/gcp/unstable/iam-v1";
|
|
3
|
+
import { Resource } from "alchemy";
|
|
4
|
+
import { Unowned } from "alchemy/AdoptPolicy";
|
|
5
|
+
import { isResolved } from "alchemy/Diff";
|
|
6
|
+
import * as Provider from "alchemy/Provider";
|
|
7
|
+
import { diffTags } from "alchemy/Tags";
|
|
8
|
+
import * as Duration from "effect/Duration";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Schedule from "effect/Schedule";
|
|
11
|
+
import { descriptionHasAlchemyMarker, gcpAlchemyDescription, stripAlchemyMarker, } from "../Tags.js";
|
|
12
|
+
export const ServiceAccount = Resource("GCP.ServiceAccount");
|
|
13
|
+
const toAttributes = (sa) => {
|
|
14
|
+
const accountId = (sa.email ?? "").split("@")[0];
|
|
15
|
+
return {
|
|
16
|
+
name: sa.name ?? "",
|
|
17
|
+
email: sa.email ?? "",
|
|
18
|
+
uniqueId: sa.uniqueId ?? "",
|
|
19
|
+
projectId: sa.projectId ?? "",
|
|
20
|
+
accountId,
|
|
21
|
+
displayName: sa.displayName,
|
|
22
|
+
description: stripAlchemyMarker(sa.description),
|
|
23
|
+
disabled: sa.disabled ?? false,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const ServiceAccountProvider = () => Provider.effect(ServiceAccount, Effect.gen(function* () {
|
|
27
|
+
const getProjectsServiceAccounts = yield* iam.getProjectsServiceAccounts;
|
|
28
|
+
const createProjectsServiceAccounts = yield* iam.createProjectsServiceAccounts;
|
|
29
|
+
const patchProjectsServiceAccounts = yield* iam.patchProjectsServiceAccounts;
|
|
30
|
+
const deleteProjectsServiceAccounts = yield* iam.deleteProjectsServiceAccounts;
|
|
31
|
+
const listProjectsServiceAccounts = yield* iam.listProjectsServiceAccounts;
|
|
32
|
+
const getIamPolicyProjectsServiceAccounts = yield* iam.getIamPolicyProjectsServiceAccounts;
|
|
33
|
+
const setIamPolicyProjectsServiceAccounts = yield* iam.setIamPolicyProjectsServiceAccounts;
|
|
34
|
+
const resourceName = (projectId, accountId) => `projects/${projectId}/serviceAccounts/${accountId}`;
|
|
35
|
+
const observeServiceAccount = (projectId, accountId) => getProjectsServiceAccounts({
|
|
36
|
+
name: resourceName(projectId, accountId),
|
|
37
|
+
}).pipe(
|
|
38
|
+
// GSAs that don't exist OR that the caller can't see both
|
|
39
|
+
// collapse to "absent" — same 403→missing pattern as the
|
|
40
|
+
// project observer.
|
|
41
|
+
Effect.catchTag("NotFound", () => Effect.succeed(undefined)), Effect.catchTag("Forbidden", () => Effect.succeed(undefined)));
|
|
42
|
+
const requireServiceAccount = (projectId, accountId, context) => observeServiceAccount(projectId, accountId).pipe(Effect.flatMap((sa) => sa
|
|
43
|
+
? Effect.succeed(sa)
|
|
44
|
+
: Effect.fail(new ConfigError({
|
|
45
|
+
message: `ServiceAccount ${accountId} in project ${projectId} ${context}.`,
|
|
46
|
+
}))));
|
|
47
|
+
// List-page scan for cold recovery. Alchemy marker in the
|
|
48
|
+
// description field identifies our GSAs; the page boundary is
|
|
49
|
+
// arbitrary — we still need to page through to find any marker
|
|
50
|
+
// that happens to fall past the first page.
|
|
51
|
+
const findByAlchemyMarker = Effect.fn(function* (id, projectId) {
|
|
52
|
+
let pageToken;
|
|
53
|
+
// Up to 100 pages × 100 items per page = 10000 GSAs; well past
|
|
54
|
+
// any realistic project size. If we ever exceed that we should
|
|
55
|
+
// cap and warn rather than silently miss matches.
|
|
56
|
+
for (let i = 0; i < 100; i++) {
|
|
57
|
+
const page = yield* listProjectsServiceAccounts({
|
|
58
|
+
name: `projects/${projectId}`,
|
|
59
|
+
...(pageToken ? { pageToken } : {}),
|
|
60
|
+
pageSize: 100,
|
|
61
|
+
});
|
|
62
|
+
for (const sa of page.accounts ?? []) {
|
|
63
|
+
if (yield* descriptionHasAlchemyMarker(id, sa.description)) {
|
|
64
|
+
return sa;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
pageToken = page.nextPageToken;
|
|
68
|
+
if (!pageToken)
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
});
|
|
73
|
+
// Sync mutable fields: displayName + description. Both use
|
|
74
|
+
// `updateMask` so we only PATCH what actually changed. Diff
|
|
75
|
+
// against OBSERVED state, not `olds`, so adoption converges
|
|
76
|
+
// correctly when a foreign description is on the GSA.
|
|
77
|
+
const syncMutable = Effect.fn(function* (observed, desired) {
|
|
78
|
+
const updateMaskFields = [];
|
|
79
|
+
if (desired.displayName !== observed.displayName) {
|
|
80
|
+
updateMaskFields.push("display_name");
|
|
81
|
+
}
|
|
82
|
+
const descDiff = diffTags({ description: observed.description ?? "" }, { description: desired.descriptionWithMarker });
|
|
83
|
+
if (descDiff.removed.length > 0 ||
|
|
84
|
+
descDiff.upsert.length > 0) {
|
|
85
|
+
updateMaskFields.push("description");
|
|
86
|
+
}
|
|
87
|
+
if (updateMaskFields.length === 0)
|
|
88
|
+
return observed;
|
|
89
|
+
return yield* patchProjectsServiceAccounts({
|
|
90
|
+
name: observed.name,
|
|
91
|
+
body: {
|
|
92
|
+
updateMask: updateMaskFields.join(","),
|
|
93
|
+
serviceAccount: {
|
|
94
|
+
displayName: desired.displayName,
|
|
95
|
+
description: desired.descriptionWithMarker,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
// Apply merged IAM bindings as a single setIamPolicy. Same
|
|
101
|
+
// foreign-binding preservation + etag-retry pattern as the
|
|
102
|
+
// Project's `syncIam` — see `src/CloudResourceManager/Project.ts:421-474`.
|
|
103
|
+
const syncIam = (args) => Effect.gen(function* () {
|
|
104
|
+
const desiredByRole = new Map();
|
|
105
|
+
for (const b of args.bindings) {
|
|
106
|
+
for (const ib of b.data.iamBindings) {
|
|
107
|
+
const set = desiredByRole.get(ib.role) ?? new Set();
|
|
108
|
+
for (const m of ib.members)
|
|
109
|
+
set.add(m);
|
|
110
|
+
desiredByRole.set(ib.role, set);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (desiredByRole.size === 0)
|
|
114
|
+
return;
|
|
115
|
+
const current = yield* getIamPolicyProjectsServiceAccounts({
|
|
116
|
+
resource: args.resourceName,
|
|
117
|
+
"options.requestedPolicyVersion": 3,
|
|
118
|
+
});
|
|
119
|
+
const existingBindings = (current.bindings ?? []).map((b) => ({
|
|
120
|
+
...b,
|
|
121
|
+
members: [...(b.members ?? [])],
|
|
122
|
+
}));
|
|
123
|
+
let mutated = false;
|
|
124
|
+
for (const [role, members] of desiredByRole) {
|
|
125
|
+
let existing = existingBindings.find((b) => b.role === role && !b.condition);
|
|
126
|
+
if (!existing) {
|
|
127
|
+
existing = { role, members: [] };
|
|
128
|
+
existingBindings.push(existing);
|
|
129
|
+
}
|
|
130
|
+
const merged = new Set([...(existing.members ?? []), ...members]);
|
|
131
|
+
if (merged.size !== (existing.members?.length ?? 0))
|
|
132
|
+
mutated = true;
|
|
133
|
+
existing.members = [...merged];
|
|
134
|
+
}
|
|
135
|
+
if (!mutated)
|
|
136
|
+
return;
|
|
137
|
+
yield* setIamPolicyProjectsServiceAccounts({
|
|
138
|
+
resource: args.resourceName,
|
|
139
|
+
body: {
|
|
140
|
+
policy: { ...current, bindings: existingBindings, version: 3 },
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}).pipe(Effect.retry({
|
|
144
|
+
schedule: Schedule.exponential(Duration.seconds(2)).pipe(Schedule.both(Schedule.recurs(8))),
|
|
145
|
+
}));
|
|
146
|
+
return {
|
|
147
|
+
// Stable identity: accountId + project; both immutable; either
|
|
148
|
+
// change → replace. The server-assigned uniqueId is also stable
|
|
149
|
+
// for the lifetime of the GSA (re-create gets a different one).
|
|
150
|
+
stables: ["accountId", "projectId", "uniqueId", "name", "email"],
|
|
151
|
+
diff: Effect.fn(function* ({ id, news, olds = {}, output }) {
|
|
152
|
+
if (!isResolved(news))
|
|
153
|
+
return undefined;
|
|
154
|
+
if (news.accountId !== (output?.accountId ?? olds.accountId) ||
|
|
155
|
+
news.project !== (output?.projectId ?? olds.project)) {
|
|
156
|
+
return { action: "replace" };
|
|
157
|
+
}
|
|
158
|
+
return undefined;
|
|
159
|
+
}),
|
|
160
|
+
reconcile: Effect.fn(function* ({ id, news, bindings }) {
|
|
161
|
+
const descriptionWithMarker = yield* gcpAlchemyDescription(id, news.description);
|
|
162
|
+
// 1. Observe — cloud state is authoritative. A second
|
|
163
|
+
// scan-by-marker covers the cold-recovery case where
|
|
164
|
+
// persisted `output`/`olds` lost the uniqueId after
|
|
165
|
+
// state loss. We prefer the direct-by-name probe first
|
|
166
|
+
// (cheap) and fall back to the scan only when direct
|
|
167
|
+
// observation returned `undefined`.
|
|
168
|
+
let observed = yield* observeServiceAccount(news.project, news.accountId);
|
|
169
|
+
if (!observed) {
|
|
170
|
+
observed = yield* findByAlchemyMarker(id, news.project);
|
|
171
|
+
}
|
|
172
|
+
// 2. Ensure — create if missing. createProjectsServiceAccounts
|
|
173
|
+
// is synchronous (returns the SA, not an LRO). Conflict
|
|
174
|
+
// covers a peer reconciler race — re-observe.
|
|
175
|
+
if (!observed) {
|
|
176
|
+
observed = yield* createProjectsServiceAccounts({
|
|
177
|
+
name: `projects/${news.project}`,
|
|
178
|
+
body: {
|
|
179
|
+
accountId: news.accountId,
|
|
180
|
+
serviceAccount: {
|
|
181
|
+
displayName: news.displayName,
|
|
182
|
+
description: descriptionWithMarker,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
}).pipe(Effect.catchTag("Conflict", () => Effect.succeed(undefined)));
|
|
186
|
+
if (!observed) {
|
|
187
|
+
observed = yield* requireServiceAccount(news.project, news.accountId, "did not appear after create");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// 3. Sync mutable fields against OBSERVED state.
|
|
191
|
+
const synced = yield* syncMutable(observed, {
|
|
192
|
+
displayName: news.displayName ?? observed.displayName,
|
|
193
|
+
descriptionWithMarker,
|
|
194
|
+
descriptionUserOnly: news.description,
|
|
195
|
+
});
|
|
196
|
+
// 4. Sync IAM bindings (Workload Identity, impersonators, …).
|
|
197
|
+
// Single setIamPolicy on the GSA with merged bindings;
|
|
198
|
+
// foreign roles preserved. Etag-retried internally.
|
|
199
|
+
yield* syncIam({
|
|
200
|
+
resourceName: synced.name,
|
|
201
|
+
bindings,
|
|
202
|
+
});
|
|
203
|
+
return toAttributes(synced);
|
|
204
|
+
}),
|
|
205
|
+
delete: Effect.fn(function* ({ output }) {
|
|
206
|
+
// Synchronous delete — Empty response, no LRO. NotFound
|
|
207
|
+
// means the GSA was already deleted (or never existed in our
|
|
208
|
+
// scope); both are idempotent successes.
|
|
209
|
+
yield* deleteProjectsServiceAccounts({
|
|
210
|
+
name: output.name,
|
|
211
|
+
}).pipe(Effect.catchTag("NotFound", () => Effect.void), Effect.catchTag("Forbidden", () => Effect.void));
|
|
212
|
+
}),
|
|
213
|
+
read: Effect.fn(function* ({ id, output, olds }) {
|
|
214
|
+
// Direct-by-name probe when we have any handle on the
|
|
215
|
+
// accountId. Falls back to a project-wide scan-by-marker
|
|
216
|
+
// for cold recovery after state loss.
|
|
217
|
+
const accountId = output?.accountId ?? olds?.accountId;
|
|
218
|
+
const projectId = output?.projectId ?? olds?.project;
|
|
219
|
+
let observed;
|
|
220
|
+
if (accountId && projectId) {
|
|
221
|
+
observed = yield* observeServiceAccount(projectId, accountId);
|
|
222
|
+
}
|
|
223
|
+
if (!observed && projectId) {
|
|
224
|
+
observed = yield* findByAlchemyMarker(id, projectId);
|
|
225
|
+
}
|
|
226
|
+
if (!observed)
|
|
227
|
+
return undefined;
|
|
228
|
+
const attrs = toAttributes(observed);
|
|
229
|
+
// Adoption gate via description marker (see Tags.ts §description).
|
|
230
|
+
return (yield* descriptionHasAlchemyMarker(id, observed.description))
|
|
231
|
+
? attrs
|
|
232
|
+
: Unowned(attrs);
|
|
233
|
+
}),
|
|
234
|
+
};
|
|
235
|
+
}));
|
|
236
|
+
//# sourceM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,CAAC,CAAC;QACF,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;YAC7C,sDAAsD;YACtD,yDAAyD;YACzD,sCAAsC;YACtC,MAAM,SAAS,GACb,MAAM,EAAE,SAAS,IAAI,IAAI,EAAE,SAAS,CAAC;YACvC,MAAM,SAAS,GACb,MAAM,EAAE,SAAS,IAAI,IAAI,EAAE,OAAO,CAAC;YAErC,IAAI,QAAwC,CAAC;YAC7C,IAAI,SAAS,IAAI,SAAS,EAAE,CAAC;gBAC3B,QAAQ,GAAG,KAAK,CAAC,CAAC,qBAAqB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAChE,CAAC;YACD,IAAI,CAAC,QAAQ,IAAI,SAAS,EAAE,CAAC;gBAC3B,QAAQ,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;YACvD,CAAC;YACD,IAAI,CAAC,QAAQ;gBAAE,OAAO,SAAS,CAAC;YAEhC,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;YACrC,mEAAmE;YACnE,OAAO,CAAC,KAAK,CAAC,CAAC,2BAA2B,CAAC,EAAE,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;gBACnE,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC,CAAC;KACH,CAAC;AACJ,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import type { ServiceAccount } from "./ServiceAccount.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Bind a single `(role, member)` IAM grant onto a {@link ServiceAccount}.
|
|
5
|
+
*
|
|
6
|
+
* This is a **target-side binding** — it records the grant onto the
|
|
7
|
+
* GSA's binding bag (`stack.bindings[gsa]`); the ServiceAccount
|
|
8
|
+
* provider's `reconcile` later merges all such bindings (across all
|
|
9
|
+
* callers, including parallel ones from different stack stages) into
|
|
10
|
+
* a single `setIamPolicy` call on the GSA. Same pattern as
|
|
11
|
+
* `projectIamMember` / `subnetworkIamMember`.
|
|
12
|
+
*
|
|
13
|
+
* Identity for dedup: the rendered SID is `IamMember(<gsa>, <key>)`.
|
|
14
|
+
* The engine collapses binds by SID, so callers MUST supply a
|
|
15
|
+
* stack-unique `key` per (gsa, role, member) triple — otherwise a
|
|
16
|
+
* later bind silently overwrites an earlier one with the same key.
|
|
17
|
+
*
|
|
18
|
+
* The reason `key` exists: `member` is usually an `Output<string>`
|
|
19
|
+
* (e.g. `Output.interpolate\`...${cluster.projectId}...\``), and
|
|
20
|
+
* `Output` expressions stringify by their AST shape, not by the
|
|
21
|
+
* eventual value. Two interpolations of the same shape but different
|
|
22
|
+
* literal templates render the same SID. `key` sidesteps that by
|
|
23
|
+
* forcing a static, caller-supplied label into the SID.
|
|
24
|
+
*
|
|
25
|
+
* Use this for the "Pulumi `gcp.serviceAccount.IAMMember`" pattern:
|
|
26
|
+
* authoritative-for-(role, member)-tuple, additive (does not displace
|
|
27
|
+
* other members on the same role).
|
|
28
|
+
*
|
|
29
|
+
* @example Workload Identity binding for one cluster
|
|
30
|
+
* ```typescript
|
|
31
|
+
* yield* GCP.serviceAccountIamMember(gsa, "ClusterA-WorkloadIdentity", {
|
|
32
|
+
* role: "roles/iam.workloadIdentityUser",
|
|
33
|
+
* member: `serviceAccount:${clusterA.projectId}.svc.id.goog[researchers/build]`,
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example Same GSA, second cluster (separate key → distinct SID)
|
|
38
|
+
* ```typescript
|
|
39
|
+
* yield* GCP.serviceAccountIamMember(gsa, "ClusterB-WorkloadIdentity", {
|
|
40
|
+
* role: "roles/iam.workloadIdentityUser",
|
|
41
|
+
* member: `serviceAccount:${clusterB.projectId}.svc.id.goog[researchers/build]`,
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const serviceAccountIamMember: (gsa: ServiceAccount, key: string, args: {
|
|
46
|
+
role: string;
|
|
47
|
+
member: string;
|
|
48
|
+
}) => Effect.Effect<void>;
|
|
49
|
+
//# sourceMappingURL=ServiceAccountIamMember.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceAccountIamMember.d.ts","sourceRoot":"","sources":["../../src/Iam/ServiceAccountIamMember.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,uBAAuB,GAClC,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,MAAM;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KACrC,MAAM,CAAC,MAAM,CAAC,IAAI,CAMiB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bind a single `(role, member)` IAM grant onto a {@link ServiceAccount}.
|
|
3
|
+
*
|
|
4
|
+
* This is a **target-side binding** — it records the grant onto the
|
|
5
|
+
* GSA's binding bag (`stack.bindings[gsa]`); the ServiceAccount
|
|
6
|
+
* provider's `reconcile` later merges all such bindings (across all
|
|
7
|
+
* callers, including parallel ones from different stack stages) into
|
|
8
|
+
* a single `setIamPolicy` call on the GSA. Same pattern as
|
|
9
|
+
* `projectIamMember` / `subnetworkIamMember`.
|
|
10
|
+
*
|
|
11
|
+
* Identity for dedup: the rendered SID is `IamMember(<gsa>, <key>)`.
|
|
12
|
+
* The engine collapses binds by SID, so callers MUST supply a
|
|
13
|
+
* stack-unique `key` per (gsa, role, member) triple — otherwise a
|
|
14
|
+
* later bind silently overwrites an earlier one with the same key.
|
|
15
|
+
*
|
|
16
|
+
* The reason `key` exists: `member` is usually an `Output<string>`
|
|
17
|
+
* (e.g. `Output.interpolate\`...${cluster.projectId}...\``), and
|
|
18
|
+
* `Output` expressions stringify by their AST shape, not by the
|
|
19
|
+
* eventual value. Two interpolations of the same shape but different
|
|
20
|
+
* literal templates render the same SID. `key` sidesteps that by
|
|
21
|
+
* forcing a static, caller-supplied label into the SID.
|
|
22
|
+
*
|
|
23
|
+
* Use this for the "Pulumi `gcp.serviceAccount.IAMMember`" pattern:
|
|
24
|
+
* authoritative-for-(role, member)-tuple, additive (does not displace
|
|
25
|
+
* other members on the same role).
|
|
26
|
+
*
|
|
27
|
+
* @example Workload Identity binding for one cluster
|
|
28
|
+
* ```typescript
|
|
29
|
+
* yield* GCP.serviceAccountIamMember(gsa, "ClusterA-WorkloadIdentity", {
|
|
30
|
+
* role: "roles/iam.workloadIdentityUser",
|
|
31
|
+
* member: `serviceAccount:${clusterA.projectId}.svc.id.goog[researchers/build]`,
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Same GSA, second cluster (separate key → distinct SID)
|
|
36
|
+
* ```typescript
|
|
37
|
+
* yield* GCP.serviceAccountIamMember(gsa, "ClusterB-WorkloadIdentity", {
|
|
38
|
+
* role: "roles/iam.workloadIdentityUser",
|
|
39
|
+
* member: `serviceAccount:${clusterB.projectId}.svc.id.goog[researchers/build]`,
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export const serviceAccountIamMember = (gsa, key, args) =>
|
|
44
|
+
// Tagged-template `.bind` records into the target's binding bag.
|
|
45
|
+
// ServiceAccount's reconcile sees `bindings: ResourceBinding<…>[]`
|
|
46
|
+
// and merges all entries by role into one setIamPolicy call.
|
|
47
|
+
gsa.bind `IamMember(${gsa}, ${key})`({
|
|
48
|
+
iamBindings: [{ role: args.role, members: [args.member] }],
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=ServiceAccountIamMember.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceAccountIamMember.js","sourceRoot":"","sources":["../../src/Iam/ServiceAccountIamMember.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,GAAmB,EACnB,GAAW,EACX,IAAsC,EACjB,EAAE;AACvB,iEAAiE;AACjE,mEAAmE;AACnE,6DAA6D;AAC7D,GAAG,CAAC,IAAI,CAAA,aAAa,GAAG,KAAK,GAAG,GAAG,CAAC;IAClC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;CAC3D,CAAmC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Iam/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,cAAc,8BAA8B,CAAC"}
|
package/lib/Iam/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Iam/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,cAAc,8BAA8B,CAAC"}
|