Compare commits
3 commits
master
...
wildcard-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
549236f515 | ||
|
|
3e95e350d5 | ||
|
|
d9f0466773 |
6 changed files with 138 additions and 21 deletions
|
|
@ -91,7 +91,7 @@ func parseBind(h Helper) ([]ConfigValue, error) {
|
|||
// ciphers <cipher_suites...>
|
||||
// curves <curves...>
|
||||
// client_auth {
|
||||
// mode [request|require|verify_if_given|require_and_verify]
|
||||
// mode [off|request|require|verify_if_given|require_and_verify]
|
||||
// trust_pool <module_name> [...]
|
||||
// trusted_leaf_cert <base64_der>
|
||||
// trusted_leaf_cert_file <filename>
|
||||
|
|
@ -242,10 +242,19 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
|
|||
}
|
||||
|
||||
case "client_auth":
|
||||
cp.ClientAuthentication = &caddytls.ClientAuthentication{}
|
||||
if err := cp.ClientAuthentication.UnmarshalCaddyfile(h.NewFromNextSegment()); err != nil {
|
||||
segment := h.NewFromNextSegment()
|
||||
clientAuth := new(caddytls.ClientAuthentication)
|
||||
if err := clientAuth.UnmarshalCaddyfile(segment); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if clientAuth.Mode == "off" {
|
||||
clientAuth.Mode = ""
|
||||
if clientAuth.Active() {
|
||||
return nil, segment.Err("client_auth mode off cannot be combined with other client authentication options")
|
||||
}
|
||||
break
|
||||
}
|
||||
cp.ClientAuthentication = clientAuth
|
||||
case "alpn":
|
||||
args := h.RemainingArgs()
|
||||
if len(args) == 0 {
|
||||
|
|
|
|||
|
|
@ -849,21 +849,6 @@ func (st *ServerType) serversFromPairings(
|
|||
emptyConnPolicies = append(emptyConnPolicies, cp)
|
||||
}
|
||||
}
|
||||
} else if specificHosts := slices.DeleteFunc(
|
||||
slices.Clone(hosts),
|
||||
func(h string) bool { return h == "" || strings.Contains(h, "*") },
|
||||
); len(specificHosts) > 0 {
|
||||
// site blocks with no TLS connection policy of their own may
|
||||
// still need an empty policy hoisted above a wildcard policy
|
||||
// that requires client authentication, or that requirement
|
||||
// would apply to their more specific hostnames too - see the
|
||||
// hoisting loop below and issue #7860
|
||||
slices.Sort(specificHosts)
|
||||
emptyConnPolicies = append(emptyConnPolicies, &caddytls.ConnectionPolicy{
|
||||
MatchersRaw: caddy.ModuleMap{
|
||||
"sni": caddyconfig.JSON(specificHosts, warnings),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
for _, addr := range sblock.parsedKeys {
|
||||
|
|
@ -1027,9 +1012,9 @@ func (st *ServerType) serversFromPairings(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// hostnames whose site blocks configure no TLS settings of their own
|
||||
// still need shielding if a policy matching a wildcard hostname would
|
||||
// otherwise impose CLIENT AUTHENTICATION on them. Because connection
|
||||
// hostnames whose site blocks explicitly configure TLS but produce an
|
||||
// empty policy need shielding if a wildcard policy would otherwise
|
||||
// impose CLIENT AUTHENTICATION on them. Because connection
|
||||
// policies are first-match, the shield hoisted above the wildcard
|
||||
// policy must be a COPY of that policy with only client_authentication
|
||||
// removed: an empty policy would not just lift the client-auth
|
||||
|
|
|
|||
|
|
@ -405,6 +405,114 @@ func TestTLSConnectionPoliciesAreIsolatedAcrossListeners(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestWildcardClientAuthenticationInheritance(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
exactTLS string
|
||||
wantFirstSNI string
|
||||
wantClientAuth bool
|
||||
wantPolicyCount int
|
||||
}{
|
||||
{
|
||||
name: "implicit TLS inherits wildcard client authentication",
|
||||
wantFirstSNI: "*.example.com",
|
||||
wantClientAuth: true,
|
||||
wantPolicyCount: 2,
|
||||
},
|
||||
{
|
||||
name: "mode off clears wildcard client authentication",
|
||||
exactTLS: "tls {\n\t\t\t\t\t\tclient_auth {\n\t\t\t\t\t\t\tmode off\n\t\t\t\t\t\t}\n\t\t\t\t\t}",
|
||||
wantFirstSNI: "test.example.com",
|
||||
wantPolicyCount: 3,
|
||||
},
|
||||
{
|
||||
name: "explicit connection settings keep their own policy",
|
||||
exactTLS: "tls {\n\t\t\t\t\t\tprotocols tls1.2 tls1.3\n\t\t\t\t\t}",
|
||||
wantFirstSNI: "test.example.com",
|
||||
wantPolicyCount: 3,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
input := fmt.Sprintf(`
|
||||
*.example.com {
|
||||
tls {
|
||||
client_auth {
|
||||
mode require
|
||||
}
|
||||
}
|
||||
}
|
||||
test.example.com {
|
||||
%s
|
||||
}
|
||||
`, tc.exactTLS)
|
||||
|
||||
adapter := caddyfile.Adapter{ServerType: ServerType{}}
|
||||
result, _, err := adapter.Adapt([]byte(input), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var config struct {
|
||||
Apps struct {
|
||||
HTTP struct {
|
||||
Servers map[string]*caddyhttp.Server `json:"servers"`
|
||||
} `json:"http"`
|
||||
} `json:"apps"`
|
||||
}
|
||||
if err := json.Unmarshal(result, &config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
server := config.Apps.HTTP.Servers["srv0"]
|
||||
if server == nil {
|
||||
t.Fatal("server srv0 was not created")
|
||||
}
|
||||
if len(server.TLSConnPolicies) != tc.wantPolicyCount {
|
||||
t.Fatalf("got %d TLS connection policies, want %d\n%s", len(server.TLSConnPolicies), tc.wantPolicyCount, result)
|
||||
}
|
||||
firstPolicy := server.TLSConnPolicies[0]
|
||||
var names []string
|
||||
if err := json.Unmarshal(firstPolicy.MatchersRaw["sni"], &names); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !slices.Equal(names, []string{tc.wantFirstSNI}) {
|
||||
t.Fatalf("first policy SNI = %v, want %q\n%s", names, tc.wantFirstSNI, result)
|
||||
}
|
||||
if got := firstPolicy.ClientAuthentication != nil; got != tc.wantClientAuth {
|
||||
t.Fatalf("client authentication = %t, want %t\n%s", got, tc.wantClientAuth, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientAuthOffValidation(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
input string
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "naked tls",
|
||||
input: "example.com {\n\ttls\n}",
|
||||
wantErr: "wrong argument count",
|
||||
},
|
||||
{
|
||||
name: "off with authentication options",
|
||||
input: "example.com {\n\ttls {\n\t\tclient_auth {\n\t\t\tmode off\n\t\t\ttrusted_leaf_cert AA==\n\t\t}\n\t}\n}",
|
||||
wantErr: "client_auth mode off cannot be combined with other client authentication options",
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
adapter := caddyfile.Adapter{ServerType: ServerType{}}
|
||||
if _, _, err := adapter.Adapt([]byte(tc.input), nil); err == nil {
|
||||
t.Fatal("expected adaptation to fail")
|
||||
} else if !strings.Contains(err.Error(), tc.wantErr) {
|
||||
t.Fatalf("error %q does not contain %q", err, tc.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientAuthConsolidation(t *testing.T) {
|
||||
const requestAuth = `client_auth {
|
||||
mode request
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@
|
|||
}
|
||||
|
||||
public.example.com {
|
||||
tls {
|
||||
client_auth {
|
||||
mode off
|
||||
}
|
||||
}
|
||||
respond "public"
|
||||
}
|
||||
----------
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@
|
|||
}
|
||||
|
||||
public.example.com {
|
||||
tls {
|
||||
client_auth {
|
||||
mode off
|
||||
}
|
||||
}
|
||||
respond "public"
|
||||
}
|
||||
----------
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@
|
|||
}
|
||||
|
||||
public.example.com, public.other.com {
|
||||
tls {
|
||||
client_auth {
|
||||
mode off
|
||||
}
|
||||
}
|
||||
respond "public"
|
||||
}
|
||||
----------
|
||||
|
|
|
|||
Loading…
Reference in a new issue