Skip to content

Commit

Permalink
fix: Ensure changes in MatchCN annotation are detected (#11528)
Browse files Browse the repository at this point in the history
Co-authored-by: Wouter Dullaert <[email protected]>
  • Loading branch information
k8s-infra-cherrypick-robot and wdullaer authored Jul 2, 2024
1 parent 22fe1d4 commit 88494aa
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/ingress/annotations/authtls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func (assl1 *Config) Equal(assl2 *Config) bool {
if assl1.PassCertToUpstream != assl2.PassCertToUpstream {
return false
}
if assl1.MatchCN != assl2.MatchCN {
return false
}

return true
}
Expand Down
9 changes: 9 additions & 0 deletions internal/ingress/annotations/authtls/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ func TestEquals(t *testing.T) {
}
cfg2.PassCertToUpstream = true

// Different MatchCN
cfg1.MatchCN = "CN=(hello-app|goodbye)"
cfg2.MatchCN = "CN=(hello-app)"
result = cfg1.Equal(cfg2)
if result != false {
t.Errorf("Expected false")
}
cfg2.MatchCN = "CN=(hello-app|goodbye)"

// Equal Configs
result = cfg1.Equal(cfg2)
if result != true {
Expand Down
43 changes: 43 additions & 0 deletions test/e2e/annotations/authtls.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,49 @@ var _ = framework.DescribeAnnotation("auth-tls-*", func() {
Status(http.StatusOK)
})

ginkgo.It("should reload the nginx config when auth-tls-match-cn is updated", func() {
host := authTLSFooHost
nameSpace := f.Namespace

clientConfig, err := framework.CreateIngressMASecret(
f.KubeClientSet,
host,
host,
nameSpace)
assert.Nil(ginkgo.GinkgoT(), err)

// First add an annotation that forbids our connection
annotations := map[string]string{
"nginx.ingress.kubernetes.io/auth-tls-secret": nameSpace + "/" + host,
"nginx.ingress.kubernetes.io/auth-tls-verify-client": "on",
"nginx.ingress.kubernetes.io/auth-tls-match-cn": "CN=notvalid",
}

ingress := f.EnsureIngress(framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, nameSpace, framework.EchoService, 80, annotations))

assertSslClientCertificateConfig(f, host, "on", "1")

f.HTTPTestClientWithTLSConfig(clientConfig).
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", host).
Expect().
Status(http.StatusForbidden)

// Update the annotation to something that allows the connection
ingress.Annotations["nginx.ingress.kubernetes.io/auth-tls-match-cn"] = "CN=authtls"
f.UpdateIngress(ingress)

assertSslClientCertificateConfig(f, host, "on", "1")

f.HTTPTestClientWithTLSConfig(clientConfig).
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
})

ginkgo.It("should return 200 using auth-tls-match-cn where atleast one of the regex options matches CN from client", func() {
host := authTLSFooHost
nameSpace := f.Namespace
Expand Down

0 comments on commit 88494aa

Please sign in to comment.