Skip to content

Commit 5b868e7

Browse files
authored
Merge pull request #96 from marklogic/MLE-21295/automountServiceAccountToken-to-false
MLE-21295: Enforce automountServiceAccountToken=false
2 parents a8a0439 + 0253625 commit 5b868e7

11 files changed

+46
-19
lines changed

api/v1/marklogiccluster_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type MarklogicClusterSpec struct {
4646
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="ServiceAccountName can not be changed"
4747
// The name of the service account to assigned to the MarkLogic pods
4848
ServiceAccountName string `json:"serviceAccountName,omitempty"`
49+
// +kubebuilder:default:=false
50+
AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty"`
4951
// +kubebuilder:default:={enabled: true, size: "10Gi"}
5052
Persistence *Persistence `json:"persistence,omitempty"`
5153
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`

api/v1/marklogicgroup_types.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ type MarklogicGroupSpec struct {
3737
// +kubebuilder:default:="progressofficial/marklogic-db:11.3.0-ubi-rootless"
3838
Image string `json:"image"`
3939
// +kubebuilder:default:="IfNotPresent"
40-
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
41-
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
42-
Auth *AdminAuth `json:"auth,omitempty"`
43-
ServiceAccountName string `json:"serviceAccountName,omitempty"`
44-
Persistence *Persistence `json:"persistence,omitempty"`
45-
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
46-
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
40+
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
41+
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
42+
Auth *AdminAuth `json:"auth,omitempty"`
43+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
44+
// +kubebuilder:default:=false
45+
AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty"`
46+
Persistence *Persistence `json:"persistence,omitempty"`
47+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
48+
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
4749
// +kubebuilder:validation:Enum=OnDelete;RollingUpdate
4850
// +kubebuilder:default:="OnDelete"
4951
UpdateStrategy appsv1.StatefulSetUpdateStrategyType `json:"updateStrategy,omitempty"`

api/v1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/marklogic.progress.com_marklogicclusters.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,6 +3260,9 @@ spec:
32603260
walletPassword:
32613261
type: string
32623262
type: object
3263+
automountServiceAccountToken:
3264+
default: false
3265+
type: boolean
32633266
clusterDomain:
32643267
default: cluster.local
32653268
type: string

config/crd/bases/marklogic.progress.com_marklogicgroups.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,6 +3265,9 @@ spec:
32653265
walletPassword:
32663266
type: string
32673267
type: object
3268+
automountServiceAccountToken:
3269+
default: false
3270+
type: boolean
32683271
bootstrapHost:
32693272
type: string
32703273
clusterDomain:

config/samples/complete.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: prod
66
annotations: {}
77
spec:
8-
image: "progressofficial/marklogic-db:11.3.1-ubi-rootless-2.1.1"
8+
image: "progressofficial/marklogic-db:11.3.1-ubi-rootless-2.2.1"
99
imagePullPolicy: IfNotPresent
1010
imagePullSecrets:
1111
- name: regcred

config/samples/minimal-production.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
name: ml-cluster
66
namespace: prod
77
spec:
8-
image: "progressofficial/marklogic-db:11.3.1-ubi-rootless-2.1.1"
8+
image: "progressofficial/marklogic-db:11.3.1-ubi-rootless-2.2.1"
99
## It is recommended to use Kubernetes secrets to store the admin credentials
1010
## To create a secret, run the following command in the same namespace as the CR:
1111
## kubectl create secret generic admincreds --from-literal=username=admin --from-literal=password=admin

config/samples/quick-start.yaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,17 @@ metadata:
44
name: single-node
55
annotations: {}
66
spec:
7-
image: "progressofficial/marklogic-db:11.3.0-ubi-rootless"
7+
image: "progressofficial/marklogic-db:11.3.1-ubi-rootless-2.2.1"
88
## It is recommended to use Kubernetes secrets to store the admin credentials
99
## To create a secret, run the following command in the same namespace as the CR:
1010
## kubectl create secret generic admincreds --from-literal=username=admin --from-literal=password=admin
1111
## If you do not provide the admin credentials, the operator will generate a secret for you containing admin credentials
1212
persistence:
13-
enabled: true
13+
enabled: false
1414
size: 10Gi
1515
markLogicGroups:
1616
- replicas: 1
1717
name: node
1818
groupConfig:
1919
name: node
20-
resources:
21-
requests:
22-
memory: "4Gi"
23-
cpu: 2000m
24-
limits:
25-
memory: "4Gi"
26-
cpu: 2000m
2720
isBootstrap: true

pkg/k8sutil/marklogicServer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type MarkLogicGroupParameters struct {
1919
Replicas *int32
2020
Name string
2121
ServiceAccountName string
22+
AutomountServiceAccountToken *bool
2223
Labels map[string]string
2324
Annotations map[string]string
2425
GroupConfig *marklogicv1.GroupConfig
@@ -124,6 +125,7 @@ func (cc *ClusterContext) GenerateMarkLogicGroupDef(cr *marklogicv1.MarklogicClu
124125
GroupConfig: params.GroupConfig,
125126
Auth: params.Auth,
126127
ServiceAccountName: params.ServiceAccountName,
128+
AutomountServiceAccountToken: params.AutomountServiceAccountToken,
127129
Image: params.Image,
128130
Labels: params.Labels,
129131
Annotations: params.Annotations,
@@ -261,6 +263,9 @@ func generateMarkLogicClusterParams(cr *marklogicv1.MarklogicCluster) *MarkLogic
261263
}
262264

263265
func generateMarkLogicGroupParams(cr *marklogicv1.MarklogicCluster, index int, clusterParams *MarkLogicClusterParameters) *MarkLogicGroupParameters {
266+
// Always enforce automountServiceAccountToken to false for security
267+
falseValue := false
268+
264269
markLogicGroupParameters := &MarkLogicGroupParameters{
265270
Replicas: cr.Spec.MarkLogicGroups[index].Replicas,
266271
Name: cr.Spec.MarkLogicGroups[index].Name,
@@ -273,6 +278,7 @@ func generateMarkLogicGroupParams(cr *marklogicv1.MarklogicCluster, index int, c
273278
ImagePullSecrets: clusterParams.ImagePullSecrets,
274279
Auth: clusterParams.Auth,
275280
ServiceAccountName: clusterParams.ServiceAccountName,
281+
AutomountServiceAccountToken: &falseValue, // Always false for security
276282
License: clusterParams.License,
277283
Persistence: clusterParams.Persistence,
278284
TerminationGracePeriodSeconds: clusterParams.TerminationGracePeriodSeconds,

pkg/k8sutil/statefulset.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type statefulSetParameters struct {
3232
ImagePullSecrets []corev1.LocalObjectReference
3333
AdditionalVolumeClaimTemplates *[]corev1.PersistentVolumeClaim
3434
ServiceAccountName string
35+
AutomountServiceAccountToken *bool
3536
}
3637

3738
type containerParameters struct {
@@ -238,6 +239,9 @@ func generateStatefulSetsDef(stsMeta metav1.ObjectMeta, params statefulSetParame
238239
if params.ServiceAccountName != "" {
239240
statefulSet.Spec.Template.Spec.ServiceAccountName = params.ServiceAccountName
240241
}
242+
if params.AutomountServiceAccountToken != nil {
243+
statefulSet.Spec.Template.Spec.AutomountServiceAccountToken = params.AutomountServiceAccountToken
244+
}
241245
if containerParams.Tls != nil && containerParams.Tls.EnableOnDefaultAppServers {
242246
copyCertsVM := []corev1.VolumeMount{
243247
{
@@ -349,10 +353,14 @@ func generateContainerDef(name string, containerParams containerParameters) []co
349353
}
350354

351355
func generateStatefulSetsParams(cr *marklogicv1.MarklogicGroup) statefulSetParameters {
356+
// Always enforce automountServiceAccountToken to false for security
357+
falseValue := false
358+
352359
params := statefulSetParameters{
353360
Replicas: cr.Spec.Replicas,
354361
Name: cr.Spec.Name,
355362
ServiceAccountName: cr.Spec.ServiceAccountName,
363+
AutomountServiceAccountToken: &falseValue, // Always false for security
356364
TerminationGracePeriodSeconds: cr.Spec.TerminationGracePeriodSeconds,
357365
UpdateStrategy: cr.Spec.UpdateStrategy,
358366
NodeSelector: cr.Spec.NodeSelector,

0 commit comments

Comments
 (0)