Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,10 @@ func validateHostname(r config.UnvalidatedIngressRule, ruleIndex, totalRules int
if err == nil {
return errHostnameContainsPort
}
// Ensure that there are no wildcards anywhere except the first character
// of the hostname.
if strings.LastIndex(r.Hostname, "*") > 0 {
// A wildcard must be the entire hostname or the entire first label.
wildcardIndex := strings.LastIndex(r.Hostname, "*")
if wildcardIndex > 0 || (wildcardIndex == 0 && r.Hostname != "*" &&
(!strings.HasPrefix(r.Hostname, "*.") || len(r.Hostname) == len("*."))) {
return errBadWildcard
}

Expand Down
27 changes: 24 additions & 3 deletions ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ func TestParseIngress(t *testing.T) {
wantErr: true,
},
{
name: "Multiple rules",
name: "Subdomain wildcard and catch-all",
args: args{rawYAML: `
ingress:
- hostname: tunnel1.example.com
- hostname: "*.example.com"
service: https://localhost:8000
- hostname: "*"
service: https://localhost:8001
`},
want: []Rule{
{
Hostname: "tunnel1.example.com",
Hostname: "*.example.com",
Service: &httpService{url: localhost8000},
Config: defaultConfig,
},
Expand Down Expand Up @@ -228,6 +228,27 @@ ingress:
ingress:
- hostname: "test.*.example.com"
service: https://localhost:8000
- service: http_status:404
`},
wantErr: true,
},
{
name: "Wildcard attached to a partial label",
args: args{rawYAML: `
ingress:
- hostname: "*app.example.com"
service: https://localhost:8000
- service: http_status:404
`},
wantErr: true,
},
{
name: "Wildcard without a domain suffix",
args: args{rawYAML: `
ingress:
- hostname: "*."
service: https://localhost:8000
- service: http_status:404
`},
wantErr: true,
},
Expand Down