Skip to content

Commit e22b504

Browse files
expose acl configuration as configMap
1 parent 9752d8c commit e22b504

3 files changed

Lines changed: 77 additions & 14 deletions

File tree

example/rocketmq_v1alpha1_broker_cr.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,39 @@ data:
2828
brokerRole=ASYNC_MASTER
2929
3030
---
31+
apiVersion: v1
32+
kind: ConfigMap
33+
metadata:
34+
name: broker-acl-config
35+
data:
36+
plain_acl.yml: |
37+
globalWhiteRemoteAddresses:
38+
- 10.10.103.*
39+
- 192.168.0.*
40+
41+
accounts:
42+
- accessKey: RocketMQ
43+
secretKey: 123456789 # |||
44+
whiteRemoteAddress:
45+
admin: false
46+
defaultTopicPerm: DENY
47+
defaultGroupPerm: SUB
48+
topicPerms:
49+
- topicA=DENY
50+
- topicB=PUB|SUB
51+
- topicC=SUB
52+
groupPerms:
53+
# the group should convert to retry topic
54+
- groupA=DENY
55+
- groupB=PUB|SUB
56+
- groupC=SUB
57+
58+
- accessKey: rocketmq2
59+
secretKey: 123456789 # |||
60+
whiteRemoteAddress: 192.168.1.*
61+
# if it is admin, it could access all resources
62+
admin: true
63+
---
3164
apiVersion: rocketmq.apache.org/v1alpha1
3265
kind: Broker
3366
metadata:
@@ -75,6 +108,12 @@ spec:
75108
items:
76109
- key: broker-common.conf
77110
path: broker-common.conf
111+
- name: broker-acl-config
112+
configMap:
113+
name: broker-acl-config
114+
items:
115+
- key: plain_acl.yml
116+
path: plain_acl.yml
78117
# volumeClaimTemplates defines the storageClass
79118
volumeClaimTemplates:
80119
- metadata:

pkg/constants/constants.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ const (
4646
// SubscriptionGroupJsonDir is the directory of subscriptionGroup.json
4747
SubscriptionGroupJsonDir = StoreConfigDir + "/subscriptionGroup.json"
4848

49-
// BrokerConfigDir is the directory of the mounted config file
49+
// BrokerConfigPath is the directory of the mounted config file
5050
BrokerConfigPath = DataPath + "/rocketmq/broker/conf"
5151

52+
// BrokerPlainAclConfigName is the name of mounted acl config file
53+
BrokerPlainAclConfigName = "plain_acl.yml"
54+
5255
// BrokerConfigName is the name of mounted configuration file
5356
BrokerConfigName = "broker-common.conf"
5457

pkg/controller/broker/broker_controller.go

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,7 @@ func (r *ReconcileBroker) getBrokerStatefulSet(broker *rocketmqv1alpha1.Broker,
484484
ContainerPort: cons.BrokerHighAvailabilityContainerPort,
485485
Name: cons.BrokerHighAvailabilityContainerPortName,
486486
}},
487-
VolumeMounts: []corev1.VolumeMount{{
488-
MountPath: cons.LogMountPath,
489-
Name: broker.Spec.VolumeClaimTemplates[0].Name,
490-
SubPath: cons.LogSubPathName + getPathSuffix(broker, brokerGroupIndex, replicaIndex),
491-
}, {
492-
MountPath: cons.StoreMountPath,
493-
Name: broker.Spec.VolumeClaimTemplates[0].Name,
494-
SubPath: cons.StoreSubPathName + getPathSuffix(broker, brokerGroupIndex, replicaIndex),
495-
}, {
496-
MountPath: cons.BrokerConfigPath + "/" + cons.BrokerConfigName,
497-
Name: broker.Spec.Volumes[0].Name,
498-
SubPath: cons.BrokerConfigName,
499-
}},
487+
VolumeMounts: getVolumeMounts(broker, brokerGroupIndex, replicaIndex),
500488
}},
501489
Volumes: getVolumes(broker),
502490
SecurityContext: getPodSecurityContext(broker),
@@ -512,6 +500,39 @@ func (r *ReconcileBroker) getBrokerStatefulSet(broker *rocketmqv1alpha1.Broker,
512500

513501
}
514502

503+
func getVolumeMounts(broker *rocketmqv1alpha1.Broker, brokerGroupIndex int, replicaIndex int) []corev1.VolumeMount {
504+
mounts := make([]corev1.VolumeMount, 0)
505+
506+
if len(broker.Spec.VolumeClaimTemplates) >= 1 {
507+
mounts = append(mounts, corev1.VolumeMount{
508+
MountPath: cons.LogMountPath,
509+
Name: broker.Spec.VolumeClaimTemplates[0].Name,
510+
SubPath: cons.LogSubPathName + getPathSuffix(broker, brokerGroupIndex, replicaIndex),
511+
})
512+
mounts = append(mounts, corev1.VolumeMount{
513+
MountPath: cons.StoreMountPath,
514+
Name: broker.Spec.VolumeClaimTemplates[0].Name,
515+
SubPath: cons.StoreSubPathName + getPathSuffix(broker, brokerGroupIndex, replicaIndex),
516+
})
517+
}
518+
if len(broker.Spec.Volumes) >= 1 {
519+
mounts = append(mounts, corev1.VolumeMount{
520+
MountPath: cons.BrokerConfigPath + "/" + cons.BrokerConfigName,
521+
Name: broker.Spec.Volumes[0].Name,
522+
SubPath: cons.BrokerConfigName,
523+
})
524+
}
525+
526+
if len(broker.Spec.Volumes) > 1 {
527+
mounts = append(mounts, corev1.VolumeMount{
528+
MountPath: cons.BrokerConfigPath + "/" + cons.BrokerPlainAclConfigName,
529+
Name: broker.Spec.Volumes[1].Name,
530+
SubPath: cons.BrokerPlainAclConfigName,
531+
})
532+
}
533+
return mounts
534+
}
535+
515536
func getENV(broker *rocketmqv1alpha1.Broker, replicaIndex int, brokerGroupIndex int) []corev1.EnvVar {
516537
envs := []corev1.EnvVar{{
517538
Name: cons.EnvNameServiceAddress,

0 commit comments

Comments
 (0)