Skip to content

Commit

Permalink
Fix clusterMonitor role
Browse files Browse the repository at this point in the history
  • Loading branch information
debdutdeb committed Nov 15, 2022
1 parent a8f128d commit 4b6751c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
62 changes: 62 additions & 0 deletions rocketchat/templates/mongodb-init-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
{{ $config := lookup "v1" "ConfigMap" .Release.Namespace "rocketchat-mongodb-fix-clustermonitor-role-configmap" }}
{{ if not $config }}
apiVersion: v1
kind: ConfigMap
metadata:
name: rocketchat-mongodb-fix-clustermonitor-role-configmap
labels:
app.kubernetes.io/name: {{ include "rocketchat.name" . }}
helm.sh/chart: {{ include "rocketchat.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}

data:
user_set_role_clusrerMonitor.sh: |
#! /bin/bash
# #include <everything>
source /opt/bitnami/scripts/libmongodb.sh
error_and_abort() {
error "$@"
exit 1
}
main() {
# mongodb_wait_for_primary_node "$MONGODB_INITIAL_PRIMARY_HOST" "$MONGODB_INITIAL_PRIMARY_PORT_NUMBER" "$MONGODB_INITIAL_PRIMARY_ROOT_USER" "$MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD"
# Shouldn't be looping over all dbs, but currently no way of knowing which db is for rocketchat
# and which might not be.
# Either way, having clusterMonitor role shouldn't hurt
local databases=($MONGODB_DATABASE)
databases+=($MONGODB_EXTRA_DATABASES)
local usernames=($MONGODB_USERNAME)
usernames+=($MONGODB_EXTRA_USERNAMES)
# each array should be of the same length
local database username last=$((${#databases[@]}-1))
for idx in $(seq 0 $last); do
database=${databases[$idx]}
username=${usernames[$idx]}
info "attempting to add clusterMonitor role to user $username"
local cmd="
db.getSiblingDB('$database').grantRolesToUser(
'$username',
[
{
role: 'clusterMonitor',
db: 'admin'
}
]
)
"
debug "Executing: ${cmd:5:-1}"
local out=$(mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "" "" "--quiet" <<< "$cmd")
# local ok=$(perl -MJSON -0ne 'print decode_json($_)->{"ok"}' <<< "$out")
local ok=$(awk '/ok:/ { print $2 }' <<< ${out/,/})
{ [[ -n $out ]] && ! ((ok)); } && error_and_abort "failed to add role clusterMonitor to user \"$username\"; Error: $out"
info "clusterMonitor role added to $username"
done
}
main
{{end}}
2 changes: 2 additions & 0 deletions rocketchat/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ mongodb:
## Enable or disable MongoDB dependency completely.
enabled: true

initdbScriptsConfigMap: rocketchat-mongodb-fix-clustermonitor-role-configmap

auth:
# rootPassword:
username: rocketchat
Expand Down

0 comments on commit 4b6751c

Please sign in to comment.