@friggframework/devtools 2.0.0--canary.744.e18e27f.0 → 2.0.0--canary.745.0209482d.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 (30) hide show
  1. package/frigg-cli/README.md +41 -1
  2. package/frigg-cli/generate-command/__tests__/generate-command.test.js +36 -0
  3. package/frigg-cli/generate-command/index.js +3 -1
  4. package/frigg-cli/generate-command/terraform-generator.js +48 -0
  5. package/frigg-cli/generate-iam-command.js +1 -0
  6. package/frigg-cli/index.js +8 -0
  7. package/frigg-cli/templates/backend/README.md +3 -2
  8. package/frigg-cli/tls-check-command/__tests__/check-post-quantum-tls.test.js +396 -0
  9. package/frigg-cli/tls-check-command/__tests__/tls-check-command.test.js +182 -0
  10. package/frigg-cli/tls-check-command/check-post-quantum-tls.js +194 -0
  11. package/frigg-cli/tls-check-command/index.js +136 -0
  12. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +69 -0
  13. package/frigg-cli/validate-command/checks/config.js +59 -0
  14. package/infrastructure/app-definition-schema-contract.test.js +10 -0
  15. package/infrastructure/domains/admin-scripts/admin-script-builder.js +8 -16
  16. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -27
  17. package/infrastructure/domains/edge/cloudfront-builder.js +237 -0
  18. package/infrastructure/domains/edge/cloudfront-builder.test.js +273 -0
  19. package/infrastructure/domains/security/iam-generator.js +45 -2
  20. package/infrastructure/domains/security/iam-generator.test.js +23 -0
  21. package/infrastructure/domains/security/templates/iam-policy-full.json +30 -1
  22. package/infrastructure/domains/shared/builder-orchestrator.js +6 -0
  23. package/infrastructure/domains/shared/builder-orchestrator.test.js +30 -0
  24. package/infrastructure/domains/shared/function-environments.js +6 -10
  25. package/infrastructure/domains/shared/function-environments.test.js +0 -9
  26. package/infrastructure/domains/shared/utilities/base-definition-factory.js +9 -2
  27. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +11 -0
  28. package/infrastructure/infrastructure-composer.js +8 -0
  29. package/infrastructure/infrastructure-composer.test.js +35 -0
  30. package/package.json +7 -7
@@ -33,9 +33,7 @@ class AdminScriptBuilder extends InfrastructureBuilder {
33
33
  appDefinition.reports.length > 0;
34
34
  const hasBuiltinReports =
35
35
  appDefinition.admin?.includeBuiltinReports === true;
36
- const hasBuiltinScripts =
37
- appDefinition.admin?.includeBuiltinScripts === true;
38
- return hasScripts || hasReports || hasBuiltinReports || hasBuiltinScripts;
36
+ return hasScripts || hasReports || hasBuiltinReports;
39
37
  }
40
38
 
41
39
  getDependencies() {
@@ -85,10 +83,6 @@ class AdminScriptBuilder extends InfrastructureBuilder {
85
83
  : [];
86
84
  const hasReports =
87
85
  reports.length > 0 || adminConfig.includeBuiltinReports === true;
88
- // The built-in scripts (registered at runtime by the admin-scripts
89
- // bootstrap) need the same queue, executor and routes as app scripts.
90
- const hasScripts =
91
- adminScripts.length > 0 || adminConfig.includeBuiltinScripts === true;
92
86
 
93
87
  // Only non-JSON report output is stored in S3, so provision the bucket
94
88
  // only for that. Built-in reports emit JSON, so they don't trigger it.
@@ -105,13 +99,8 @@ class AdminScriptBuilder extends InfrastructureBuilder {
105
99
  iamStatements: [],
106
100
  };
107
101
 
108
- if (hasScripts) {
109
- const builtinNote = adminConfig.includeBuiltinScripts
110
- ? ' and the built-in scripts'
111
- : '';
112
- console.log(
113
- ` Processing ${adminScripts.length} app scripts${builtinNote}...`
114
- );
102
+ if (adminScripts.length > 0) {
103
+ console.log(` Processing ${adminScripts.length} scripts...`);
115
104
  this.createAdminScriptQueue(result, appDefinition);
116
105
  this.createScriptExecutorFunction(appDefinition, result, usePrismaLayer);
117
106
  this.createAdminScriptRoutes(appDefinition, result, usePrismaLayer);
@@ -138,9 +127,12 @@ class AdminScriptBuilder extends InfrastructureBuilder {
138
127
  }
139
128
  }
140
129
 
141
- if (adminConfig.enableScheduling && (hasScripts || hasReports)) {
130
+ if (
131
+ adminConfig.enableScheduling &&
132
+ (adminScripts.length > 0 || hasReports)
133
+ ) {
142
134
  this.createSchedulerResources(appDefinition, result, {
143
- scriptsPresent: hasScripts,
135
+ scriptsPresent: adminScripts.length > 0,
144
136
  hasReports,
145
137
  });
146
138
  }
@@ -44,12 +44,6 @@ describe('AdminScriptBuilder', () => {
44
44
  expect(adminScriptBuilder.shouldExecute(appDefinition)).toBe(true);
45
45
  });
46
46
 
47
- it('should return true when only the built-in scripts are enabled', () => {
48
- expect(
49
- adminScriptBuilder.shouldExecute({ admin: { includeBuiltinScripts: true } })
50
- ).toBe(true);
51
- });
52
-
53
47
  it('should return false when adminScripts is not an array', () => {
54
48
  const appDefinition = {
55
49
  adminScripts: { name: 'test' },
@@ -748,27 +742,6 @@ describe('AdminScriptBuilder', () => {
748
742
  expect(result.functions.reportExecutor).toBeDefined();
749
743
  });
750
744
 
751
- it('creates the script queue, executor and routes when only the built-in scripts are enabled', async () => {
752
- const result = await adminScriptBuilder.build(
753
- { admin: { includeBuiltinScripts: true } },
754
- {}
755
- );
756
-
757
- expect(result.resources.AdminScriptQueue).toBeDefined();
758
- expect(result.functions.adminScriptExecutor).toBeDefined();
759
- expect(result.functions.adminScriptRouter).toBeDefined();
760
- });
761
-
762
- it('provisions scheduling for the built-in scripts', async () => {
763
- const result = await adminScriptBuilder.build(
764
- { admin: { includeBuiltinScripts: true, enableScheduling: true } },
765
- {}
766
- );
767
-
768
- expect(result.resources.AdminScriptQueue).toBeDefined();
769
- expect(JSON.stringify(result.resources)).toMatch(/Schedule/);
770
- });
771
-
772
745
  it('does NOT create ReportQueue or reportExecutor when only adminScripts are present', async () => {
773
746
  const appDefinition = {
774
747
  adminScripts: [{ Definition: { name: 'test-script' } }],
@@ -0,0 +1,237 @@
1
+ /**
2
+ * CloudFront Builder
3
+ *
4
+ * Domain Layer - Hexagonal Architecture
5
+ *
6
+ * Opt-in CloudFront distribution in front of the app's HTTP API.
7
+ *
8
+ * Why: API Gateway HTTP APIs support only the TLS_1_2 security policy, which
9
+ * has no post-quantum key exchange. CloudFront prefers hybrid post-quantum key
10
+ * exchange (X25519MLKEM768) on every TLS security policy for client-to-edge
11
+ * connections. With this builder, clients that use the CloudFront URL get
12
+ * post-quantum protection against "harvest now, decrypt later".
13
+ *
14
+ * Limits (documented in docs/reference/post-quantum-readiness.md):
15
+ * - The CloudFront-to-API Gateway connection is classical TLS (AWS: origin
16
+ * support is "coming soon").
17
+ * - The execute-api URL stays reachable with classical TLS.
18
+ * - The WebSocket API is not covered.
19
+ *
20
+ * Configuration (app definition):
21
+ * cloudFront: {
22
+ * enable: true,
23
+ * priceClass: 'PriceClass_100', // optional
24
+ * domainNames: ['api.example.com'], // optional, with certificateArn
25
+ * certificateArn: 'arn:aws:acm:us-east-1:...', // ACM, us-east-1 only
26
+ * }
27
+ */
28
+
29
+ const {
30
+ InfrastructureBuilder,
31
+ ValidationResult,
32
+ } = require('../shared/base-builder');
33
+
34
+ /** AWS managed cache policy "Managed-CachingDisabled". */
35
+ const CACHING_DISABLED_POLICY_ID = '4135ea2d-6df8-44a3-9df3-4b5a84be39ad';
36
+
37
+ /**
38
+ * AWS managed origin request policy "Managed-AllViewerExceptHostHeader":
39
+ * forwards all viewer headers (Authorization included), cookies and query
40
+ * strings, but not Host, which API Gateway needs to be its own host name.
41
+ */
42
+ const ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID =
43
+ 'b689b0a8-53d0-40ab-baf2-68738e2966ac';
44
+
45
+ const PRICE_CLASSES = ['PriceClass_100', 'PriceClass_200', 'PriceClass_All'];
46
+ const DEFAULT_PRICE_CLASS = 'PriceClass_100';
47
+ const ORIGIN_ID = 'FriggHttpApi';
48
+ const DISTRIBUTION_LOGICAL_ID = 'FriggCloudFrontDistribution';
49
+ const ACM_US_EAST_1_ARN =
50
+ /^arn:aws[a-z-]*:acm:us-east-1:\d{12}:certificate\/[A-Za-z0-9-]+$/;
51
+
52
+ class CloudFrontBuilder extends InfrastructureBuilder {
53
+ constructor() {
54
+ super();
55
+ this.name = 'CloudFrontBuilder';
56
+ }
57
+
58
+ shouldExecute(appDefinition) {
59
+ // Local builds (frigg start) deploy nothing to AWS.
60
+ if (process.env.FRIGG_SKIP_AWS_DISCOVERY === 'true') {
61
+ return false;
62
+ }
63
+ return appDefinition.cloudFront?.enable === true;
64
+ }
65
+
66
+ getDependencies() {
67
+ return [];
68
+ }
69
+
70
+ validate(appDefinition) {
71
+ const result = new ValidationResult();
72
+ const config = appDefinition.cloudFront || {};
73
+
74
+ if (
75
+ config.priceClass !== undefined &&
76
+ !PRICE_CLASSES.includes(config.priceClass)
77
+ ) {
78
+ result.addError(
79
+ `cloudFront.priceClass must be one of ${PRICE_CLASSES.join(
80
+ ', '
81
+ )}.`
82
+ );
83
+ }
84
+
85
+ const hasDomainNames = config.domainNames !== undefined;
86
+ const hasCertificate = config.certificateArn !== undefined;
87
+
88
+ if (
89
+ hasDomainNames &&
90
+ (!Array.isArray(config.domainNames) ||
91
+ config.domainNames.length === 0 ||
92
+ !config.domainNames.every(
93
+ (name) => typeof name === 'string' && name.length > 0
94
+ ))
95
+ ) {
96
+ result.addError(
97
+ 'cloudFront.domainNames must be a non-empty list of host names.'
98
+ );
99
+ }
100
+ if (hasDomainNames && !hasCertificate) {
101
+ result.addError(
102
+ 'cloudFront.domainNames needs cloudFront.certificateArn (an ACM certificate in us-east-1).'
103
+ );
104
+ }
105
+ if (hasCertificate && !hasDomainNames) {
106
+ result.addError(
107
+ 'cloudFront.certificateArn needs cloudFront.domainNames.'
108
+ );
109
+ }
110
+ if (
111
+ hasCertificate &&
112
+ !ACM_US_EAST_1_ARN.test(String(config.certificateArn))
113
+ ) {
114
+ result.addError(
115
+ 'cloudFront.certificateArn must be an ACM certificate ARN in us-east-1. CloudFront reads certificates only from us-east-1.'
116
+ );
117
+ }
118
+
119
+ return result;
120
+ }
121
+
122
+ async build(appDefinition) {
123
+ console.log(
124
+ `\n[${this.name}] Configuring CloudFront in front of the HTTP API...`
125
+ );
126
+ const config = appDefinition.cloudFront || {};
127
+ const hasCustomDomain =
128
+ Array.isArray(config.domainNames) && config.domainNames.length > 0;
129
+
130
+ const distributionConfig = {
131
+ Enabled: true,
132
+ // CloudFront allows 128 characters; a stack name is at most 128.
133
+ Comment: '${self:service}-${self:provider.stage}',
134
+ HttpVersion: 'http2and3',
135
+ IPV6Enabled: true,
136
+ PriceClass: config.priceClass || DEFAULT_PRICE_CLASS,
137
+ Origins: [
138
+ {
139
+ Id: ORIGIN_ID,
140
+ DomainName: {
141
+ 'Fn::Join': [
142
+ '',
143
+ [
144
+ { Ref: 'HttpApi' },
145
+ '.execute-api.',
146
+ { Ref: 'AWS::Region' },
147
+ '.amazonaws.com',
148
+ ],
149
+ ],
150
+ },
151
+ CustomOriginConfig: {
152
+ OriginProtocolPolicy: 'https-only',
153
+ OriginSSLProtocols: ['TLSv1.2'],
154
+ // API Gateway ends HTTP API requests after 30 s.
155
+ OriginReadTimeout: 30,
156
+ OriginKeepaliveTimeout: 5,
157
+ },
158
+ },
159
+ ],
160
+ DefaultCacheBehavior: {
161
+ TargetOriginId: ORIGIN_ID,
162
+ ViewerProtocolPolicy: 'https-only',
163
+ AllowedMethods: [
164
+ 'GET',
165
+ 'HEAD',
166
+ 'OPTIONS',
167
+ 'PUT',
168
+ 'PATCH',
169
+ 'POST',
170
+ 'DELETE',
171
+ ],
172
+ CachedMethods: ['GET', 'HEAD'],
173
+ CachePolicyId: CACHING_DISABLED_POLICY_ID,
174
+ OriginRequestPolicyId: ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID,
175
+ },
176
+ ViewerCertificate: hasCustomDomain
177
+ ? {
178
+ AcmCertificateArn: config.certificateArn,
179
+ SslSupportMethod: 'sni-only',
180
+ MinimumProtocolVersion: 'TLSv1.2_2021',
181
+ }
182
+ : { CloudFrontDefaultCertificate: true },
183
+ };
184
+
185
+ if (hasCustomDomain) {
186
+ distributionConfig.Aliases = [...config.domainNames];
187
+ }
188
+
189
+ console.log(
190
+ ` ✓ CloudFront distribution (${distributionConfig.PriceClass}${
191
+ hasCustomDomain ? `, ${config.domainNames.join(', ')}` : ''
192
+ })`
193
+ );
194
+
195
+ return {
196
+ resources: {
197
+ [DISTRIBUTION_LOGICAL_ID]: {
198
+ Type: 'AWS::CloudFront::Distribution',
199
+ Properties: { DistributionConfig: distributionConfig },
200
+ },
201
+ },
202
+ outputs: {
203
+ FriggCloudFrontUrl: {
204
+ Description:
205
+ 'Public URL of the app through CloudFront (hybrid post-quantum TLS for clients)',
206
+ Value: {
207
+ 'Fn::Join': [
208
+ '',
209
+ [
210
+ 'https://',
211
+ {
212
+ 'Fn::GetAtt': [
213
+ DISTRIBUTION_LOGICAL_ID,
214
+ 'DomainName',
215
+ ],
216
+ },
217
+ ],
218
+ ],
219
+ },
220
+ },
221
+ FriggCloudFrontDistributionId: {
222
+ Description: 'CloudFront distribution id',
223
+ Value: { Ref: DISTRIBUTION_LOGICAL_ID },
224
+ },
225
+ },
226
+ iamStatements: [],
227
+ functions: {},
228
+ environment: {},
229
+ };
230
+ }
231
+ }
232
+
233
+ module.exports = {
234
+ CloudFrontBuilder,
235
+ CACHING_DISABLED_POLICY_ID,
236
+ ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID,
237
+ };
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Tests for the CloudFront edge builder: an opt-in CloudFront distribution in
3
+ * front of the HTTP API, so that clients get hybrid post-quantum TLS key
4
+ * exchange (API Gateway HTTP APIs support only the classical TLS_1_2 policy).
5
+ */
6
+
7
+ const {
8
+ CloudFrontBuilder,
9
+ CACHING_DISABLED_POLICY_ID,
10
+ ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID,
11
+ } = require('./cloudfront-builder');
12
+
13
+ const CERT_ARN =
14
+ 'arn:aws:acm:us-east-1:123456789012:certificate/0f1e2d3c-4b5a-6978-8a9b-0c1d2e3f4a5b';
15
+
16
+ describe('CloudFrontBuilder', () => {
17
+ let builder;
18
+ const originalSkipDiscovery = process.env.FRIGG_SKIP_AWS_DISCOVERY;
19
+
20
+ beforeEach(() => {
21
+ builder = new CloudFrontBuilder();
22
+ delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
23
+ });
24
+
25
+ afterEach(() => {
26
+ if (originalSkipDiscovery === undefined) {
27
+ delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
28
+ } else {
29
+ process.env.FRIGG_SKIP_AWS_DISCOVERY = originalSkipDiscovery;
30
+ }
31
+ });
32
+
33
+ describe('shouldExecute()', () => {
34
+ it('runs only when cloudFront.enable is true', () => {
35
+ expect(
36
+ builder.shouldExecute({ cloudFront: { enable: true } })
37
+ ).toBe(true);
38
+ expect(
39
+ builder.shouldExecute({ cloudFront: { enable: false } })
40
+ ).toBe(false);
41
+ expect(builder.shouldExecute({})).toBe(false);
42
+ });
43
+
44
+ it('skips local builds', () => {
45
+ process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
46
+ expect(
47
+ builder.shouldExecute({ cloudFront: { enable: true } })
48
+ ).toBe(false);
49
+ });
50
+
51
+ it('has no builder dependencies (osls creates the HttpApi)', () => {
52
+ expect(builder.getDependencies()).toEqual([]);
53
+ expect(builder.getName()).toBe('CloudFrontBuilder');
54
+ });
55
+ });
56
+
57
+ describe('validate()', () => {
58
+ it('accepts the minimal configuration', () => {
59
+ const result = builder.validate({ cloudFront: { enable: true } });
60
+ expect(result.errors).toEqual([]);
61
+ });
62
+
63
+ it('accepts a custom domain with a us-east-1 ACM certificate', () => {
64
+ const result = builder.validate({
65
+ cloudFront: {
66
+ enable: true,
67
+ domainNames: ['api.example.com'],
68
+ certificateArn: CERT_ARN,
69
+ priceClass: 'PriceClass_All',
70
+ },
71
+ });
72
+ expect(result.errors).toEqual([]);
73
+ });
74
+
75
+ it('refuses an unknown price class', () => {
76
+ const result = builder.validate({
77
+ cloudFront: { enable: true, priceClass: 'PriceClass_Cheap' },
78
+ });
79
+ expect(result.errors.join('\n')).toMatch(/priceClass/);
80
+ });
81
+
82
+ it('refuses domainNames without a certificateArn, and the reverse', () => {
83
+ expect(
84
+ builder
85
+ .validate({
86
+ cloudFront: {
87
+ enable: true,
88
+ domainNames: ['api.example.com'],
89
+ },
90
+ })
91
+ .errors.join('\n')
92
+ ).toMatch(/certificateArn/);
93
+ expect(
94
+ builder
95
+ .validate({
96
+ cloudFront: { enable: true, certificateArn: CERT_ARN },
97
+ })
98
+ .errors.join('\n')
99
+ ).toMatch(/domainNames/);
100
+ });
101
+
102
+ it('refuses a certificate outside us-east-1 (CloudFront reads ACM only there)', () => {
103
+ const result = builder.validate({
104
+ cloudFront: {
105
+ enable: true,
106
+ domainNames: ['api.example.com'],
107
+ certificateArn: CERT_ARN.replace('us-east-1', 'eu-west-1'),
108
+ },
109
+ });
110
+ expect(result.errors.join('\n')).toMatch(/us-east-1/);
111
+ });
112
+
113
+ it('refuses domainNames that are not a list of strings', () => {
114
+ const result = builder.validate({
115
+ cloudFront: {
116
+ enable: true,
117
+ domainNames: 'api.example.com',
118
+ certificateArn: CERT_ARN,
119
+ },
120
+ });
121
+ expect(result.errors.join('\n')).toMatch(/domainNames/);
122
+ });
123
+ });
124
+
125
+ describe('build()', () => {
126
+ it('puts a distribution in front of the HttpApi with caching disabled', async () => {
127
+ const result = await builder.build(
128
+ { cloudFront: { enable: true } },
129
+ {}
130
+ );
131
+ const distribution = result.resources.FriggCloudFrontDistribution;
132
+
133
+ expect(distribution.Type).toBe('AWS::CloudFront::Distribution');
134
+ const config = distribution.Properties.DistributionConfig;
135
+ expect(config.Enabled).toBe(true);
136
+ expect(config.PriceClass).toBe('PriceClass_100');
137
+ expect(config.HttpVersion).toBe('http2and3');
138
+
139
+ expect(config.Origins).toHaveLength(1);
140
+ const [origin] = config.Origins;
141
+ expect(origin.DomainName).toEqual({
142
+ 'Fn::Join': [
143
+ '',
144
+ [
145
+ { Ref: 'HttpApi' },
146
+ '.execute-api.',
147
+ { Ref: 'AWS::Region' },
148
+ '.amazonaws.com',
149
+ ],
150
+ ],
151
+ });
152
+ expect(origin.CustomOriginConfig).toEqual(
153
+ expect.objectContaining({
154
+ OriginProtocolPolicy: 'https-only',
155
+ OriginSSLProtocols: ['TLSv1.2'],
156
+ OriginReadTimeout: 30,
157
+ })
158
+ );
159
+
160
+ const behavior = config.DefaultCacheBehavior;
161
+ expect(behavior.TargetOriginId).toBe(origin.Id);
162
+ expect(behavior.ViewerProtocolPolicy).toBe('https-only');
163
+ expect(behavior.AllowedMethods).toEqual(
164
+ expect.arrayContaining([
165
+ 'GET',
166
+ 'HEAD',
167
+ 'OPTIONS',
168
+ 'PUT',
169
+ 'PATCH',
170
+ 'POST',
171
+ 'DELETE',
172
+ ])
173
+ );
174
+ expect(behavior.CachePolicyId).toBe(CACHING_DISABLED_POLICY_ID);
175
+ expect(behavior.OriginRequestPolicyId).toBe(
176
+ ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID
177
+ );
178
+ });
179
+
180
+ it('uses only the stack name as Comment, to stay within the 128-character limit', async () => {
181
+ const result = await builder.build({ cloudFront: { enable: true } }, {});
182
+ const config = result.resources.FriggCloudFrontDistribution.Properties.DistributionConfig;
183
+
184
+ // CloudFormation stack names are at most 128 characters.
185
+ expect(config.Comment).toBe('${self:service}-${self:provider.stage}');
186
+ });
187
+
188
+ it('uses the AWS managed policy ids for CachingDisabled and AllViewerExceptHostHeader', () => {
189
+ expect(CACHING_DISABLED_POLICY_ID).toBe(
190
+ '4135ea2d-6df8-44a3-9df3-4b5a84be39ad'
191
+ );
192
+ expect(ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID).toBe(
193
+ 'b689b0a8-53d0-40ab-baf2-68738e2966ac'
194
+ );
195
+ });
196
+
197
+ it('uses the default CloudFront certificate without a custom domain', async () => {
198
+ const result = await builder.build(
199
+ { cloudFront: { enable: true } },
200
+ {}
201
+ );
202
+ const config =
203
+ result.resources.FriggCloudFrontDistribution.Properties
204
+ .DistributionConfig;
205
+
206
+ expect(config.ViewerCertificate).toEqual({
207
+ CloudFrontDefaultCertificate: true,
208
+ });
209
+ expect(config).not.toHaveProperty('Aliases');
210
+ });
211
+
212
+ it('uses the ACM certificate, SNI and TLS 1.2+ with a custom domain', async () => {
213
+ const result = await builder.build(
214
+ {
215
+ cloudFront: {
216
+ enable: true,
217
+ domainNames: ['api.example.com'],
218
+ certificateArn: CERT_ARN,
219
+ priceClass: 'PriceClass_200',
220
+ },
221
+ },
222
+ {}
223
+ );
224
+ const config =
225
+ result.resources.FriggCloudFrontDistribution.Properties
226
+ .DistributionConfig;
227
+
228
+ expect(config.Aliases).toEqual(['api.example.com']);
229
+ expect(config.PriceClass).toBe('PriceClass_200');
230
+ expect(config.ViewerCertificate).toEqual({
231
+ AcmCertificateArn: CERT_ARN,
232
+ SslSupportMethod: 'sni-only',
233
+ MinimumProtocolVersion: 'TLSv1.2_2021',
234
+ });
235
+ });
236
+
237
+ it('exports the public URL and the distribution id as stack outputs', async () => {
238
+ const result = await builder.build(
239
+ { cloudFront: { enable: true } },
240
+ {}
241
+ );
242
+
243
+ expect(result.outputs.FriggCloudFrontUrl.Value).toEqual({
244
+ 'Fn::Join': [
245
+ '',
246
+ [
247
+ 'https://',
248
+ {
249
+ 'Fn::GetAtt': [
250
+ 'FriggCloudFrontDistribution',
251
+ 'DomainName',
252
+ ],
253
+ },
254
+ ],
255
+ ],
256
+ });
257
+ expect(result.outputs.FriggCloudFrontDistributionId.Value).toEqual({
258
+ Ref: 'FriggCloudFrontDistribution',
259
+ });
260
+ });
261
+
262
+ it('adds no IAM statements, functions or environment to the app', async () => {
263
+ const result = await builder.build(
264
+ { cloudFront: { enable: true } },
265
+ {}
266
+ );
267
+
268
+ expect(result.iamStatements).toEqual([]);
269
+ expect(result.functions).toEqual({});
270
+ expect(result.environment).toEqual({});
271
+ });
272
+ });
273
+ });
@@ -9,7 +9,7 @@ const path = require('path');
9
9
  * granted for `*<serviceName>*`, because `frigg deploy` names the stack,
10
10
  * functions, role, queues, topics, alarms, log groups, layer and buckets
11
11
  * after the service, not after "frigg".
12
- * @param {Object} [options.features={}] - Enabled features { vpc, kms, ssm, websockets }
12
+ * @param {Object} [options.features={}] - Enabled features { vpc, kms, ssm, websockets, cloudFront }
13
13
  * @param {string} [options.userPrefix='frigg-deployment-user'] - IAM user name prefix
14
14
  * @param {string} [options.stackName='frigg-deployment-iam'] - CloudFormation stack name
15
15
  * @param {string} [options.ssmKmsKeyArn] - Customer-managed KMS key ARN for SecureString offload (appDefinition.ssm.kmsKeyArn)
@@ -28,7 +28,7 @@ function generateIAMCloudFormation(options = {}) {
28
28
  const deploymentUserName = userPrefix;
29
29
 
30
30
  // Features are already analyzed by caller (use getFeatureSummary to extract features from appDefinition)
31
- // Expected features: { vpc, kms, ssm, websockets }
31
+ // Expected features: { vpc, kms, ssm, websockets, cloudFront }
32
32
 
33
33
  // Build the CloudFormation template
34
34
  const template = {
@@ -576,6 +576,48 @@ function generateIAMCloudFormation(options = {}) {
576
576
  }
577
577
  );
578
578
 
579
+ // Opt-in CloudFront edge (cloudFront.enable): the distribution in front of
580
+ // the HTTP API that gives clients hybrid post-quantum TLS. Distribution
581
+ // ids are random, so the scope is the account's distributions.
582
+ if (features.cloudFront) {
583
+ coreStatements.push(
584
+ {
585
+ Sid: 'FriggCloudFrontDistributions',
586
+ Effect: 'Allow',
587
+ Action: [
588
+ 'cloudfront:CreateDistribution',
589
+ 'cloudfront:CreateDistributionWithTags',
590
+ 'cloudfront:UpdateDistribution',
591
+ 'cloudfront:DeleteDistribution',
592
+ 'cloudfront:GetDistribution',
593
+ 'cloudfront:GetDistributionConfig',
594
+ 'cloudfront:TagResource',
595
+ 'cloudfront:UntagResource',
596
+ 'cloudfront:ListTagsForResource',
597
+ ],
598
+ Resource: [
599
+ {
600
+ 'Fn::Sub':
601
+ 'arn:aws:cloudfront::${AWS::AccountId}:distribution/*',
602
+ },
603
+ ],
604
+ },
605
+ {
606
+ // Read-only: the AWS managed cache and origin request
607
+ // policies, and the ACM certificate of a custom domain.
608
+ Sid: 'FriggCloudFrontReadPolicies',
609
+ Effect: 'Allow',
610
+ Action: [
611
+ 'cloudfront:GetCachePolicy',
612
+ 'cloudfront:GetOriginRequestPolicy',
613
+ 'acm:DescribeCertificate',
614
+ 'acm:ListCertificates',
615
+ ],
616
+ Resource: '*',
617
+ }
618
+ );
619
+ }
620
+
579
621
  template.Resources.FriggCoreDeploymentPolicy = {
580
622
  Type: 'AWS::IAM::ManagedPolicy',
581
623
  Properties: {
@@ -899,6 +941,7 @@ function getFeatureSummary(appDefinition) {
899
941
  kms: appDefinition.encryption?.fieldLevelEncryptionMethod === 'kms',
900
942
  ssm: appDefinition.ssm?.enable === true,
901
943
  websockets: appDefinition.websockets?.enable === true,
944
+ cloudFront: appDefinition.cloudFront?.enable === true,
902
945
  };
903
946
 
904
947
  const integrationCount = appDefinition.integrations?.length || 0;