Skip to content

Commit

Permalink
Adding support for multiple client certificates (#1263)
Browse files Browse the repository at this point in the history
Add support for passing multiple client certificates via the
`tenant.spec.externalClientCertSecrets` field

Multiple client certificates will be mounted using the following folder
structure:

```
certs
  |
  + client-0
  |     + client.crt
  |     + client.key
  + client-1
  |     + client.crt
  |     + client.key
  + client-2
  |     + client.crt
  |     + client.key
```

Iterate over all provided client TLS certificates
and store them on the list of Volumes that will be
mounted to the Pod

Signed-off-by: Lenin Alevski <alevsk.8772@gmail.com>
  • Loading branch information
Alevsk authored Aug 30, 2022
1 parent afa8851 commit 2f58272
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 1 deletion.
31 changes: 31 additions & 0 deletions examples/kustomization/base/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,37 @@ spec:
## Create secrets as explained here:
## https://github.com/minio/minio/tree/master/docs/tls/kubernetes#2-create-kubernetes-secret
# externalClientCertSecret: {}
##
## Use this field to provide additional client certificate for the MinIO Tenant
## Certificate secret files will be mounted under /tmp/certs folder, supported types:
## Opaque | kubernetes.io/tls | cert-manager.io/v1alpha2 | cert-manager.io/v1
##
## mount path inside container:
##
## certs
## |
## + client-0
## | + client.crt
## | + client.key
## + client-1
## | + client.crt
## | + client.key
## + client-2
## | + client.crt
## | + client.key
## ie:
##
## externalClientCertSecrets:
## - name: client-certificate-1
## type: kubernetes.io/tls
## - name: client-certificate-2
## type: kubernetes.io/tls
## - name:client-certificate-3
## type: kubernetes.io/tls
##
## Create secrets as explained here:
## https://github.com/minio/minio/tree/master/docs/tls/kubernetes#2-create-kubernetes-secret
externalClientCertSecrets: [ ]
## Registry location and Tag to download MinIO Server image
image: quay.io/minio/minio:RELEASE.2022-08-02T23-59-16Z
imagePullSecret: { }
Expand Down
22 changes: 22 additions & 0 deletions helm/operator/templates/minio.min.io_tenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ spec:
required:
- name
type: object
externalClientCertSecrets:
items:
properties:
name:
type: string
type:
type: string
required:
- name
type: object
type: array
image:
type: string
imagePullPolicy:
Expand Down Expand Up @@ -4541,6 +4552,17 @@ spec:
required:
- name
type: object
externalClientCertSecrets:
items:
properties:
name:
type: string
type:
type: string
required:
- name
type: object
type: array
features:
properties:
bucketDNS:
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/minio.min.io/v1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (src *Tenant) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.ExternalCertSecret = src.Spec.ExternalCertSecret
dst.Spec.ExternalCaCertSecret = src.Spec.ExternalCaCertSecret
dst.Spec.ExternalClientCertSecret = src.Spec.ExternalClientCertSecret
dst.Spec.ExternalClientCertSecrets = src.Spec.ExternalClientCertSecrets
dst.Spec.Mountpath = src.Spec.Mountpath
dst.Spec.Subpath = src.Spec.Subpath
dst.Spec.RequestAutoCert = src.Spec.RequestAutoCert
Expand Down Expand Up @@ -150,6 +151,7 @@ func (dst *Tenant) ConvertFrom(srcRaw conversion.Hub) error { //nolint
dst.Spec.ExternalCertSecret = src.Spec.ExternalCertSecret
dst.Spec.ExternalCaCertSecret = src.Spec.ExternalCaCertSecret
dst.Spec.ExternalClientCertSecret = src.Spec.ExternalClientCertSecret
dst.Spec.ExternalClientCertSecrets = src.Spec.ExternalClientCertSecrets
dst.Spec.Mountpath = src.Spec.Mountpath
dst.Spec.Subpath = src.Spec.Subpath
dst.Spec.RequestAutoCert = src.Spec.RequestAutoCert
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/minio.min.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ type TenantSpec struct {
// used for enabling TLS with SNI support on MinIO Pods.
// +optional
ExternalCertSecret []*miniov2.LocalCertificateReference `json:"externalCertSecret,omitempty"`
// ExternalClientCertSecret allows a user to specify custom CA client certificate, and private key. This is
// ExternalClientCertSecret allows a user to specify custom client certificate, and private key. This is
// used for adding client certificates on MinIO Pods --> used for KES authentication.
// +optional
ExternalClientCertSecret *miniov2.LocalCertificateReference `json:"externalClientCertSecret,omitempty"`
// ExternalClientCertSecrets allows a user to specify additional client certificates, and private keys. This is
// used for adding client certificates on MinIO Pods and perform mTLS with external services.
// +optional
ExternalClientCertSecrets []*miniov2.LocalCertificateReference `json:"externalClientCertSecrets,omitempty"`
// ExternalCaCertSecret allows a user to provide additional CA certificates. This is
// used for Console to verify TLS connections with other applications.
// +optional
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/minio.min.io/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/minio.min.io/v2/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func (t *Tenant) ExternalClientCert() bool {
return t.Spec.ExternalClientCertSecret != nil && t.Spec.ExternalClientCertSecret.Name != ""
}

// ExternalClientCerts returns true is the user has provided additional client certificates
func (t *Tenant) ExternalClientCerts() bool {
return len(t.Spec.ExternalClientCertSecrets) > 0
}

// KESExternalCert returns true is the user has provided a secret
// that contains CA cert, server cert and server key for KES pods
func (t *Tenant) KESExternalCert() bool {
Expand Down
25 changes: 25 additions & 0 deletions pkg/apis/minio.min.io/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,31 @@ type TenantSpec struct {
ExternalClientCertSecret *LocalCertificateReference `json:"externalClientCertSecret,omitempty"`
// *Optional* +
//
// Provide support for mounting additional client certificate into MinIO Tenant pods
// Multiple client certificates will be mounted using the following folder structure:
//
// certs
// |
// + client-0
// | + client.crt
// | + client.key
// + client-1
// | + client.crt
// | + client.key
// + client-2
// | + client.crt
// | + client.key
//
// Specify a https://kubernetes.io/docs/concepts/configuration/secret/[Kubernetes TLS secrets]. The MinIO Operator copies the specified certificate to every MinIO server pod in the tenant that later can be referenced using environment variables. The secret *must* contain the following fields: +
//
// * `name` - The name of the Kubernetes secret containing the TLS certificate. +
//
// * `type` - Specify `kubernetes.io/tls` +
//
// +optional
ExternalClientCertSecrets []*LocalCertificateReference `json:"externalClientCertSecrets,omitempty"`
// *Optional* +
//
// Mount path for MinIO volume (PV). Defaults to `/export`
// +optional
Mountpath string `json:"mountPath,omitempty"`
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/minio.min.io/v2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions pkg/resources/statefulsets/minio-statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,51 @@ func NewPool(t *miniov2.Tenant, wsSecret *v1.Secret, skipEnvVars map[string][]by
},
})
}
// Multiple client certificates will be mounted using the following folder structure:
//
// certs
// |
// + client-0
// | + client.crt
// | + client.key
// + client-1
// | + client.crt
// | + client.key
// + client-2
// | + client.crt
// | + client.key
//
// Iterate over all provided client TLS certificates and store them on the list of Volumes that will be mounted to the Pod
for index, secret := range t.Spec.ExternalClientCertSecrets {
crtMountPath := fmt.Sprintf("client-%d/client.crt", index)
keyMountPath := fmt.Sprintf("client-%d/client.key", index)
var clientKeyPairPaths []corev1.KeyToPath
if secret.Type == "kubernetes.io/tls" {
clientKeyPairPaths = []corev1.KeyToPath{
{Key: "tls.crt", Path: crtMountPath},
{Key: "tls.key", Path: keyMountPath},
}
} else if secret.Type == "cert-manager.io/v1alpha2" || secret.Type == "cert-manager.io/v1" {
clientKeyPairPaths = []corev1.KeyToPath{
{Key: "tls.crt", Path: crtMountPath},
{Key: "tls.key", Path: keyMountPath},
{Key: "ca.crt", Path: fmt.Sprintf("CAs/client-ca-%d.crt", index)},
}
} else {
clientKeyPairPaths = []corev1.KeyToPath{
{Key: "public.crt", Path: crtMountPath},
{Key: "private.key", Path: keyMountPath},
}
}
certVolumeSources = append(certVolumeSources, corev1.VolumeProjection{
Secret: &corev1.SecretProjection{
LocalObjectReference: corev1.LocalObjectReference{
Name: secret.Name,
},
Items: clientKeyPairPaths,
},
})
}

// Will mount into ~/.minio/certs/CAs folder the user provided CA certificates.
// This is used for MinIO to verify TLS connections with other applications.
Expand Down
22 changes: 22 additions & 0 deletions resources/base/crds/minio.min.io_tenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ spec:
required:
- name
type: object
externalClientCertSecrets:
items:
properties:
name:
type: string
type:
type: string
required:
- name
type: object
type: array
image:
type: string
imagePullPolicy:
Expand Down Expand Up @@ -4541,6 +4552,17 @@ spec:
required:
- name
type: object
externalClientCertSecrets:
items:
properties:
name:
type: string
type:
type: string
required:
- name
type: object
type: array
features:
properties:
bucketDNS:
Expand Down

0 comments on commit 2f58272

Please sign in to comment.