Skip to content

Commit c514be9

Browse files
Allow TLS to Goldmane (#3807)
1 parent 4ff8794 commit c514be9

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

pkg/controller/whisker/controller.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ import (
3636
"github.com/tigera/operator/pkg/controller/utils"
3737
"github.com/tigera/operator/pkg/controller/utils/imageset"
3838
"github.com/tigera/operator/pkg/ctrlruntime"
39+
"github.com/tigera/operator/pkg/dns"
3940
"github.com/tigera/operator/pkg/render"
41+
rcertificatemanagement "github.com/tigera/operator/pkg/render/certificatemanagement"
4042
"github.com/tigera/operator/pkg/render/monitor"
4143
"github.com/tigera/operator/pkg/render/whisker"
4244
"github.com/tigera/operator/pkg/tls/certificatemanagement"
@@ -199,6 +201,27 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
199201
return reconcile.Result{}, err
200202
}
201203

204+
// Goldmane needs a server certificate for it's gRPC API.
205+
// TODO: Add this to the trusted bundle. This isn't stritctly needed, since the bundle already includes the operator CA that
206+
// signed this certificate. But in order to support custom user-supplied certificates, we will need to do this.
207+
goldmaneCertificateNames := dns.GetServiceDNSNames(whisker.GoldmaneServiceName, whisker.WhiskerNamespace, r.clusterDomain)
208+
goldmaneCertificateNames = append(goldmaneCertificateNames, "localhost", "127.0.0.1")
209+
keyPair, err := certificateManager.GetOrCreateKeyPair(r.cli, whisker.GoldmaneServerSecret, common.OperatorNamespace(), goldmaneCertificateNames)
210+
if err != nil {
211+
r.status.SetDegraded(operatorv1.ResourceCreateError, "Error creating TLS certificate", err, log)
212+
return reconcile.Result{}, err
213+
}
214+
certComponent := rcertificatemanagement.CertificateManagement(&rcertificatemanagement.Config{
215+
Namespace: whisker.WhiskerNamespace,
216+
TruthNamespace: common.OperatorNamespace(),
217+
ServiceAccounts: []string{whisker.WhiskerServiceAccountName},
218+
KeyPairOptions: []rcertificatemanagement.KeyPairOption{
219+
rcertificatemanagement.NewKeyPairOption(keyPair, true, true),
220+
},
221+
// TrustedBundle is managed by the core controller.
222+
TrustedBundle: nil,
223+
})
224+
202225
trustedCertBundle, err := certificateManager.LoadTrustedBundle(ctx, r.cli, whisker.WhiskerNamespace)
203226
if err != nil {
204227
r.status.SetDegraded(operatorv1.ResourceReadError, "Error loading trusted cert bundle", err, reqLogger)
@@ -213,9 +236,10 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
213236
TunnelSecret: tunnelSecret,
214237
TrustedCertBundle: trustedCertBundle,
215238
ManagementClusterConnection: managementClusterConnection,
239+
GoldmaneServerKeyPair: keyPair,
216240
}
217241

218-
components := []render.Component{whisker.Whisker(cfg)}
242+
components := []render.Component{certComponent, whisker.Whisker(cfg)}
219243
if err = imageset.ApplyImageSet(ctx, r.cli, variant, components...); err != nil {
220244
r.status.SetDegraded(operatorv1.ResourceUpdateError, "Error with images from ImageSet", err, reqLogger)
221245
return reconcile.Result{}, err

pkg/render/whisker/component.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const (
4242
WhiskerServiceAccountName = WhiskerName
4343
WhiskerDeploymentName = WhiskerName
4444
WhiskerRoleName = WhiskerName
45+
GoldmaneServerSecret = "goldmane-server-secret"
46+
GoldmaneServiceName = "goldmane"
4547

4648
GuardianContainerName = "guardian"
4749
GoldmaneContainerName = "goldmane"
@@ -64,6 +66,7 @@ type Configuration struct {
6466
TunnelSecret *corev1.Secret
6567
TrustedCertBundle certificatemanagement.TrustedBundleRO
6668
ManagementClusterConnection *operatorv1.ManagementClusterConnection
69+
GoldmaneServerKeyPair certificatemanagement.KeyPairInterface
6770
}
6871

6972
type Component struct {
@@ -185,25 +188,43 @@ func (c *Component) whiskerBackendContainer() corev1.Container {
185188
{Name: "GOLDMANE_HOST", Value: "localhost:7443"},
186189
},
187190
SecurityContext: securitycontext.NewNonRootContext(),
191+
VolumeMounts: c.cfg.TrustedCertBundle.VolumeMounts(rmeta.OSTypeLinux),
188192
}
189193
}
190194

191195
func (c *Component) goldmaneContainer() corev1.Container {
196+
var volumeMounts []corev1.VolumeMount
197+
192198
env := []corev1.EnvVar{
193199
{Name: "LOG_LEVEL", Value: "INFO"},
194200
{Name: "PORT", Value: "7443"},
195201
}
196-
var volumeMounts []corev1.VolumeMount
202+
203+
if c.cfg.GoldmaneServerKeyPair != nil {
204+
env = append(env, corev1.EnvVar{
205+
Name: "SERVER_KEY_PATH",
206+
Value: c.cfg.GoldmaneServerKeyPair.VolumeMountKeyFilePath(),
207+
})
208+
env = append(env, corev1.EnvVar{
209+
Name: "SERVER_CERT_PATH",
210+
Value: c.cfg.GoldmaneServerKeyPair.VolumeMountCertificateFilePath(),
211+
})
212+
213+
volumeMounts = append(volumeMounts, c.cfg.GoldmaneServerKeyPair.VolumeMount(c.SupportedOSType()))
214+
}
215+
197216
if c.cfg.ManagementClusterConnection != nil {
198217
env = append(env,
199218
corev1.EnvVar{
200219
Name: "PUSH_URL",
201-
Value: "https://localhost:8080/api/v1/flows/bulk"},
220+
Value: "https://localhost:8080/api/v1/flows/bulk",
221+
},
202222
corev1.EnvVar{
203223
Name: "CA_CERT_PATH",
204-
Value: c.cfg.TrustedCertBundle.MountPath()},
224+
Value: c.cfg.TrustedCertBundle.MountPath(),
225+
},
205226
)
206-
volumeMounts = c.cfg.TrustedCertBundle.VolumeMounts(c.SupportedOSType())
227+
volumeMounts = append(volumeMounts, c.cfg.TrustedCertBundle.VolumeMounts(c.SupportedOSType())...)
207228
}
208229

209230
return corev1.Container{
@@ -219,7 +240,7 @@ func (c *Component) goldmaneContainer() corev1.Container {
219240
func (c *Component) goldmaneService() *corev1.Service {
220241
return &corev1.Service{
221242
ObjectMeta: metav1.ObjectMeta{
222-
Name: "goldmane",
243+
Name: GoldmaneServiceName,
223244
Namespace: WhiskerNamespace,
224245
},
225246
Spec: corev1.ServiceSpec{
@@ -261,6 +282,10 @@ func (c *Component) deployment() *appsv1.Deployment {
261282
ctrs := []corev1.Container{c.whiskerContainer(), c.whiskerBackendContainer(), c.goldmaneContainer()}
262283
volumes := []corev1.Volume{c.cfg.TrustedCertBundle.Volume()}
263284

285+
if c.cfg.GoldmaneServerKeyPair != nil {
286+
volumes = append(volumes, c.cfg.GoldmaneServerKeyPair.Volume())
287+
}
288+
264289
if c.cfg.ManagementClusterConnection != nil {
265290
ctrs = append(ctrs, c.guardianContainer())
266291
volumes = append(volumes, secretVolume(c.cfg.TunnelSecret))

pkg/render/whisker/component_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ var _ = Describe("ComponentRendering", func() {
115115
{Name: "GOLDMANE_HOST", Value: "localhost:7443"},
116116
},
117117
SecurityContext: securitycontext.NewNonRootContext(),
118+
VolumeMounts: certificatemanagement.CreateTrustedBundle(nil).VolumeMounts(rmeta.OSTypeAny),
118119
},
119120
{
120121
Name: whisker.GoldmaneContainerName,
@@ -142,6 +143,7 @@ var _ = Describe("ComponentRendering", func() {
142143
},
143144
},
144145
),
146+
145147
Entry("Should configure guardian",
146148
&whisker.Configuration{
147149
Installation: &operatorv1.InstallationSpec{
@@ -196,6 +198,7 @@ var _ = Describe("ComponentRendering", func() {
196198
{Name: "GOLDMANE_HOST", Value: "localhost:7443"},
197199
},
198200
SecurityContext: securitycontext.NewNonRootContext(),
201+
VolumeMounts: certificatemanagement.CreateTrustedBundle(nil).VolumeMounts(rmeta.OSTypeAny),
199202
},
200203
{
201204
Name: whisker.GoldmaneContainerName,

0 commit comments

Comments
 (0)