@fjall/components-infrastructure 40.0.3 → 40.1.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/dist/lib/config/aws/scpPreset.d.ts +8 -1
- package/dist/lib/config/aws/scpPreset.js +40 -2
- package/dist/lib/lambda-assets/ci-oidc-provider/asset/THIRD-PARTY-NOTICES.txt +1302 -0
- package/dist/lib/lambda-assets/ci-oidc-provider/asset/index.js +47 -0
- package/dist/lib/lambda-assets/ci-oidc-provider/asset/package.json +4 -0
- package/dist/lib/patterns/aws/buildkite/image/components/ciNode.d.ts +7 -5
- package/dist/lib/patterns/aws/buildkite/image/components/ciNode.js +7 -5
- package/dist/lib/patterns/aws/cdn.d.ts +12 -1
- package/dist/lib/patterns/aws/cdn.js +25 -55
- package/dist/lib/patterns/aws/interfaces/pattern.d.ts +12 -0
- package/dist/lib/patterns/aws/organisation.d.ts +7 -2
- package/dist/lib/patterns/aws/organisation.js +6 -2
- package/dist/lib/patterns/aws/redirectHosts.d.ts +24 -0
- package/dist/lib/patterns/aws/redirectHosts.js +48 -0
- package/dist/lib/patterns/aws/staticSite.d.ts +1 -0
- package/dist/lib/patterns/aws/staticSite.js +52 -18
- package/dist/lib/resources/aws/cdn/cloudFront.d.ts +4 -1
- package/dist/lib/resources/aws/cdn/cloudFront.js +8 -2
- package/dist/lib/resources/aws/cdn/cloudFrontHostRedirect.d.ts +6 -6
- package/dist/lib/resources/aws/cdn/cloudFrontHostRedirect.js +6 -6
- package/dist/lib/resources/aws/iam/oidcProviderAdoption.d.ts +2 -2
- package/dist/lib/resources/aws/iam/oidcProviderAdoption.js +12 -6
- package/dist/lib/terminology/parity/storageAndNetworking.js +2 -0
- package/dist/lib/utils/orgConfigParser.d.ts +2 -2
- package/dist/lib/utils/orgConfigParser.js +2 -2
- package/package.json +5 -4
|
@@ -26,10 +26,12 @@ export declare function bakedNodeCheck(ownerUid: number): string;
|
|
|
26
26
|
* main, checked against the SHA-256 that same commit's arm64 pin gives it,
|
|
27
27
|
* where the lane runner looks for it. The runner keeps an install whose
|
|
28
28
|
* version matches without checking it again, so this is the only check a
|
|
29
|
-
* baked Node gets. The highest version goes on the system's PATH,
|
|
30
|
-
* CI takes
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
29
|
+
* baked Node gets. The highest version goes on the system's PATH, which main
|
|
30
|
+
* CI takes only with its Node pin switch off; otherwise its `ensure_node_24`
|
|
31
|
+
* reads the bake of `.nvmrc`'s version as the runner does (FJL-3409). It runs
|
|
32
|
+
* after the git mirrors component, whose mirrors it reads, so the document
|
|
33
|
+
* holds no version. The build step runs the validate phase's check too, so a
|
|
34
|
+
* broken bake fails the build whether or not Image Builder runs that phase
|
|
35
|
+
* with image tests off.
|
|
34
36
|
*/
|
|
35
37
|
export declare function ciNodeDocument(): AwstoeDocument;
|
|
@@ -119,11 +119,13 @@ export function bakedNodeCheck(ownerUid) {
|
|
|
119
119
|
* main, checked against the SHA-256 that same commit's arm64 pin gives it,
|
|
120
120
|
* where the lane runner looks for it. The runner keeps an install whose
|
|
121
121
|
* version matches without checking it again, so this is the only check a
|
|
122
|
-
* baked Node gets. The highest version goes on the system's PATH,
|
|
123
|
-
* CI takes
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
122
|
+
* baked Node gets. The highest version goes on the system's PATH, which main
|
|
123
|
+
* CI takes only with its Node pin switch off; otherwise its `ensure_node_24`
|
|
124
|
+
* reads the bake of `.nvmrc`'s version as the runner does (FJL-3409). It runs
|
|
125
|
+
* after the git mirrors component, whose mirrors it reads, so the document
|
|
126
|
+
* holds no version. The build step runs the validate phase's check too, so a
|
|
127
|
+
* broken bake fails the build whether or not Image Builder runs that phase
|
|
128
|
+
* with image tests off.
|
|
127
129
|
*/
|
|
128
130
|
export function ciNodeDocument() {
|
|
129
131
|
return {
|
|
@@ -4,7 +4,7 @@ import { type IApplicationLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalanc
|
|
|
4
4
|
import { type ICertificate } from "aws-cdk-lib/aws-certificatemanager";
|
|
5
5
|
import { type AllowedMethods, type ICachePolicy, OriginProtocolPolicy, type PriceClass } from "aws-cdk-lib/aws-cloudfront";
|
|
6
6
|
import type { App } from "../../app.js";
|
|
7
|
-
import { CloudFrontDistribution, type CloudFrontLogFormat, type CdnBehaviorOptions, type CdnDefaultBehaviorOptions, type CachePolicyPreset, type AccessGateConfig } from "../../resources/aws/cdn/index.js";
|
|
7
|
+
import { CloudFrontDistribution, type CloudFrontLogFormat, type CdnBehaviorOptions, type CdnDefaultBehaviorOptions, type CachePolicyPreset, type AccessGateConfig, type CloudFrontHostRedirect } from "../../resources/aws/cdn/index.js";
|
|
8
8
|
import { type ICdn } from "./interfaces/cdn.js";
|
|
9
9
|
import { type StaticSiteRouting, type DomainRecordMode } from "@fjall/util";
|
|
10
10
|
import { type BackupTier } from "../../utils/backupTierMapping.js";
|
|
@@ -99,6 +99,17 @@ interface BaseCdnProps {
|
|
|
99
99
|
*/
|
|
100
100
|
additionalBehaviors?: Record<string, SmartCdnBehaviorOptions>;
|
|
101
101
|
domainNames?: string[];
|
|
102
|
+
/**
|
|
103
|
+
* Hosts among `domainNames` that answer with a 301 to `targetHost`, path
|
|
104
|
+
* and query kept: the flat twin of `domainConfig.redirectHosts`, for a
|
|
105
|
+
* pattern that resolves its own zone and certificate, as the static site
|
|
106
|
+
* does. It is construct plumbing, so no plan field, CLI flag or MCP tool
|
|
107
|
+
* carries it. The Cdn writes no record for these hosts, as it writes none
|
|
108
|
+
* for `domainNames`, and the resource layer refuses a host that is not one
|
|
109
|
+
* of the literal `domainNames` (`validateHostRedirect`). Refused beside
|
|
110
|
+
* `domainConfig`.
|
|
111
|
+
*/
|
|
112
|
+
hostRedirect?: CloudFrontHostRedirect;
|
|
102
113
|
/**
|
|
103
114
|
* The viewer certificate, which CloudFront takes from us-east-1 only.
|
|
104
115
|
* `CdnFactory.build` also takes its ARN.
|
|
@@ -7,7 +7,7 @@ import { assertBehaviorRecord, assertNoLegacyLoggingProps, CLOUDFRONT_LOG_DELIVE
|
|
|
7
7
|
import { refuseRenamed } from "../../terminology/refuseRenamed.js";
|
|
8
8
|
import { loadBalancerIngressWarning } from "../../resources/aws/compute/loadBalancerIngress.js";
|
|
9
9
|
import { AliasRecord } from "../../resources/aws/networking/index.js";
|
|
10
|
-
import { VALUE_NOT_REPEATED,
|
|
10
|
+
import { VALUE_NOT_REPEATED, refuseOperatorValue, refusedHostLabel } from "@fjall/util";
|
|
11
11
|
import { ARN_PARTITION_SEGMENT, RECORD_GAP_BETWEEN_DEPLOYS } from "@fjall/util/aws";
|
|
12
12
|
import { backupColumn } from "../../utils/backupTierMapping.js";
|
|
13
13
|
import { readOptionalBackupTier, refuseOffListBackupTier } from "../../resources/aws/backup/backupTierReading.js";
|
|
@@ -18,6 +18,7 @@ import { recordLabelWithin } from "../../utils/domainTypes.js";
|
|
|
18
18
|
import { resolvePatternZone, resolvePatternCloudFrontCertificate } from "./patternDomain.js";
|
|
19
19
|
import { isStorage } from "./storage.js";
|
|
20
20
|
import { warnWhenHttpOriginsReachComputes } from "./cdnHttpOriginReach.js";
|
|
21
|
+
import { validateRedirectHosts } from "./redirectHosts.js";
|
|
21
22
|
import { CdnEcsOriginResolver, cdnOriginRefusal, normaliseDnsName } from "./cdnAppOrigin.js";
|
|
22
23
|
import { isCompute, isEcsCompute, isLambdaCompute } from "./compute.js";
|
|
23
24
|
/**
|
|
@@ -129,50 +130,6 @@ function collectRecordedNames(props, domain) {
|
|
|
129
130
|
zone: domain.zone
|
|
130
131
|
}));
|
|
131
132
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Refuses a `domainConfig.redirectHosts` entry the edge could not serve: one
|
|
134
|
-
* that is not a literal lower-case DNS name (the viewer-request function
|
|
135
|
-
* compares the viewer's Host header with each), a duplicate, the domain
|
|
136
|
-
* itself, which would redirect to itself, or one whose record id another
|
|
137
|
-
* host already derives. The domain, the redirect's target, must be a literal
|
|
138
|
-
* lower-case name too.
|
|
139
|
-
*/
|
|
140
|
-
function validateRedirectHosts(id, domainConfig) {
|
|
141
|
-
const hosts = domainConfig.redirectHosts ?? [];
|
|
142
|
-
if (hosts.length === 0)
|
|
143
|
-
return;
|
|
144
|
-
if (Token.isUnresolved(domainConfig.domainName) ||
|
|
145
|
-
!isDnsNameShape(domainConfig.domainName)) {
|
|
146
|
-
throw new Error(`CDN '${id}': 'domainConfig.domainName' ${refusedHostLabel(domainConfig.domainName)} ` +
|
|
147
|
-
"must be a literal lower-case DNS name while 'domainConfig.redirectHosts' " +
|
|
148
|
-
"is set, because the viewer-request function redirects each host to it.");
|
|
149
|
-
}
|
|
150
|
-
const domain = normaliseDnsName(domainConfig.domainName);
|
|
151
|
-
const seen = new Set();
|
|
152
|
-
for (const host of hosts) {
|
|
153
|
-
if (Token.isUnresolved(host) || !isDnsNameShape(host)) {
|
|
154
|
-
throw new Error(`CDN '${id}': 'domainConfig.redirectHosts' entry ${refusedHostLabel(host)} ` +
|
|
155
|
-
"must be a literal lower-case DNS name, because the viewer-request " +
|
|
156
|
-
"function compares the viewer's Host header with it.");
|
|
157
|
-
}
|
|
158
|
-
if (seen.has(host)) {
|
|
159
|
-
throw new Error(`CDN '${id}': 'domainConfig.redirectHosts' lists ${refusedHostLabel(host)} ` +
|
|
160
|
-
"twice. List each host once.");
|
|
161
|
-
}
|
|
162
|
-
seen.add(host);
|
|
163
|
-
if (host === domain) {
|
|
164
|
-
throw new Error(`CDN '${id}': 'domainConfig.redirectHosts' names the domain ` +
|
|
165
|
-
`${refusedHostLabel(host)} itself, so every request to it would ` +
|
|
166
|
-
"redirect to itself. Drop it from redirectHosts.");
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const collision = hostConstructKeyCollision(hosts);
|
|
170
|
-
if (collision !== undefined) {
|
|
171
|
-
throw new Error(`CDN '${id}': 'domainConfig.redirectHosts' entries ` +
|
|
172
|
-
hostConstructKeyCollisionReason(collision, redirectRecordId) +
|
|
173
|
-
". Keep one of them on this Cdn.");
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
133
|
/** The construct id of a redirect host's alias record. */
|
|
177
134
|
function redirectRecordId(hostKey) {
|
|
178
135
|
return `${hostKey}RedirectAliasRecord`;
|
|
@@ -361,15 +318,22 @@ function validateCdnProps(id, props) {
|
|
|
361
318
|
// mixing it with the literal surface would give the alias list and the
|
|
362
319
|
// certificate two owners with no defined precedence.
|
|
363
320
|
if (props.domainConfig !== undefined) {
|
|
321
|
+
const domainLabel = refusedHostLabel(props.domainConfig.domainName);
|
|
322
|
+
if (props.hostRedirect !== undefined) {
|
|
323
|
+
throw new Error(`CDN 'domainConfig' (${domainLabel}) cannot be ` +
|
|
324
|
+
"combined with 'hostRedirect'. List the hosts in " +
|
|
325
|
+
"'domainConfig.redirectHosts', or drop 'domainConfig' and set " +
|
|
326
|
+
"'domainNames', 'certificate' and 'hostRedirect' by hand.");
|
|
327
|
+
}
|
|
364
328
|
if (props.domainNames !== undefined || hasCertificate) {
|
|
365
|
-
throw new Error(`CDN 'domainConfig' (
|
|
329
|
+
throw new Error(`CDN 'domainConfig' (${domainLabel}) cannot be ` +
|
|
366
330
|
"combined with 'domainNames' or 'certificate'. " +
|
|
367
331
|
"'domainConfig' derives the alternate domain names and resolves " +
|
|
368
332
|
"the us-east-1 viewer certificate itself — drop the literal props, " +
|
|
369
333
|
"or drop 'domainConfig' and manage both by hand.");
|
|
370
334
|
}
|
|
371
335
|
if (props.app === undefined) {
|
|
372
|
-
throw new Error(`CDN 'domainConfig' (
|
|
336
|
+
throw new Error(`CDN 'domainConfig' (${domainLabel}) requires ` +
|
|
373
337
|
"the App for certificate placement, but 'app' is unset. Create the " +
|
|
374
338
|
"CDN through the factory path — app.addCdn(CdnFactory.build(...)) " +
|
|
375
339
|
"— which fills it, or pass 'app' explicitly.");
|
|
@@ -391,7 +355,15 @@ function validateCdnProps(id, props) {
|
|
|
391
355
|
"(Route53 SetIdentifier limit). Omit it to use the derived " +
|
|
392
356
|
`'<id><region>' value. ${VALUE_NOT_REPEATED}`);
|
|
393
357
|
}
|
|
394
|
-
validateRedirectHosts(
|
|
358
|
+
validateRedirectHosts({
|
|
359
|
+
context: `CDN '${id}'`,
|
|
360
|
+
hostsField: "'domainConfig.redirectHosts'",
|
|
361
|
+
domainField: "'domainConfig.domainName'",
|
|
362
|
+
domain: props.domainConfig.domainName,
|
|
363
|
+
hosts: props.domainConfig.redirectHosts ?? [],
|
|
364
|
+
collisionCure: "Keep one of them on this Cdn.",
|
|
365
|
+
recordId: redirectRecordId
|
|
366
|
+
});
|
|
395
367
|
}
|
|
396
368
|
// Origin-loop guard (design 2026-08-17 cdn-domain-ownership C4): an HTTP
|
|
397
369
|
// origin pointing at one of the distribution's own domain names sends
|
|
@@ -762,6 +734,10 @@ export class Cdn extends CloudFrontDistribution {
|
|
|
762
734
|
(props.domainConfig !== undefined
|
|
763
735
|
? [props.domainConfig.domainName, ...redirectHosts]
|
|
764
736
|
: undefined);
|
|
737
|
+
const hostRedirect = props.hostRedirect ??
|
|
738
|
+
(props.domainConfig !== undefined && redirectHosts.length > 0
|
|
739
|
+
? { hosts: redirectHosts, targetHost: props.domainConfig.domainName }
|
|
740
|
+
: undefined);
|
|
765
741
|
// ANY origin resolved through the ECS profile lane serves a hostname
|
|
766
742
|
// that differs from the viewer-facing aliases, so host fidelity via
|
|
767
743
|
// x-forwarded-host is the sensible default (design D3 step 9) — for a
|
|
@@ -800,13 +776,7 @@ export class Cdn extends CloudFrontDistribution {
|
|
|
800
776
|
priceClass: props.priceClass,
|
|
801
777
|
forwardHostHeader: props.forwardHostHeader ?? impliedForwardHostHeader,
|
|
802
778
|
accessGate: props.accessGate,
|
|
803
|
-
...(
|
|
804
|
-
redirectHosts.length > 0 && {
|
|
805
|
-
hostRedirect: {
|
|
806
|
-
hosts: redirectHosts,
|
|
807
|
-
targetHost: props.domainConfig.domainName
|
|
808
|
-
}
|
|
809
|
-
}),
|
|
779
|
+
...(hostRedirect !== undefined && { hostRedirect }),
|
|
810
780
|
...s3Routing
|
|
811
781
|
},
|
|
812
782
|
recordPlans: ecsOriginResolver.recordPlans
|
|
@@ -660,6 +660,18 @@ export interface IStaticSiteProps {
|
|
|
660
660
|
security?: StaticSiteSecurityConfig;
|
|
661
661
|
/** Custom domain (same machinery as payload). Required when `forms` is set. */
|
|
662
662
|
domain?: string;
|
|
663
|
+
/**
|
|
664
|
+
* Hosts that answer with a 301 to `https://<domain>`, path and query kept,
|
|
665
|
+
* such as `www` beside an apex. Each is a lower-case DNS name in the
|
|
666
|
+
* domain's zone, and needs `domain`. The distribution answers for each
|
|
667
|
+
* host, so the viewer certificate must cover it: an app-owned certificate
|
|
668
|
+
* lists the hosts as alternative names, and a managed domain's certificate
|
|
669
|
+
* must already cover them. Under `domainRecord: "alias"` the site creates
|
|
670
|
+
* an alias record for each host beside the domain's. Under `"none"` it
|
|
671
|
+
* creates none, and the CDN stack's `ZoneOwnedRecord` output lists the
|
|
672
|
+
* hosts, so the deploy's next steps name a record for each.
|
|
673
|
+
*/
|
|
674
|
+
redirectHosts?: string[];
|
|
663
675
|
/**
|
|
664
676
|
* Who creates the Route 53 record for `domain`, in the vocabulary of the
|
|
665
677
|
* CDN construct's `domainConfig.record` (`DOMAIN_RECORD_VALUES` in
|
|
@@ -22,6 +22,10 @@ export interface OrganisationProps extends AccountProps {
|
|
|
22
22
|
* ManagementAccountAccess).
|
|
23
23
|
*/
|
|
24
24
|
identityCentre?: IdentityCentreConfig | false;
|
|
25
|
+
/**
|
|
26
|
+
* Never read: the SCPs take their regions from `enableScps`. Setting it
|
|
27
|
+
* warns, and 41.0.0 refuses it.
|
|
28
|
+
*/
|
|
25
29
|
allowedRegions?: string[];
|
|
26
30
|
env?: Required<Pick<Environment, "region" | "account">> & Partial<Omit<Environment, "region" | "account">>;
|
|
27
31
|
}
|
|
@@ -102,9 +106,10 @@ export declare class Organisation extends Account {
|
|
|
102
106
|
/**
|
|
103
107
|
* The root the SCPs attach to defaults to this organisation's own, which
|
|
104
108
|
* the constructor read from the CDK context the CLI injects. An empty
|
|
105
|
-
* `rootId` is the `-c key=` boundary and reads as absent.
|
|
109
|
+
* `rootId` is the `-c key=` boundary and reads as absent. Without
|
|
110
|
+
* `allowedRegions`, the SCPs allow the organisation's own regions.
|
|
106
111
|
*/
|
|
107
|
-
enableScps(props
|
|
112
|
+
enableScps(props?: Omit<ScpPresetProps, "rootId"> & {
|
|
108
113
|
rootId?: string;
|
|
109
114
|
}): ScpPreset;
|
|
110
115
|
/**
|
|
@@ -37,6 +37,9 @@ export class Organisation extends Account {
|
|
|
37
37
|
refuseRenamed("OrganisationProps", props);
|
|
38
38
|
const config = getConfig();
|
|
39
39
|
super(scope, id, props);
|
|
40
|
+
if (Object.hasOwn(props, "allowedRegions")) {
|
|
41
|
+
Annotations.of(this).addWarningV2("fjall:organisation:allowed-regions-unread", "OrganisationProps.allowedRegions is never read, so it changes no SCP. In the organisation's infrastructure.ts, take it out of the props passed to OrganisationFactory.build, and pass any region list to enableScps instead. 41.0.0 refuses it.");
|
|
42
|
+
}
|
|
40
43
|
// Normalise account map keys to lowercase for case-insensitive lookups.
|
|
41
44
|
// providerAccounts stores names as lowercase; ACCOUNTS config uses PascalCase.
|
|
42
45
|
const rawMap = props.accountIds ?? config.accountIds ?? {};
|
|
@@ -235,9 +238,10 @@ export class Organisation extends Account {
|
|
|
235
238
|
/**
|
|
236
239
|
* The root the SCPs attach to defaults to this organisation's own, which
|
|
237
240
|
* the constructor read from the CDK context the CLI injects. An empty
|
|
238
|
-
* `rootId` is the `-c key=` boundary and reads as absent.
|
|
241
|
+
* `rootId` is the `-c key=` boundary and reads as absent. Without
|
|
242
|
+
* `allowedRegions`, the SCPs allow the organisation's own regions.
|
|
239
243
|
*/
|
|
240
|
-
enableScps(props) {
|
|
244
|
+
enableScps(props = {}) {
|
|
241
245
|
const rootId = props.rootId !== undefined && props.rootId !== ""
|
|
242
246
|
? props.rootId
|
|
243
247
|
: this.org.rootId;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** A pattern's redirect hosts, and how its refusals name them. */
|
|
2
|
+
export interface RedirectHostsDeclaration {
|
|
3
|
+
/** Starts each refusal, such as `CDN 'site'`. */
|
|
4
|
+
readonly context: string;
|
|
5
|
+
/** The hosts' prop as a refusal quotes it, such as `'redirectHosts'`. */
|
|
6
|
+
readonly hostsField: string;
|
|
7
|
+
/** The domain's prop as a refusal quotes it, such as `'domain'`. */
|
|
8
|
+
readonly domainField: string;
|
|
9
|
+
readonly domain: string;
|
|
10
|
+
readonly hosts: readonly string[];
|
|
11
|
+
/** Ends the refusal of 2 hosts whose record ids collide. */
|
|
12
|
+
readonly collisionCure: string;
|
|
13
|
+
/** The construct id of a host's alias record, from the host's key. */
|
|
14
|
+
readonly recordId: (hostKey: string) => string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Refuses a redirect host the edge could not serve: one that is not a
|
|
18
|
+
* literal lower-case DNS name (the viewer-request function compares the
|
|
19
|
+
* viewer's Host header with each), a duplicate, the domain itself, which
|
|
20
|
+
* would redirect to itself, or one whose record id another host already
|
|
21
|
+
* derives. The domain, the redirect's target, must be a literal lower-case
|
|
22
|
+
* name too.
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateRedirectHosts(declaration: RedirectHostsDeclaration): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Token } from "aws-cdk-lib";
|
|
2
|
+
import { isDnsNameShape, refusedHostLabel } from "@fjall/util";
|
|
3
|
+
import { hostConstructKeyCollision, hostConstructKeyCollisionReason } from "../../utils/hostConstructKey.js";
|
|
4
|
+
import { normaliseDnsName } from "./cdnAppOrigin.js";
|
|
5
|
+
/**
|
|
6
|
+
* Refuses a redirect host the edge could not serve: one that is not a
|
|
7
|
+
* literal lower-case DNS name (the viewer-request function compares the
|
|
8
|
+
* viewer's Host header with each), a duplicate, the domain itself, which
|
|
9
|
+
* would redirect to itself, or one whose record id another host already
|
|
10
|
+
* derives. The domain, the redirect's target, must be a literal lower-case
|
|
11
|
+
* name too.
|
|
12
|
+
*/
|
|
13
|
+
export function validateRedirectHosts(declaration) {
|
|
14
|
+
const { context, hostsField, domainField, hosts } = declaration;
|
|
15
|
+
if (hosts.length === 0)
|
|
16
|
+
return;
|
|
17
|
+
if (Token.isUnresolved(declaration.domain) ||
|
|
18
|
+
!isDnsNameShape(declaration.domain)) {
|
|
19
|
+
throw new Error(`${context}: ${domainField} ${refusedHostLabel(declaration.domain)} ` +
|
|
20
|
+
`must be a literal lower-case DNS name while ${hostsField} ` +
|
|
21
|
+
"is set, because the viewer-request function redirects each host to it.");
|
|
22
|
+
}
|
|
23
|
+
const domain = normaliseDnsName(declaration.domain);
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
for (const host of hosts) {
|
|
26
|
+
if (Token.isUnresolved(host) || !isDnsNameShape(host)) {
|
|
27
|
+
throw new Error(`${context}: ${hostsField} entry ${refusedHostLabel(host)} ` +
|
|
28
|
+
"must be a literal lower-case DNS name, because the viewer-request " +
|
|
29
|
+
"function compares the viewer's Host header with it.");
|
|
30
|
+
}
|
|
31
|
+
if (seen.has(host)) {
|
|
32
|
+
throw new Error(`${context}: ${hostsField} lists ${refusedHostLabel(host)} ` +
|
|
33
|
+
"twice. List each host once.");
|
|
34
|
+
}
|
|
35
|
+
seen.add(host);
|
|
36
|
+
if (host === domain) {
|
|
37
|
+
throw new Error(`${context}: ${hostsField} names the domain ` +
|
|
38
|
+
`${refusedHostLabel(host)} itself, so every request to it would ` +
|
|
39
|
+
"redirect to itself. Drop it from redirectHosts.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const collision = hostConstructKeyCollision(hosts);
|
|
43
|
+
if (collision !== undefined) {
|
|
44
|
+
throw new Error(`${context}: ${hostsField} entries ` +
|
|
45
|
+
hostConstructKeyCollisionReason(collision, declaration.recordId) +
|
|
46
|
+
`. ${declaration.collisionCure}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -56,6 +56,7 @@ export declare class StaticSite extends Construct implements IStaticSite {
|
|
|
56
56
|
constructor(scope: Construct, id: string, app: App, props: IStaticSiteProps);
|
|
57
57
|
private registerManifest;
|
|
58
58
|
private validateProps;
|
|
59
|
+
private validateRedirectHosts;
|
|
59
60
|
private createBucket;
|
|
60
61
|
private deploySiteAssets;
|
|
61
62
|
/**
|
|
@@ -42,11 +42,14 @@ import { Code, Runtime, Architecture, FunctionUrlAuthType, HttpMethod } from "aw
|
|
|
42
42
|
import { PolicyStatement, Effect } from "aws-cdk-lib/aws-iam";
|
|
43
43
|
import { AllowedMethods, PriceClass } from "aws-cdk-lib/aws-cloudfront";
|
|
44
44
|
import { CloudFrontTarget } from "aws-cdk-lib/aws-route53-targets";
|
|
45
|
-
import {
|
|
45
|
+
import { defaultFormsCorsOrigin, defaultFormsFromAddress, isAddressAtDomain, VALUE_NOT_REPEATED } from "@fjall/util";
|
|
46
46
|
import { hasDeployableContent } from "@fjall/util/staticSiteOutput";
|
|
47
47
|
import { StorageFactory } from "./storage.js";
|
|
48
48
|
import { CdnFactory } from "./cdn.js";
|
|
49
49
|
import { assertBehaviorRecord, SecurityHeadersPolicy } from "../../resources/aws/cdn/index.js";
|
|
50
|
+
import { hostConstructKey } from "../../utils/hostConstructKey.js";
|
|
51
|
+
import { recordLabelWithin } from "../../utils/domainTypes.js";
|
|
52
|
+
import { validateRedirectHosts } from "./redirectHosts.js";
|
|
50
53
|
import { NONCURRENT_VERSION_EXPIRY_DAYS } from "../../resources/aws/storage/index.js";
|
|
51
54
|
import { LambdaFunction, tierOrScope } from "../../resources/aws/compute/index.js";
|
|
52
55
|
import { AliasRecord } from "../../resources/aws/networking/index.js";
|
|
@@ -81,12 +84,9 @@ const UNREQUESTED_HSTS = {
|
|
|
81
84
|
};
|
|
82
85
|
/** The path the contact form's behaviour takes on the distribution. */
|
|
83
86
|
const FORMS_PATH_PATTERN = "/api/contact*";
|
|
84
|
-
/**
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
return DNS_APEX;
|
|
88
|
-
const suffix = `.${zoneName}`;
|
|
89
|
-
return domain.endsWith(suffix) ? domain.slice(0, -suffix.length) : domain;
|
|
87
|
+
/** The construct id of a redirect host's alias record in the CDN stack. */
|
|
88
|
+
function redirectRecordIdFor(pascalName) {
|
|
89
|
+
return (hostKey) => `${pascalName}${hostKey}RedirectAliasRecord`;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* Static-site pattern implementation.
|
|
@@ -137,6 +137,7 @@ export class StaticSite extends Construct {
|
|
|
137
137
|
if (typeof hsts === "object")
|
|
138
138
|
refuseRenamed("HstsConfig", hsts);
|
|
139
139
|
assertBehaviorRecord(`Static site '${this.props.name}'`, this.props.cdn?.additionalBehaviors);
|
|
140
|
+
this.validateRedirectHosts();
|
|
140
141
|
const forms = this.props.forms;
|
|
141
142
|
if (!forms)
|
|
142
143
|
return;
|
|
@@ -161,6 +162,26 @@ export class StaticSite extends Construct {
|
|
|
161
162
|
`and may be any address. ${VALUE_NOT_REPEATED}`);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
165
|
+
validateRedirectHosts() {
|
|
166
|
+
const hosts = this.props.redirectHosts ?? [];
|
|
167
|
+
if (hosts.length === 0)
|
|
168
|
+
return;
|
|
169
|
+
const domain = this.props.domain;
|
|
170
|
+
if (domain === undefined || domain === "") {
|
|
171
|
+
throw new Error(`Static site '${this.props.name}' sets 'redirectHosts' but no ` +
|
|
172
|
+
"'domain'. Each host redirects to the domain, so set 'domain' " +
|
|
173
|
+
"alongside 'redirectHosts'.");
|
|
174
|
+
}
|
|
175
|
+
validateRedirectHosts({
|
|
176
|
+
context: `Static site '${this.props.name}'`,
|
|
177
|
+
hostsField: "'redirectHosts'",
|
|
178
|
+
domainField: "'domain'",
|
|
179
|
+
domain,
|
|
180
|
+
hosts,
|
|
181
|
+
collisionCure: "Keep one of them on this site.",
|
|
182
|
+
recordId: redirectRecordIdFor(this.pascalName)
|
|
183
|
+
});
|
|
184
|
+
}
|
|
164
185
|
createBucket() {
|
|
165
186
|
// No `deployment` here — assets deploy via deploySiteAssets() once the
|
|
166
187
|
// distribution exists, so the upload can invalidate it.
|
|
@@ -301,7 +322,7 @@ export class StaticSite extends Construct {
|
|
|
301
322
|
})
|
|
302
323
|
});
|
|
303
324
|
}
|
|
304
|
-
createCdn({ domainNames, certificate }) {
|
|
325
|
+
createCdn({ domainNames, certificate, hostRedirect }) {
|
|
305
326
|
const headersPolicy = this.responseHeadersPolicy;
|
|
306
327
|
const additionalBehaviors = this.buildAdditionalBehaviors();
|
|
307
328
|
const cdnProps = {
|
|
@@ -327,6 +348,7 @@ export class StaticSite extends Construct {
|
|
|
327
348
|
priceClass: this.props.cdn?.priceClass ?? PriceClass.PRICE_CLASS_100,
|
|
328
349
|
domainNames,
|
|
329
350
|
certificate,
|
|
351
|
+
...(hostRedirect !== undefined && { hostRedirect }),
|
|
330
352
|
...(this.props.cdn?.logging !== undefined && {
|
|
331
353
|
logging: this.props.cdn.logging
|
|
332
354
|
}),
|
|
@@ -381,11 +403,13 @@ export class StaticSite extends Construct {
|
|
|
381
403
|
domainNames: undefined,
|
|
382
404
|
certificate: undefined,
|
|
383
405
|
hostedZone: undefined,
|
|
384
|
-
zoneName: undefined
|
|
406
|
+
zoneName: undefined,
|
|
407
|
+
hostRedirect: undefined
|
|
385
408
|
};
|
|
386
409
|
return this._resolvedDomain;
|
|
387
410
|
}
|
|
388
411
|
resolveSimpleDomain(domain) {
|
|
412
|
+
const hosts = this.props.redirectHosts ?? [];
|
|
389
413
|
// Zone identity is explicit only, and the domain is validated against the
|
|
390
414
|
// declared zone; the CloudFront certificate is the binding's literal
|
|
391
415
|
// us-east-1 ARN or an app-owned us-east-1 certificate (design H2 + H3/D3
|
|
@@ -400,15 +424,17 @@ export class StaticSite extends Construct {
|
|
|
400
424
|
managedDomain: this.props.managedDomain,
|
|
401
425
|
zoneName: this.props.zoneName,
|
|
402
426
|
hostedZoneId: this.props.hostedZoneId
|
|
403
|
-
}
|
|
427
|
+
},
|
|
428
|
+
...(hosts.length > 0 && { alternateNames: hosts })
|
|
404
429
|
};
|
|
405
430
|
const zone = resolvePatternZone(request);
|
|
406
431
|
const certificate = resolvePatternCloudFrontCertificate(request, zone);
|
|
407
432
|
return {
|
|
408
|
-
domainNames: [domain],
|
|
433
|
+
domainNames: [domain, ...hosts],
|
|
409
434
|
certificate,
|
|
410
435
|
hostedZone: zone.hostedZone,
|
|
411
|
-
zoneName: zone.zoneName
|
|
436
|
+
zoneName: zone.zoneName,
|
|
437
|
+
hostRedirect: hosts.length > 0 ? { hosts, targetHost: domain } : undefined
|
|
412
438
|
};
|
|
413
439
|
}
|
|
414
440
|
createDnsRecord() {
|
|
@@ -416,6 +442,7 @@ export class StaticSite extends Construct {
|
|
|
416
442
|
return;
|
|
417
443
|
// The zone's owner declares the record; createCdn has already claimed
|
|
418
444
|
// `domain` and its certificate on the distribution.
|
|
445
|
+
const hosts = this.props.redirectHosts ?? [];
|
|
419
446
|
if (this.props.domainRecord === "none") {
|
|
420
447
|
this.cdn.declareZoneOwnedRecord(this.props.domain);
|
|
421
448
|
return;
|
|
@@ -426,12 +453,19 @@ export class StaticSite extends Construct {
|
|
|
426
453
|
// Alias record lives in the CDN stack (where the distribution is) so there
|
|
427
454
|
// is no cross-stack cycle back to this pattern node.
|
|
428
455
|
const cdnStack = this.app.getDefaultCdnStack().getStack();
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
456
|
+
const aliasTo = (constructId, host) => {
|
|
457
|
+
new AliasRecord(cdnStack, constructId, {
|
|
458
|
+
zone: hostedZone,
|
|
459
|
+
zoneName,
|
|
460
|
+
recordName: recordLabelWithin(host, zoneName),
|
|
461
|
+
target: new CloudFrontTarget(this.cdn.distribution)
|
|
462
|
+
});
|
|
463
|
+
};
|
|
464
|
+
aliasTo(`${this.pascalName}AliasRecord`, this.props.domain);
|
|
465
|
+
const recordId = redirectRecordIdFor(this.pascalName);
|
|
466
|
+
for (const host of hosts) {
|
|
467
|
+
aliasTo(recordId(hostConstructKey(host)), host);
|
|
468
|
+
}
|
|
435
469
|
}
|
|
436
470
|
}
|
|
437
471
|
installRenamedAccessorStubs(StaticSite, "StaticSite");
|
|
@@ -202,6 +202,8 @@ export declare class CloudFrontDistribution extends Construct {
|
|
|
202
202
|
readonly distributionId: string;
|
|
203
203
|
/** `fjallCdn`'s first argument for this distribution: the app it fronts. */
|
|
204
204
|
private readonly aliasAppName;
|
|
205
|
+
/** The hosts this distribution redirects, once validated. */
|
|
206
|
+
private readonly hostRedirect;
|
|
205
207
|
private readonly origins;
|
|
206
208
|
/** Shared S3 access identities, keyed by the owning stack (see
|
|
207
209
|
* `s3OriginAccessIdentityFor` for why the key is a Stack). */
|
|
@@ -267,7 +269,8 @@ export declare class CloudFrontDistribution extends Construct {
|
|
|
267
269
|
* stack then outputs the domain with the `fjallCdn` arguments whose record
|
|
268
270
|
* targets this distribution, the same ones its domain-name export is named
|
|
269
271
|
* from (`ZoneOwnedRecordOutputSchema` in `@fjall/util`), and a deploy's next
|
|
270
|
-
* steps read them there
|
|
272
|
+
* steps read them there, with the hosts this distribution redirects, whose
|
|
273
|
+
* records the zone's owner declares too.
|
|
271
274
|
*/
|
|
272
275
|
declareZoneOwnedRecord(domain: string): void;
|
|
273
276
|
}
|
|
@@ -132,6 +132,8 @@ export class CloudFrontDistribution extends Construct {
|
|
|
132
132
|
distributionId;
|
|
133
133
|
/** `fjallCdn`'s first argument for this distribution: the app it fronts. */
|
|
134
134
|
aliasAppName;
|
|
135
|
+
/** The hosts this distribution redirects, once validated. */
|
|
136
|
+
hostRedirect;
|
|
135
137
|
origins = new Map();
|
|
136
138
|
/** Shared S3 access identities, keyed by the owning stack (see
|
|
137
139
|
* `s3OriginAccessIdentityFor` for why the key is a Stack). */
|
|
@@ -163,6 +165,7 @@ export class CloudFrontDistribution extends Construct {
|
|
|
163
165
|
if (props.hostRedirect !== undefined) {
|
|
164
166
|
validateHostRedirect(`CloudFront distribution '${id}'`, props.hostRedirect, props.domainNames);
|
|
165
167
|
}
|
|
168
|
+
this.hostRedirect = props.hostRedirect;
|
|
166
169
|
// Build composable viewer request function (accessGate + hostRedirect +
|
|
167
170
|
// forwardHostHeader + uriRewrite)
|
|
168
171
|
const viewerRequestFunction = this.buildViewerRequestFunction(id, props.forwardHostHeader, props.accessGate, props.uriRewrite, props.hostRedirect);
|
|
@@ -488,9 +491,11 @@ export class CloudFrontDistribution extends Construct {
|
|
|
488
491
|
* stack then outputs the domain with the `fjallCdn` arguments whose record
|
|
489
492
|
* targets this distribution, the same ones its domain-name export is named
|
|
490
493
|
* from (`ZoneOwnedRecordOutputSchema` in `@fjall/util`), and a deploy's next
|
|
491
|
-
* steps read them there
|
|
494
|
+
* steps read them there, with the hosts this distribution redirects, whose
|
|
495
|
+
* records the zone's owner declares too.
|
|
492
496
|
*/
|
|
493
497
|
declareZoneOwnedRecord(domain) {
|
|
498
|
+
const redirect = this.hostRedirect;
|
|
494
499
|
declareStackOutput(this, {
|
|
495
500
|
owner: this.id,
|
|
496
501
|
attribute: "ZoneOwnedRecord",
|
|
@@ -498,7 +503,8 @@ export class CloudFrontDistribution extends Construct {
|
|
|
498
503
|
value: zoneOwnedRecordOutputValue({
|
|
499
504
|
domain,
|
|
500
505
|
appName: this.aliasAppName,
|
|
501
|
-
cdnName: this.id
|
|
506
|
+
cdnName: this.id,
|
|
507
|
+
...(redirect !== undefined && { redirectHosts: [...redirect.hosts] })
|
|
502
508
|
}),
|
|
503
509
|
description: `Custom domain of ${this.id} whose Route 53 record the zone's owner declares, with the fjallCdn arguments whose record targets it; a deploy reads it for its next steps`
|
|
504
510
|
});
|
|
@@ -28,11 +28,11 @@ export declare function validateHostRedirect(context: string, redirect: CloudFro
|
|
|
28
28
|
* CloudFront hands the function a parsed query string, never the raw one, so
|
|
29
29
|
* the fragment rebuilds it from the `querystring` object, joining each name
|
|
30
30
|
* and value as received, the way AWS's own CloudFront Functions examples do
|
|
31
|
-
* (read 8 November 2026).
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
31
|
+
* (read 8 November 2026). A probe distribution measured on 22 November 2026
|
|
32
|
+
* returned every name and value as sent, still encoded, with each name's
|
|
33
|
+
* values together in the order sent. The order of the names is CloudFront's
|
|
34
|
+
* own, so `?a=1&b=2` redirected with `?b=2&a=1`. A parameter with an empty
|
|
35
|
+
* value comes back without its `=`, because the parsed object reads `?a` and
|
|
36
|
+
* `?a=` the same way.
|
|
37
37
|
*/
|
|
38
38
|
export declare function hostRedirectFragment(redirect: CloudFrontHostRedirect): string;
|
|
@@ -44,12 +44,12 @@ export function validateHostRedirect(context, redirect, domainNames) {
|
|
|
44
44
|
* CloudFront hands the function a parsed query string, never the raw one, so
|
|
45
45
|
* the fragment rebuilds it from the `querystring` object, joining each name
|
|
46
46
|
* and value as received, the way AWS's own CloudFront Functions examples do
|
|
47
|
-
* (read 8 November 2026).
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
47
|
+
* (read 8 November 2026). A probe distribution measured on 22 November 2026
|
|
48
|
+
* returned every name and value as sent, still encoded, with each name's
|
|
49
|
+
* values together in the order sent. The order of the names is CloudFront's
|
|
50
|
+
* own, so `?a=1&b=2` redirected with `?b=2&a=1`. A parameter with an empty
|
|
51
|
+
* value comes back without its `=`, because the parsed object reads `?a` and
|
|
52
|
+
* `?a=` the same way.
|
|
53
53
|
*/
|
|
54
54
|
export function hostRedirectFragment(redirect) {
|
|
55
55
|
return (" var redirectHost = request.headers.host ? request.headers.host.value.toLowerCase().replace(/\\.?(:\\d+)?$/, '') : '';" +
|
|
@@ -3,8 +3,8 @@ import { Construct } from "constructs";
|
|
|
3
3
|
* The stack's one CI OIDC provider handler, and one custom resource for each
|
|
4
4
|
* issuer an identity in the stack trusts. Each custom resource adopts or
|
|
5
5
|
* creates the account's provider for its issuer and answers its ARN
|
|
6
|
-
* (`
|
|
7
|
-
* the issuers the stack names.
|
|
6
|
+
* (`lambda-assets/ci-oidc-provider/src/index.cjs`). The handler may write
|
|
7
|
+
* only the providers of the issuers the stack names.
|
|
8
8
|
*/
|
|
9
9
|
export declare class OidcProviderAdoption extends Construct {
|
|
10
10
|
/** The stack's adoption, made on first use. */
|