Skip to content

Commit 415bdfb

Browse files
fix
Signed-off-by: Yaroslav Borbat <[email protected]>
1 parent ba0d275 commit 415bdfb

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

images/virt-artifact/patches/011-virt-api-authentication.patch

+48-16
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,34 @@ index 5cbb8197f..82f6f9238 100644
2525
+ })
2626
+}
2727
diff --git a/pkg/util/tls/tls.go b/pkg/util/tls/tls.go
28-
index e9e140548..922ae9826 100644
28+
index e9e140548..7e46688c6 100644
2929
--- a/pkg/util/tls/tls.go
3030
+++ b/pkg/util/tls/tls.go
31-
@@ -91,7 +91,7 @@ func SetupExportProxyTLS(certManager certificate.Manager, kubeVirtInformer cache
31+
@@ -132,6 +132,57 @@ func SetupTLSWithCertManager(caManager ClientCAManager, certManager certificate.
3232
return tlsConfig
3333
}
3434

35-
-func SetupTLSWithCertManager(caManager ClientCAManager, certManager certificate.Manager, clientAuth tls.ClientAuthType, clusterConfig *virtconfig.ClusterConfig) *tls.Config {
36-
+func SetupTLSWithCertManager(caManager, virtualizationCAManager ClientCAManager, certManager certificate.Manager, clientAuth tls.ClientAuthType, clusterConfig *virtconfig.ClusterConfig) *tls.Config {
37-
tlsConfig := &tls.Config{
38-
GetCertificate: func(info *tls.ClientHelloInfo) (certificate *tls.Certificate, err error) {
39-
cert := certManager.Current()
40-
@@ -112,6 +112,16 @@ func SetupTLSWithCertManager(caManager ClientCAManager, certManager certificate.
41-
return nil, err
42-
}
43-
35+
+func SetupTLSWithVirtualizationCAManager(caManager, virtualizationCAManager ClientCAManager, certManager certificate.Manager, clientAuth tls.ClientAuthType, clusterConfig *virtconfig.ClusterConfig) *tls.Config {
36+
+ tlsConfig := &tls.Config{
37+
+ GetCertificate: func(info *tls.ClientHelloInfo) (certificate *tls.Certificate, err error) {
38+
+ cert := certManager.Current()
39+
+ if cert == nil {
40+
+ return nil, fmt.Errorf(noSrvCertMessage)
41+
+ }
42+
+ return cert, nil
43+
+ },
44+
+ GetConfigForClient: func(hi *tls.ClientHelloInfo) (*tls.Config, error) {
45+
+ cert := certManager.Current()
46+
+ if cert == nil {
47+
+ return nil, fmt.Errorf(noSrvCertMessage)
48+
+ }
49+
+
50+
+ clientCAPool, err := caManager.GetCurrent()
51+
+ if err != nil {
52+
+ log.Log.Reason(err).Error("Failed to get requestheader client CA")
53+
+ return nil, err
54+
+ }
55+
+
4456
+ virtualizationClientCAPool, err := virtualizationCAManager.GetCurrent()
4557
+ if err != nil {
4658
+ log.Log.Reason(err).Error("Failed to get CA from config-map virtualization-ca")
@@ -51,11 +63,31 @@ index e9e140548..922ae9826 100644
5163
+ clientCAPool.AppendCertsFromPEM(subj)
5264
+ }
5365
+
54-
kv := clusterConfig.GetConfigFromKubeVirtCR()
55-
tlsConfig := getTLSConfiguration(kv)
56-
ciphers := CipherSuiteIds(tlsConfig.Ciphers)
66+
+ kv := clusterConfig.GetConfigFromKubeVirtCR()
67+
+ tlsConfig := getTLSConfiguration(kv)
68+
+ ciphers := CipherSuiteIds(tlsConfig.Ciphers)
69+
+ minTLSVersion := TLSVersion(tlsConfig.MinTLSVersion)
70+
+ config := &tls.Config{
71+
+ CipherSuites: ciphers,
72+
+ MinVersion: minTLSVersion,
73+
+ Certificates: []tls.Certificate{*cert},
74+
+ ClientCAs: clientCAPool,
75+
+ ClientAuth: clientAuth,
76+
+ }
77+
+
78+
+ config.BuildNameToCertificate()
79+
+ return config, nil
80+
+ },
81+
+ }
82+
+ tlsConfig.BuildNameToCertificate()
83+
+ return tlsConfig
84+
+}
85+
+
86+
func SetupTLSForVirtHandlerServer(caManager ClientCAManager, certManager certificate.Manager, externallyManaged bool, clusterConfig *virtconfig.ClusterConfig) *tls.Config {
87+
// #nosec cause: InsecureSkipVerify: true
88+
// resolution: Neither the client nor the server should validate anything itself, `VerifyPeerCertificate` is still executed
5789
diff --git a/pkg/virt-api/api.go b/pkg/virt-api/api.go
58-
index 120f2d68f..8eaa011d2 100644
90+
index 120f2d68f..4b82edd13 100644
5991
--- a/pkg/virt-api/api.go
6092
+++ b/pkg/virt-api/api.go
6193
@@ -884,7 +884,7 @@ func (app *virtAPIApp) registerMutatingWebhook(informers *webhooks.Informers) {
@@ -72,7 +104,7 @@ index 120f2d68f..8eaa011d2 100644
72104
// if the TLS handshake requests it. As a result, the TLS handshake fails
73105
// and our aggregated endpoint never becomes available.
74106
- app.tlsConfig = kvtls.SetupTLSWithCertManager(k8sCAManager, app.certmanager, tls.VerifyClientCertIfGiven, app.clusterConfig)
75-
+ app.tlsConfig = kvtls.SetupTLSWithCertManager(k8sCAManager, virtualizationCAManager, app.certmanager, tls.VerifyClientCertIfGiven, app.clusterConfig)
107+
+ app.tlsConfig = kvtls.SetupTLSWithVirtualizationCAManager(k8sCAManager, virtualizationCAManager, app.certmanager, tls.VerifyClientCertIfGiven, app.clusterConfig)
76108
app.handlerTLSConfiguration = kvtls.SetupTLSForVirtHandlerClients(kubevirtCAManager, app.handlerCertManager, app.externallyManaged)
77109
}
78110

0 commit comments

Comments
 (0)