Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit c0264ec

Browse files
authored
Plumb trust domain through to helm chart (#4877)
* Plumb trust domain through to helm chart Signed-off-by: Keith Mattix II <[email protected]> * Address PR comments Signed-off-by: Keith Mattix II <[email protected]>
1 parent 4da737e commit c0264ec

File tree

11 files changed

+75
-7
lines changed

11 files changed

+75
-7
lines changed

charts/osm/templates/osm-bootstrap-deployment.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ spec:
6161
"--osm-version", "{{ .Chart.AppVersion }}",
6262
"--ca-bundle-secret-name", "{{.Values.osm.caBundleSecretName}}",
6363
"--certificate-manager", "{{.Values.osm.certificateProvider.kind}}",
64+
"--trust-domain", "{{.Values.osm.trustDomain}}",
6465
"--enable-mesh-root-certificate={{.Values.osm.featureFlags.enableMeshRootCertificate}}",
6566
{{ if eq .Values.osm.certificateProvider.kind "vault" }}
6667
"--vault-host", "{{.Values.osm.vault.host}}",

charts/osm/templates/osm-deployment.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ spec:
6161
"--validator-webhook-config", "{{ include "osm.validatorWebhookConfigName" . }}",
6262
"--ca-bundle-secret-name", "{{.Values.osm.caBundleSecretName}}",
6363
"--certificate-manager", "{{.Values.osm.certificateProvider.kind}}",
64+
"--trust-domain", "{{.Values.osm.trustDomain}}",
6465
"--enable-mesh-root-certificate={{.Values.osm.featureFlags.enableMeshRootCertificate}}",
6566
{{ if eq .Values.osm.certificateProvider.kind "vault" }}
6667
"--vault-host", "{{ required "osm.vault.host is required when osm.certificateProvider.kind==vault" .Values.osm.vault.host }}",

charts/osm/templates/osm-injector-deployment.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ spec:
5858
"--webhook-timeout", "{{.Values.osm.injector.webhookTimeoutSeconds}}",
5959
"--ca-bundle-secret-name", "{{.Values.osm.caBundleSecretName}}",
6060
"--certificate-manager", "{{.Values.osm.certificateProvider.kind}}",
61+
"--trust-domain", "{{.Values.osm.trustDomain}}",
6162
"--enable-mesh-root-certificate={{.Values.osm.featureFlags.enableMeshRootCertificate}}",
6263
{{ if eq .Values.osm.certificateProvider.kind "vault" }}
6364
"--vault-host", "{{.Values.osm.vault.host}}",

cmd/osm-bootstrap/osm-bootstrap.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ var (
6363
osmMeshConfigName string
6464
meshName string
6565
osmVersion string
66+
trustDomain string
6667

6768
certProviderKind string
6869
enableMeshRootCertificate bool
@@ -99,6 +100,9 @@ func init() {
99100
flags.BoolVar(&enableMeshRootCertificate, "enable-mesh-root-certificate", false, "Enable unsupported MeshRootCertificate to create the OSM Certificate Manager")
100101
flags.StringVar(&caBundleSecretName, "ca-bundle-secret-name", "", "Name of the Kubernetes Secret for the OSM CA bundle")
101102

103+
// TODO (#4502): Remove when we add full MRC support
104+
flags.StringVar(&trustDomain, "trust-domain", "cluster.local", "The trust domain to use as part of the common name when requesting new certificates")
105+
102106
// Vault certificate manager/provider options
103107
flags.StringVar(&vaultOptions.VaultProtocol, "vault-protocol", "http", "Host name of the Hashi Vault")
104108
flags.StringVar(&vaultOptions.VaultHost, "vault-host", "vault.default.svc.cluster.local", "Host name of the Hashi Vault")
@@ -230,7 +234,7 @@ func main() {
230234
"Error initializing certificate manager of kind %s from MRC", certProviderKind)
231235
}
232236
} else {
233-
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace, certOpts, msgBroker, 5*time.Second)
237+
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace, certOpts, msgBroker, 5*time.Second, trustDomain)
234238
if err != nil {
235239
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
236240
"Error initializing certificate manager of kind %s", certProviderKind)

cmd/osm-controller/osm-controller.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ var (
7373
caBundleSecretName string
7474
osmMeshConfigName string
7575
osmVersion string
76+
trustDomain string
7677

7778
certProviderKind string
7879
enableMeshRootCertificate bool
@@ -106,6 +107,9 @@ func init() {
106107
flags.BoolVar(&enableMeshRootCertificate, "enable-mesh-root-certificate", false, "Enable unsupported MeshRootCertificate to create the OSM Certificate Manager")
107108
flags.StringVar(&caBundleSecretName, "ca-bundle-secret-name", "", "Name of the Kubernetes Secret for the OSM CA bundle")
108109

110+
// TODO (#4502): Remove when we add full MRC support
111+
flags.StringVar(&trustDomain, "trust-domain", "cluster.local", "The trust domain to use as part of the common name when requesting new certificates")
112+
109113
// Vault certificate manager/provider options
110114
flags.StringVar(&vaultOptions.VaultProtocol, "vault-protocol", "http", "Host name of the Hashi Vault")
111115
flags.StringVar(&vaultOptions.VaultHost, "vault-host", "vault.default.svc.cluster.local", "Host name of the Hashi Vault")
@@ -222,7 +226,7 @@ func main() {
222226
}
223227
} else {
224228
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
225-
certOpts, msgBroker, 5*time.Second)
229+
certOpts, msgBroker, 5*time.Second, trustDomain)
226230
if err != nil {
227231
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
228232
"Error fetching certificate manager of kind %s", certProviderKind)

cmd/osm-injector/osm-injector.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var (
5757
osmMeshConfigName string
5858
webhookTimeout int32
5959
osmVersion string
60+
trustDomain string
6061

6162
certProviderKind string
6263
enableMeshRootCertificate bool
@@ -92,6 +93,9 @@ func init() {
9293
flags.BoolVar(&enableMeshRootCertificate, "enable-mesh-root-certificate", false, "Enable unsupported MeshRootCertificate to create the OSM Certificate Manager")
9394
flags.StringVar(&caBundleSecretName, "ca-bundle-secret-name", "", "Name of the Kubernetes Secret for the OSM CA bundle")
9495

96+
// TODO (#4502): Remove when we add full MRC support
97+
flags.StringVar(&trustDomain, "trust-domain", "cluster.local", "The trust domain to use as part of the common name when requesting new certificates")
98+
9599
// Vault certificate manager/provider options
96100
flags.StringVar(&vaultOptions.VaultProtocol, "vault-protocol", "http", "Host name of the Hashi Vault")
97101
flags.StringVar(&vaultOptions.VaultHost, "vault-host", "vault.default.svc.cluster.local", "Host name of the Hashi Vault")
@@ -216,7 +220,7 @@ func main() {
216220
}
217221
} else {
218222
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
219-
certOpts, msgBroker, 5*time.Second)
223+
certOpts, msgBroker, 5*time.Second, trustDomain)
220224
if err != nil {
221225
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
222226
"Error initializing certificate manager of kind %s", certProviderKind)

pkg/certificate/fake_manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (c *fakeMRCClient) Watch(ctx context.Context) (<-chan MRCEvent, error) {
4545
Namespace: "osm-system",
4646
},
4747
Spec: v1alpha2.MeshRootCertificateSpec{
48+
TrustDomain: "fake.domain.com",
4849
Provider: v1alpha2.ProviderSpec{
4950
Tresor: &v1alpha2.TresorProviderSpec{
5051
CA: v1alpha2.TresorCASpec{

pkg/certificate/manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (m *Manager) handleMRCEvent(mrcClient MRCClient, event MRCEvent) error {
129129
return err
130130
}
131131

132-
c := &issuer{Issuer: client, ID: mrc.Name, CertificateAuthority: ca}
132+
c := &issuer{Issuer: client, ID: mrc.Name, CertificateAuthority: ca, TrustDomain: mrc.Spec.TrustDomain}
133133
switch {
134134
case mrc.Status.State == constants.MRCStateActive:
135135
m.mu.Lock()

pkg/certificate/manager_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import (
77

88
tassert "github.com/stretchr/testify/assert"
99
trequire "github.com/stretchr/testify/require"
10+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011

1112
"github.com/openservicemesh/osm/pkg/announcements"
13+
"github.com/openservicemesh/osm/pkg/apis/config/v1alpha2"
1214
"github.com/openservicemesh/osm/pkg/certificate/pem"
15+
"github.com/openservicemesh/osm/pkg/constants"
1316
"github.com/openservicemesh/osm/pkg/messaging"
1417
)
1518

@@ -313,3 +316,52 @@ func TestIssueCertificate(t *testing.T) {
313316
assert.Nil(cert)
314317
})
315318
}
319+
320+
func TestHandleMRCEvent(t *testing.T) {
321+
testCases := []struct {
322+
name string
323+
mrcClient MRCClient
324+
mrcEvent MRCEvent
325+
wantErr bool
326+
wantSigningIssuer issuer
327+
wantValidatingIssuer issuer
328+
}{
329+
{
330+
name: "success",
331+
mrcClient: &fakeMRCClient{},
332+
mrcEvent: MRCEvent{
333+
Type: MRCEventAdded,
334+
MRC: &v1alpha2.MeshRootCertificate{
335+
ObjectMeta: v1.ObjectMeta{
336+
Name: "my-mrc",
337+
},
338+
Spec: v1alpha2.MeshRootCertificateSpec{
339+
TrustDomain: "foo.bar.com",
340+
},
341+
Status: v1alpha2.MeshRootCertificateStatus{
342+
State: constants.MRCStateActive,
343+
},
344+
},
345+
},
346+
wantSigningIssuer: issuer{Issuer: &fakeIssuer{}, ID: "my-mrc", TrustDomain: "foo.bar.com", CertificateAuthority: pem.RootCertificate("rootCA")},
347+
wantValidatingIssuer: issuer{Issuer: &fakeIssuer{}, ID: "my-mrc", TrustDomain: "foo.bar.com", CertificateAuthority: pem.RootCertificate("rootCA")},
348+
},
349+
}
350+
351+
for _, tt := range testCases {
352+
t.Run(tt.name, func(t *testing.T) {
353+
assert := tassert.New(t)
354+
m := &Manager{}
355+
356+
err := m.handleMRCEvent(tt.mrcClient, tt.mrcEvent)
357+
if !tt.wantErr {
358+
assert.NoError(err)
359+
} else {
360+
assert.Error(err)
361+
}
362+
363+
assert.Equal(tt.wantSigningIssuer, *m.signingIssuer)
364+
assert.Equal(tt.wantValidatingIssuer, *m.validatingIssuer)
365+
})
366+
}
367+
}

pkg/certificate/providers/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var getCA func(certificate.Issuer) (pem.RootCertificate, error) = func(i certifi
4444
// NewCertificateManager returns a new certificate manager with a MRC compat client.
4545
// TODO(4713): Remove and use NewCertificateManagerFromMRC
4646
func NewCertificateManager(ctx context.Context, kubeClient kubernetes.Interface, kubeConfig *rest.Config, cfg configurator.Configurator,
47-
providerNamespace string, option Options, msgBroker *messaging.Broker, checkInterval time.Duration) (*certificate.Manager, error) {
47+
providerNamespace string, option Options, msgBroker *messaging.Broker, checkInterval time.Duration, trustDomain string) (*certificate.Manager, error) {
4848
if err := option.Validate(); err != nil {
4949
return nil, err
5050
}
@@ -63,7 +63,7 @@ func NewCertificateManager(ctx context.Context, kubeClient kubernetes.Interface,
6363
},
6464
Spec: v1alpha2.MeshRootCertificateSpec{
6565
Provider: option.AsProviderSpec(),
66-
TrustDomain: "cluster.local",
66+
TrustDomain: trustDomain,
6767
},
6868
Status: v1alpha2.MeshRootCertificateStatus{
6969
State: constants.MRCStateActive,

pkg/certificate/providers/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestGetCertificateManager(t *testing.T) {
143143
getCA = oldCA
144144
}()
145145

146-
manager, err := NewCertificateManager(context.Background(), tc.kubeClient, tc.restConfig, tc.cfg, tc.providerNamespace, tc.options, tc.msgBroker, 1*time.Hour)
146+
manager, err := NewCertificateManager(context.Background(), tc.kubeClient, tc.restConfig, tc.cfg, tc.providerNamespace, tc.options, tc.msgBroker, 1*time.Hour, "cluster.local")
147147
if tc.expectError {
148148
assert.Empty(manager)
149149
assert.Error(err)

0 commit comments

Comments
 (0)