@microagi/alchemy-gcp 0.8.1 → 0.10.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 +28 -0
- package/lib/ArtifactRegistry/Operations.d.ts +2 -2
- package/lib/ArtifactRegistry/Operations.d.ts.map +1 -1
- package/lib/ArtifactRegistry/Repository.d.ts +1 -1
- package/lib/ArtifactRegistry/Validation.d.ts.map +1 -1
- package/lib/Auth/AuthProvider.d.ts.map +1 -1
- package/lib/Auth/AuthProvider.js.map +1 -1
- package/lib/Auth/Credentials.d.ts +1 -1
- package/lib/Auth/Credentials.d.ts.map +1 -1
- package/lib/CloudResourceManager/Project.d.ts +1 -1
- package/lib/CloudResourceManager/ProjectIamMember.d.ts.map +1 -1
- package/lib/Compute/Address.d.ts +1 -1
- package/lib/Compute/Firewall.d.ts +1 -1
- package/lib/Compute/ForwardingRule.d.ts +1 -1
- package/lib/Compute/GlobalAddress.d.ts +1 -1
- package/lib/Compute/Network.d.ts +1 -1
- package/lib/Compute/Network.d.ts.map +1 -1
- package/lib/Compute/Operations.d.ts +4 -4
- package/lib/Compute/Operations.d.ts.map +1 -1
- package/lib/Compute/Subnetwork.d.ts +1 -1
- package/lib/Compute/SubnetworkIamMember.d.ts.map +1 -1
- package/lib/Container/Cluster.d.ts +1 -1
- package/lib/Container/NodePool.d.ts +1 -1
- package/lib/Container/NodePool.d.ts.map +1 -1
- package/lib/Container/Operations.d.ts +2 -2
- package/lib/Container/Operations.d.ts.map +1 -1
- package/lib/Iam/ServiceAccount.d.ts +1 -1
- package/lib/Iam/ServiceAccountIamMember.d.ts.map +1 -1
- package/lib/Iam/ServiceAccountKey.js +1 -1
- package/lib/Iam/ServiceAccountKey.js.map +1 -1
- package/lib/Kubernetes/Helm.d.ts +132 -0
- package/lib/Kubernetes/Helm.d.ts.map +1 -0
- package/lib/Kubernetes/Helm.js +314 -0
- package/lib/Kubernetes/Helm.js.map +1 -0
- package/lib/Kubernetes/KubernetesManifest.d.ts +1 -1
- package/lib/Kubernetes/Secret.d.ts +1 -1
- package/lib/Kubernetes/client.d.ts.map +1 -1
- package/lib/Kubernetes/connection.d.ts.map +1 -1
- 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/ManagedLustre/Instance.d.ts +1 -1
- package/lib/Providers.d.ts +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/Run/IamMember.d.ts.map +1 -1
- package/lib/Run/IamSync.d.ts.map +1 -1
- package/lib/Run/Job.d.ts +1 -1
- package/lib/Run/Operations.d.ts +2 -2
- package/lib/Run/Operations.d.ts.map +1 -1
- package/lib/Run/Service.d.ts +1 -1
- package/lib/Run/Validation.d.ts.map +1 -1
- package/lib/Sqladmin/Instance.d.ts +1 -1
- package/lib/Sqladmin/Operations.d.ts +2 -2
- package/lib/Sqladmin/Operations.d.ts.map +1 -1
- package/lib/Sqladmin/Types.d.ts.map +1 -1
- package/lib/Sqladmin/Validation.d.ts.map +1 -1
- package/lib/Storage/Bucket.d.ts +1 -1
- package/lib/Storage/BucketIamMember.d.ts.map +1 -1
- package/lib/Storage/StorageBucketIamMember.d.ts +66 -0
- package/lib/Storage/StorageBucketIamMember.d.ts.map +1 -0
- package/lib/Storage/StorageBucketIamMember.js +130 -0
- package/lib/Storage/StorageBucketIamMember.js.map +1 -0
- package/lib/Storage/index.d.ts +2 -0
- package/lib/Storage/index.d.ts.map +1 -1
- package/lib/Storage/index.js +1 -0
- package/lib/Storage/index.js.map +1 -1
- package/lib/Tags.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/Iam/ServiceAccountKey.ts +1 -1
- package/src/Kubernetes/Helm.ts +536 -0
- package/src/Kubernetes/index.ts +1 -0
- package/src/Providers.ts +12 -0
- package/src/Storage/StorageBucketIamMember.ts +244 -0
- package/src/Storage/index.ts +8 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { ConfigError } from "@distilled.cloud/gcp";
|
|
2
|
+
import * as storage from "@distilled.cloud/gcp/storage-v1";
|
|
3
|
+
import { Resource } from "alchemy";
|
|
4
|
+
import { isResolved } from "alchemy/Diff";
|
|
5
|
+
import * as Provider from "alchemy/Provider";
|
|
6
|
+
import * as Duration from "effect/Duration";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Schedule from "effect/Schedule";
|
|
9
|
+
import type * as GCP from "../Providers.ts";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A single `(role, member)` IAM binding entry on an **existing** GCS
|
|
13
|
+
* bucket that this stack does not manage. Contrast with
|
|
14
|
+
* {@link storageBucketIamMember}, the target-side binding helper: that
|
|
15
|
+
* one requires a stack-owned {@link StorageBucket} and is additive-only
|
|
16
|
+
* (bindings written into the bucket's binding bag are merged on
|
|
17
|
+
* reconcile but never pruned). This standalone resource takes the raw
|
|
18
|
+
* bucket name, adds the member on reconcile, and — the part the helper
|
|
19
|
+
* cannot do — **removes it again on delete**, so grants revoke when the
|
|
20
|
+
* declaring resource leaves the stack.
|
|
21
|
+
*
|
|
22
|
+
* Identity is the `(bucket, role, member)` triple; all three are
|
|
23
|
+
* immutable — changing any replaces (the old triple is revoked, the new
|
|
24
|
+
* one granted).
|
|
25
|
+
*
|
|
26
|
+
* The read-modify-write on the shared bucket policy is member-scoped:
|
|
27
|
+
* exactly one member is added/removed, every foreign role and member is
|
|
28
|
+
* preserved verbatim, and the whole cycle retries with backoff so
|
|
29
|
+
* concurrent writers on the same bucket compose safely (GCS rejects a
|
|
30
|
+
* stale-etag set with `Conflict`/`PreconditionFailed`).
|
|
31
|
+
*
|
|
32
|
+
* There is nothing GCP-side to carry alchemy ownership labels on an IAM
|
|
33
|
+
* binding, so `read` has no `Unowned` adoption gate — presence of the
|
|
34
|
+
* exact member under the exact role IS the resource.
|
|
35
|
+
*
|
|
36
|
+
* @section Granting on an unmanaged bucket
|
|
37
|
+
* @example Read access for a collaborator group's namespace identity
|
|
38
|
+
* ```typescript
|
|
39
|
+
* yield* GCP.StorageBucketIamMember("SrlPackagingRead", {
|
|
40
|
+
* bucket: "srl_200hr_packaging",
|
|
41
|
+
* role: "roles/storage.objectViewer",
|
|
42
|
+
* member:
|
|
43
|
+
* "principal://iam.googleapis.com/projects/864268824536/locations/global/workloadIdentityPools/micro-research-cluster-a.svc.id.goog/subject/ns/collab-srl/sa/default",
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export type StorageBucketIamMemberProps = {
|
|
48
|
+
/**
|
|
49
|
+
* Name of the (pre-existing) GCS bucket to grant on. The bucket is
|
|
50
|
+
* NOT created, adopted, or deleted by this resource. Immutable —
|
|
51
|
+
* replace.
|
|
52
|
+
*/
|
|
53
|
+
bucket: string;
|
|
54
|
+
/** IAM role, e.g. `roles/storage.objectViewer`. Immutable — replace. */
|
|
55
|
+
role: string;
|
|
56
|
+
/**
|
|
57
|
+
* IAM member string (`serviceAccount:…`, `principal://…`,
|
|
58
|
+
* `group:…`, …). Immutable — replace.
|
|
59
|
+
*/
|
|
60
|
+
member: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type StorageBucketIamMemberAttributes = {
|
|
64
|
+
/** Bucket name, threaded through from props. */
|
|
65
|
+
bucket: string;
|
|
66
|
+
/** IAM role, threaded through from props. */
|
|
67
|
+
role: string;
|
|
68
|
+
/** IAM member, threaded through from props. */
|
|
69
|
+
member: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type StorageBucketIamMember = Resource<
|
|
73
|
+
"GCP.StorageBucketIamMember",
|
|
74
|
+
StorageBucketIamMemberProps,
|
|
75
|
+
StorageBucketIamMemberAttributes,
|
|
76
|
+
never,
|
|
77
|
+
GCP.Providers
|
|
78
|
+
>;
|
|
79
|
+
|
|
80
|
+
export const StorageBucketIamMember = Resource<StorageBucketIamMember>(
|
|
81
|
+
"GCP.StorageBucketIamMember",
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
export const StorageBucketIamMemberProvider = () =>
|
|
85
|
+
Provider.effect(
|
|
86
|
+
StorageBucketIamMember,
|
|
87
|
+
Effect.gen(function* () {
|
|
88
|
+
const getIamPolicyBuckets = yield* storage.getIamPolicyBuckets;
|
|
89
|
+
const setIamPolicyBuckets = yield* storage.setIamPolicyBuckets;
|
|
90
|
+
|
|
91
|
+
// Same backoff as StorageBucket's syncIam: the get→set cycle races
|
|
92
|
+
// other writers on the bucket policy (including sibling instances
|
|
93
|
+
// of this resource); a stale etag fails the set, the retry re-reads.
|
|
94
|
+
// ConfigError (bucket doesn't exist) is a terminal misconfiguration
|
|
95
|
+
// — fail fast instead of burning the ~8-minute backoff on it.
|
|
96
|
+
const etagRetry = <A, E, R>(eff: Effect.Effect<A, E, R>) =>
|
|
97
|
+
eff.pipe(
|
|
98
|
+
Effect.retry({
|
|
99
|
+
while: (e) => (e as { _tag?: string })?._tag !== "ConfigError",
|
|
100
|
+
schedule: Schedule.exponential(Duration.seconds(2)).pipe(
|
|
101
|
+
Schedule.both(Schedule.recurs(8)),
|
|
102
|
+
),
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Membership check scoped to the unconditional binding for `role`
|
|
107
|
+
// — conditional bindings are someone else's and never touched.
|
|
108
|
+
const hasMember = (
|
|
109
|
+
policy: storage.Policy,
|
|
110
|
+
role: string,
|
|
111
|
+
member: string,
|
|
112
|
+
) =>
|
|
113
|
+
(policy.bindings ?? []).some(
|
|
114
|
+
(b) => b.role === role && !b.condition && (b.members ?? []).includes(member),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
// Identity IS the triple; all three are static strings.
|
|
119
|
+
stables: ["bucket", "role", "member"],
|
|
120
|
+
diff: Effect.fn(function* ({ news, olds = {}, output }) {
|
|
121
|
+
if (!isResolved(news)) return undefined;
|
|
122
|
+
// Prior identity from persisted attributes first, then olds —
|
|
123
|
+
// mirrors Bucket.ts (`output?.name || olds.name`). `||`, not
|
|
124
|
+
// `??`: an empty string in a partially-persisted attribute is
|
|
125
|
+
// NOT a prior identity — treating it as one would force a
|
|
126
|
+
// spurious replace whose delete targets the wrong (empty)
|
|
127
|
+
// identity. If only `output` survives (e.g. props were lost),
|
|
128
|
+
// a changed triple must still replace, or the old member is
|
|
129
|
+
// never revoked.
|
|
130
|
+
const priorBucket = output?.bucket || olds.bucket;
|
|
131
|
+
const priorRole = output?.role || olds.role;
|
|
132
|
+
const priorMember = output?.member || olds.member;
|
|
133
|
+
if (
|
|
134
|
+
(priorBucket && priorBucket !== news.bucket) ||
|
|
135
|
+
(priorRole && priorRole !== news.role) ||
|
|
136
|
+
(priorMember && priorMember !== news.member)
|
|
137
|
+
) {
|
|
138
|
+
return { action: "replace" } as const;
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
}),
|
|
142
|
+
reconcile: Effect.fn(function* ({ news }) {
|
|
143
|
+
yield* etagRetry(
|
|
144
|
+
Effect.gen(function* () {
|
|
145
|
+
const current = yield* getIamPolicyBuckets({
|
|
146
|
+
bucket: news.bucket,
|
|
147
|
+
optionsRequestedPolicyVersion: 3,
|
|
148
|
+
}).pipe(
|
|
149
|
+
Effect.catchTag("NotFound", () =>
|
|
150
|
+
Effect.fail(
|
|
151
|
+
new ConfigError({
|
|
152
|
+
message: `Bucket ${news.bucket} does not exist — StorageBucketIamMember grants on pre-existing buckets only.`,
|
|
153
|
+
}),
|
|
154
|
+
),
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
if (hasMember(current, news.role, news.member)) return;
|
|
158
|
+
|
|
159
|
+
const bindings = (current.bindings ?? []).map((b) => ({
|
|
160
|
+
...b,
|
|
161
|
+
members: [...(b.members ?? [])],
|
|
162
|
+
}));
|
|
163
|
+
const existing = bindings.find(
|
|
164
|
+
(b) => b.role === news.role && !b.condition,
|
|
165
|
+
);
|
|
166
|
+
if (existing) {
|
|
167
|
+
existing.members = [...(existing.members ?? []), news.member];
|
|
168
|
+
} else {
|
|
169
|
+
bindings.push({ role: news.role, members: [news.member] });
|
|
170
|
+
}
|
|
171
|
+
yield* setIamPolicyBuckets({
|
|
172
|
+
bucket: news.bucket,
|
|
173
|
+
body: { ...current, bindings, version: 3 },
|
|
174
|
+
});
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
return { bucket: news.bucket, role: news.role, member: news.member };
|
|
178
|
+
}),
|
|
179
|
+
delete: Effect.fn(function* ({ output }) {
|
|
180
|
+
// Partially-persisted attributes (empty fields) name no real
|
|
181
|
+
// grant — nothing to revoke, and getIamPolicy("") would 4xx.
|
|
182
|
+
if (!output.bucket || !output.role || !output.member) return;
|
|
183
|
+
yield* etagRetry(
|
|
184
|
+
Effect.gen(function* () {
|
|
185
|
+
const current = yield* getIamPolicyBuckets({
|
|
186
|
+
bucket: output.bucket,
|
|
187
|
+
optionsRequestedPolicyVersion: 3,
|
|
188
|
+
}).pipe(
|
|
189
|
+
// Bucket gone (or unreadable because gone) — the grant
|
|
190
|
+
// went with it; idempotent success.
|
|
191
|
+
Effect.catchTag("NotFound", () =>
|
|
192
|
+
Effect.succeed(undefined as storage.Policy | undefined),
|
|
193
|
+
),
|
|
194
|
+
);
|
|
195
|
+
if (!current || !hasMember(current, output.role, output.member)) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
// Remove exactly our member from the unconditional binding;
|
|
199
|
+
// drop the binding entirely if that empties it (GCS rejects
|
|
200
|
+
// bindings with zero members).
|
|
201
|
+
const bindings = (current.bindings ?? [])
|
|
202
|
+
.map((b) =>
|
|
203
|
+
b.role === output.role && !b.condition
|
|
204
|
+
? {
|
|
205
|
+
...b,
|
|
206
|
+
members: (b.members ?? []).filter(
|
|
207
|
+
(m) => m !== output.member,
|
|
208
|
+
),
|
|
209
|
+
}
|
|
210
|
+
: { ...b, members: [...(b.members ?? [])] },
|
|
211
|
+
)
|
|
212
|
+
.filter((b) => (b.members?.length ?? 0) > 0);
|
|
213
|
+
yield* setIamPolicyBuckets({
|
|
214
|
+
bucket: output.bucket,
|
|
215
|
+
body: { ...current, bindings, version: 3 },
|
|
216
|
+
}).pipe(Effect.catchTag("NotFound", () => Effect.void));
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
219
|
+
}),
|
|
220
|
+
read: Effect.fn(function* ({ output, olds }) {
|
|
221
|
+
const bucket = output?.bucket ?? olds?.bucket;
|
|
222
|
+
const role = output?.role ?? olds?.role;
|
|
223
|
+
const member = output?.member ?? olds?.member;
|
|
224
|
+
if (!bucket || !role || !member) return undefined;
|
|
225
|
+
const current = yield* getIamPolicyBuckets({
|
|
226
|
+
bucket,
|
|
227
|
+
optionsRequestedPolicyVersion: 3,
|
|
228
|
+
}).pipe(
|
|
229
|
+
Effect.catchTag("NotFound", () =>
|
|
230
|
+
Effect.succeed(undefined as storage.Policy | undefined),
|
|
231
|
+
),
|
|
232
|
+
Effect.catchTag("Forbidden", () =>
|
|
233
|
+
Effect.succeed(undefined as storage.Policy | undefined),
|
|
234
|
+
),
|
|
235
|
+
);
|
|
236
|
+
if (!current) return undefined;
|
|
237
|
+
// Absent member → undefined: the engine treats that as drift
|
|
238
|
+
// and the next plan re-grants.
|
|
239
|
+
if (!hasMember(current, role, member)) return undefined;
|
|
240
|
+
return { bucket, role, member };
|
|
241
|
+
}),
|
|
242
|
+
};
|
|
243
|
+
}),
|
|
244
|
+
);
|
package/src/Storage/index.ts
CHANGED
|
@@ -8,3 +8,11 @@ export type {
|
|
|
8
8
|
StorageBucketBindingContract,
|
|
9
9
|
} from "./Bucket.ts";
|
|
10
10
|
export * from "./BucketIamMember.ts";
|
|
11
|
+
export {
|
|
12
|
+
StorageBucketIamMember,
|
|
13
|
+
StorageBucketIamMemberProvider,
|
|
14
|
+
} from "./StorageBucketIamMember.ts";
|
|
15
|
+
export type {
|
|
16
|
+
StorageBucketIamMemberProps,
|
|
17
|
+
StorageBucketIamMemberAttributes,
|
|
18
|
+
} from "./StorageBucketIamMember.ts";
|