Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure changes in MatchCN annotation are detected #11528

Merged
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
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