Skip to content

Commit d5b7622

Browse files
authored
fix: remove geolocation allowlist in favour of suppression (#747)
1 parent 383d6b8 commit d5b7622

File tree

14 files changed

+414
-316
lines changed

14 files changed

+414
-316
lines changed

packages/infrastructure/samples/infrastructure/java/src/java/groupId/constructs/websites/WebsiteConstruct.java.mustache

+8-13
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import java.util.Map;
44
import java.util.TreeMap;
55

66
import software.amazon.awscdk.Stack;
7-
import software.amazon.awscdk.services.cloudfront.GeoRestriction;
7+
import io.github.cdklabs.cdknag.NagSuppressions;
8+
import io.github.cdklabs.cdknag.NagPackSuppression;
89
import software.aws.pdk.identity.UserIdentity;
9-
import software.aws.pdk.static_website.DistributionProps;
1010
import software.aws.pdk.static_website.RuntimeOptions;
1111
import software.aws.pdk.static_website.StaticWebsite;
1212
import software.aws.pdk.static_website.StaticWebsiteProps;
@@ -23,7 +23,7 @@ public class {{{websiteName}}} extends Construct {
2323
public {{{websiteName}}}(Construct scope, String id, UserIdentity userIdentity{{#typeSafeApis}}, {{{apiName}}} {{{apiNameLowercase}}}{{/typeSafeApis}}) {
2424
super(scope, id);
2525
26-
new StaticWebsite(this, id, StaticWebsiteProps.builder()
26+
StaticWebsite website = new StaticWebsite(this, id, StaticWebsiteProps.builder()
2727
.websiteContentPath("{{{websiteDistRelativePath}}}")
2828
.runtimeOptions(RuntimeOptions.builder()
2929
.jsonPayload(new TreeMap<>(Map.of(
@@ -38,16 +38,11 @@ public class {{{websiteName}}} extends Construct {
3838
)
3939
)))
4040
.build())
41-
.distributionProps(DistributionProps.builder()
42-
.geoRestriction(GeoRestriction.allowlist(
43-
"AU",
44-
"ID",
45-
"IN",
46-
"JP",
47-
"KR",
48-
"SG",
49-
"US"))
50-
.build())
5141
.build());
42+
43+
NagSuppressions.addResourceSuppressions(website, Arrays.asList(NagPackSuppression.builder()
44+
.id("AwsPrototyping-CloudFrontDistributionGeoRestrictions")
45+
.reason("Suppressed to allow unrestricted access. Not recommended in production.")
46+
.build()), true);
5247
}
5348
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from aws_cdk import Stack
2+
from cdk_nag import NagSuppressions, NagPackSuppression
23
from constructs import Construct
34
from aws_cdk.aws_cloudfront import GeoRestriction
45
{{#typeSafeApis}}
@@ -12,7 +13,7 @@ class {{{websiteName}}}(Construct):
1213
def __init__(self, scope: Construct, id: str, user_identity: UserIdentity{{#typeSafeApis}}, {{{apiNameLowercase}}}: {{{apiName}}}{{/typeSafeApis}}, **kwargs) -> None:
1314
super().__init__(scope, id, **kwargs)
1415

15-
StaticWebsite(self, id,
16+
website = StaticWebsite(self, id,
1617
website_content_path='{{{websiteDistRelativePath}}}',
1718
runtime_options=RuntimeOptions(
1819
json_payload={
@@ -23,14 +24,6 @@ class {{{websiteName}}}(Construct):
2324
'typeSafeApis': { {{#typeSafeApis}}'{{{apiName}}}': {{{apiNameLowercase}}}.api.api.url_for_path(){{^isLast}}, {{/isLast}}{{/typeSafeApis}} }
2425
}
2526
),
26-
distribution_props=DistributionProps(
27-
geo_restriction=GeoRestriction.allowlist(
28-
"AU",
29-
"ID",
30-
"IN",
31-
"JP",
32-
"KR",
33-
"SG",
34-
"US"
35-
)
36-
))
27+
)
28+
29+
NagSuppressions.add_resource_suppressions(website, [NagPackSuppression(id='AwsPrototyping-CloudFrontDistributionGeoRestrictions', reason='Suppressed to allow unrestricted access. Not recommended in production.')], True)

packages/infrastructure/samples/infrastructure/typescript/src/constructs/websites/website.ts.mustache

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { UserIdentity } from "@aws/pdk/identity";
22
import { StaticWebsite } from "@aws/pdk/static-website";
33
import { Stack } from "aws-cdk-lib";
4-
import { GeoRestriction } from "aws-cdk-lib/aws-cloudfront";
4+
import { NagSuppressions } from "cdk-nag";
55
import { Construct } from "constructs";
66
{{#typeSafeApis}}
77
import { {{{apiName}}} } from "../apis/{{{apiNameLowercase}}}";
@@ -53,17 +53,18 @@ export class {{{websiteName}}} extends Construct {
5353
typeSafeWebSocketApis: { {{#typeSafeWebSocketApis}}{{{apiName}}}: props?.{{{apiNameLowercase}}}.api.defaultStage.url{{^isLast}},{{/isLast}}{{/typeSafeWebSocketApis}} },
5454
},
5555
},
56-
distributionProps: {
57-
geoRestriction: GeoRestriction.allowlist(
58-
"AU",
59-
"ID",
60-
"IN",
61-
"JP",
62-
"KR",
63-
"SG",
64-
"US",
65-
),
66-
},
6756
});
57+
58+
NagSuppressions.addResourceSuppressions(
59+
website,
60+
[
61+
{
62+
id: "AwsPrototyping-CloudFrontDistributionGeoRestrictions",
63+
reason:
64+
"Suppressed to allow unrestricted access. Not recommended in production.",
65+
},
66+
],
67+
true,
68+
);
6869
}
6970
}

packages/infrastructure/src/projects/java/infrastructure-java-project.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ export class InfrastructureJavaProject extends AwsCdkJavaApp {
8282
"software.constructs/constructs",
8383
DependencyType.RUNTIME
8484
);
85-
this.addDependency("software.constructs/[email protected]");
85+
[
86+
"software.constructs/[email protected]",
87+
"io.github.cdklabs/[email protected]",
88+
].forEach((d) => this.addDependency(d));
8689

8790
InfrastructureCommands.ensure(this);
8891

packages/infrastructure/src/projects/python/infrastructure-py-project.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export class InfrastructurePyProject extends AwsCdkPythonApp {
8282
["pytest@^7", "syrupy@^4"].forEach((devDep) =>
8383
this.addDevDependency(devDep)
8484
);
85-
["aws_pdk@^0", "python@^3.9"].forEach((dep) => this.addDependency(dep));
85+
["aws_pdk@^0", "cdk_nag@^2", "python@^3.9"].forEach((dep) =>
86+
this.addDependency(dep)
87+
);
8688

8789
const srcDir = path.resolve(
8890
__dirname,

packages/infrastructure/src/projects/typescript/infrastructure-ts-project.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class InfrastructureTsProject extends AwsCdkTypeScriptApp {
8686

8787
InfrastructureCommands.ensure(this);
8888

89-
this.addDeps("@aws/pdk");
89+
this.addDeps("@aws/pdk", "cdk-nag");
9090

9191
const srcDir = path.resolve(
9292
__dirname,

0 commit comments

Comments
 (0)