Skip to content

Commit ae88e4f

Browse files
beastawakensTwsouza
authored andcommitted
Allow network whitelisting on the service level
1 parent e087555 commit ae88e4f

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

pkg/manifest/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Service struct {
3131
Termination ServiceTermination `yaml:"termination,omitempty"`
3232
Test string `yaml:"test,omitempty"`
3333
Volumes []string `yaml:"volumes,omitempty"`
34+
Whitelist string `yaml:"whitelist,omitempty"`
3435
}
3536

3637
type Services []Service

provider/aws/formation/service.json.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
{{ end }}
239239
"Properties": {
240240
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if .Internal }}Internal{{ end }}" } } ],
241-
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Join": [ ".", [ "{{$.App}}-{{.Name}}", { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Host" } } ] ] } ] } ],
241+
"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 }} ] } } ],
242242
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Listener80" } },
243243
"Priority": "{{ priority $.App .Name "default" -1 }}"
244244
}
@@ -250,7 +250,7 @@
250250
{{ end }}
251251
"Properties": {
252252
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if .Internal }}Internal{{ end }}" } } ],
253-
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Join": [ ".", [ "{{$.App}}-{{.Name}}", { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Host" } } ] ] } ] } ],
253+
"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 }} ] } } ],
254254
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Listener443" } },
255255
"Priority": "{{ priority $.App .Name "default" -1 }}"
256256
}
@@ -271,7 +271,7 @@
271271
"Condition": "InternalDomainsAndRouteHttp",
272272
"Properties": {
273273
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if .Internal }}Internal{{ end }}" } } ],
274-
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Sub": "{{.Name}}.{{$.App}}.${Rack}.convox" } ] } ],
274+
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Sub": "{{.Name}}.{{$.App}}.${Rack}.convox" } ] } , { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
275275
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Listener80" } },
276276
"Priority": "{{ priority $.App .Name "internal" -1 }}"
277277
}
@@ -281,7 +281,7 @@
281281
"Condition": "InternalDomains",
282282
"Properties": {
283283
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if .Internal }}Internal{{ end }}" } } ],
284-
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Sub": "{{.Name}}.{{$.App}}.${Rack}.convox" } ] } ],
284+
"Conditions": [ { "Field": "host-header", "Values": [ { "Fn::Sub": "{{.Name}}.{{$.App}}.${Rack}.convox" } ] } , { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
285285
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router .Name $.Manifest }}Listener443" } },
286286
"Priority": "{{ priority $.App .Name "internal" -1 }}"
287287
}
@@ -303,7 +303,7 @@
303303
{{ end }}
304304
"Properties": {
305305
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if $.Service.Internal }}Internal{{ end }}" } } ],
306-
"Conditions": [ { "Field": "host-header", "Values": [ "{{$domain}}" ] } ],
306+
"Conditions": [ { "Field": "host-header", "Values": [ "{{$domain}}" ] } , { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
307307
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router $.Service.Name $.Manifest }}Listener80" } },
308308
"Priority": "{{ priority $.App $.Service.Name $domain $i }}"
309309
}
@@ -315,7 +315,7 @@
315315
{{ end }}
316316
"Properties": {
317317
"Actions": [ { "Type": "forward", "TargetGroupArn": { "Ref": "BalancerTargetGroup{{ if $.Service.Internal }}Internal{{ end }}" } } ],
318-
"Conditions": [ { "Field": "host-header", "Values": [ "{{$domain}}" ] } ],
318+
"Conditions": [ { "Field": "host-header", "Values": [ "{{$domain}}" ] } , { "Field": "source-ip", "SourceIpConfig": { "Values": [ {{ range safeWhitelist .Whitelist }} "{{ . }}", {{ end }} ] } } ],
319319
"ListenerArn": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:{{ router $.Service.Name $.Manifest }}Listener443" } },
320320
"Priority": "{{ priority $.App $.Service.Name $domain $i }}"
321321
}

provider/aws/template.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ func formationHelpers() template.FuncMap {
7575
"safe": func(s string) template.HTML {
7676
return template.HTML(fmt.Sprintf("%q", s))
7777
},
78+
"safeWhitelist": func(s string) []string {
79+
if s == "" {
80+
return []string{"0.0.0.0/0"}
81+
} else {
82+
return strings.Split(s,",")
83+
}
84+
},
7885
"services": func(m *manifest.Manifest) string {
7986
if m == nil {
8087
return ""

0 commit comments

Comments
 (0)