Skip to content

Commit bcb98c0

Browse files
authored
fix: Ensure changes in MatchCN annotation are detected (#11173)
1 parent 6a111a9 commit bcb98c0

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

internal/ingress/annotations/authtls/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ func (assl1 *Config) Equal(assl2 *Config) bool {
122122
if assl1.PassCertToUpstream != assl2.PassCertToUpstream {
123123
return false
124124
}
125+
if assl1.MatchCN != assl2.MatchCN {
126+
return false
127+
}
125128

126129
return true
127130
}

internal/ingress/annotations/authtls/main_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,15 @@ func TestEquals(t *testing.T) {
333333
}
334334
cfg2.PassCertToUpstream = true
335335

336+
// Different MatchCN
337+
cfg1.MatchCN = "CN=(hello-app|goodbye)"
338+
cfg2.MatchCN = "CN=(hello-app)"
339+
result = cfg1.Equal(cfg2)
340+
if result != false {
341+
t.Errorf("Expected false")
342+
}
343+
cfg2.MatchCN = "CN=(hello-app|goodbye)"
344+
336345
// Equal Configs
337346
result = cfg1.Equal(cfg2)
338347
if result != true {

test/e2e/annotations/authtls.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,49 @@ var _ = framework.DescribeAnnotation("auth-tls-*", func() {
322322
Status(http.StatusOK)
323323
})
324324

325+
ginkgo.It("should reload the nginx config when auth-tls-match-cn is updated", func() {
326+
host := authTLSFooHost
327+
nameSpace := f.Namespace
328+
329+
clientConfig, err := framework.CreateIngressMASecret(
330+
f.KubeClientSet,
331+
host,
332+
host,
333+
nameSpace)
334+
assert.Nil(ginkgo.GinkgoT(), err)
335+
336+
// First add an annotation that forbids our connection
337+
annotations := map[string]string{
338+
"nginx.ingress.kubernetes.io/auth-tls-secret": nameSpace + "/" + host,
339+
"nginx.ingress.kubernetes.io/auth-tls-verify-client": "on",
340+
"nginx.ingress.kubernetes.io/auth-tls-match-cn": "CN=notvalid",
341+
}
342+
343+
ingress := f.EnsureIngress(framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, nameSpace, framework.EchoService, 80, annotations))
344+
345+
assertSslClientCertificateConfig(f, host, "on", "1")
346+
347+
f.HTTPTestClientWithTLSConfig(clientConfig).
348+
GET("/").
349+
WithURL(f.GetURL(framework.HTTPS)).
350+
WithHeader("Host", host).
351+
Expect().
352+
Status(http.StatusForbidden)
353+
354+
// Update the annotation to something that allows the connection
355+
ingress.Annotations["nginx.ingress.kubernetes.io/auth-tls-match-cn"] = "CN=authtls"
356+
f.UpdateIngress(ingress)
357+
358+
assertSslClientCertificateConfig(f, host, "on", "1")
359+
360+
f.HTTPTestClientWithTLSConfig(clientConfig).
361+
GET("/").
362+
WithURL(f.GetURL(framework.HTTPS)).
363+
WithHeader("Host", host).
364+
Expect().
365+
Status(http.StatusOK)
366+
})
367+
325368
ginkgo.It("should return 200 using auth-tls-match-cn where atleast one of the regex options matches CN from client", func() {
326369
host := authTLSFooHost
327370
nameSpace := f.Namespace

0 commit comments

Comments
 (0)