mirror of
https://git.vectorsigma.ru/public/k3s.git
synced 2026-07-30 05:59:50 +00:00
Add FilterCN function to prevent SAN Stuffing
Wire up a node watch to collect addresses of server nodes, to prevent adding unauthorized SANs to the dynamiclistener cert. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
committed by
Brad Davidson
parent
8c38d1169d
commit
aa76942d0f
@@ -51,11 +51,15 @@ func (c *Cluster) newListener(ctx context.Context) (net.Listener, http.Handler,
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
c.config.SANs = append(c.config.SANs, "kubernetes", "kubernetes.default", "kubernetes.default.svc", "kubernetes.default.svc."+c.config.ClusterDomain)
|
||||
c.config.Runtime.ClusterControllerStarts["server-cn-filter"] = func(ctx context.Context) {
|
||||
registerAddressHandlers(ctx, c)
|
||||
}
|
||||
storage := tlsStorage(ctx, c.config.DataDir, c.config.Runtime)
|
||||
return wrapHandler(dynamiclistener.NewListener(tcp, storage, cert, key, dynamiclistener.Config{
|
||||
ExpirationDaysCheck: config.CertificateRenewDays,
|
||||
Organization: []string{version.Program},
|
||||
SANs: append(c.config.SANs, "kubernetes", "kubernetes.default", "kubernetes.default.svc", "kubernetes.default.svc."+c.config.ClusterDomain),
|
||||
SANs: c.config.SANs,
|
||||
CN: version.Program,
|
||||
TLSConfig: &tls.Config{
|
||||
ClientAuth: tls.RequestClientCert,
|
||||
@@ -63,6 +67,7 @@ func (c *Cluster) newListener(ctx context.Context) (net.Listener, http.Handler,
|
||||
CipherSuites: c.config.TLSCipherSuites,
|
||||
NextProtos: []string{"h2", "http/1.1"},
|
||||
},
|
||||
FilterCN: c.filterCN,
|
||||
RegenerateCerts: func() bool {
|
||||
const regenerateDynamicListenerFile = "dynamic-cert-regenerate"
|
||||
dynamicListenerRegenFilePath := filepath.Join(c.config.DataDir, "tls", regenerateDynamicListenerFile)
|
||||
@@ -75,6 +80,13 @@ func (c *Cluster) newListener(ctx context.Context) (net.Listener, http.Handler,
|
||||
}))
|
||||
}
|
||||
|
||||
func (c *Cluster) filterCN(cn ...string) []string {
|
||||
if c.cnFilterFunc != nil {
|
||||
return c.cnFilterFunc(cn...)
|
||||
}
|
||||
return cn
|
||||
}
|
||||
|
||||
// initClusterAndHTTPS sets up the dynamic tls listener, request router,
|
||||
// and cluster database. Once the database is up, it starts the supervisor http server.
|
||||
func (c *Cluster) initClusterAndHTTPS(ctx context.Context) error {
|
||||
|
||||
Reference in New Issue
Block a user