mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-29 14:39:40 +02:00
autocert: exclude non-https routes (#5733)
Exclude non-https routes from the domains eligible for autocert.
This commit is contained in:
parent
254b86c479
commit
bbf0f60e2d
2 changed files with 44 additions and 3 deletions
|
@ -496,8 +496,8 @@ func sourceHostnames(cfg *config.Config) []string {
|
|||
|
||||
dedupe := map[string]struct{}{}
|
||||
for p := range cfg.Options.GetAllPolicies() {
|
||||
if u, _ := urlutil.ParseAndValidateURL(p.From); u != nil && !strings.Contains(u.Host, "*") {
|
||||
dedupe[u.Hostname()] = struct{}{}
|
||||
if h := eligibleHostname(p); h != "" {
|
||||
dedupe[h] = struct{}{}
|
||||
}
|
||||
}
|
||||
if cfg.Options.AuthenticateURLString != "" {
|
||||
|
@ -520,6 +520,24 @@ func sourceHostnames(cfg *config.Config) []string {
|
|||
return h
|
||||
}
|
||||
|
||||
var eligibleSchemes = map[string]struct{}{
|
||||
"https": {},
|
||||
"tcp+https": {},
|
||||
"udp+https": {},
|
||||
}
|
||||
|
||||
// eligibleHostname accepts a route and returns the hostname, if eligible for use
|
||||
// with autocert, or the empty string if not.
|
||||
func eligibleHostname(p *config.Policy) string {
|
||||
u, _ := urlutil.ParseAndValidateURL(p.From)
|
||||
if u == nil || strings.Contains(u.Host, "*") {
|
||||
return ""
|
||||
} else if _, ok := eligibleSchemes[u.Scheme]; !ok {
|
||||
return ""
|
||||
}
|
||||
return u.Hostname()
|
||||
}
|
||||
|
||||
func shouldEnableHTTPChallenge(cfg *config.Config) bool {
|
||||
if cfg == nil || cfg.Options == nil {
|
||||
return false
|
||||
|
|
|
@ -231,7 +231,7 @@ func TestConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
p1 := config.Policy{
|
||||
From: "http://from.example.com", To: to,
|
||||
From: "https://from.example.com", To: to,
|
||||
}
|
||||
_ = p1.Validate()
|
||||
|
||||
|
@ -631,6 +631,29 @@ func Test_configureTrustedRoots(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_sourceHostnames(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cfg := &config.Config{
|
||||
Options: config.NewDefaultOptions(),
|
||||
}
|
||||
cfg.Options.Policies = []config.Policy{
|
||||
{From: "https://foo.example.com"},
|
||||
{From: "http://non-https-route.example.com"},
|
||||
{From: "https://bar.example.com:5443"},
|
||||
{From: "ssh://ssh-hostname"},
|
||||
{From: "tcp+https://baz.example.com:1234"},
|
||||
{From: "udp+https://quux.example.com:5678"},
|
||||
}
|
||||
|
||||
assert.ElementsMatch(t, []string{
|
||||
"foo.example.com",
|
||||
"bar.example.com",
|
||||
"baz.example.com",
|
||||
"quux.example.com",
|
||||
}, sourceHostnames(cfg))
|
||||
}
|
||||
|
||||
func TestShouldEnableHTTPChallenge(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue