@geekmidas/cloud 10.0.0-alpha.98 → 10.0.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.
Files changed (74) hide show
  1. package/README.md +6 -14
  2. package/dist/index-ByEJy40r.d.cts +56 -0
  3. package/dist/index-ByEJy40r.d.cts.map +1 -0
  4. package/dist/index-DZ0QrJQr.d.mts +56 -0
  5. package/dist/index-DZ0QrJQr.d.mts.map +1 -0
  6. package/dist/index.cjs +3 -3
  7. package/dist/index.d.cts +1 -1
  8. package/dist/index.d.mts +1 -1
  9. package/dist/index.mjs +3 -2
  10. package/dist/utils/index.cjs +5 -106
  11. package/dist/utils/index.d.cts +2 -62
  12. package/dist/utils/index.d.mts +2 -62
  13. package/dist/utils/index.mjs +2 -78
  14. package/dist/utils-BdKG20_m.mjs +83 -0
  15. package/dist/utils-BdKG20_m.mjs.map +1 -0
  16. package/dist/utils-CtMjuIMR.cjs +129 -0
  17. package/dist/utils-CtMjuIMR.cjs.map +1 -0
  18. package/package.json +9 -47
  19. package/src/sst/{aws/Api.ts → Api.ts} +47 -19
  20. package/src/sst/{aws/Cron.ts → Cron.ts} +46 -6
  21. package/src/sst/{aws/Function.ts → Function.ts} +41 -12
  22. package/src/sst/Queue.ts +46 -0
  23. package/src/sst/{aws/Storage.ts → Storage.ts} +3 -3
  24. package/src/sst/Topic.ts +37 -0
  25. package/src/sst/__tests__/LinkedEnvironment.spec.ts +1 -4
  26. package/src/sst/__type-tests__/authorizers.type-test.ts +2 -2
  27. package/src/sst/__type-tests__/manifest.type-test.ts +77 -0
  28. package/src/sst/__type-tests__/messaging.type-test.ts +3 -3
  29. package/src/sst/__type-tests__/storage.type-test.ts +2 -2
  30. package/src/sst/index.ts +7 -67
  31. package/src/sst/naming.ts +16 -37
  32. package/src/sst/tsconfig.json +2 -2
  33. package/dist/utils/index.cjs.map +0 -1
  34. package/dist/utils/index.d.cts.map +0 -1
  35. package/dist/utils/index.d.mts.map +0 -1
  36. package/dist/utils/index.mjs.map +0 -1
  37. package/src/dokploy/Application.ts +0 -306
  38. package/src/dokploy/__tests__/Application.provider.spec.ts +0 -206
  39. package/src/dokploy/__tests__/Application.spec.ts +0 -69
  40. package/src/dokploy/index.ts +0 -18
  41. package/src/sst/__tests__/api.spec.ts +0 -185
  42. package/src/sst/__tests__/backends.spec.ts +0 -249
  43. package/src/sst/__tests__/bootstrap.spec.ts +0 -140
  44. package/src/sst/__tests__/database.spec.ts +0 -119
  45. package/src/sst/__tests__/encryption.spec.ts +0 -90
  46. package/src/sst/__tests__/fromManifest.integration.spec.ts +0 -427
  47. package/src/sst/__tests__/fromManifest.spec.ts +0 -567
  48. package/src/sst/__tests__/function.spec.ts +0 -121
  49. package/src/sst/__tests__/links.spec.ts +0 -209
  50. package/src/sst/__tests__/provides.spec.ts +0 -107
  51. package/src/sst/__tests__/ses.spec.ts +0 -93
  52. package/src/sst/__tests__/surfaces.spec.ts +0 -149
  53. package/src/sst/__type-tests__/overrides.type-test.ts +0 -152
  54. package/src/sst/aws/Cache.ts +0 -259
  55. package/src/sst/aws/Credential.ts +0 -61
  56. package/src/sst/aws/Database.ts +0 -204
  57. package/src/sst/aws/DatabaseBootstrap.ts +0 -312
  58. package/src/sst/aws/DerivedDatabase.ts +0 -117
  59. package/src/sst/aws/Email.ts +0 -181
  60. package/src/sst/aws/Encryption.ts +0 -91
  61. package/src/sst/aws/ExternalApi.ts +0 -58
  62. package/src/sst/aws/FileServer.ts +0 -82
  63. package/src/sst/aws/ObjectStorage.ts +0 -76
  64. package/src/sst/aws/Queue.ts +0 -149
  65. package/src/sst/aws/RestApiSurface.ts +0 -114
  66. package/src/sst/aws/Secret.ts +0 -76
  67. package/src/sst/aws/StaticSite.ts +0 -92
  68. package/src/sst/aws/Topic.ts +0 -68
  69. package/src/sst/aws/bootstrap/handler.ts +0 -119
  70. package/src/sst/aws/ses.ts +0 -132
  71. package/src/sst/errors.ts +0 -65
  72. package/src/sst/fromManifest.ts +0 -1116
  73. package/src/sst/overrides.ts +0 -133
  74. package/src/sst/upstash.d.ts +0 -38
@@ -1,312 +0,0 @@
1
- import * as aws from '@pulumi/aws';
2
- import { secretsmanager } from '@pulumi/aws';
3
- import { RandomPassword } from '@pulumi/random';
4
- import type { BootstrapTenant } from './bootstrap/handler';
5
- import type { Database } from './Database';
6
-
7
- /**
8
- * The roles a tenant needs, provisioned — and the function that creates them.
9
- *
10
- * Two halves that only make sense together. Pulumi can generate a password and
11
- * store it; it cannot run `CREATE ROLE`. So the passwords are resources here and
12
- * the DDL is a Lambda invoked once per deploy, inside the VPC, connecting as the
13
- * cluster master — the only credential that exists before any role does.
14
- *
15
- * **One secret for the cluster, holding every role in it.** The obvious worry —
16
- * that a shared secret lets anything holding it connect as any role — describes
17
- * a read that does not happen. No function fetches a credential: each node's URL
18
- * is carried in its own link (`getSSTLink` publishes `provides()` and nothing
19
- * else), so a handler is *given* exactly its own role and has no IAM to read
20
- * Secrets Manager at all. Splitting the secret would not narrow runtime
21
- * privilege, because runtime never touches it.
22
- *
23
- * What the secret is actually for is out-of-band access — a person with
24
- * break-glass, an external tool, a rotation job. That is where the case for
25
- * splitting it lives, and it is a real one: per-tenant secrets are what let IAM
26
- * grant somebody the reporting role's password without also handing them the
27
- * auth schema's. Nothing here needs that yet, and one secret is one resource and
28
- * one place to look, so it stays one until somebody has that second reader.
29
- *
30
- * :::caution
31
- * Not verified against a live deploy. The shape is sound and every decision in
32
- * it is asserted as data, but no stack has come up.
33
- * :::
34
- */
35
- export class DatabaseBootstrap {
36
- /** The generated passwords, by role name. */
37
- private readonly passwords = new Map<string, $util.Output<string>>();
38
-
39
- /**
40
- * The cluster's credentials, for out-of-band use.
41
- *
42
- * Created by `run()` rather than by `add()`, because it holds every tenant
43
- * and there is no every-tenant until the last one is added.
44
- */
45
- secret?: secretsmanager.Secret;
46
-
47
- private readonly tenants: BootstrapTenant[] = [];
48
-
49
- constructor(
50
- private readonly name: string,
51
- private readonly cluster: Database,
52
- ) {}
53
-
54
- /**
55
- * Add a tenant to bootstrap, and provision its credentials.
56
- *
57
- * Returns the runtime password so the tenant's URL can carry it. The value is
58
- * a Pulumi output either way — it exists in state whether or not it is also
59
- * in Secrets Manager — so putting it in the URL adds no exposure the link did
60
- * not already have.
61
- */
62
- add(tenant: {
63
- id: string;
64
- schema: string;
65
- runtime: string;
66
- owner: string;
67
- reader?: string;
68
- /** The database's own roles, whose owner may create in it. */
69
- ownsDatabase?: boolean;
70
- }): { runtime: $util.Output<string>; reader?: $util.Output<string> } {
71
- const runtime = this.password(tenant.runtime);
72
- const reader = tenant.reader ? this.password(tenant.reader) : undefined;
73
-
74
- this.tenants.push({
75
- id: tenant.id,
76
- schema: tenant.schema,
77
- runtime: tenant.runtime,
78
- owner: tenant.owner,
79
- ...(tenant.reader ? { reader: tenant.reader } : {}),
80
- ...(tenant.ownsDatabase ? { ownsDatabase: true } : {}),
81
- // Filled in by `bootstrapEvent` once the outputs resolve. The function
82
- // reads them straight out of its input and never fetches a secret, so
83
- // it needs no IAM to read one.
84
- passwords: { runtime: '', owner: '' },
85
- });
86
-
87
- return { runtime, ...(reader ? { reader } : {}) };
88
- }
89
-
90
- /**
91
- * The event this bootstrap should be invoked with.
92
- *
93
- * Kept as data rather than performed here, so the caller decides *when* — and
94
- * so the decision is assertable without Pulumi. Feed it to a function
95
- * invocation whose input changes when this changes, which is what makes a
96
- * re-deploy re-apply only when something actually moved.
97
- */
98
- event(): $util.Output<string> {
99
- // Every password, flat, so one `all` resolves them and the shape is put
100
- // back together by a pure function that can be asserted without Pulumi.
101
- const roles = [...this.passwords.keys()];
102
-
103
- return $util
104
- .all([
105
- this.cluster.host as $util.Input<unknown>,
106
- this.cluster.port,
107
- this.cluster.database,
108
- this.cluster.username,
109
- this.cluster.password,
110
- ...roles.map((role) => this.passwords.get(role)!),
111
- ] as $util.Input<unknown>[])
112
- .apply((resolved) => {
113
- const [host, port, database, username, password, ...secrets] =
114
- resolved as unknown as [
115
- string,
116
- number,
117
- string,
118
- string,
119
- string,
120
- ...string[],
121
- ];
122
-
123
- return bootstrapEvent(
124
- { host, port, database, username, password },
125
- this.tenants,
126
- new Map(roles.map((role, index) => [role, secrets[index] as string])),
127
- );
128
- });
129
- }
130
-
131
- /**
132
- * The read-only credential for a runtime role, once its tenant is added.
133
- *
134
- * Returns nothing where no reader was provisioned — a reader role is created
135
- * only where something points at one, so asking for one that was never asked
136
- * for is a question with a real answer rather than an error.
137
- */
138
- readerFor(
139
- runtime: string,
140
- ): { user: string; password: $util.Output<string> } | undefined {
141
- const role = `${runtime}_reader`;
142
- const password = this.passwords.get(role);
143
-
144
- return password ? { user: role, password } : undefined;
145
- }
146
-
147
- /** Whether anything needs bootstrapping at all. */
148
- get empty(): boolean {
149
- return this.tenants.length === 0;
150
- }
151
-
152
- /**
153
- * Create the function and invoke it once for this deploy.
154
- *
155
- * The invocation's input is `event()`, so it re-runs when — and only when —
156
- * the roles, the schemas, or the cluster's address actually change. A deploy
157
- * that touched neither costs nothing, which is what makes running this on
158
- * every deploy acceptable rather than something to remember.
159
- *
160
- * @param vpc the database's VPC. The function has to reach the database, and
161
- * a database reachable from outside its VPC is the problem this avoids.
162
- *
163
- * The component rather than a component's `vpc` argument: a function in a VPC
164
- * needs subnets *and* security groups, and the two database components spell
165
- * their argument differently — a cluster asks for both, an instance asks only
166
- * for subnets. Naming the shared thing avoids inheriting whichever spelling
167
- * the database happens to use, which is how this came to be typed as
168
- * something that could not carry a security group.
169
- */
170
- run(vpc: sst.aws.Vpc): void {
171
- if (this.empty) return;
172
-
173
- this.storeCredentials();
174
-
175
- const fn = new sst.aws.Function(`${this.name}Bootstrap`, {
176
- // Shipped by this package rather than by the application: the DDL is
177
- // the framework's, and an app that had to carry a bootstrap handler
178
- // could get it wrong.
179
- handler: HANDLER,
180
- runtime: 'nodejs24.x',
181
- // Long enough for a database that is still coming up to answer —
182
- // `min: 0 ACU` means the first connection of the day pays for a
183
- // resume, and timing out there would leave a half-bootstrapped schema.
184
- timeout: '5 minutes',
185
- vpc,
186
- nodejs: { install: ['pg'] },
187
- });
188
-
189
- new aws.lambda.Invocation(`${this.name}BootstrapRun`, {
190
- functionName: fn.name,
191
- input: this.event(),
192
- });
193
- }
194
-
195
- /**
196
- * Write every role's password to one secret, for out-of-band use.
197
- *
198
- * Nothing at runtime reads this — a handler is given its own URL through its
199
- * link — so this exists for a person with break-glass, an external tool, or a
200
- * rotation job. Keyed by role name rather than by tenant, because a role name
201
- * is what somebody at a `psql` prompt actually has in hand.
202
- *
203
- * Note what this is *not*: the source of truth. The passwords are generated
204
- * here and this records them. Making the secret authoritative — read at
205
- * deploy, so rotating it in Secrets Manager propagates on the next deploy —
206
- * is a better rotation story and a different design: it needs a first-deploy
207
- * seed, and changing a value there does not change the role until the DDL
208
- * runs again.
209
- */
210
- private storeCredentials(): void {
211
- this.secret = new secretsmanager.Secret(`${this.name}Credentials`, {
212
- // A name somebody can find. `namePrefix` was the first attempt and it
213
- // produced `KitchenSink/roles/20260830202841251200000001` — unique,
214
- // and useless to the person doing break-glass at 3am, which is the
215
- // only reason this secret exists.
216
- name: `${$app.name}/${$app.stage}/${this.name}/roles`,
217
- description: `Database roles for ${this.name} (${$app.stage})`,
218
- // Rotating a password *updates* this secret — a new version on the
219
- // same resource — so none of this applies to normal operation. It
220
- // applies to one flow: tearing a stage down and standing it back up.
221
- // Secrets Manager holds a deleted secret for a recovery window and
222
- // keeps its name reserved for the duration, so the recreate fails on
223
- // a name pointing at something nobody can see. That flow is what a
224
- // disposable stage *is*, so those waive the window; a retained app
225
- // keeps the default, because there the recovery window is the point.
226
- ...($app.removal === 'remove' ? { recoveryWindowInDays: 0 } : {}),
227
- });
228
-
229
- const roles = [...this.passwords.keys()];
230
-
231
- new secretsmanager.SecretVersion(`${this.name}CredentialsValue`, {
232
- secretId: this.secret.id,
233
- secretString: $util
234
- .all(roles.map((role) => this.passwords.get(role)!))
235
- .apply((values) =>
236
- JSON.stringify(
237
- Object.fromEntries(
238
- roles.map((role, index) => [role, values[index]]),
239
- ),
240
- ),
241
- ),
242
- });
243
- }
244
-
245
- private password(role: string): $util.Output<string> {
246
- const existing = this.passwords.get(role);
247
- if (existing) return existing;
248
-
249
- const generated = new RandomPassword(`${this.name}${role}Password`, {
250
- length: 32,
251
- // Postgres accepts these in a password; a `'` would need escaping in
252
- // DDL and a `/` breaks a URL's authority section, so neither is worth
253
- // the risk for entropy this module has plenty of.
254
- special: true,
255
- overrideSpecial: '-_',
256
- }).result;
257
-
258
- this.passwords.set(role, generated);
259
-
260
- return generated;
261
- }
262
- }
263
-
264
- /**
265
- * Where the bootstrap handler lives, from the application's root.
266
- *
267
- * A path into this package's own published files, so an app that installed
268
- * `@geekmidas/cloud` gets the handler without copying it — and so a fix to the
269
- * DDL reaches every app on the next upgrade rather than the next time somebody
270
- * remembers.
271
- *
272
- * `src/`, not `dist/`: `src/sst/**` is published as raw TypeScript on purpose,
273
- * because it extends ambient globals that only exist inside a consuming SST
274
- * app. SST bundles the handler with esbuild at deploy, which is the same thing
275
- * it does for the application's own handlers.
276
- */
277
- const HANDLER =
278
- 'node_modules/@geekmidas/cloud/src/sst/aws/bootstrap/handler.handler';
279
-
280
- /**
281
- * The bootstrap's input, assembled from resolved values.
282
- *
283
- * Pure, and separate from the component for the reason every decision in this
284
- * package is: composing it needs no Pulumi, so what the function will be handed
285
- * can be asserted without a deploy — including that it is exactly what
286
- * `roleStatements` accepts, which is the contract between the two halves.
287
- */
288
- export function bootstrapEvent(
289
- master: {
290
- host: string;
291
- port: number;
292
- database: string;
293
- username: string;
294
- password: string;
295
- },
296
- tenants: readonly BootstrapTenant[],
297
- passwords: ReadonlyMap<string, string>,
298
- ): string {
299
- return JSON.stringify({
300
- master,
301
- tenants: tenants.map((tenant) => ({
302
- ...tenant,
303
- passwords: {
304
- runtime: passwords.get(tenant.runtime) ?? '',
305
- owner: passwords.get(tenant.owner) ?? '',
306
- ...(tenant.reader
307
- ? { reader: passwords.get(tenant.reader) ?? '' }
308
- : {}),
309
- },
310
- })),
311
- });
312
- }
@@ -1,117 +0,0 @@
1
- import { type GkmLinkable, ResourceType } from '../Linkable';
2
- import type { Database } from './Database';
3
-
4
- /**
5
- * The two database kinds that provision nothing: a reader, and a schema tenant.
6
- *
7
- * Neither is an AWS resource. A reader is an endpoint the cluster already has,
8
- * and a tenant is a schema *inside* the parent's database, created by DDL that
9
- * `gkm` runs rather than by anything Pulumi declares. What they contribute is a
10
- * URL — a different endpoint, or the same one with a different `search_path` —
11
- * and the identity that lets an edge point at them.
12
- *
13
- * That makes them the first `Provisioned`s that wrap no component. They are
14
- * still linkable, because a function depending on one still needs its URL
15
- * injected, and the link is what carries it.
16
- */
17
- abstract class DerivedDatabase implements GkmLinkable {
18
- readonly _id: string;
19
-
20
- constructor(
21
- id: string,
22
- /**
23
- * Public because `fromManifest` walks it: a tenant may derive from another
24
- * tenant, and what both ultimately need is the cluster underneath.
25
- */
26
- readonly parent: Database,
27
- ) {
28
- this._id = id;
29
- }
30
-
31
- abstract get _type(): ResourceType;
32
- abstract provides(): Record<string, $util.Input<string>>;
33
-
34
- /**
35
- * A link carrying only this node's own URL.
36
- *
37
- * Deliberately *not* the parent's link. A handler depending on the reader
38
- * should receive the reader's URL and no other, which is the same
39
- * least-privilege rule edges get everywhere else — inheriting the parent's
40
- * properties would hand it the writer's address under a second key.
41
- */
42
- getSSTLink() {
43
- return { properties: { ...this.provides() } };
44
- }
45
- }
46
-
47
- /**
48
- * A read-only endpoint on an existing cluster.
49
- *
50
- * Nothing is provisioned. An RDS instance has one endpoint, so this resolves to
51
- * the same address the writer uses — which is safe rather than a silently
52
- * writable connection behind a name that says reader, because read-only is
53
- * enforced by the role's grants and never by which endpoint was reached.
54
- */
55
- export class DatabaseReader extends DerivedDatabase {
56
- constructor(
57
- id: string,
58
- parent: Database,
59
- /**
60
- * The read-only role, where one was provisioned.
61
- *
62
- * Absent under `roles: false`, where there is one credential and it is
63
- * the master's — and read-only then holds by convention rather than by
64
- * grant, which is exactly why that mode is a downgrade.
65
- */
66
- private readonly role?: { user: string; password: $util.Input<string> },
67
- ) {
68
- super(id, parent);
69
- }
70
-
71
- get _type() {
72
- return ResourceType.SSTPostgres;
73
- }
74
-
75
- provides(): Record<string, $util.Input<string>> {
76
- return {
77
- url: this.parent.urlFor({
78
- reader: true,
79
- ...(this.role ? { as: this.role } : {}),
80
- }),
81
- };
82
- }
83
- }
84
-
85
- /**
86
- * A second schema in the parent's database, with its own URL.
87
- *
88
- * The schema and its role are created by DDL, so what this contributes is the
89
- * parent's connection pinned to a different `search_path`. Through the codec,
90
- * because `?search_path=` is not a libpq parameter: a URL carrying it is
91
- * accepted by every parser, ignored by the server, and produces a database that
92
- * looks empty.
93
- */
94
- export class DatabaseSchema extends DerivedDatabase {
95
- constructor(
96
- id: string,
97
- parent: Database,
98
- private readonly schema: string,
99
- /** The tenant's runtime role, where one was provisioned. */
100
- private readonly role?: { user: string; password: $util.Input<string> },
101
- ) {
102
- super(id, parent);
103
- }
104
-
105
- get _type() {
106
- return ResourceType.SSTPostgres;
107
- }
108
-
109
- provides(): Record<string, $util.Input<string>> {
110
- return {
111
- url: this.parent.urlFor({
112
- schema: this.schema,
113
- ...(this.role ? { as: this.role } : {}),
114
- }),
115
- };
116
- }
117
- }
@@ -1,181 +0,0 @@
1
- import { iam } from '@pulumi/aws';
2
- import { type GkmLinkable, ResourceType } from '../Linkable';
3
- import type { StackType } from '../Stack';
4
- import { sesSmtpUrl } from './ses';
5
-
6
- /**
7
- * `Email` — outbound mail, and the infra half of the `email` kind.
8
- *
9
- * The kind whose backends differ least. Every one of them speaks SMTP, so the
10
- * declaration's `smtp://` URL is true of all of them and the client never
11
- * changes — Mailpit locally, Resend or SES or somebody's relay deployed. What
12
- * differs is only who issues the credential, which is why the backend is config
13
- * rather than a field on the construct.
14
- *
15
- * Two of the three are barely a component: `resend` and `smtp` compose a URL
16
- * from a value you already hold. Only `ses` provisions anything, and it
17
- * provisions a *chain* — an identity, a user, an access key, and a password
18
- * derived from that key — because SES does not issue SMTP passwords, it issues
19
- * IAM credentials and documents the arithmetic.
20
- */
21
- export class Email<
22
- TStage extends string = string,
23
- TDomain extends string = string,
24
- > implements GkmLinkable
25
- {
26
- readonly _id: string;
27
-
28
- /** Composed once, in the constructor, so `provides` cannot drift from it. */
29
- private readonly url: $util.Input<string>;
30
-
31
- /**
32
- * The address mail is sent from.
33
- *
34
- * Required rather than defaulted: an unverified sender is rejected by every
35
- * provider, and a guess would be rejected at the first send rather than at
36
- * synth.
37
- */
38
- private readonly from: $util.Input<string>;
39
-
40
- get _type() {
41
- return ResourceType.Email;
42
- }
43
-
44
- constructor(
45
- _stack: StackType<TStage, TDomain>,
46
- name: string,
47
- props: EmailProps,
48
- ) {
49
- this._id = name;
50
-
51
- // A supplied URL wins over provisioning, for every backend including SES.
52
- // Credentials that already exist are the common case — a sending identity
53
- // set up once, by hand — and creating a second IAM user for it would be
54
- // this deploy quietly adding another way into the account.
55
- this.url = props.url ?? this.provision(name, props);
56
- this.from = props.from;
57
- }
58
-
59
- /**
60
- * Mint a credential, for the one backend that can.
61
- *
62
- * @throws {EmailNeedsUrl} for the backends that cannot. Resend and a plain
63
- * relay *are* accounts somebody created, so a missing URL is a missing setup
64
- * step — and saying so at synth beats composing something that cannot
65
- * deliver and finding out at the first send.
66
- */
67
- private provision(name: string, props: EmailProps): $util.Input<string> {
68
- if (props.backend !== 'ses') throw new EmailNeedsUrl(name, props.backend);
69
-
70
- return this.provisionSes(name, props);
71
- }
72
-
73
- /**
74
- * One key, the `smtp://` URL — and a second the app declared, the sending
75
- * identity, which is the one thing about mail that genuinely differs per
76
- * stage.
77
- */
78
- provides(): Record<string, $util.Input<string>> {
79
- return { url: this.url, from: this.from };
80
- }
81
-
82
- getSSTLink() {
83
- return { properties: { ...this.provides() } };
84
- }
85
-
86
- /**
87
- * The SES chain: a user that may send, a key for it, and the derived password.
88
- *
89
- * A user of its own rather than the application's role, because SMTP is a
90
- * long-lived static credential and the execution role is not — there is no
91
- * way to hand a relay a rotating token. Scoped to `ses:SendRawEmail` and
92
- * nothing else, so a leaked SMTP password sends mail and does not read the
93
- * account's send statistics or verify new identities.
94
- */
95
- private provisionSes(name: string, props: EmailProps): $util.Input<string> {
96
- const user = new iam.User(`${name}SmtpUser`, {
97
- path: '/gkm/ses/',
98
- });
99
-
100
- new iam.UserPolicy(`${name}SmtpPolicy`, {
101
- user: user.name,
102
- policy: JSON.stringify({
103
- Version: '2012-10-17',
104
- Statement: [
105
- { Effect: 'Allow', Action: 'ses:SendRawEmail', Resource: '*' },
106
- ],
107
- }),
108
- });
109
-
110
- const key = new iam.AccessKey(`${name}SmtpKey`, { user: user.name });
111
-
112
- return $util
113
- .all([key.id, key.secret, props.region])
114
- .apply(([accessKeyId, secretAccessKey, region]) =>
115
- sesSmtpUrl({ accessKeyId, secretAccessKey, region }),
116
- );
117
- }
118
- }
119
-
120
- export interface EmailProps {
121
- /** Who delivers the mail. Only `ses` provisions anything. */
122
- backend: 'resend' | 'ses' | 'smtp';
123
- /**
124
- * The `smtp://` URL, where the credentials already exist.
125
- *
126
- * Required for `resend` and `smtp`, which are accounts rather than
127
- * infrastructure. Optional for `ses`, and supplying it is the difference
128
- * between using the sending identity you have and provisioning a second one.
129
- */
130
- url?: $util.Input<string>;
131
- /** The region to derive SES credentials for. Required for `ses`. */
132
- region?: $util.Input<string>;
133
- /**
134
- * The identity mail is sent from — a verified address or domain.
135
- *
136
- * Stage-varying by nature, which is why it is here rather than on the
137
- * construct: `noreply@myapp.test` locally, a verified domain deployed.
138
- */
139
- from: $util.Input<string>;
140
- }
141
-
142
- /**
143
- * A backend that cannot mint its own credentials was given none.
144
- *
145
- * Resend and a plain relay are accounts somebody created, so there is nothing
146
- * for a deploy to provision and a missing URL is a missing setup step.
147
- */
148
- export class EmailNeedsUrl extends Error {
149
- constructor(
150
- readonly id: string,
151
- readonly backend: string,
152
- ) {
153
- super(
154
- `'${id}' sends through ${backend}, which is an account rather than ` +
155
- `something to provision, and no URL was supplied for it. Set it with ` +
156
- `\`sst secret set\` and pass it through the deploy layer — ` +
157
- `fromManifest(stack, manifest, { ${id}: { url } }).`,
158
- );
159
- this.name = 'EmailNeedsUrl';
160
- }
161
- }
162
-
163
- /**
164
- * Mail was declared and no sending identity was supplied.
165
- *
166
- * Not defaultable: every provider rejects an unverified sender, so a guess would
167
- * deploy cleanly and fail at the first send. The address is also stage-varying
168
- * by nature, which is why it belongs in the deploy layer rather than the
169
- * construct.
170
- */
171
- export class EmailNeedsSender extends Error {
172
- constructor(readonly id: string) {
173
- super(
174
- `'${id}' sends mail and no sending identity was supplied. Pass one ` +
175
- `through the deploy layer — ` +
176
- `fromManifest(stack, manifest, { ${id}: { from: 'noreply@example.com' } }) ` +
177
- `— and make sure it is verified with the provider.`,
178
- );
179
- this.name = 'EmailNeedsSender';
180
- }
181
- }
@@ -1,91 +0,0 @@
1
- import { kmsUrl } from '@geekmidas/manifest';
2
- import { kms } from '@pulumi/aws';
3
- import { type GkmLinkable, ResourceType } from '../Linkable';
4
- import type { StackType } from '../Stack';
5
-
6
- /**
7
- * `Encryption` — two KMS keys, and the infra half of the `encryption` kind.
8
- *
9
- * One key encrypts, by envelope: each value is sealed with a data key KMS
10
- * mints and wraps, so the key itself never leaves KMS. It rotates yearly, and
11
- * KMS keeps every version it rotated through, so nothing written is ever
12
- * stranded. The other is an HMAC key for the blind index, which does not
13
- * rotate — a rotated index key would make every stored index miss.
14
- *
15
- * Both are reached through one `kms://` URL, and a function linked to this is
16
- * granted exactly the calls the cipher makes on exactly these two keys. Not
17
- * `kms:*`, and not any other key in the account.
18
- *
19
- * It holds the keys rather than being one, and reports its own type, so a link
20
- * resolves to `<ID>_URL` — the key the construct declared.
21
- */
22
- export class Encryption<
23
- TStage extends string = string,
24
- TDomain extends string = string,
25
- > implements GkmLinkable
26
- {
27
- readonly _id: string;
28
-
29
- readonly key: kms.Key;
30
- readonly indexKey: kms.Key;
31
- private readonly region: string;
32
-
33
- get _type() {
34
- return ResourceType.Encryption;
35
- }
36
-
37
- constructor(
38
- _stack: StackType<TStage, TDomain>,
39
- name: string,
40
- props: EncryptionProps,
41
- ) {
42
- this._id = name;
43
- this.region = props.region;
44
-
45
- this.key = new kms.Key(`${name}Key`, {
46
- description: `${name}: encrypts what the application stores`,
47
- enableKeyRotation: true,
48
- deletionWindowInDays: props.deletionWindowInDays ?? 30,
49
- });
50
- this.indexKey = new kms.Key(`${name}IndexKey`, {
51
- description: `${name}: the blind index's HMAC key`,
52
- keyUsage: 'GENERATE_VERIFY_MAC',
53
- customerMasterKeySpec: 'HMAC_256',
54
- deletionWindowInDays: props.deletionWindowInDays ?? 30,
55
- });
56
- }
57
-
58
- provides(): Record<string, $util.Input<string>> {
59
- return {
60
- url: $util
61
- .all([this.key.arn, this.indexKey.arn])
62
- .apply(([key, index]) => kmsUrl({ region: this.region, key, index })),
63
- };
64
- }
65
-
66
- getSSTLink() {
67
- return {
68
- properties: { ...this.provides() },
69
- include: [
70
- sst.aws.permission({
71
- actions: ['kms:GenerateDataKey', 'kms:Decrypt'],
72
- resources: [this.key.arn],
73
- }),
74
- sst.aws.permission({
75
- actions: ['kms:GenerateMac'],
76
- resources: [this.indexKey.arn],
77
- }),
78
- ],
79
- };
80
- }
81
- }
82
-
83
- export interface EncryptionProps {
84
- /** Where the keys live — the stage's region. */
85
- region: string;
86
- /**
87
- * How long a deleted key can still be recovered, 7–30 days. A key's
88
- * deletion is the deletion of everything it encrypted, so the longest.
89
- */
90
- deletionWindowInDays?: number;
91
- }