Skip to content

Commit 3171d7a

Browse files
committed
Enabling the configuration of the hostname during initialization. Done via the environment variable MONGODB_LOCALHOST_NAME
Signed-off-by: Douglas Thomson <[email protected]>
1 parent 406a099 commit 3171d7a

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

bitnami/mongodb/5.0/debian-11/rootfs/opt/bitnami/scripts/libmongodb.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ mongodb_create_user() {
667667
[[ -z "$database" ]] && query="db.getSiblingDB(db.stats().db).createUser({ user: '$user', pwd: '$password', roles: [{role: 'readWrite', db: db.getSiblingDB(db.stats().db).stats().db }] })"
668668
# Create user, discarding mongo CLI output for clean logs
669669
info "Creating user '$user'..."
670-
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "127.0.0.1" <<<"$query"
670+
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "$MONGODB_LOCALHOST_NAME" <<<"$query"
671671
}
672672

673673
########################
@@ -684,7 +684,7 @@ mongodb_create_users() {
684684

685685
if [[ -n "$MONGODB_ROOT_PASSWORD" ]] && ! [[ "$MONGODB_REPLICA_SET_MODE" =~ ^(secondary|arbiter|hidden) ]]; then
686686
info "Creating $MONGODB_ROOT_USER user..."
687-
mongodb_execute "" "" "" "127.0.0.1" <<EOF
687+
mongodb_execute "" "" "" "$MONGODB_LOCALHOST_NAME" <<EOF
688688
db.getSiblingDB('admin').createUser({ user: '$MONGODB_ROOT_USER', pwd: '$MONGODB_ROOT_PASSWORD', roles: [{role: 'root', db: 'admin'}] })
689689
EOF
690690
fi
@@ -714,7 +714,7 @@ EOF
714714

715715
if [[ -n "$MONGODB_METRICS_USERNAME" ]] && [[ -n "$MONGODB_METRICS_PASSWORD" ]]; then
716716
info "Creating '$MONGODB_METRICS_USERNAME' user..."
717-
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "127.0.0.1" <<EOF
717+
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "$MONGODB_LOCALHOST_NAME" <<EOF
718718
db.getSiblingDB('admin').createUser({ user: '$MONGODB_METRICS_USERNAME', pwd: '$MONGODB_METRICS_PASSWORD', roles: [{role: 'clusterMonitor', db: 'admin'},{ role: 'read', db: 'local' }] })
719719
EOF
720720
fi
@@ -784,7 +784,7 @@ mongodb_is_primary_node_initiated() {
784784
local port="${2:?port is required}"
785785
local result
786786
result=$(
787-
mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "127.0.0.1" "$MONGODB_PORT_NUMBER" <<EOF
787+
mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "$MONGODB_LOCALHOST_NAME" "$MONGODB_PORT_NUMBER" <<EOF
788788
rs.initiate({"_id":"$MONGODB_REPLICA_SET_NAME", "members":[{"_id":0,"host":"$node:$port","priority":5}]})
789789
EOF
790790
)

bitnami/mongodb/5.0/debian-11/rootfs/opt/bitnami/scripts/mongodb-env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ mongodb_env_vars=(
6363
MONGODB_PRIMARY_PORT_NUMBER
6464
MONGODB_PRIMARY_ROOT_PASSWORD
6565
MONGODB_PRIMARY_ROOT_USER
66+
MONGODB_LOCALHOST_NAME
6667
)
6768
for env_var in "${mongodb_env_vars[@]}"; do
6869
file_env_var="${env_var}_FILE"
@@ -127,6 +128,7 @@ export MONGODB_ENABLE_IPV6="${MONGODB_ENABLE_IPV6:-}"
127128
export MONGODB_DEFAULT_ENABLE_IPV6="false"
128129
export MONGODB_SYSTEM_LOG_VERBOSITY="${MONGODB_SYSTEM_LOG_VERBOSITY:-}"
129130
export MONGODB_DEFAULT_SYSTEM_LOG_VERBOSITY="0"
131+
export MONGODB_LOCALHOST_NAME="${MONGODB_LOCALHOST_NAME:-127.0.0.1}"
130132

131133
# User and database creation settings
132134
export MONGODB_ROOT_USER="${MONGODB_ROOT_USER:-root}"

bitnami/mongodb/6.0/debian-11/rootfs/opt/bitnami/scripts/libmongodb.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ mongodb_create_user() {
667667
[[ -z "$database" ]] && query="db.getSiblingDB(db.stats().db).createUser({ user: '$user', pwd: '$password', roles: [{role: 'readWrite', db: db.getSiblingDB(db.stats().db).stats().db }] })"
668668
# Create user, discarding mongo CLI output for clean logs
669669
info "Creating user '$user'..."
670-
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "127.0.0.1" <<<"$query"
670+
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "$MONGODB_LOCALHOST_NAME" <<<"$query"
671671
}
672672

673673
########################
@@ -684,7 +684,7 @@ mongodb_create_users() {
684684

685685
if [[ -n "$MONGODB_ROOT_PASSWORD" ]] && ! [[ "$MONGODB_REPLICA_SET_MODE" =~ ^(secondary|arbiter|hidden) ]]; then
686686
info "Creating $MONGODB_ROOT_USER user..."
687-
mongodb_execute "" "" "" "127.0.0.1" <<EOF
687+
mongodb_execute "" "" "" "$MONGODB_LOCALHOST_NAME" <<EOF
688688
db.getSiblingDB('admin').createUser({ user: '$MONGODB_ROOT_USER', pwd: '$MONGODB_ROOT_PASSWORD', roles: [{role: 'root', db: 'admin'}] })
689689
EOF
690690
fi
@@ -714,7 +714,7 @@ EOF
714714

715715
if [[ -n "$MONGODB_METRICS_USERNAME" ]] && [[ -n "$MONGODB_METRICS_PASSWORD" ]]; then
716716
info "Creating '$MONGODB_METRICS_USERNAME' user..."
717-
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "127.0.0.1" <<EOF
717+
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "$MONGODB_LOCALHOST_NAME" <<EOF
718718
db.getSiblingDB('admin').createUser({ user: '$MONGODB_METRICS_USERNAME', pwd: '$MONGODB_METRICS_PASSWORD', roles: [{role: 'clusterMonitor', db: 'admin'},{ role: 'read', db: 'local' }] })
719719
EOF
720720
fi
@@ -784,7 +784,7 @@ mongodb_is_primary_node_initiated() {
784784
local port="${2:?port is required}"
785785
local result
786786
result=$(
787-
mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "127.0.0.1" "$MONGODB_PORT_NUMBER" <<EOF
787+
mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "$MONGODB_LOCALHOST_NAME" "$MONGODB_PORT_NUMBER" <<EOF
788788
rs.initiate({"_id":"$MONGODB_REPLICA_SET_NAME", "members":[{"_id":0,"host":"$node:$port","priority":5}]})
789789
EOF
790790
)

bitnami/mongodb/6.0/debian-11/rootfs/opt/bitnami/scripts/mongodb-env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ mongodb_env_vars=(
6363
MONGODB_PRIMARY_PORT_NUMBER
6464
MONGODB_PRIMARY_ROOT_PASSWORD
6565
MONGODB_PRIMARY_ROOT_USER
66+
MONGODB_LOCALHOST_NAME
6667
)
6768
for env_var in "${mongodb_env_vars[@]}"; do
6869
file_env_var="${env_var}_FILE"
@@ -127,6 +128,7 @@ export MONGODB_ENABLE_IPV6="${MONGODB_ENABLE_IPV6:-}"
127128
export MONGODB_DEFAULT_ENABLE_IPV6="false"
128129
export MONGODB_SYSTEM_LOG_VERBOSITY="${MONGODB_SYSTEM_LOG_VERBOSITY:-}"
129130
export MONGODB_DEFAULT_SYSTEM_LOG_VERBOSITY="0"
131+
export MONGODB_LOCALHOST_NAME="${MONGODB_LOCALHOST_NAME:-127.0.0.1}"
130132

131133
# User and database creation settings
132134
export MONGODB_ROOT_USER="${MONGODB_ROOT_USER:-root}"

bitnami/mongodb/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ Before starting the cluster you need to generate PEM certificates as required by
579579

580580
Another option would be to use letsencrypt certificates; the required configuration steps for that scenario are left as an exercise for the user and are beyond the scope of this README.
581581

582+
The hostname used during initialization can be configured using `MONGODB_LOCALHOST_NAME`. Use this to provide a vaild domain for your certificate. Preferably this hostname should be routed back to `127.0.0.1` through the hosts file. If not possible then progress can be made bybinding the mongo server to the correct ip, or all ips, in the configuration.
583+
582584
#### Generating self-signed certificates
583585

584586
* Generate a new private key which will be used to create your own Certificate Authority (CA):

0 commit comments

Comments
 (0)