@elumixor/devkit 0.12.17 → 0.12.18
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/README.md +41 -1
- package/package.json +3 -1
- package/src/bin/devkit.ts +6 -0
- package/src/cloud/cli.ts +17 -1
- package/src/cloud/commands/deploy-key.ts +254 -0
- package/src/cloud/deploy-key-policies.test.ts +114 -0
- package/src/cloud/deploy-key-policies.ts +146 -0
- package/src/cloud/edge/router.js +16 -0
- package/src/cloud/edge/router.test.ts +41 -0
- package/src/deploy-targets/aws.ts +4 -2
package/README.md
CHANGED
|
@@ -329,7 +329,47 @@ of `@vercel/blob`: public blobs are served at `https://<host>/_blob/<path>`.
|
|
|
329
329
|
|
|
330
330
|
CI assumes the `dk-deploy` role through GitHub's OIDC provider, so no AWS keys are stored anywhere.
|
|
331
331
|
`bootstrap` also writes a scoped `devkit` AWS profile for deploying from a laptop. `examples/hello`
|
|
332
|
-
exercises every feature and is what `.github/workflows/deploy-cloud.yml` deploys.
|
|
332
|
+
exercises every feature and is what `.github/workflows/deploy-cloud.yml` deploys. `devkit deploy`
|
|
333
|
+
uses the standard AWS credential chain (`AWS_PROFILE`, or `AWS_ACCESS_KEY_ID` + `AWS_SECRET_ACCESS_KEY`
|
|
334
|
+
+ `AWS_SESSION_TOKEN`), and a stage's own `AWS_*` keys never replace those during a deploy.
|
|
335
|
+
|
|
336
|
+
#### Deploying from a machine without GitHub Actions
|
|
337
|
+
|
|
338
|
+
A server that cannot use GitHub's OIDC gets its own deploy key. Run this on a trusted machine with
|
|
339
|
+
admin credentials and pipe the output straight to the server; nothing is written to disk locally:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
devkit cloud deploy-key box --source-ip 203.0.113.7 | ssh box 'cat > ~/.config/dk-deploy.env && chmod 600 ~/.config/dk-deploy.env'
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
It makes the IAM user `dk-deploy-box`, whose only permission is `sts:AssumeRole` on the role
|
|
346
|
+
`dk-deploy-box` from that address with `DurationSeconds` of 900 or less. The role carries the
|
|
347
|
+
`dk-deploy` policy plus a guard that denies every call from any other address and any IAM action on
|
|
348
|
+
`dk-deploy*` identities. The trust names only that user, also IP-locked. The `dk-deploy` OIDC role
|
|
349
|
+
is not touched. stdout gets `DK_DEPLOY_ACCESS_KEY_ID`, `DK_DEPLOY_SECRET_ACCESS_KEY`,
|
|
350
|
+
`DK_DEPLOY_ROLE_ARN` and `AWS_REGION`. These names are deliberately not `AWS_*`: the key alone
|
|
351
|
+
cannot deploy.
|
|
352
|
+
|
|
353
|
+
On the server, the holder of those values trades them for 15-minute credentials and gives a deploy
|
|
354
|
+
only those:
|
|
355
|
+
|
|
356
|
+
```bash
|
|
357
|
+
set -a; . ~/.config/dk-deploy.env; set +a
|
|
358
|
+
eval "$(devkit cloud session | sed 's/^/export /')" # AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN
|
|
359
|
+
devkit deploy
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
An EventBridge rule `dk-deploy-box-ip` in eu-central-1 and us-east-1 (IAM and CloudFront events
|
|
363
|
+
land there) matches any API call by the user or its role sessions from another address. It sends
|
|
364
|
+
the match to the SNS topic `dk-deploy-alerts`, which emails `--email` (default `git config
|
|
365
|
+
user.email`). Confirm the subscription email from each region once. The rule uses
|
|
366
|
+
`ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS`, so read-only calls count too. Management events
|
|
367
|
+
need no trail. S3 object reads and writes are data events: they are only seen with a trail that logs
|
|
368
|
+
data events. Off-IP calls are denied either way.
|
|
369
|
+
|
|
370
|
+
Rotate the key every 90 days: `devkit cloud deploy-key box --source-ip <ip> --rotate | ssh box ...`
|
|
371
|
+
creates the new key, then deletes the old one. The same command with a new `--source-ip` moves the
|
|
372
|
+
lock to a new address. `--revoke` deletes the key, user, role and alert rules.
|
|
333
373
|
|
|
334
374
|
### Dashboard and MCP
|
|
335
375
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elumixor/devkit",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.18",
|
|
4
4
|
"description": "Dev orchestrator for bun monorepos — free ports, run apps side-by-side, open the browser when ready",
|
|
5
5
|
"author": "elumixor",
|
|
6
6
|
"license": "ISC",
|
|
@@ -39,10 +39,12 @@
|
|
|
39
39
|
"@aws-sdk/client-cloudwatch": "^3.1161.0",
|
|
40
40
|
"@aws-sdk/client-cloudwatch-logs": "^3.1161.0",
|
|
41
41
|
"@aws-sdk/client-cost-explorer": "^3.1161.0",
|
|
42
|
+
"@aws-sdk/client-eventbridge": "^3.1161.0",
|
|
42
43
|
"@aws-sdk/client-iam": "^3.1161.0",
|
|
43
44
|
"@aws-sdk/client-lambda": "^3.1161.0",
|
|
44
45
|
"@aws-sdk/client-s3": "^3.1161.0",
|
|
45
46
|
"@aws-sdk/client-scheduler": "^3.1161.0",
|
|
47
|
+
"@aws-sdk/client-sns": "^3.1161.0",
|
|
46
48
|
"@aws-sdk/client-ssm": "^3.1161.0",
|
|
47
49
|
"@aws-sdk/client-sts": "^3.1161.0",
|
|
48
50
|
"@aws-sdk/credential-providers": "^3.1161.0",
|
package/src/bin/devkit.ts
CHANGED
|
@@ -31,6 +31,9 @@ const { values, positionals } = parseArgs({
|
|
|
31
31
|
follow: { type: "boolean", default: false },
|
|
32
32
|
to: { type: "string" },
|
|
33
33
|
email: { type: "string" },
|
|
34
|
+
"source-ip": { type: "string" },
|
|
35
|
+
rotate: { type: "boolean", default: false },
|
|
36
|
+
revoke: { type: "boolean", default: false },
|
|
34
37
|
yes: { type: "boolean", short: "y", default: false },
|
|
35
38
|
version: { type: "boolean", short: "v", default: false },
|
|
36
39
|
help: { type: "boolean", short: "h", default: false },
|
|
@@ -120,6 +123,9 @@ try {
|
|
|
120
123
|
to: values.to,
|
|
121
124
|
email: values.email,
|
|
122
125
|
yes: values.yes,
|
|
126
|
+
sourceIp: values["source-ip"],
|
|
127
|
+
rotate: values.rotate,
|
|
128
|
+
revoke: values.revoke,
|
|
123
129
|
});
|
|
124
130
|
break;
|
|
125
131
|
}
|
package/src/cloud/cli.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bootstrap } from "./bootstrap.ts";
|
|
2
|
+
import { deployKey, session } from "./commands/deploy-key.ts";
|
|
2
3
|
import { destroy } from "./commands/destroy.ts";
|
|
3
4
|
import { domains } from "./commands/domains.ts";
|
|
4
5
|
import { env } from "./commands/env.ts";
|
|
@@ -16,6 +17,9 @@ export interface CloudFlags {
|
|
|
16
17
|
to?: string;
|
|
17
18
|
email?: string;
|
|
18
19
|
yes?: boolean;
|
|
20
|
+
sourceIp?: string;
|
|
21
|
+
rotate?: boolean;
|
|
22
|
+
revoke?: boolean;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
export const CLOUD_USAGE = `usage: devkit cloud bootstrap [--email x] once per account: buckets, edge, roles, budgets
|
|
@@ -27,7 +31,10 @@ export const CLOUD_USAGE = `usage: devkit cloud bootstrap [--email x] once
|
|
|
27
31
|
devkit cloud env ls|pull|push|set|rm [--stage s]
|
|
28
32
|
devkit cloud infra plan|apply|sync [--yes] Terraform resources, outputs into stage env
|
|
29
33
|
devkit cloud domains ls|add|rm <project> [host] [--stage s]
|
|
30
|
-
devkit cloud destroy <project> --stage s
|
|
34
|
+
devkit cloud destroy <project> --stage s
|
|
35
|
+
devkit cloud deploy-key <name> --source-ip <ip> [--rotate|--revoke] [--email x]
|
|
36
|
+
admin, once per machine: IP-locked key on stdout
|
|
37
|
+
devkit cloud session on that machine: key env -> 15-min AWS_* creds`;
|
|
31
38
|
|
|
32
39
|
/** `devkit cloud <command> ...` */
|
|
33
40
|
export function runCloud(args: readonly string[], flags: CloudFlags) {
|
|
@@ -53,6 +60,15 @@ export function runCloud(args: readonly string[], flags: CloudFlags) {
|
|
|
53
60
|
return infra(rest[0], { yes: flags.yes });
|
|
54
61
|
case "domains":
|
|
55
62
|
return domains(rest[0], rest[1], rest[2], flags.stage);
|
|
63
|
+
case "deploy-key":
|
|
64
|
+
return deployKey(rest[0], {
|
|
65
|
+
sourceIp: flags.sourceIp,
|
|
66
|
+
rotate: flags.rotate,
|
|
67
|
+
revoke: flags.revoke,
|
|
68
|
+
email: flags.email,
|
|
69
|
+
});
|
|
70
|
+
case "session":
|
|
71
|
+
return session();
|
|
56
72
|
case "destroy":
|
|
57
73
|
return destroy(rest[0], flags.stage);
|
|
58
74
|
default:
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { hostname } from "node:os";
|
|
2
|
+
import {
|
|
3
|
+
DeleteRuleCommand,
|
|
4
|
+
EventBridgeClient,
|
|
5
|
+
PutRuleCommand,
|
|
6
|
+
PutTargetsCommand,
|
|
7
|
+
RemoveTargetsCommand,
|
|
8
|
+
} from "@aws-sdk/client-eventbridge";
|
|
9
|
+
import {
|
|
10
|
+
AttachRolePolicyCommand,
|
|
11
|
+
CreateAccessKeyCommand,
|
|
12
|
+
CreateRoleCommand,
|
|
13
|
+
CreateUserCommand,
|
|
14
|
+
DeleteAccessKeyCommand,
|
|
15
|
+
DeleteRoleCommand,
|
|
16
|
+
DeleteRolePolicyCommand,
|
|
17
|
+
DeleteUserCommand,
|
|
18
|
+
DeleteUserPolicyCommand,
|
|
19
|
+
DetachRolePolicyCommand,
|
|
20
|
+
GetRoleCommand,
|
|
21
|
+
GetUserCommand,
|
|
22
|
+
ListAccessKeysCommand,
|
|
23
|
+
PutRolePolicyCommand,
|
|
24
|
+
PutUserPolicyCommand,
|
|
25
|
+
UpdateAssumeRolePolicyCommand,
|
|
26
|
+
} from "@aws-sdk/client-iam";
|
|
27
|
+
import {
|
|
28
|
+
CreateTopicCommand,
|
|
29
|
+
ListSubscriptionsByTopicCommand,
|
|
30
|
+
SetTopicAttributesCommand,
|
|
31
|
+
SNSClient,
|
|
32
|
+
SubscribeCommand,
|
|
33
|
+
} from "@aws-sdk/client-sns";
|
|
34
|
+
import { AssumeRoleCommand, STSClient } from "@aws-sdk/client-sts";
|
|
35
|
+
import { $ } from "bun";
|
|
36
|
+
import { accountId, CloudError, iam, orUndefined, platformTags, retryWhile } from "../aws.ts";
|
|
37
|
+
import {
|
|
38
|
+
DEPLOY_KEY_SESSION_SECONDS,
|
|
39
|
+
deployKeyAlertPattern,
|
|
40
|
+
deployKeyEnv,
|
|
41
|
+
deployKeyGuard,
|
|
42
|
+
deployKeyName,
|
|
43
|
+
deployKeyTrust,
|
|
44
|
+
deployKeyUserPolicy,
|
|
45
|
+
sessionEnv,
|
|
46
|
+
sourceIp,
|
|
47
|
+
} from "../deploy-key-policies.ts";
|
|
48
|
+
import { GLOBAL_REGION, platform, REGION } from "../names.ts";
|
|
49
|
+
import { deployPolicy, ensureManagedPolicy } from "../reconcile/iam.ts";
|
|
50
|
+
|
|
51
|
+
export interface DeployKeyOptions {
|
|
52
|
+
sourceIp?: string;
|
|
53
|
+
rotate?: boolean;
|
|
54
|
+
revoke?: boolean;
|
|
55
|
+
email?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Progress goes to stderr: stdout carries only the credentials, so it can be piped to another machine. */
|
|
59
|
+
const say = (message: string) => console.error(message);
|
|
60
|
+
|
|
61
|
+
/** IAM is global, but its events (and CloudFront's) arrive in us-east-1; everything else in the home region. */
|
|
62
|
+
const ALERT_REGIONS = [REGION, GLOBAL_REGION] as const;
|
|
63
|
+
const ALERT_TOPIC = "dk-deploy-alerts";
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* `devkit cloud deploy-key <name> --source-ip <ip>`: a user `dk-deploy-<name>` whose key may only assume
|
|
67
|
+
* the role `dk-deploy-<name>` (the `dk-deploy` policy) for 15 minutes from that address, plus an alert on
|
|
68
|
+
* any use from elsewhere. Prints the key once; nothing is written to disk. Run with admin credentials.
|
|
69
|
+
*/
|
|
70
|
+
export async function deployKey(name: string | undefined, options: DeployKeyOptions) {
|
|
71
|
+
const user = deployKeyName(name);
|
|
72
|
+
if (options.revoke) return revoke(user);
|
|
73
|
+
const { ip, cidr } = sourceIp(options.sourceIp);
|
|
74
|
+
const account = await accountId();
|
|
75
|
+
|
|
76
|
+
const existing = await orUndefined(iam().send(new GetUserCommand({ UserName: user })), "NoSuchEntityException");
|
|
77
|
+
if (!existing)
|
|
78
|
+
await iam().send(new CreateUserCommand({ UserName: user, Tags: platformTags({ "dk-source-ip": ip }) }));
|
|
79
|
+
await iam().send(
|
|
80
|
+
new PutUserPolicyCommand({
|
|
81
|
+
UserName: user,
|
|
82
|
+
PolicyName: user,
|
|
83
|
+
PolicyDocument: JSON.stringify(deployKeyUserPolicy(account, user, cidr)),
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
say(`user ${user} ${existing ? "ok" : "created"} (only sts:AssumeRole on role/${user} from ${ip})`);
|
|
87
|
+
|
|
88
|
+
await ensureKeyRole(account, user, cidr);
|
|
89
|
+
say(`role ${user} ok (policy ${platform.deployPolicy}, ${DEPLOY_KEY_SESSION_SECONDS}s sessions from ${ip})`);
|
|
90
|
+
|
|
91
|
+
await ensureAlerts(account, user, ip, options.email);
|
|
92
|
+
|
|
93
|
+
const keys = (await iam().send(new ListAccessKeysCommand({ UserName: user }))).AccessKeyMetadata ?? [];
|
|
94
|
+
if (keys.length && !options.rotate) {
|
|
95
|
+
say(`policies updated; ${user} keeps its key ${keys[0]?.AccessKeyId} (pass --rotate for a new one)`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (keys.length >= 2)
|
|
99
|
+
throw new CloudError(`${user} has two keys already; run --rotate once the older one is no longer needed`);
|
|
100
|
+
|
|
101
|
+
const key = await iam().send(new CreateAccessKeyCommand({ UserName: user }));
|
|
102
|
+
if (!key.AccessKey?.AccessKeyId || !key.AccessKey.SecretAccessKey) throw new CloudError("IAM returned no access key");
|
|
103
|
+
for (const old of keys) {
|
|
104
|
+
if (!old.AccessKeyId) continue;
|
|
105
|
+
await iam().send(new DeleteAccessKeyCommand({ UserName: user, AccessKeyId: old.AccessKeyId }));
|
|
106
|
+
say(`deleted old key ${old.AccessKeyId}`);
|
|
107
|
+
}
|
|
108
|
+
say(`key ${key.AccessKey.AccessKeyId} created; rotate within 90 days with --rotate`);
|
|
109
|
+
console.log(deployKeyEnv(account, user, key.AccessKey.AccessKeyId, key.AccessKey.SecretAccessKey, REGION));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function ensureKeyRole(account: string, name: string, cidr: string) {
|
|
113
|
+
const trust = JSON.stringify(deployKeyTrust(account, name, cidr));
|
|
114
|
+
const existing = await orUndefined(iam().send(new GetRoleCommand({ RoleName: name })), "NoSuchEntityException");
|
|
115
|
+
// A user just created is not always accepted as a principal yet.
|
|
116
|
+
if (existing) await iam().send(new UpdateAssumeRolePolicyCommand({ RoleName: name, PolicyDocument: trust }));
|
|
117
|
+
else
|
|
118
|
+
await retryWhile(
|
|
119
|
+
() =>
|
|
120
|
+
iam().send(
|
|
121
|
+
new CreateRoleCommand({
|
|
122
|
+
RoleName: name,
|
|
123
|
+
AssumeRolePolicyDocument: trust,
|
|
124
|
+
MaxSessionDuration: 3600,
|
|
125
|
+
Description: "Devkit Cloud: deploys from one machine through its deploy key",
|
|
126
|
+
Tags: platformTags(),
|
|
127
|
+
}),
|
|
128
|
+
),
|
|
129
|
+
["MalformedPolicyDocumentException"],
|
|
130
|
+
);
|
|
131
|
+
const policyArn = await ensureManagedPolicy(platform.deployPolicy, await deployPolicy());
|
|
132
|
+
await retryWhile(
|
|
133
|
+
() => iam().send(new AttachRolePolicyCommand({ RoleName: name, PolicyArn: policyArn })),
|
|
134
|
+
["NoSuchEntityException"],
|
|
135
|
+
);
|
|
136
|
+
await iam().send(
|
|
137
|
+
new PutRolePolicyCommand({
|
|
138
|
+
RoleName: name,
|
|
139
|
+
PolicyName: `${name}-guard`,
|
|
140
|
+
PolicyDocument: JSON.stringify(deployKeyGuard(account, cidr)),
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** One SNS topic per region (EventBridge targets stay in-region) and a rule per key in each. */
|
|
146
|
+
async function ensureAlerts(account: string, name: string, ip: string, email: string | undefined) {
|
|
147
|
+
const to = email ?? (await $`git config user.email`.quiet().nothrow().text()).trim();
|
|
148
|
+
if (!to) throw new CloudError("No email for alerts: pass --email or set git config user.email");
|
|
149
|
+
for (const region of ALERT_REGIONS) {
|
|
150
|
+
const sns = new SNSClient({ region });
|
|
151
|
+
const { TopicArn } = await sns.send(new CreateTopicCommand({ Name: ALERT_TOPIC, Tags: platformTags() }));
|
|
152
|
+
if (!TopicArn) throw new CloudError(`SNS returned no topic ARN in ${region}`);
|
|
153
|
+
await sns.send(
|
|
154
|
+
new SetTopicAttributesCommand({
|
|
155
|
+
TopicArn,
|
|
156
|
+
AttributeName: "Policy",
|
|
157
|
+
AttributeValue: JSON.stringify({
|
|
158
|
+
Version: "2012-10-17",
|
|
159
|
+
Statement: [
|
|
160
|
+
{
|
|
161
|
+
Effect: "Allow",
|
|
162
|
+
Principal: { Service: "events.amazonaws.com" },
|
|
163
|
+
Action: "sns:Publish",
|
|
164
|
+
Resource: TopicArn,
|
|
165
|
+
Condition: { StringEquals: { "aws:SourceAccount": account } },
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
}),
|
|
169
|
+
}),
|
|
170
|
+
);
|
|
171
|
+
const subscriptions = (await sns.send(new ListSubscriptionsByTopicCommand({ TopicArn }))).Subscriptions ?? [];
|
|
172
|
+
if (!subscriptions.some((subscription) => subscription.Endpoint === to)) {
|
|
173
|
+
await sns.send(new SubscribeCommand({ TopicArn, Protocol: "email", Endpoint: to }));
|
|
174
|
+
say(` alerts ${region}: confirm the subscription email sent to ${to}`);
|
|
175
|
+
}
|
|
176
|
+
const events = new EventBridgeClient({ region });
|
|
177
|
+
await events.send(
|
|
178
|
+
new PutRuleCommand({
|
|
179
|
+
Name: `${name}-ip`,
|
|
180
|
+
Description: `Devkit Cloud: ${name} used from an address other than ${ip}`,
|
|
181
|
+
EventPattern: JSON.stringify(deployKeyAlertPattern(account, name, ip)),
|
|
182
|
+
State: "ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS",
|
|
183
|
+
Tags: platformTags(),
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
await events.send(new PutTargetsCommand({ Rule: `${name}-ip`, Targets: [{ Id: "sns", Arn: TopicArn }] }));
|
|
187
|
+
}
|
|
188
|
+
say(`alert rule ${name}-ip ok in ${ALERT_REGIONS.join(", ")} (SNS ${ALERT_TOPIC} to ${to})`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Deletes the keys, the user, the role and its alert rules; the shared alert topic stays. */
|
|
192
|
+
async function revoke(name: string) {
|
|
193
|
+
const account = await accountId();
|
|
194
|
+
const keys = (await orUndefined(iam().send(new ListAccessKeysCommand({ UserName: name })), "NoSuchEntityException"))
|
|
195
|
+
?.AccessKeyMetadata;
|
|
196
|
+
for (const key of keys ?? [])
|
|
197
|
+
if (key.AccessKeyId) await iam().send(new DeleteAccessKeyCommand({ UserName: name, AccessKeyId: key.AccessKeyId }));
|
|
198
|
+
const gone = ["NoSuchEntityException"];
|
|
199
|
+
await orUndefined(iam().send(new DeleteUserPolicyCommand({ UserName: name, PolicyName: name })), ...gone);
|
|
200
|
+
await orUndefined(iam().send(new DeleteUserCommand({ UserName: name })), ...gone);
|
|
201
|
+
await orUndefined(
|
|
202
|
+
iam().send(
|
|
203
|
+
new DetachRolePolicyCommand({
|
|
204
|
+
RoleName: name,
|
|
205
|
+
PolicyArn: `arn:aws:iam::${account}:policy/${platform.deployPolicy}`,
|
|
206
|
+
}),
|
|
207
|
+
),
|
|
208
|
+
...gone,
|
|
209
|
+
);
|
|
210
|
+
await orUndefined(iam().send(new DeleteRolePolicyCommand({ RoleName: name, PolicyName: `${name}-guard` })), ...gone);
|
|
211
|
+
await orUndefined(iam().send(new DeleteRoleCommand({ RoleName: name })), ...gone);
|
|
212
|
+
for (const region of ALERT_REGIONS) {
|
|
213
|
+
const events = new EventBridgeClient({ region });
|
|
214
|
+
await orUndefined(
|
|
215
|
+
events.send(new RemoveTargetsCommand({ Rule: `${name}-ip`, Ids: ["sns"] })),
|
|
216
|
+
"ResourceNotFoundException",
|
|
217
|
+
);
|
|
218
|
+
await orUndefined(events.send(new DeleteRuleCommand({ Name: `${name}-ip` })), "ResourceNotFoundException");
|
|
219
|
+
}
|
|
220
|
+
say(`revoked ${name}: keys, user, role and alert rules deleted`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* `devkit cloud session`: on the machine holding the deploy key, trades it for 15-minute credentials and
|
|
225
|
+
* prints only those, so a deploy never sees the long-lived key.
|
|
226
|
+
*/
|
|
227
|
+
export async function session() {
|
|
228
|
+
const { DK_DEPLOY_ACCESS_KEY_ID: accessKeyId, DK_DEPLOY_SECRET_ACCESS_KEY: secretAccessKey } = process.env;
|
|
229
|
+
const roleArn = process.env.DK_DEPLOY_ROLE_ARN;
|
|
230
|
+
if (!accessKeyId || !secretAccessKey || !roleArn)
|
|
231
|
+
throw new CloudError(
|
|
232
|
+
"Set DK_DEPLOY_ACCESS_KEY_ID, DK_DEPLOY_SECRET_ACCESS_KEY and DK_DEPLOY_ROLE_ARN (from deploy-key)",
|
|
233
|
+
);
|
|
234
|
+
const sts = new STSClient({
|
|
235
|
+
region: process.env.AWS_REGION ?? REGION,
|
|
236
|
+
credentials: { accessKeyId, secretAccessKey },
|
|
237
|
+
});
|
|
238
|
+
const { Credentials } = await sts.send(
|
|
239
|
+
new AssumeRoleCommand({
|
|
240
|
+
RoleArn: roleArn,
|
|
241
|
+
RoleSessionName: `devkit-${hostname()}`.replace(/[^\w+=,.@-]/g, "-").slice(0, 64),
|
|
242
|
+
DurationSeconds: DEPLOY_KEY_SESSION_SECONDS,
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
if (!Credentials?.AccessKeyId || !Credentials.SecretAccessKey || !Credentials.SessionToken)
|
|
246
|
+
throw new CloudError("STS returned no credentials");
|
|
247
|
+
console.log(
|
|
248
|
+
sessionEnv({
|
|
249
|
+
AccessKeyId: Credentials.AccessKeyId,
|
|
250
|
+
SecretAccessKey: Credentials.SecretAccessKey,
|
|
251
|
+
SessionToken: Credentials.SessionToken,
|
|
252
|
+
}),
|
|
253
|
+
);
|
|
254
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
DEPLOY_KEY_SESSION_SECONDS,
|
|
4
|
+
deployKeyAlertPattern,
|
|
5
|
+
deployKeyEnv,
|
|
6
|
+
deployKeyGuard,
|
|
7
|
+
deployKeyName,
|
|
8
|
+
deployKeyTrust,
|
|
9
|
+
deployKeyUserPolicy,
|
|
10
|
+
sourceIp,
|
|
11
|
+
withoutDeployCredentials,
|
|
12
|
+
} from "./deploy-key-policies.ts";
|
|
13
|
+
|
|
14
|
+
const account = "123456789012";
|
|
15
|
+
const name = "dk-deploy-box";
|
|
16
|
+
const cidr = "203.0.113.7/32";
|
|
17
|
+
|
|
18
|
+
describe("deploy key names and addresses", () => {
|
|
19
|
+
test("names map to dk-deploy-<name>, never the laptop user", () => {
|
|
20
|
+
expect(deployKeyName("box")).toBe("dk-deploy-box");
|
|
21
|
+
expect(() => deployKeyName("local")).toThrow();
|
|
22
|
+
expect(() => deployKeyName("Box")).toThrow();
|
|
23
|
+
expect(() => deployKeyName("a/b")).toThrow();
|
|
24
|
+
expect(() => deployKeyName(undefined)).toThrow();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("source ip is required and one host", () => {
|
|
28
|
+
expect(sourceIp("203.0.113.7")).toEqual({ ip: "203.0.113.7", cidr });
|
|
29
|
+
expect(sourceIp("2001:db8::1").cidr).toBe("2001:db8::1/128");
|
|
30
|
+
expect(() => sourceIp(undefined)).toThrow("--source-ip is required");
|
|
31
|
+
expect(() => sourceIp("0.0.0.0/0")).toThrow();
|
|
32
|
+
expect(() => sourceIp("300.0.0.1")).toThrow();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("deploy key policies", () => {
|
|
37
|
+
test("user may only assume its own role, from the ip, for at most 15 minutes", () => {
|
|
38
|
+
const { Statement } = deployKeyUserPolicy(account, name, cidr);
|
|
39
|
+
expect(Statement).toEqual([
|
|
40
|
+
{
|
|
41
|
+
Effect: "Allow",
|
|
42
|
+
Action: "sts:AssumeRole",
|
|
43
|
+
Resource: `arn:aws:iam::${account}:role/${name}`,
|
|
44
|
+
Condition: {
|
|
45
|
+
IpAddress: { "aws:SourceIp": cidr },
|
|
46
|
+
NumericLessThanEquals: { "sts:DurationSeconds": 900 },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
expect(Statement.map((statement) => statement.Action)).toEqual(["sts:AssumeRole"]);
|
|
51
|
+
expect(DEPLOY_KEY_SESSION_SECONDS).toBe(900);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("role trusts only that user, from the ip, for at most 15 minutes", () => {
|
|
55
|
+
const [statement, ...rest] = deployKeyTrust(account, name, cidr).Statement;
|
|
56
|
+
expect(rest).toHaveLength(0);
|
|
57
|
+
expect(statement).toEqual({
|
|
58
|
+
Effect: "Allow",
|
|
59
|
+
Principal: { AWS: `arn:aws:iam::${account}:user/${name}` },
|
|
60
|
+
Action: "sts:AssumeRole",
|
|
61
|
+
Condition: {
|
|
62
|
+
IpAddress: { "aws:SourceIp": cidr },
|
|
63
|
+
NumericLessThanEquals: { "sts:DurationSeconds": 900 },
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("guard denies use off the ip (except AWS acting for the session) and any IAM on deploy identities", () => {
|
|
69
|
+
const [offIp, iam] = deployKeyGuard(account, cidr).Statement;
|
|
70
|
+
expect(offIp).toEqual({
|
|
71
|
+
Effect: "Deny",
|
|
72
|
+
Action: "*",
|
|
73
|
+
Resource: "*",
|
|
74
|
+
Condition: { NotIpAddress: { "aws:SourceIp": cidr }, Bool: { "aws:ViaAWSService": "false" } },
|
|
75
|
+
});
|
|
76
|
+
expect(iam).toMatchObject({ Effect: "Deny", Action: "iam:*" });
|
|
77
|
+
expect(iam?.Resource).toContain(`arn:aws:iam::${account}:role/dk-deploy*`);
|
|
78
|
+
expect(iam?.Resource).toContain(`arn:aws:iam::${account}:user/dk-deploy*`);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("alert matches the user and its role sessions from any other address", () => {
|
|
82
|
+
expect(deployKeyAlertPattern(account, name, "203.0.113.7")).toEqual({
|
|
83
|
+
"detail-type": ["AWS API Call via CloudTrail"],
|
|
84
|
+
detail: {
|
|
85
|
+
userIdentity: {
|
|
86
|
+
arn: [`arn:aws:iam::${account}:user/${name}`, { prefix: `arn:aws:sts::${account}:assumed-role/${name}/` }],
|
|
87
|
+
},
|
|
88
|
+
sourceIPAddress: [{ "anything-but": ["203.0.113.7"] }],
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("printed key never uses AWS_* credential names, so it cannot deploy directly", () => {
|
|
94
|
+
const env = deployKeyEnv(account, name, "AKIA1", "secret", "eu-central-1");
|
|
95
|
+
expect(env).toContain("DK_DEPLOY_ACCESS_KEY_ID=AKIA1");
|
|
96
|
+
expect(env).toContain(`DK_DEPLOY_ROLE_ARN=arn:aws:iam::${account}:role/${name}`);
|
|
97
|
+
expect(env).not.toMatch(/^AWS_(ACCESS_KEY_ID|SECRET_ACCESS_KEY)=/m);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("deploy credentials", () => {
|
|
102
|
+
test("a stage env's AWS keys never replace the deploy's own credentials", () => {
|
|
103
|
+
expect(
|
|
104
|
+
withoutDeployCredentials({
|
|
105
|
+
AWS_ACCESS_KEY_ID: "app",
|
|
106
|
+
AWS_SECRET_ACCESS_KEY: "app",
|
|
107
|
+
AWS_SESSION_TOKEN: "app",
|
|
108
|
+
AWS_PROFILE: "app",
|
|
109
|
+
VITE_API: "x",
|
|
110
|
+
AWS_S3_BUCKET: "kept",
|
|
111
|
+
}),
|
|
112
|
+
).toEqual({ VITE_API: "x", AWS_S3_BUCKET: "kept" });
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The IAM and EventBridge documents behind `devkit cloud deploy-key`: a machine that cannot use GitHub's
|
|
3
|
+
* OIDC (the box) deploys with a long-lived key that can do exactly one thing, assume an IP-locked role
|
|
4
|
+
* for 15 minutes. Pure functions, so the documents are tested without AWS.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Names may only make `dk-deploy-<name>`; `local` is the laptop profile's user and is never handed out. */
|
|
8
|
+
const NAME = /^[a-z0-9][a-z0-9-]{0,30}$/;
|
|
9
|
+
|
|
10
|
+
export function deployKeyName(name: string | undefined) {
|
|
11
|
+
if (!name || !NAME.test(name) || name === "local")
|
|
12
|
+
throw new Error(`deploy key name must match ${NAME} and not be "local" (got "${name ?? ""}")`);
|
|
13
|
+
return `dk-deploy-${name}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The one address the key may be used from, checked; policies get it as a one-host CIDR. */
|
|
17
|
+
export function sourceIp(ip: string | undefined) {
|
|
18
|
+
if (!ip) throw new Error("--source-ip is required: the one address the key may be used from");
|
|
19
|
+
const v4 = /^\d{1,3}(\.\d{1,3}){3}$/.test(ip) && ip.split(".").every((part) => Number(part) <= 255);
|
|
20
|
+
const v6 = !v4 && /^[0-9a-f:]+$/i.test(ip) && ip.includes(":");
|
|
21
|
+
if (!v4 && !v6) throw new Error(`--source-ip "${ip}" is not a single IP address`);
|
|
22
|
+
return { ip, cidr: `${ip}/${v4 ? 32 : 128}` };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The cap AssumeRole's DurationSeconds is held to, through the `sts:DurationSeconds` condition: a role's
|
|
27
|
+
* MaxSessionDuration cannot go below 3600, so the trust and the user's policy enforce the 15 minutes.
|
|
28
|
+
*/
|
|
29
|
+
export const DEPLOY_KEY_SESSION_SECONDS = 900;
|
|
30
|
+
|
|
31
|
+
type Document = { Version: "2012-10-17"; Statement: Record<string, unknown>[] };
|
|
32
|
+
|
|
33
|
+
/** The user's only permission: assume its own role, from the one address. */
|
|
34
|
+
export function deployKeyUserPolicy(account: string, name: string, cidr: string): Document {
|
|
35
|
+
return {
|
|
36
|
+
Version: "2012-10-17",
|
|
37
|
+
Statement: [
|
|
38
|
+
{
|
|
39
|
+
Effect: "Allow",
|
|
40
|
+
Action: "sts:AssumeRole",
|
|
41
|
+
Resource: `arn:aws:iam::${account}:role/${name}`,
|
|
42
|
+
Condition: {
|
|
43
|
+
IpAddress: { "aws:SourceIp": cidr },
|
|
44
|
+
NumericLessThanEquals: { "sts:DurationSeconds": DEPLOY_KEY_SESSION_SECONDS },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The role trusts that one user, from the one address. */
|
|
52
|
+
export function deployKeyTrust(account: string, name: string, cidr: string): Document {
|
|
53
|
+
return {
|
|
54
|
+
Version: "2012-10-17",
|
|
55
|
+
Statement: [
|
|
56
|
+
{
|
|
57
|
+
Effect: "Allow",
|
|
58
|
+
Principal: { AWS: `arn:aws:iam::${account}:user/${name}` },
|
|
59
|
+
Action: "sts:AssumeRole",
|
|
60
|
+
Condition: {
|
|
61
|
+
IpAddress: { "aws:SourceIp": cidr },
|
|
62
|
+
NumericLessThanEquals: { "sts:DurationSeconds": DEPLOY_KEY_SESSION_SECONDS },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Inline on the role, next to the `dk-deploy` managed policy: session credentials copied off the box are
|
|
71
|
+
* useless anywhere else, and the session can never touch the deploy identities themselves (the managed
|
|
72
|
+
* policy's `iam:*Role*` on `role/dk-*` would otherwise reach this very role). Calls AWS makes on the
|
|
73
|
+
* session's behalf (Lambda fetching code from S3) carry no source IP, so they are exempt.
|
|
74
|
+
*/
|
|
75
|
+
export function deployKeyGuard(account: string, cidr: string): Document {
|
|
76
|
+
return {
|
|
77
|
+
Version: "2012-10-17",
|
|
78
|
+
Statement: [
|
|
79
|
+
{
|
|
80
|
+
Effect: "Deny",
|
|
81
|
+
Action: "*",
|
|
82
|
+
Resource: "*",
|
|
83
|
+
Condition: { NotIpAddress: { "aws:SourceIp": cidr }, Bool: { "aws:ViaAWSService": "false" } },
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
Effect: "Deny",
|
|
87
|
+
Action: "iam:*",
|
|
88
|
+
Resource: [
|
|
89
|
+
`arn:aws:iam::${account}:role/dk-deploy*`,
|
|
90
|
+
`arn:aws:iam::${account}:user/dk-deploy*`,
|
|
91
|
+
`arn:aws:iam::${account}:policy/dk-deploy*`,
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Any API call by the user or a session of its role from an address other than the allowed one. A call an
|
|
100
|
+
* AWS service makes for the session reports the service as its source and alerts too; those are rare here.
|
|
101
|
+
*/
|
|
102
|
+
export function deployKeyAlertPattern(account: string, name: string, ip: string) {
|
|
103
|
+
return {
|
|
104
|
+
"detail-type": ["AWS API Call via CloudTrail"],
|
|
105
|
+
detail: {
|
|
106
|
+
userIdentity: {
|
|
107
|
+
arn: [`arn:aws:iam::${account}:user/${name}`, { prefix: `arn:aws:sts::${account}:assumed-role/${name}/` }],
|
|
108
|
+
},
|
|
109
|
+
sourceIPAddress: [{ "anything-but": [ip] }],
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** What `deploy-key` prints: the base key and the role, as env lines a secrets holder stores. */
|
|
115
|
+
export function deployKeyEnv(account: string, name: string, accessKeyId: string, secret: string, region: string) {
|
|
116
|
+
return [
|
|
117
|
+
`DK_DEPLOY_ACCESS_KEY_ID=${accessKeyId}`,
|
|
118
|
+
`DK_DEPLOY_SECRET_ACCESS_KEY=${secret}`,
|
|
119
|
+
`DK_DEPLOY_ROLE_ARN=arn:aws:iam::${account}:role/${name}`,
|
|
120
|
+
`AWS_REGION=${region}`,
|
|
121
|
+
].join("\n");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** What `devkit cloud session` prints: temporary credentials only, ready for `export`. */
|
|
125
|
+
export function sessionEnv(credentials: { AccessKeyId: string; SecretAccessKey: string; SessionToken: string }) {
|
|
126
|
+
return [
|
|
127
|
+
`AWS_ACCESS_KEY_ID=${credentials.AccessKeyId}`,
|
|
128
|
+
`AWS_SECRET_ACCESS_KEY=${credentials.SecretAccessKey}`,
|
|
129
|
+
`AWS_SESSION_TOKEN=${credentials.SessionToken}`,
|
|
130
|
+
].join("\n");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Credential variables a stage's env must never put over the deploy's own. */
|
|
134
|
+
const DEPLOY_CREDENTIALS = new Set([
|
|
135
|
+
"AWS_ACCESS_KEY_ID",
|
|
136
|
+
"AWS_SECRET_ACCESS_KEY",
|
|
137
|
+
"AWS_SESSION_TOKEN",
|
|
138
|
+
"AWS_PROFILE",
|
|
139
|
+
"AWS_ROLE_ARN",
|
|
140
|
+
"AWS_WEB_IDENTITY_TOKEN_FILE",
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
/** The stage's env minus anything that would swap the credentials the deploy itself runs with. */
|
|
144
|
+
export function withoutDeployCredentials(env: Readonly<Record<string, string>>) {
|
|
145
|
+
return Object.fromEntries(Object.entries(env).filter(([key]) => !DEPLOY_CREDENTIALS.has(key)));
|
|
146
|
+
}
|
package/src/cloud/edge/router.js
CHANGED
|
@@ -88,10 +88,26 @@ function staticPath(uri, mode) {
|
|
|
88
88
|
return "/index.html";
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// A Lambda Function URL renames some response headers it reserves (WWW-Authenticate among them) to
|
|
92
|
+
// `x-amzn-remapped-<name>`. OAuth clients need the real `WWW-Authenticate` on a 401, so the original
|
|
93
|
+
// names come back here.
|
|
94
|
+
var REMAPPED_PREFIX = "x-amzn-remapped-";
|
|
95
|
+
var RESTORED = ["www-authenticate"];
|
|
96
|
+
|
|
97
|
+
function restoreRemapped(headers) {
|
|
98
|
+
for (var i = 0; i < RESTORED.length; i++) {
|
|
99
|
+
var remapped = REMAPPED_PREFIX + RESTORED[i];
|
|
100
|
+
if (!headers[remapped]) continue;
|
|
101
|
+
headers[RESTORED[i]] = headers[remapped];
|
|
102
|
+
delete headers[remapped];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
91
106
|
// Rules match the path the viewer asked for. The request here may carry the rewritten static path
|
|
92
107
|
// (`/<project>/<deploy>/...`), so that prefix comes off first.
|
|
93
108
|
async function withHeaders(event) {
|
|
94
109
|
var response = event.response;
|
|
110
|
+
restoreRemapped(response.headers);
|
|
95
111
|
var request = event.request;
|
|
96
112
|
var host = request.headers.host ? request.headers.host.value.toLowerCase() : "";
|
|
97
113
|
try {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { expect, mock, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
const store: Record<string, string> = {};
|
|
7
|
+
mock.module("cloudfront", () => ({
|
|
8
|
+
default: {
|
|
9
|
+
kvs: () => ({
|
|
10
|
+
get: (key: string) => (key in store ? Promise.resolve(store[key]) : Promise.reject(new Error("missing"))),
|
|
11
|
+
}),
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const source = await Bun.file(new URL("./router.js", import.meta.url)).text();
|
|
16
|
+
// The router is a CloudFront Function script, not a module: export its handler from a copy.
|
|
17
|
+
const copy = join(mkdtempSync(join(tmpdir(), "dk-router-")), "router.js");
|
|
18
|
+
await Bun.write(copy, `${source}\nexport { handler };`);
|
|
19
|
+
const { handler } = await import(copy);
|
|
20
|
+
|
|
21
|
+
function viewerResponse(headers: Record<string, { value: string }>) {
|
|
22
|
+
return {
|
|
23
|
+
context: { eventType: "viewer-response" },
|
|
24
|
+
request: { uri: "/mcp", headers: { host: { value: "api.example.com" } } },
|
|
25
|
+
response: { statusCode: 401, headers },
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test("restores WWW-Authenticate remapped by the Lambda Function URL", async () => {
|
|
30
|
+
store["api.example.com"] = JSON.stringify({ p: "app", d: "d1", fn: "x.lambda-url.aws" });
|
|
31
|
+
const value = 'Bearer resource_metadata="https://api.example.com/.well-known/oauth-protected-resource/mcp"';
|
|
32
|
+
const response = await handler(viewerResponse({ "x-amzn-remapped-www-authenticate": { value } }));
|
|
33
|
+
expect(response.headers["www-authenticate"]).toEqual({ value });
|
|
34
|
+
expect(response.headers["x-amzn-remapped-www-authenticate"]).toBeUndefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("restores the header even when the host has no route", async () => {
|
|
38
|
+
delete store["api.example.com"];
|
|
39
|
+
const response = await handler(viewerResponse({ "x-amzn-remapped-www-authenticate": { value: "Bearer" } }));
|
|
40
|
+
expect(response.headers["www-authenticate"]).toEqual({ value: "Bearer" });
|
|
41
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join, resolve } from "node:path";
|
|
2
2
|
import { AWS_OUTPUT, buildWeb } from "../build-targets/web.ts";
|
|
3
|
+
import { withoutDeployCredentials } from "../cloud/deploy-key-policies.ts";
|
|
3
4
|
import { readStageEnv } from "../cloud/env.ts";
|
|
4
5
|
import { assertNoLocalEnvInBuild } from "../cloud/env-leak.ts";
|
|
5
6
|
import { STAGE_BRANCHES } from "../cloud/names.ts";
|
|
@@ -20,9 +21,10 @@ export async function deployAws(options: AwsTargetOptions) {
|
|
|
20
21
|
const target = new Target(project, stage, options);
|
|
21
22
|
|
|
22
23
|
// The stage's variables are the build's too, so `VITE_*` values reach the frontend bundle in CI
|
|
23
|
-
// exactly as they do from a laptop's `.env`.
|
|
24
|
+
// exactly as they do from a laptop's `.env`. The deploy's own AWS credentials (a profile, GitHub's OIDC
|
|
25
|
+
// role, or session keys in AWS_* env) stay: an app's AWS_* keys must not swap them mid-deploy.
|
|
24
26
|
const stageEnv = await readStageEnv(target);
|
|
25
|
-
Object.assign(process.env, stageEnv);
|
|
27
|
+
Object.assign(process.env, withoutDeployCredentials(stageEnv));
|
|
26
28
|
|
|
27
29
|
await buildWeb({ ...options, host: "aws", static: target.isStatic });
|
|
28
30
|
await assertNoLocalEnvInBuild(
|