From 0532e1380793bbabd314d43dae7d2ebbaef0ca93 Mon Sep 17 00:00:00 2001 From: penghaoh Date: Fri, 8 Jul 2022 15:00:11 -0700 Subject: [PATCH 1/3] fix: wildcard should be allowed in alias --- .../testdata/workloads/backend/https-path-alias-template.yml | 4 ++-- .../stack/testdata/workloads/svc-grpc-test.stack.yml | 4 ++-- .../stack/testdata/workloads/svc-prod.stack.yml | 4 ++-- .../stack/testdata/workloads/svc-staging.stack.yml | 4 ++-- .../stack/testdata/workloads/svc-test.stack.yml | 4 ++-- .../templates/workloads/partials/cf/env-controller.yml | 2 +- .../templates/workloads/partials/cf/https-listener.yml | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-template.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-template.yml index 57d390cfb69..e5a89cfa34d 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-template.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-template.yml @@ -326,7 +326,7 @@ Resources: Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com, foobar.com, v1.foobar.com] + Values: ["example.com", "foobar.com", "v1.foobar.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If @@ -347,7 +347,7 @@ Resources: Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com, foobar.com, v1.foobar.com] + Values: ["example.com", "foobar.com", "v1.foobar.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-grpc-test.stack.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-grpc-test.stack.yml index 8275dc55918..9d36ad7ba12 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-grpc-test.stack.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-grpc-test.stack.yml @@ -524,7 +524,7 @@ Resources: # If a bucket URL is specified, that means the template exists. Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com] + Values: ["example.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If @@ -545,7 +545,7 @@ Resources: # If a bucket URL is specified, that means the template exists. Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com] + Values: ["example.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-prod.stack.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-prod.stack.yml index edac436fca4..5000bc960b5 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-prod.stack.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-prod.stack.yml @@ -611,7 +611,7 @@ Resources: # If a bucket URL is specified, that means the template exists. Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com] + Values: ["example.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If @@ -632,7 +632,7 @@ Resources: # If a bucket URL is specified, that means the template exists. Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com] + Values: ["example.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-staging.stack.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-staging.stack.yml index 03156e29e22..a089b767dcc 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-staging.stack.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-staging.stack.yml @@ -427,7 +427,7 @@ Resources: # If a bucket URL is specified, that means the template exists. Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com] + Values: ["example.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If @@ -448,7 +448,7 @@ Resources: # If a bucket URL is specified, that means the template exists. Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com] + Values: ["example.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-test.stack.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-test.stack.yml index 135e8ece177..acaeb742526 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-test.stack.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-test.stack.yml @@ -523,7 +523,7 @@ Resources: # If a bucket URL is specified, that means the template exists. Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com] + Values: ["example.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If @@ -544,7 +544,7 @@ Resources: # If a bucket URL is specified, that means the template exists. Conditions: - Field: 'host-header' HostHeaderConfig: - Values: [example.com] + Values: ["example.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If diff --git a/internal/pkg/template/templates/workloads/partials/cf/env-controller.yml b/internal/pkg/template/templates/workloads/partials/cf/env-controller.yml index 240be018367..1951f98e871 100644 --- a/internal/pkg/template/templates/workloads/partials/cf/env-controller.yml +++ b/internal/pkg/template/templates/workloads/partials/cf/env-controller.yml @@ -6,7 +6,7 @@ EnvControllerAction: ServiceToken: !GetAtt EnvControllerFunction.Arn Workload: !Ref WorkloadName {{- if and (not .UseImportedCerts) (.Aliases)}} - Aliases: {{ fmtSlice .Aliases }} + Aliases: {{ fmtSlice (quoteSlice .Aliases) }} {{- end}} EnvStack: !Sub '${AppName}-${EnvName}' Parameters: {{ envControllerParams . }} diff --git a/internal/pkg/template/templates/workloads/partials/cf/https-listener.yml b/internal/pkg/template/templates/workloads/partials/cf/https-listener.yml index e35ed26ab48..2e94e19febd 100644 --- a/internal/pkg/template/templates/workloads/partials/cf/https-listener.yml +++ b/internal/pkg/template/templates/workloads/partials/cf/https-listener.yml @@ -76,7 +76,7 @@ HTTPListenerRuleWithDomain: {{- if .Aliases }} - Field: 'host-header' HostHeaderConfig: - Values: {{ fmtSlice .Aliases }} + Values: {{ fmtSlice (quoteSlice .Aliases) }} {{- else }} - Field: 'host-header' HostHeaderConfig: @@ -124,7 +124,7 @@ HTTPSListenerRule: {{- if .Aliases }} - Field: 'host-header' HostHeaderConfig: - Values: {{ fmtSlice .Aliases }} + Values: {{ fmtSlice (quoteSlice .Aliases) }} {{- else }} - Field: 'host-header' HostHeaderConfig: From 63070ea9ad7a1ac4a914d34ab825fccb2b441f1b Mon Sep 17 00:00:00 2001 From: penghaoh Date: Fri, 8 Jul 2022 15:46:44 -0700 Subject: [PATCH 2/3] Add wildcard example to integ tests --- .../workloads/backend/https-path-alias-manifest.yml | 2 +- .../workloads/backend/https-path-alias-template.yml | 10 +++++----- .../stack/testdata/workloads/svc-staging.stack.yml | 2 +- internal/pkg/template/template_functions.go | 5 +++++ .../templates/workloads/partials/cf/https-listener.yml | 2 +- internal/pkg/template/workload.go | 1 + 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-manifest.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-manifest.yml index 7f702026a47..91e06831d51 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-manifest.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-manifest.yml @@ -7,7 +7,7 @@ http: - name: example.com hosted_zone: mockHostedZone2 - name: foobar.com - - name: v1.foobar.com + - name: "*.foobar.com" hosted_zone: mockHostedZone1 image: diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-template.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-template.yml index e5a89cfa34d..d9a9ca61454 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-template.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/backend/https-path-alias-template.yml @@ -278,12 +278,12 @@ Resources: HostedZoneId: mockHostedZone1 Comment: !Sub "LoadBalancer aliases for service ${WorkloadName} in hosted zone mockHostedZone1" RecordSets: - - Name: foobar.com + - Name: "foobar.com" Type: A AliasTarget: HostedZoneId: !GetAtt EnvControllerAction.InternalLoadBalancerHostedZone DNSName: !GetAtt EnvControllerAction.InternalLoadBalancerDNSName - - Name: v1.foobar.com + - Name: "*.foobar.com" Type: A AliasTarget: HostedZoneId: !GetAtt EnvControllerAction.InternalLoadBalancerHostedZone @@ -296,7 +296,7 @@ Resources: HostedZoneId: mockHostedZone2 Comment: !Sub "LoadBalancer aliases for service ${WorkloadName} in hosted zone mockHostedZone2" RecordSets: - - Name: example.com + - Name: "example.com" Type: A AliasTarget: HostedZoneId: !GetAtt EnvControllerAction.InternalLoadBalancerHostedZone @@ -326,7 +326,7 @@ Resources: Conditions: - Field: 'host-header' HostHeaderConfig: - Values: ["example.com", "foobar.com", "v1.foobar.com"] + Values: ["example.com", "foobar.com", "*.foobar.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If @@ -347,7 +347,7 @@ Resources: Conditions: - Field: 'host-header' HostHeaderConfig: - Values: ["example.com", "foobar.com", "v1.foobar.com"] + Values: ["example.com", "foobar.com", "*.foobar.com"] - Field: 'path-pattern' PathPatternConfig: Values: !If diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-staging.stack.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-staging.stack.yml index a089b767dcc..e0f816d6d81 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-staging.stack.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-staging.stack.yml @@ -397,7 +397,7 @@ Resources: # If a bucket URL is specified, that means the template exists. HostedZoneId: mockHostedZone Comment: !Sub "LoadBalancer aliases for service ${WorkloadName} in hosted zone mockHostedZone" RecordSets: - - Name: example.com + - Name: "example.com" Type: A AliasTarget: HostedZoneId: !GetAtt EnvControllerAction.PublicLoadBalancerHostedZone diff --git a/internal/pkg/template/template_functions.go b/internal/pkg/template/template_functions.go index 8b5e7622000..55825511d06 100644 --- a/internal/pkg/template/template_functions.go +++ b/internal/pkg/template/template_functions.go @@ -105,6 +105,11 @@ func QuoteSliceFunc(elems []string) []string { return quotedElems } +// QuoteStringFunc places quotation marks around a string. +func QuoteStringFunc(s string) string { + return strconv.Quote(s) +} + // generateMountPointJSON turns a list of MountPoint objects into a JSON string: // `{"myEFSVolume": "/var/www", "myEBSVolume": "/usr/data"}` // This function must be called on an array of correctly constructed MountPoint objects. diff --git a/internal/pkg/template/templates/workloads/partials/cf/https-listener.yml b/internal/pkg/template/templates/workloads/partials/cf/https-listener.yml index 2e94e19febd..dac2b67b36c 100644 --- a/internal/pkg/template/templates/workloads/partials/cf/https-listener.yml +++ b/internal/pkg/template/templates/workloads/partials/cf/https-listener.yml @@ -31,7 +31,7 @@ LoadBalancerDNSAlias{{$hostedZoneID}}: Comment: !Sub "LoadBalancer aliases for service ${WorkloadName} in hosted zone {{$hostedZoneID}}" RecordSets: {{- range $alias := $aliases}} - - Name: {{$alias}} + - Name: {{quote $alias}} Type: A AliasTarget: {{- if eq $.WorkloadType "Backend Service"}} diff --git a/internal/pkg/template/workload.go b/internal/pkg/template/workload.go index 5b882ac803d..821423415e7 100644 --- a/internal/pkg/template/workload.go +++ b/internal/pkg/template/workload.go @@ -611,6 +611,7 @@ func withSvcParsingFuncs() ParseOption { "hasSecrets": hasSecrets, "fmtSlice": FmtSliceFunc, "quoteSlice": QuoteSliceFunc, + "quote": QuoteStringFunc, "randomUUID": randomUUIDFunc, "jsonMountPoints": generateMountPointJSON, "jsonSNSTopics": generateSNSJSON, From 295b2317717004a5be7ad03bc0f3e7004e02b286 Mon Sep 17 00:00:00 2001 From: penghaoh Date: Fri, 8 Jul 2022 16:18:36 -0700 Subject: [PATCH 3/3] Addr fb --- internal/pkg/template/template_functions.go | 5 ----- internal/pkg/template/workload.go | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/internal/pkg/template/template_functions.go b/internal/pkg/template/template_functions.go index 55825511d06..8b5e7622000 100644 --- a/internal/pkg/template/template_functions.go +++ b/internal/pkg/template/template_functions.go @@ -105,11 +105,6 @@ func QuoteSliceFunc(elems []string) []string { return quotedElems } -// QuoteStringFunc places quotation marks around a string. -func QuoteStringFunc(s string) string { - return strconv.Quote(s) -} - // generateMountPointJSON turns a list of MountPoint objects into a JSON string: // `{"myEFSVolume": "/var/www", "myEBSVolume": "/usr/data"}` // This function must be called on an array of correctly constructed MountPoint objects. diff --git a/internal/pkg/template/workload.go b/internal/pkg/template/workload.go index 821423415e7..03287c39b01 100644 --- a/internal/pkg/template/workload.go +++ b/internal/pkg/template/workload.go @@ -6,6 +6,7 @@ package template import ( "bytes" "fmt" + "strconv" "text/template" "github.com/aws/aws-sdk-go/service/secretsmanager" @@ -611,7 +612,7 @@ func withSvcParsingFuncs() ParseOption { "hasSecrets": hasSecrets, "fmtSlice": FmtSliceFunc, "quoteSlice": QuoteSliceFunc, - "quote": QuoteStringFunc, + "quote": strconv.Quote, "randomUUID": randomUUIDFunc, "jsonMountPoints": generateMountPointJSON, "jsonSNSTopics": generateSNSJSON,