-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Dataplane-trust Adding mTLS and TLS To Activator #13969
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
Changes from 23 commits
2c7446e
cd59288
667b62f
3c78734
57554c8
c00adf1
5fc0409
ae63ea2
0a1305a
0722ef3
d666360
68c65f6
83a30a7
4f40a36
22f1d06
6fc785c
a69c439
d6e22e7
96644d9
31f5a38
449dc96
4908795
eca4205
70f977f
250b31c
61286df
f786633
ccd7045
b886b11
b789f23
516b899
fc23dd6
bbbfbb5
be5c882
ccaaf6e
f8be5dc
01804ac
64683a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
| "crypto/tls" | ||
| "crypto/x509" | ||
| "encoding/pem" | ||
| "fmt" | ||
| "sync" | ||
|
|
||
| "go.uber.org/zap" | ||
|
|
@@ -40,23 +41,26 @@ import ( | |
| type CertCache struct { | ||
| secretInformer v1.SecretInformer | ||
| logger *zap.SugaredLogger | ||
| trust netcfg.Trust | ||
|
davidhadas marked this conversation as resolved.
Outdated
|
||
|
|
||
| certificate *tls.Certificate | ||
| TLSConf tls.Config | ||
| certificate *tls.Certificate | ||
| ClientTLSConf tls.Config | ||
| ServerTLSConf tls.Config | ||
|
davidhadas marked this conversation as resolved.
|
||
|
|
||
| certificatesMux sync.RWMutex | ||
| } | ||
|
|
||
| // NewCertCache starts secretInformer. | ||
| func NewCertCache(ctx context.Context) *CertCache { | ||
| func NewCertCache(ctx context.Context, trust netcfg.Trust) *CertCache { | ||
| secretInformer := secretinformer.Get(ctx) | ||
|
|
||
| cr := &CertCache{ | ||
| secretInformer: secretInformer, | ||
| logger: logging.FromContext(ctx), | ||
| trust: trust, | ||
| } | ||
|
|
||
| secret, err := cr.secretInformer.Lister().Secrets(system.Namespace()).Get(netcfg.ServingInternalCertName) | ||
| secret, err := cr.secretInformer.Lister().Secrets(system.Namespace()).Get(netcfg.ServingRoutingCertName) | ||
| if err != nil { | ||
| cr.logger.Warnw("failed to get secret", zap.Error(err)) | ||
| return nil | ||
|
|
@@ -65,7 +69,7 @@ func NewCertCache(ctx context.Context) *CertCache { | |
| cr.updateCache(secret) | ||
|
|
||
| secretInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ | ||
| FilterFunc: controller.FilterWithNameAndNamespace(system.Namespace(), netcfg.ServingInternalCertName), | ||
| FilterFunc: controller.FilterWithNameAndNamespace(system.Namespace(), netcfg.ServingRoutingCertName), | ||
| Handler: cache.ResourceEventHandlerFuncs{ | ||
| UpdateFunc: cr.handleCertificateUpdate, | ||
| AddFunc: cr.handleCertificateAdd, | ||
|
|
@@ -101,9 +105,32 @@ func (cr *CertCache) updateCache(secret *corev1.Secret) { | |
| } | ||
| pool.AddCert(ca) | ||
|
|
||
| cr.TLSConf.RootCAs = pool | ||
| cr.TLSConf.ServerName = certificates.LegacyFakeDnsName | ||
| cr.TLSConf.MinVersion = tls.VersionTLS12 | ||
| cr.ClientTLSConf.RootCAs = pool | ||
| cr.ClientTLSConf.ServerName = certificates.LegacyFakeDnsName | ||
| cr.ClientTLSConf.MinVersion = tls.VersionTLS12 | ||
| cr.ClientTLSConf.Certificates = []tls.Certificate{cert} | ||
|
|
||
| cr.ServerTLSConf.MinVersion = tls.VersionTLS12 | ||
| cr.ServerTLSConf.GetCertificate = cr.GetCertificate | ||
|
|
||
| switch cr.trust { | ||
| case netcfg.TrustIdentity, netcfg.TrustMutual: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between identity and mutual?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The difference is only at the ingress.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using what mechanic/format?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have not yet designed this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FYI we can't assume envoy is the underlying proxy here. Whatever use case you have you'll want to ensure it's possible to do this with the GatewayAPI - https://gateway-api.sigs.k8s.io/ In the future we'll be dropping our net-* repos in favour of programming against this API. |
||
| cr.ServerTLSConf.ClientAuth = tls.RequireAndVerifyClientCert | ||
| cr.ServerTLSConf.ClientCAs = pool | ||
| cr.ServerTLSConf.VerifyConnection = func(cs tls.ConnectionState) error { | ||
| for _, match := range cs.PeerCertificates[0].DNSNames { | ||
|
davidhadas marked this conversation as resolved.
Outdated
|
||
| if match == "kn-routing-0" { // routingId not yet supported | ||
|
davidhadas marked this conversation as resolved.
Outdated
|
||
| return nil | ||
| } | ||
| //Until all ingresses work with updated dataplane certificates - allow also any legacy certificate | ||
| if match == certificates.LegacyFakeDnsName { | ||
| return nil | ||
| } | ||
| } | ||
| cr.logger.Info("mTLS: Failed Client with DNSNames: %v\n", cs.PeerCertificates[0].DNSNames) | ||
|
davidhadas marked this conversation as resolved.
Outdated
|
||
| return fmt.Errorf("mTLS Failed to approve %v", cs.PeerCertificates[0].DNSNames) | ||
|
davidhadas marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| func (cr *CertCache) handleCertificateUpdate(_, new interface{}) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.