Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow network whitelisting on the service level #3581

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/manifest/service.go
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ type Service struct {
Termination ServiceTermination `yaml:"termination,omitempty"`
Test string `yaml:"test,omitempty"`
Volumes []string `yaml:"volumes,omitempty"`
Whitelist string `yaml:"whitelist,omitempty"`
}

type Services []Service
12 changes: 6 additions & 6 deletions provider/aws/formation/service.json.tmpl
Original file line number Diff line number Diff line change
@@ -238,7 +238,7 @@
{{ end }}
"Properties": {
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if .Internal }}Internal{{ end }}" } } ],
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Join": [ ".", [ "{{$.App}}-{{.Name}}", { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Host" } } ] ] } ] } ],
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Join": [ ".", [ "{{$.App}}-{{.Name}}", { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Host" } } ] ] } ] }, { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beastawakens the e2e tests got an error here:

Promoting RHQCJJDYHME... ERROR: json syntax error: line 248 pos 241: invalid character ']' looking for beginning of value:             "Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Join": [ ".", [ "ci2-web", { "Fn::ImportValue": { "Fn::Sub": "${Rack}:RouterHost" } } ] ] } ] }, { "Field": "source-ip", "SourceIpConfig": { "Values": [  "0.0.0.0/0",  ] } } ],

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uuurgh, I know the syntax is a nested mess but that's CloudFormation for you. I'm not seeing an extra closing bracket though 🤔 there's 5 opening, and 5 closing by my reckoning? Can you spot it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any extra closing. I think I've found the problem when you create the app with an empty whitelist it will create "SourceIpConfig": { "Values": [ "0.0.0.0/0", ] } } ], you can see that will create an invalid comma in the values list.

"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Listener80" } },
"Priority": "{{ priority $.App .Name "default" -1 }}"
}
@@ -250,7 +250,7 @@
{{ end }}
"Properties": {
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if .Internal }}Internal{{ end }}" } } ],
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Join": [ ".", [ "{{$.App}}-{{.Name}}", { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Host" } } ] ] } ] } ],
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Join": [ ".", [ "{{$.App}}-{{.Name}}", { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Host" } } ] ] } ] }, { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Listener443" } },
"Priority": "{{ priority $.App .Name "default" -1 }}"
}
@@ -271,7 +271,7 @@
"Condition": "InternalDomainsAndRouteHttp",
"Properties": {
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if .Internal }}Internal{{ end }}" } } ],
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Sub": "{{.Name}}.{{$.App}}.${Rack}.convox" } ] } ],
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Sub": "{{.Name}}.{{$.App}}.${Rack}.convox" } ] } , { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Listener80" } },
"Priority": "{{ priority $.App .Name "internal" -1 }}"
}
@@ -281,7 +281,7 @@
"Condition": "InternalDomains",
"Properties": {
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if .Internal }}Internal{{ end }}" } } ],
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Sub": "{{.Name}}.{{$.App}}.${Rack}.convox" } ] } ],
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Sub": "{{.Name}}.{{$.App}}.${Rack}.convox" } ] } , { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Listener443" } },
"Priority": "{{ priority $.App .Name "internal" -1 }}"
}
@@ -303,7 +303,7 @@
{{ end }}
"Properties": {
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if $.Service.Internal }}Internal{{ end }}" } } ],
"Conditions": [ { "Field": "host-header", "Values": [ "{{$domain}}" ] } ],
"Conditions": [ { "Field": "host-header", "Values": [ "{{$domain}}" ] } , { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router $.Service.Name $.Manifest }}Listener80" } },
"Priority": "{{ priority $.App $.Service.Name $domain $i }}"
}
@@ -315,7 +315,7 @@
{{ end }}
"Properties": {
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if $.Service.Internal }}Internal{{ end }}" } } ],
"Conditions": [ { "Field": "host-header", "Values": [ "{{$domain}}" ] } ],
"Conditions": [ { "Field": "host-header", "Values": [ "{{$domain}}" ] } , { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router $.Service.Name $.Manifest }}Listener443" } },
"Priority": "{{ priority $.App $.Service.Name $domain $i }}"
}
7 changes: 7 additions & 0 deletions provider/aws/template.go
Original file line number Diff line number Diff line change
@@ -75,6 +75,13 @@ func formationHelpers() template.FuncMap {
"safe": func(s string) template.HTML {
return template.HTML(fmt.Sprintf("%q", s))
},
"safeWhitelist": func(s string) []string {
if s == "" {
return []string{"0.0.0.0/0"}
} else {
return strings.Split(s,",")
}
},
"services": func(m *manifest.Manifest) string {
if m == nil {
return ""