Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bitnami/mongodb] Configure mongodb hostname during initialization #34297

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ mongodb_create_user() {
[[ -z "$database" ]] && query="db.getSiblingDB(db.stats().db).createUser({ user: '$user', pwd: '$password', roles: [{role: 'readWrite', db: db.getSiblingDB(db.stats().db).stats().db }] })"
# Create user, discarding mongo CLI output for clean logs
info "Creating user '$user'..."
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "127.0.0.1" <<<"$query"
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "$MONGODB_LOCALHOST_NAME" <<<"$query"
}

########################
Expand All @@ -684,7 +684,7 @@ mongodb_create_users() {

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

if [[ -n "$MONGODB_METRICS_USERNAME" ]] && [[ -n "$MONGODB_METRICS_PASSWORD" ]]; then
info "Creating '$MONGODB_METRICS_USERNAME' user..."
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "127.0.0.1" <<EOF
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "$MONGODB_LOCALHOST_NAME" <<EOF
db.getSiblingDB('admin').createUser({ user: '$MONGODB_METRICS_USERNAME', pwd: '$MONGODB_METRICS_PASSWORD', roles: [{role: 'clusterMonitor', db: 'admin'},{ role: 'read', db: 'local' }] })
EOF
fi
Expand Down Expand Up @@ -784,7 +784,7 @@ mongodb_is_primary_node_initiated() {
local port="${2:?port is required}"
local result
result=$(
mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "127.0.0.1" "$MONGODB_PORT_NUMBER" <<EOF
mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "$MONGODB_LOCALHOST_NAME" "$MONGODB_PORT_NUMBER" <<EOF
rs.initiate({"_id":"$MONGODB_REPLICA_SET_NAME", "members":[{"_id":0,"host":"$node:$port","priority":5}]})
EOF
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mongodb_env_vars=(
MONGODB_PRIMARY_PORT_NUMBER
MONGODB_PRIMARY_ROOT_PASSWORD
MONGODB_PRIMARY_ROOT_USER
MONGODB_LOCALHOST_NAME
)
for env_var in "${mongodb_env_vars[@]}"; do
file_env_var="${env_var}_FILE"
Expand Down Expand Up @@ -127,6 +128,7 @@ export MONGODB_ENABLE_IPV6="${MONGODB_ENABLE_IPV6:-}"
export MONGODB_DEFAULT_ENABLE_IPV6="false"
export MONGODB_SYSTEM_LOG_VERBOSITY="${MONGODB_SYSTEM_LOG_VERBOSITY:-}"
export MONGODB_DEFAULT_SYSTEM_LOG_VERBOSITY="0"
export MONGODB_LOCALHOST_NAME="${MONGODB_LOCALHOST_NAME:-127.0.0.1}"

# User and database creation settings
export MONGODB_ROOT_USER="${MONGODB_ROOT_USER:-root}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ mongodb_create_user() {
[[ -z "$database" ]] && query="db.getSiblingDB(db.stats().db).createUser({ user: '$user', pwd: '$password', roles: [{role: 'readWrite', db: db.getSiblingDB(db.stats().db).stats().db }] })"
# Create user, discarding mongo CLI output for clean logs
info "Creating user '$user'..."
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "127.0.0.1" <<<"$query"
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "$MONGODB_LOCALHOST_NAME" <<<"$query"
}

########################
Expand All @@ -684,7 +684,7 @@ mongodb_create_users() {

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

if [[ -n "$MONGODB_METRICS_USERNAME" ]] && [[ -n "$MONGODB_METRICS_PASSWORD" ]]; then
info "Creating '$MONGODB_METRICS_USERNAME' user..."
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "127.0.0.1" <<EOF
mongodb_execute "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "" "$MONGODB_LOCALHOST_NAME" <<EOF
db.getSiblingDB('admin').createUser({ user: '$MONGODB_METRICS_USERNAME', pwd: '$MONGODB_METRICS_PASSWORD', roles: [{role: 'clusterMonitor', db: 'admin'},{ role: 'read', db: 'local' }] })
EOF
fi
Expand Down Expand Up @@ -784,7 +784,7 @@ mongodb_is_primary_node_initiated() {
local port="${2:?port is required}"
local result
result=$(
mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "127.0.0.1" "$MONGODB_PORT_NUMBER" <<EOF
mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "$MONGODB_LOCALHOST_NAME" "$MONGODB_PORT_NUMBER" <<EOF
rs.initiate({"_id":"$MONGODB_REPLICA_SET_NAME", "members":[{"_id":0,"host":"$node:$port","priority":5}]})
EOF
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mongodb_env_vars=(
MONGODB_PRIMARY_PORT_NUMBER
MONGODB_PRIMARY_ROOT_PASSWORD
MONGODB_PRIMARY_ROOT_USER
MONGODB_LOCALHOST_NAME
)
for env_var in "${mongodb_env_vars[@]}"; do
file_env_var="${env_var}_FILE"
Expand Down Expand Up @@ -127,6 +128,7 @@ export MONGODB_ENABLE_IPV6="${MONGODB_ENABLE_IPV6:-}"
export MONGODB_DEFAULT_ENABLE_IPV6="false"
export MONGODB_SYSTEM_LOG_VERBOSITY="${MONGODB_SYSTEM_LOG_VERBOSITY:-}"
export MONGODB_DEFAULT_SYSTEM_LOG_VERBOSITY="0"
export MONGODB_LOCALHOST_NAME="${MONGODB_LOCALHOST_NAME:-127.0.0.1}"

# User and database creation settings
export MONGODB_ROOT_USER="${MONGODB_ROOT_USER:-root}"
Expand Down
3 changes: 3 additions & 0 deletions bitnami/mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@

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.

The hostname used during initialization can be configured using `MONGODB_LOCALHOST_NAME`. Use this to provide a valid 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 by binding the MongoDB server to the correct IP, or all IPs, in the `mongodb.conf` configuration file.
https://www.mongodb.com/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp

Check warning on line 583 in bitnami/mongodb/README.md

View workflow job for this annotation

GitHub Actions / markdown-linter

MD034/no-bare-urls Bare URL used [Context: "https://www.mongodb.com/docs/m..."]

#### Generating self-signed certificates

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