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

ref: use binary flag to enable use of MeshRootCertificate #4871

Merged
merged 5 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions charts/osm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ The following table lists the configurable parameters of the osm chart and their
| osm.tracing.port | int | `9411` | Port of the tracing collector service |
| osm.tracing.tolerations | list | `[]` | Node tolerations applied to control plane pods. The specified tolerations allow pods to schedule onto nodes with matching taints. |
| osm.trustDomain | string | `"cluster.local"` | The trust domain to use as part of the common name when requesting new certificates. |
| osm.unsafe | object | `{"enableMeshRootCertificate":false}` | Unsafe values. Behavior is not supported. |
| osm.unsafe.enableMeshRootCertificate | bool | `false` | Enable the MeshRootCertificate to configure the OSM certificate provider. |
| osm.validatorWebhook.webhookConfigurationName | string | `""` | Name of the ValidatingWebhookConfiguration |
| osm.vault.host | string | `""` | Hashicorp Vault host/service - where Vault is installed |
| osm.vault.port | int | `8200` | port to use to connect to Vault |
Expand Down
3 changes: 3 additions & 0 deletions charts/osm/templates/osm-bootstrap-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ spec:
"--osm-version", "{{ .Chart.AppVersion }}",
"--ca-bundle-secret-name", "{{.Values.osm.caBundleSecretName}}",
"--certificate-manager", "{{.Values.osm.certificateProvider.kind}}",
"--enable-mesh-root-certificate={{.Values.osm.unsafe.enableMeshRootCertificate}}",
{{ if eq .Values.osm.certificateProvider.kind "vault" }}
"--vault-host", "{{.Values.osm.vault.host}}",
"--vault-port", "{{.Values.osm.vault.port}}",
"--vault-protocol", "{{.Values.osm.vault.protocol}}",
"--vault-token", "{{.Values.osm.vault.token}}",
"--vault-token-secret-name", "{{ .Values.osm.vault.secret.name }}",
"--vault-token-secret-key", "{{ .Values.osm.vault.secret.key }}",
{{- end }}
"--cert-manager-issuer-name", "{{.Values.osm.certmanager.issuerName}}",
"--cert-manager-issuer-kind", "{{.Values.osm.certmanager.issuerKind}}",
Expand Down
5 changes: 4 additions & 1 deletion charts/osm/templates/osm-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ spec:
"--validator-webhook-config", "{{ include "osm.validatorWebhookConfigName" . }}",
"--ca-bundle-secret-name", "{{.Values.osm.caBundleSecretName}}",
"--certificate-manager", "{{.Values.osm.certificateProvider.kind}}",
"--enable-mesh-root-certificate={{.Values.osm.unsafe.enableMeshRootCertificate}}",
{{ if eq .Values.osm.certificateProvider.kind "vault" }}
"--vault-host", "{{ required "osm.vault.host is required when osm.certificateProvider.kind==vault" .Values.osm.vault.host }}",
"--vault-port", "{{.Values.osm.vault.port}}",
"--vault-protocol", "{{.Values.osm.vault.protocol}}",
"--vault-token", "{{ required "osm.vault.token is required when osm.certificateProvider.kind==vault" .Values.osm.vault.token }}",
"--vault-token", "{{ .Values.osm.vault.token }}",
"--vault-token-secret-name", "{{ .Values.osm.vault.secret.name }}",
"--vault-token-secret-key", "{{ .Values.osm.vault.secret.key }}",
{{- end }}
"--cert-manager-issuer-name", "{{.Values.osm.certmanager.issuerName}}",
"--cert-manager-issuer-kind", "{{.Values.osm.certmanager.issuerKind}}",
Expand Down
3 changes: 3 additions & 0 deletions charts/osm/templates/osm-injector-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ spec:
"--webhook-timeout", "{{.Values.osm.injector.webhookTimeoutSeconds}}",
"--ca-bundle-secret-name", "{{.Values.osm.caBundleSecretName}}",
"--certificate-manager", "{{.Values.osm.certificateProvider.kind}}",
"--enable-mesh-root-certificate={{.Values.osm.unsafe.enableMeshRootCertificate}}",
{{ if eq .Values.osm.certificateProvider.kind "vault" }}
"--vault-host", "{{.Values.osm.vault.host}}",
"--vault-port", "{{.Values.osm.vault.port}}",
"--vault-protocol", "{{.Values.osm.vault.protocol}}",
"--vault-token", "{{.Values.osm.vault.token}}",
"--vault-token-secret-name", "{{ .Values.osm.vault.secret.name }}",
"--vault-token-secret-key", "{{ .Values.osm.vault.secret.key }}",
{{- end }}
"--cert-manager-issuer-name", "{{.Values.osm.certmanager.issuerName}}",
"--cert-manager-issuer-kind", "{{.Values.osm.certmanager.issuerKind}}",
Expand Down
2 changes: 2 additions & 0 deletions charts/osm/templates/preset-mesh-root-certificate.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.osm.unsafe.enableMeshRootCertificate }}
apiVersion: v1
kind: ConfigMap
metadata:
Expand Down Expand Up @@ -42,3 +43,4 @@ data:
{{- end}}
}
}
{{- end}}
18 changes: 18 additions & 0 deletions charts/osm/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@
"envoyproxy/envoy-windows:v1.22.1@sha256:92733f8e5beae5c45df204a0e13edbd29e99adf962d1b1c7869b197d85c64bd0"
]
},
"unsafe": {
"$id": "#/properties/osm/properties/unsafe",
"type": "object",
"title": "The unsafe schema",
"description": "Parameters that are unsupported by OSM",
"additionalProperties": false,
"properties": {
"enableMeshRootCertificate": {
"$id": "#/properties/osm/properties/unsafe/properties/enableMeshRootCertificate",
"type": "boolean",
"title": "Enable the MeshRootCertificate",
"description": "Using the MeshRootCertificate to configure the OSM certificate provider is not supported",
"examples": [
false
]
}
}
},
"trustDomain": {
"$id": "#/properties/osm/properties/trustDomain",
"type": "string",
Expand Down
10 changes: 8 additions & 2 deletions charts/osm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ osm:
# The specified tolerations allow pods to schedule onto nodes with matching taints.
tolerations: []

# -- Unsafe values. Behavior is not supported.
unsafe:
# -- Enable the MeshRootCertificate to configure the OSM certificate provider.
enableMeshRootCertificate: false

# -- The trust domain to use as part of the common name when requesting new certificates.
trustDomain: cluster.local

Expand Down Expand Up @@ -198,6 +203,7 @@ osm:
# -- The Kubernetes secret key with the value bring the Vault token
key: ""


#
# -- cert-manager.io configuration
certmanager:
Expand Down Expand Up @@ -547,7 +553,7 @@ osm:

#
# -- OSM's preinstall hook parameters

preinstall:
## Affinity settings for pod assignment
## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
Expand Down Expand Up @@ -580,7 +586,7 @@ osm:

## Affinity settings for pod assignment
## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
affinity:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
Expand Down
8 changes: 0 additions & 8 deletions cmd/cli/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,6 @@ var _ = Describe("Running the install command", func() {
err := installCmd.run(config)
Expect(err.Error()).To(ContainSubstring("osm.vault.host is required"))
})

It("should error when token isn't set", func() {
installCmd.setOptions = append(installCmd.setOptions,
"osm.vault.host=my-host",
)
err := installCmd.run(config)
Expect(err.Error()).To(ContainSubstring("osm.vault.token is required"))
})
})

Describe("with the cert-manager certificate manager", func() {
Expand Down
40 changes: 27 additions & 13 deletions cmd/osm-bootstrap/osm-bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/kubectl/pkg/util"

configv1alpha2 "github.com/openservicemesh/osm/pkg/apis/config/v1alpha2"
"github.com/openservicemesh/osm/pkg/certificate"
configClientset "github.com/openservicemesh/osm/pkg/gen/client/config/clientset/versioned"
"github.com/openservicemesh/osm/pkg/health"

Expand Down Expand Up @@ -63,7 +64,8 @@ var (
meshName string
osmVersion string

certProviderKind string
certProviderKind string
enableMeshRootCertificate bool

tresorOptions providers.TresorOptions
vaultOptions providers.VaultOptions
Expand Down Expand Up @@ -94,6 +96,7 @@ func init() {

// Generic certificate manager/provider options
flags.StringVar(&certProviderKind, "certificate-manager", providers.TresorKind.String(), fmt.Sprintf("Certificate manager, one of [%v]", providers.ValidCertificateProviders))
flags.BoolVar(&enableMeshRootCertificate, "enable-mesh-root-certificate", false, "Enable unsupported MeshRootCertificate to create the OSM Certificate Manager")
flags.StringVar(&caBundleSecretName, "ca-bundle-secret-name", "", "Name of the Kubernetes Secret for the OSM CA bundle")

// Vault certificate manager/provider options
Expand All @@ -102,6 +105,8 @@ func init() {
flags.StringVar(&vaultOptions.VaultToken, "vault-token", "", "Secret token for the the Hashi Vault")
flags.StringVar(&vaultOptions.VaultRole, "vault-role", "openservicemesh", "Name of the Vault role dedicated to Open Service Mesh")
flags.IntVar(&vaultOptions.VaultPort, "vault-port", 8200, "Port of the Hashi Vault")
flags.StringVar(&vaultOptions.VaultTokenSecretName, "vault-token-secret-name", "", "Name of the secret storing the Vault token used in OSM")
flags.StringVar(&vaultOptions.VaultTokenSecretKey, "vault-token-secret-key", "", "Key for the vault token used in OSM")

// Cert-manager certificate manager/provider options
flags.StringVar(&certManagerOptions.IssuerName, "cert-manager-issuer-name", "osm-ca", "cert-manager issuer name")
Expand All @@ -122,6 +127,7 @@ func getCertOptions() (providers.Options, error) {
tresorOptions.SecretName = caBundleSecretName
return tresorOptions, nil
case providers.VaultKind:
vaultOptions.VaultTokenSecretNamespace = osmNamespace
return vaultOptions, nil
case providers.CertManagerKind:
return certManagerOptions, nil
Expand Down Expand Up @@ -171,10 +177,12 @@ func main() {
return
}

err = bootstrap.ensureMeshRootCertificate()
if err != nil {
log.Fatal().Err(err).Msgf("Error setting up default MeshRootCertificate %s from ConfigMap %s", meshRootCertificateName, presetMeshRootCertificateName)
return
if enableMeshRootCertificate {
err = bootstrap.ensureMeshRootCertificate()
if err != nil {
log.Fatal().Err(err).Msgf("Error setting up default MeshRootCertificate %s from ConfigMap %s", meshRootCertificateName, presetMeshRootCertificateName)
return
}
}

err = bootstrap.initiatilizeKubernetesEventsRecorder()
Expand Down Expand Up @@ -214,10 +222,19 @@ func main() {
log.Fatal().Err(err).Msg("Error getting certificate options")
}

certManager, err := providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace, certOpts, msgBroker, informerCollection, 5*time.Second)
if err != nil {
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
"Error initializing certificate manager of kind %s", certProviderKind)
var certManager *certificate.Manager
if enableMeshRootCertificate {
certManager, err = providers.NewCertificateManagerFromMRC(ctx, kubeClient, kubeConfig, cfg, osmNamespace, certOpts, msgBroker, informerCollection, 5*time.Second)
if err != nil {
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
"Error initializing certificate manager of kind %s from MRC", certProviderKind)
}
} else {
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace, certOpts, msgBroker, 5*time.Second)
if err != nil {
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
"Error initializing certificate manager of kind %s", certProviderKind)
}
}

// Initialize the crd conversion webhook server to support the conversion of OSM's CRDs
Expand Down Expand Up @@ -414,7 +431,7 @@ func (b *bootstrap) createMeshRootCertificate() error {

_, err = b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).UpdateStatus(context.Background(), createdMRC, metav1.UpdateOptions{})
if apierrors.IsAlreadyExists(err) {
log.Info().Msgf("MeshRootCertificate statys already exists in %s. Skip creating.", b.namespace)
log.Info().Msgf("MeshRootCertificate status already exists in %s. Skip creating.", b.namespace)
}

if err != nil {
Expand All @@ -440,9 +457,6 @@ func buildMeshRootCertificate(presetMeshRootCertificateConfigMap *corev1.ConfigM
},
ObjectMeta: metav1.ObjectMeta{
Name: meshRootCertificateName,
Annotations: map[string]string{
constants.MRCVersionAnnotation: "0",
},
},
Spec: presetMeshRootCertificateSpec,
}
Expand Down
28 changes: 21 additions & 7 deletions cmd/osm-controller/osm-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ var (
osmMeshConfigName string
osmVersion string

certProviderKind string
certProviderKind string
enableMeshRootCertificate bool

tresorOptions providers.TresorOptions
vaultOptions providers.VaultOptions
Expand Down Expand Up @@ -102,6 +103,7 @@ func init() {

// Generic certificate manager/provider options
flags.StringVar(&certProviderKind, "certificate-manager", providers.TresorKind.String(), fmt.Sprintf("Certificate manager, one of [%v]", providers.ValidCertificateProviders))
flags.BoolVar(&enableMeshRootCertificate, "enable-mesh-root-certificate", false, "Enable unsupported MeshRootCertificate to create the OSM Certificate Manager")
flags.StringVar(&caBundleSecretName, "ca-bundle-secret-name", "", "Name of the Kubernetes Secret for the OSM CA bundle")

// Vault certificate manager/provider options
Expand All @@ -110,6 +112,8 @@ func init() {
flags.StringVar(&vaultOptions.VaultToken, "vault-token", "", "Secret token for the the Hashi Vault")
flags.StringVar(&vaultOptions.VaultRole, "vault-role", "openservicemesh", "Name of the Vault role dedicated to Open Service Mesh")
flags.IntVar(&vaultOptions.VaultPort, "vault-port", 8200, "Port of the Hashi Vault")
flags.StringVar(&vaultOptions.VaultTokenSecretName, "vault-token-secret-name", "", "Name of the secret storing the Vault token used in OSM")
flags.StringVar(&vaultOptions.VaultTokenSecretKey, "vault-token-secret-key", "", "Key for the vault token used in OSM")

// Cert-manager certificate manager/provider options
flags.StringVar(&certManagerOptions.IssuerName, "cert-manager-issuer-name", "osm-ca", "cert-manager issuer name")
Expand All @@ -131,6 +135,7 @@ func getCertOptions() (providers.Options, error) {
tresorOptions.SecretName = caBundleSecretName
return tresorOptions, nil
case providers.VaultKind:
vaultOptions.VaultTokenSecretNamespace = osmNamespace
return vaultOptions, nil
case providers.CertManagerKind:
return certManagerOptions, nil
Expand Down Expand Up @@ -207,12 +212,21 @@ func main() {
}

// Intitialize certificate manager/provider
certManager, err := providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
certOpts, msgBroker, informerCollection, 5*time.Second)

if err != nil {
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
"Error fetching certificate manager of kind %s", certProviderKind)
var certManager *certificate.Manager
if enableMeshRootCertificate {
certManager, err = providers.NewCertificateManagerFromMRC(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
certOpts, msgBroker, informerCollection, 5*time.Second)
if err != nil {
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
"Error fetching certificate manager of kind %s from MRC", certProviderKind)
}
} else {
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
certOpts, msgBroker, 5*time.Second)
if err != nil {
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
"Error fetching certificate manager of kind %s", certProviderKind)
}
}

kubeProvider := kube.NewClient(k8sClient, cfg)
Expand Down
28 changes: 22 additions & 6 deletions cmd/osm-injector/osm-injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/tools/clientcmd"

"github.com/openservicemesh/osm/pkg/certificate"
configClientset "github.com/openservicemesh/osm/pkg/gen/client/config/clientset/versioned"
policyClientset "github.com/openservicemesh/osm/pkg/gen/client/policy/clientset/versioned"
"github.com/openservicemesh/osm/pkg/health"
Expand Down Expand Up @@ -57,7 +58,8 @@ var (
webhookTimeout int32
osmVersion string

certProviderKind string
certProviderKind string
enableMeshRootCertificate bool

enableReconciler bool

Expand Down Expand Up @@ -87,6 +89,7 @@ func init() {

// Generic certificate manager/provider options
flags.StringVar(&certProviderKind, "certificate-manager", providers.TresorKind.String(), fmt.Sprintf("Certificate manager, one of [%v]", providers.ValidCertificateProviders))
flags.BoolVar(&enableMeshRootCertificate, "enable-mesh-root-certificate", false, "Enable unsupported MeshRootCertificate to create the OSM Certificate Manager")
flags.StringVar(&caBundleSecretName, "ca-bundle-secret-name", "", "Name of the Kubernetes Secret for the OSM CA bundle")

// Vault certificate manager/provider options
Expand All @@ -95,6 +98,8 @@ func init() {
flags.StringVar(&vaultOptions.VaultToken, "vault-token", "", "Secret token for the the Hashi Vault")
flags.StringVar(&vaultOptions.VaultRole, "vault-role", "openservicemesh", "Name of the Vault role dedicated to Open Service Mesh")
flags.IntVar(&vaultOptions.VaultPort, "vault-port", 8200, "Port of the Hashi Vault")
flags.StringVar(&vaultOptions.VaultTokenSecretName, "vault-token-secret-name", "", "Name of the secret storing the Vault token used in OSM")
flags.StringVar(&vaultOptions.VaultTokenSecretKey, "vault-token-secret-key", "", "Key for the vault token used in OSM")

// Cert-manager certificate manager/provider options
flags.StringVar(&certManagerOptions.IssuerName, "cert-manager-issuer-name", "osm-ca", "cert-manager issuer name")
Expand All @@ -117,6 +122,7 @@ func getCertOptions() (providers.Options, error) {
tresorOptions.SecretName = caBundleSecretName
return tresorOptions, nil
case providers.VaultKind:
vaultOptions.VaultTokenSecretNamespace = osmNamespace
return vaultOptions, nil
case providers.CertManagerKind:
return certManagerOptions, nil
Expand Down Expand Up @@ -200,11 +206,21 @@ func main() {
log.Fatal().Err(err).Msg("Error getting certificate options")
}
// Intitialize certificate manager/provider
certManager, err := providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
certOpts, msgBroker, informerCollection, 5*time.Second)
if err != nil {
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
"Error initializing certificate manager of kind %s", certProviderKind)
var certManager *certificate.Manager
if enableMeshRootCertificate {
certManager, err = providers.NewCertificateManagerFromMRC(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
certOpts, msgBroker, informerCollection, 5*time.Second)
if err != nil {
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
"Error initializing certificate manager of kind %s from MRC", certProviderKind)
}
} else {
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
certOpts, msgBroker, 5*time.Second)
if err != nil {
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
"Error initializing certificate manager of kind %s", certProviderKind)
}
}

// Initialize the sidecar injector webhook
Expand Down
3 changes: 0 additions & 3 deletions pkg/certificate/fake_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ func (c *fakeMRCClient) Watch(ctx context.Context) (<-chan MRCEvent, error) {
ObjectMeta: metav1.ObjectMeta{
Name: "osm-mesh-root-certificate",
Namespace: "osm-system",
Annotations: map[string]string{
constants.MRCVersionAnnotation: "0",
},
},
Spec: v1alpha2.MeshRootCertificateSpec{
Provider: v1alpha2.ProviderSpec{
Expand Down
Loading