Skip to content

Commit 7a94802

Browse files
authored
Merge pull request #107 from nitisht/mcs
Update mcs config
2 parents f424a95 + 53ee997 commit 7a94802

File tree

9 files changed

+120
-80
lines changed

9 files changed

+120
-80
lines changed

docs/mcs.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ MCS Configuration is a part of MinIOInstance yaml file. Check the sample file [a
2121
|-----------------------|-------------|
2222
| spec.mcs | Defines the mcs configuration. mcs is a graphical user interface for MinIO. Refer [this](https://github.com/minio/mcs) |
2323
| spec.mcs.image | Defines the mcs image |
24-
| spec.mcs.mcsAccessKey | Specify the access key to be used by mcs |
24+
| spec.mcs.replicas | Number of MCS pods to be created. |
2525
| spec.mcs.mcsSecret | Use this secret to assign mcs credentials to MinIOInstance. |
2626
| spec.mcs.selector | Add a selector for the mcs. Which will be used by the mcs container for grouping. (Note: Should not match the labels provided in `spec.selector`) |
2727
| spec.mcs.metadata | This allows a way to map metadata to the mcs container. Internally `metadata` is a struct type as [explained here](https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta). [Note: Should match the labels in `spec.mcs.selector`] |
@@ -39,3 +39,16 @@ Alternatively, you can deploy the example like this
3939
```
4040
kubectl create -f https://raw.githubusercontent.com/minio/minio-operator/master/examples/minioinstance-mcs.yaml
4141
```
42+
43+
Above example file uses CSR for self signed certificate generation. MinIO requires one certificates/key pair
44+
45+
- X.509 certificate for the MinIO server and the corresponding private key.
46+
47+
Accordingly, you'll need to approve the CSR request, using below approach
48+
49+
```
50+
kubectl get csr
51+
kubectl certificate approve <csr-name>
52+
```
53+
54+
Once all the CSRs are approved, MinIO Operator will deploy MCS Pods and start MinIO Server with MCS integration.

docs/operator-fields.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ If the MirrorInstance is named as `mirrorinstance`, resources and their names as
4545
| spec.securityContext | Define a security context for the MinIOInstance pod. Refer [this document](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) for details. |
4646
| spec.mcs | Defines the mcs configuration. mcs is a graphical user interface for MinIO. Refer [this](https://github.com/minio/mcs) |
4747
| spec.mcs.image | Defines the mcs image. |
48-
| spec.mcs.mcsAccessKey | Specify the access key to be used by mcs |
48+
| spec.mcs.replicas | Number of MCS pods to be created. |
4949
| spec.mcs.mcsSecret | Use this secret to assign mcs credentials to MinIOInstance. |
5050
| spec.mcs.selector | Add a selector for the mcs. Which will be used by the mcs container for grouping. (Note: Should not match the labels provided in `spec.selector`) |
5151
| spec.mcs.metadata | This allows a way to map metadata to the mcs container. Internally `metadata` is a struct type as [explained here](https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta). [Note: Should match the labels in `spec.mcs.selector`] |

examples/minioinstance-kes.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ spec:
8484
storage: 10Gi
8585
## Define configuration for MCS (Graphical user interface for MinIO)
8686
mcs:
87-
image: minio/mcs:v0.0.3
88-
mcsAccessKey: "mcs"
87+
image: minio/mcs:v0.0.4
88+
replicas: 2
8989
mcsSecret:
9090
name: minio-mcs-secret
9191
metadata:

examples/minioinstance-mcs.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ metadata:
1313
name: minio-mcs-secret
1414
type: Opaque
1515
data:
16-
mcshmacjwt: WU9VUkpXVFNJR05JTkdTRUNSRVQ= # base 64 encoded "YOURJWTSIGNINGSECRET" (echo -n 'YOURJWTSIGNINGSECRET' | base64)
17-
mcspbkdfpassphrase: U0VDUkVU # base 64 encoded "SECRET" (echo -n 'SECRET' | base64)
18-
mcspbkdfsalt: U0VDUkVU # base 64 encoded "SECRET" (echo -n 'SECRET' | base64)
19-
mcssecretkey: WU9VUk1DU1NFQ1JFVA== # base 64 encoded "YOURMCSSECRET" (echo -n 'YOURMCSSECRET' | base64)
16+
MCS_HMAC_JWT_SECRET: WU9VUkpXVFNJR05JTkdTRUNSRVQ= # base 64 encoded "YOURJWTSIGNINGSECRET" (echo -n 'YOURJWTSIGNINGSECRET' | base64)
17+
MCS_PBKDF_PASSPHRASE: U0VDUkVU # base 64 encoded "SECRET" (echo -n 'SECRET' | base64)
18+
MCS_PBKDF_SALT: U0VDUkVU # base 64 encoded "SECRET" (echo -n 'SECRET' | base64)
19+
MCS_ACCESS_KEY: WU9VUk1DU0FDQ0VTUw== # base 64 encoded "YOURMCSACCESS" (echo -n 'YOURMCSACCESS' | base64)
20+
MCS_SECRET_KEY: WU9VUk1DU1NFQ1JFVA== # base 64 encoded "YOURMCSSECRET" (echo -n 'YOURMCSSECRET' | base64)
2021
---
2122
apiVersion: v1
2223
kind: Service
@@ -84,8 +85,8 @@ spec:
8485
storage: 10Gi
8586
## Define configuration for MCS (Graphical user interface for MinIO)
8687
mcs:
87-
image: minio/mcs:v0.0.3
88-
mcsAccessKey: "mcs"
88+
image: minio/mcs:v0.0.4
89+
replicas: 2
8990
mcsSecret:
9091
name: minio-mcs-secret
9192
metadata:
@@ -100,7 +101,7 @@ spec:
100101
# name: tls-ssl-minio
101102
## Enable Kubernetes based certificate generation and signing as explained in
102103
## https://kubernetes.io/docs/tasks/tls/managing-tls-in-a-cluster
103-
requestAutoCert: false
104+
requestAutoCert: true
104105
## PodManagement policy for pods created by StatefulSet. Can be "OrderedReady" or "Parallel"
105106
## Refer https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#pod-management-policy
106107
## for details. Defaults to "Parallel"
@@ -136,6 +137,7 @@ spec:
136137
## restarts the pods if liveness checks fail.
137138
liveness:
138139
httpGet:
140+
scheme: HTTPS
139141
path: /minio/health/live
140142
port: 9000
141143
initialDelaySeconds: 120
@@ -147,6 +149,7 @@ spec:
147149
## Disable this check if you're setting PodManagementPolicy to "OrderedReady".
148150
readiness:
149151
httpGet:
152+
scheme: HTTPS
150153
path: /minio/health/ready
151154
port: 9000
152155
initialDelaySeconds: 120

examples/minioinstance.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ spec:
110110
# value: storage
111111
## Define configuration for mcs (A graphical user interface for MinIO)
112112
mcs:
113-
image: minio/mcs:v0.0.3
114-
mcsAccessKey: "mcs"
113+
image: minio/mcs:v0.0.4
114+
replicas: 2
115115
mcsSecret:
116116
name: minio-mcs-secret
117117
selector:

pkg/apis/operator.min.io/v1/constants.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const MirrorCRDResourceKind = "MirrorInstance"
104104
// MCS Related Constants
105105

106106
// DefaultMCSImage specifies the latest MCS Docker hub image
107-
const DefaultMCSImage = "minio/mcs:v0.0.3"
107+
const DefaultMCSImage = "minio/mcs:v0.0.4"
108108

109109
// MCSInstanceLabel is applied to the MCS pods of a MinIOInstance cluster
110110
const MCSInstanceLabel = "v1.min.io/mcs"
@@ -127,6 +127,9 @@ const MCSAdminPolicyName = "mcsAdmin"
127127
// MCSRestartPolicy defines the default restart policy for MCS Containers
128128
const MCSRestartPolicy = corev1.RestartPolicyAlways
129129

130+
// DefaultMCSReplicas specifies the default number of MCS pods to be created if not specified
131+
const DefaultMCSReplicas = 2
132+
130133
// KES Related Constants
131134

132135
// DefaultKESImage specifies the latest KES Docker hub image

pkg/apis/operator.min.io/v1/helper.go

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ package v1
1919

2020
import (
2121
"context"
22+
"crypto/tls"
2223
"errors"
2324
"fmt"
2425
"net"
26+
"net/http"
2527
"path"
2628
"strconv"
2729
"time"
@@ -167,8 +169,13 @@ func (mi *MinIOInstance) EnsureDefaults() *MinIOInstance {
167169
}
168170
}
169171

170-
if mi.HasMCSEnabled() && mi.Spec.MCS.Image == "" {
171-
mi.Spec.MCS.Image = DefaultMCSImage
172+
if mi.HasMCSEnabled() {
173+
if mi.Spec.MCS.Image == "" {
174+
mi.Spec.MCS.Image = DefaultMCSImage
175+
}
176+
if mi.Spec.MCS.Replicas == 0 {
177+
mi.Spec.MCS.Replicas = DefaultMCSReplicas
178+
}
172179
}
173180

174181
if mi.HasKESEnabled() {
@@ -292,7 +299,7 @@ func (mi *MinIOInstance) HasKESSelector() bool {
292299
// CreateMCSUser function creates an admin user
293300
func (mi *MinIOInstance) CreateMCSUser(minioSecret, mcsSecret map[string][]byte) error {
294301

295-
var accessKey, secretKey, mcsSecretKey []byte
302+
var accessKey, secretKey, mcsAccessKey, mcsSecretKey []byte
296303
var ok bool
297304

298305
host := net.JoinHostPort(mi.MinIOCIServiceHost(), strconv.Itoa(MinIOPort))
@@ -310,19 +317,30 @@ func (mi *MinIOInstance) CreateMCSUser(minioSecret, mcsSecret map[string][]byte)
310317
return errors.New("secretkey not provided")
311318
}
312319

313-
mcsSecretKey, ok = mcsSecret["mcssecretkey"]
320+
mcsAccessKey, ok = mcsSecret["MCS_ACCESS_KEY"]
321+
if !ok {
322+
return errors.New("MCS_ACCESS_KEY not provided")
323+
}
324+
325+
mcsSecretKey, ok = mcsSecret["MCS_SECRET_KEY"]
314326
if !ok {
315-
return errors.New("mcssecretkey not provided")
327+
return errors.New("MCS_SECRET_KEY not provided")
316328
}
317329

318330
madmClnt, err := madmin.New(host, string(accessKey), string(secretKey), Scheme == "https")
319331
if err != nil {
320332
return err
321333
}
322-
// try to add user with a 20 seconds timeout
334+
335+
if Scheme == "https" {
336+
madmClnt = setUpInsecureTLS(madmClnt)
337+
}
338+
339+
// add user with a 20 seconds timeout
323340
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
324341
defer cancel()
325-
if err = madmClnt.AddUser(ctx, mi.Spec.MCS.MCSAccessKey, string(mcsSecretKey)); err != nil {
342+
343+
if err = madmClnt.AddUser(ctx, string(mcsAccessKey), string(mcsSecretKey)); err != nil {
326344
return err
327345
}
328346

@@ -351,13 +369,37 @@ func (mi *MinIOInstance) CreateMCSUser(minioSecret, mcsSecret map[string][]byte)
351369
return err
352370
}
353371

354-
if err = madmClnt.SetPolicy(context.Background(), MCSAdminPolicyName, string(mi.Spec.MCS.MCSAccessKey), false); err != nil {
372+
if err = madmClnt.SetPolicy(context.Background(), MCSAdminPolicyName, string(mcsAccessKey), false); err != nil {
355373
return err
356374
}
357375

358376
return nil
359377
}
360378

379+
// Set up admin client to use self certificates
380+
func setUpInsecureTLS(api *madmin.AdminClient) *madmin.AdminClient {
381+
// Keep TLS config.
382+
tlsConfig := &tls.Config{
383+
// Can't use SSLv3 because of POODLE and BEAST
384+
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
385+
// Can't use TLSv1.1 because of RC4 cipher usage
386+
MinVersion: tls.VersionTLS12,
387+
InsecureSkipVerify: true,
388+
}
389+
390+
var transport http.RoundTripper = &http.Transport{
391+
DialContext: (&net.Dialer{
392+
Timeout: 10 * time.Second,
393+
KeepAlive: 15 * time.Second,
394+
}).DialContext,
395+
TLSClientConfig: tlsConfig,
396+
}
397+
398+
// Set custom transport.
399+
api.SetCustomTransport(transport)
400+
return api
401+
}
402+
361403
// OwnerRef returns the OwnerReference to be added to all resources created by MinIOInstance
362404
func (mi *MinIOInstance) OwnerRef() []metav1.OwnerReference {
363405
return []metav1.OwnerReference{

pkg/apis/operator.min.io/v1/types.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,17 @@ type Zone struct {
154154

155155
// MCSConfig defines the credentials for mcs
156156
type MCSConfig struct {
157-
Image string `json:"image,omitempty"`
158-
MCSAccessKey string `json:"mcsAccessKey"`
159-
MCSSecret *corev1.LocalObjectReference `json:"mcsSecret,omitempty"`
160-
Selector *metav1.LabelSelector `json:"selector,omitempty"`
161-
Metadata *metav1.ObjectMeta `json:"metadata,omitempty"`
157+
// Replicas defines number of pods for KES StatefulSet.
158+
// +optional
159+
Replicas int32 `json:"replicas,omitempty"`
160+
// Image defines the MinIOInstance Docker image.
161+
// +optional
162+
Image string `json:"image,omitempty"`
163+
// This secret provides all environment variables for KES
164+
// This is a mandatory field
165+
MCSSecret *corev1.LocalObjectReference `json:"mcsSecret,omitempty"`
166+
Selector *metav1.LabelSelector `json:"selector,omitempty"`
167+
Metadata *metav1.ObjectMeta `json:"metadata,omitempty"`
162168
}
163169

164170
// KESConfig defines the specifications for KES StatefulSet

pkg/resources/deployments/mcs-deployment.go

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,33 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
)
2929

30-
// Returns the MCS environment variables set in configuration.
31-
func mcsEnvironmentVars(mi *miniov1.MinIOInstance) []corev1.EnvVar {
32-
envVars := make([]corev1.EnvVar, 0)
33-
if mi.HasMCSSecret() {
34-
var secretName string
35-
secretName = mi.Spec.MCS.MCSSecret.Name
36-
envVars = append(envVars, corev1.EnvVar{
37-
Name: "MCS_HMAC_JWT_SECRET",
38-
ValueFrom: &corev1.EnvVarSource{
39-
SecretKeyRef: &corev1.SecretKeySelector{
40-
LocalObjectReference: corev1.LocalObjectReference{
41-
Name: secretName,
42-
},
43-
Key: "mcshmacjwt",
44-
},
45-
},
46-
}, corev1.EnvVar{
47-
Name: "MCS_PBKDF_PASSPHRASE",
48-
ValueFrom: &corev1.EnvVarSource{
49-
SecretKeyRef: &corev1.SecretKeySelector{
50-
LocalObjectReference: corev1.LocalObjectReference{
51-
Name: secretName,
52-
},
53-
Key: "mcspbkdfpassphrase",
54-
},
55-
},
56-
}, corev1.EnvVar{
57-
Name: "MCS_PBKDF_SALT",
58-
ValueFrom: &corev1.EnvVarSource{
59-
SecretKeyRef: &corev1.SecretKeySelector{
60-
LocalObjectReference: corev1.LocalObjectReference{
61-
Name: secretName,
62-
},
63-
Key: "mcspbkdfsalt",
64-
},
65-
},
66-
}, corev1.EnvVar{
30+
// Adds required MCS environment variables
31+
func mcsEnvVars(mi *miniov1.MinIOInstance) []corev1.EnvVar {
32+
envVars := []corev1.EnvVar{
33+
{
6734
Name: "MCS_MINIO_SERVER",
6835
Value: miniov1.Scheme + "://" + net.JoinHostPort(mi.MinIOCIServiceHost(), strconv.Itoa(miniov1.MinIOPort)),
69-
}, corev1.EnvVar{
70-
Name: "MCS_SECRET_KEY",
71-
ValueFrom: &corev1.EnvVarSource{
72-
SecretKeyRef: &corev1.SecretKeySelector{
73-
LocalObjectReference: corev1.LocalObjectReference{
74-
Name: secretName,
75-
},
76-
Key: "mcssecretkey",
36+
},
37+
}
38+
if miniov1.Scheme == "https" {
39+
envVars = append(envVars, corev1.EnvVar{
40+
Name: "MCS_MINIO_SERVER_TLS_SKIP_VERIFICATION",
41+
Value: "on",
42+
})
43+
}
44+
return envVars
45+
}
46+
47+
// Returns the MCS environment variables set in configuration.
48+
func mcsSecretEnvVars(mi *miniov1.MinIOInstance) []corev1.EnvFromSource {
49+
envVars := []corev1.EnvFromSource{
50+
{
51+
SecretRef: &corev1.SecretEnvSource{
52+
LocalObjectReference: corev1.LocalObjectReference{
53+
Name: mi.Spec.MCS.MCSSecret.Name,
7754
},
7855
},
79-
}, corev1.EnvVar{
80-
Name: "MCS_ACCESS_KEY",
81-
Value: mi.Spec.MCS.MCSAccessKey,
82-
})
56+
},
8357
}
8458
return envVars
8559
}
@@ -123,24 +97,23 @@ func mcsContainer(mi *miniov1.MinIOInstance) corev1.Container {
12397
},
12498
ImagePullPolicy: miniov1.DefaultImagePullPolicy,
12599
Args: args,
126-
Env: mcsEnvironmentVars(mi),
100+
Env: mcsEnvVars(mi),
101+
EnvFrom: mcsSecretEnvVars(mi),
127102
Resources: mi.Spec.Resources,
128103
}
129104
}
130105

131106
// NewForMCS creates a new Deployment for the given MinIO instance.
132107
func NewForMCS(mi *miniov1.MinIOInstance) *appsv1.Deployment {
133108

134-
var replicas int32 = 1
135-
136109
d := &appsv1.Deployment{
137110
ObjectMeta: metav1.ObjectMeta{
138111
Namespace: mi.Namespace,
139112
Name: mi.MCSDeploymentName(),
140113
OwnerReferences: mi.OwnerRef(),
141114
},
142115
Spec: appsv1.DeploymentSpec{
143-
Replicas: &replicas,
116+
Replicas: &mi.Spec.MCS.Replicas,
144117
Selector: mi.Spec.MCS.Selector,
145118
Template: corev1.PodTemplateSpec{
146119
ObjectMeta: mcsMetadata(mi),

0 commit comments

Comments
 (0)