From fb1322235433151da218f493ffe7412c9721313f Mon Sep 17 00:00:00 2001 From: Joe Ferguson Date: Wed, 4 Jan 2023 14:20:17 -0800 Subject: [PATCH] Fix configsvr with user/pass env vars --- 6.0/docker-entrypoint.sh | 23 +++++++++++++++++------ 7.0-rc/docker-entrypoint.sh | 23 +++++++++++++++++------ 7.0/docker-entrypoint.sh | 23 +++++++++++++++++------ 8.0-rc/docker-entrypoint.sh | 23 +++++++++++++++++------ 8.0/docker-entrypoint.sh | 23 +++++++++++++++++------ docker-entrypoint.sh | 23 +++++++++++++++++------ 6 files changed, 102 insertions(+), 36 deletions(-) diff --git a/6.0/docker-entrypoint.sh b/6.0/docker-entrypoint.sh index df4073d8cc..3ff06cad49 100755 --- a/6.0/docker-entrypoint.sh +++ b/6.0/docker-entrypoint.sh @@ -208,12 +208,21 @@ _parse_config() { cat >&2 "$jsonConfigFile" exit 1 fi - jq 'del(.systemLog, .processManagement, .net, .security, .replication)' "$jsonConfigFile" > "$tempConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security, .replication, .sharding)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi return 1 } + +_isConfigServer() { + _mongod_hack_have_arg --configsvr "$@" || { + _parse_config "$@" \ + && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ + && [ "$clusterRole" = 'configsvr' ] + } +} + dbPath= _dbPath() { if [ -n "$dbPath" ]; then @@ -228,11 +237,7 @@ _dbPath() { fi if [ -z "$dbPath" ]; then - if _mongod_hack_have_arg --configsvr "$@" || { - _parse_config "$@" \ - && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ - && [ "$clusterRole" = 'configsvr' ] - }; then + if _isConfigServer "$@"; then # if running as config server, then the default dbpath is /data/configdb # https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr dbPath=/data/configdb @@ -316,6 +321,12 @@ if [ "$originalArgOne" = 'mongod' ]; then if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then _mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}" fi + # Setting sharding.clusterRole=configsvr requires the mongod instance to be running with replication + # disable configsvr for initial startup (https://github.com/docker-library/mongo/issues/509) + if _isConfigServer "$@"; then + _mongod_hack_ensure_no_arg '--configsvr' "${mongodHackedArgs[@]}" + _mongod_hack_ensure_arg_val '--dbpath' "$dbPath" "${mongodHackedArgs[@]}" + fi # "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters" tlsMode='disabled' diff --git a/7.0-rc/docker-entrypoint.sh b/7.0-rc/docker-entrypoint.sh index df4073d8cc..3ff06cad49 100755 --- a/7.0-rc/docker-entrypoint.sh +++ b/7.0-rc/docker-entrypoint.sh @@ -208,12 +208,21 @@ _parse_config() { cat >&2 "$jsonConfigFile" exit 1 fi - jq 'del(.systemLog, .processManagement, .net, .security, .replication)' "$jsonConfigFile" > "$tempConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security, .replication, .sharding)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi return 1 } + +_isConfigServer() { + _mongod_hack_have_arg --configsvr "$@" || { + _parse_config "$@" \ + && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ + && [ "$clusterRole" = 'configsvr' ] + } +} + dbPath= _dbPath() { if [ -n "$dbPath" ]; then @@ -228,11 +237,7 @@ _dbPath() { fi if [ -z "$dbPath" ]; then - if _mongod_hack_have_arg --configsvr "$@" || { - _parse_config "$@" \ - && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ - && [ "$clusterRole" = 'configsvr' ] - }; then + if _isConfigServer "$@"; then # if running as config server, then the default dbpath is /data/configdb # https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr dbPath=/data/configdb @@ -316,6 +321,12 @@ if [ "$originalArgOne" = 'mongod' ]; then if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then _mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}" fi + # Setting sharding.clusterRole=configsvr requires the mongod instance to be running with replication + # disable configsvr for initial startup (https://github.com/docker-library/mongo/issues/509) + if _isConfigServer "$@"; then + _mongod_hack_ensure_no_arg '--configsvr' "${mongodHackedArgs[@]}" + _mongod_hack_ensure_arg_val '--dbpath' "$dbPath" "${mongodHackedArgs[@]}" + fi # "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters" tlsMode='disabled' diff --git a/7.0/docker-entrypoint.sh b/7.0/docker-entrypoint.sh index df4073d8cc..3ff06cad49 100755 --- a/7.0/docker-entrypoint.sh +++ b/7.0/docker-entrypoint.sh @@ -208,12 +208,21 @@ _parse_config() { cat >&2 "$jsonConfigFile" exit 1 fi - jq 'del(.systemLog, .processManagement, .net, .security, .replication)' "$jsonConfigFile" > "$tempConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security, .replication, .sharding)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi return 1 } + +_isConfigServer() { + _mongod_hack_have_arg --configsvr "$@" || { + _parse_config "$@" \ + && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ + && [ "$clusterRole" = 'configsvr' ] + } +} + dbPath= _dbPath() { if [ -n "$dbPath" ]; then @@ -228,11 +237,7 @@ _dbPath() { fi if [ -z "$dbPath" ]; then - if _mongod_hack_have_arg --configsvr "$@" || { - _parse_config "$@" \ - && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ - && [ "$clusterRole" = 'configsvr' ] - }; then + if _isConfigServer "$@"; then # if running as config server, then the default dbpath is /data/configdb # https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr dbPath=/data/configdb @@ -316,6 +321,12 @@ if [ "$originalArgOne" = 'mongod' ]; then if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then _mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}" fi + # Setting sharding.clusterRole=configsvr requires the mongod instance to be running with replication + # disable configsvr for initial startup (https://github.com/docker-library/mongo/issues/509) + if _isConfigServer "$@"; then + _mongod_hack_ensure_no_arg '--configsvr' "${mongodHackedArgs[@]}" + _mongod_hack_ensure_arg_val '--dbpath' "$dbPath" "${mongodHackedArgs[@]}" + fi # "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters" tlsMode='disabled' diff --git a/8.0-rc/docker-entrypoint.sh b/8.0-rc/docker-entrypoint.sh index df4073d8cc..3ff06cad49 100755 --- a/8.0-rc/docker-entrypoint.sh +++ b/8.0-rc/docker-entrypoint.sh @@ -208,12 +208,21 @@ _parse_config() { cat >&2 "$jsonConfigFile" exit 1 fi - jq 'del(.systemLog, .processManagement, .net, .security, .replication)' "$jsonConfigFile" > "$tempConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security, .replication, .sharding)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi return 1 } + +_isConfigServer() { + _mongod_hack_have_arg --configsvr "$@" || { + _parse_config "$@" \ + && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ + && [ "$clusterRole" = 'configsvr' ] + } +} + dbPath= _dbPath() { if [ -n "$dbPath" ]; then @@ -228,11 +237,7 @@ _dbPath() { fi if [ -z "$dbPath" ]; then - if _mongod_hack_have_arg --configsvr "$@" || { - _parse_config "$@" \ - && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ - && [ "$clusterRole" = 'configsvr' ] - }; then + if _isConfigServer "$@"; then # if running as config server, then the default dbpath is /data/configdb # https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr dbPath=/data/configdb @@ -316,6 +321,12 @@ if [ "$originalArgOne" = 'mongod' ]; then if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then _mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}" fi + # Setting sharding.clusterRole=configsvr requires the mongod instance to be running with replication + # disable configsvr for initial startup (https://github.com/docker-library/mongo/issues/509) + if _isConfigServer "$@"; then + _mongod_hack_ensure_no_arg '--configsvr' "${mongodHackedArgs[@]}" + _mongod_hack_ensure_arg_val '--dbpath' "$dbPath" "${mongodHackedArgs[@]}" + fi # "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters" tlsMode='disabled' diff --git a/8.0/docker-entrypoint.sh b/8.0/docker-entrypoint.sh index df4073d8cc..3ff06cad49 100755 --- a/8.0/docker-entrypoint.sh +++ b/8.0/docker-entrypoint.sh @@ -208,12 +208,21 @@ _parse_config() { cat >&2 "$jsonConfigFile" exit 1 fi - jq 'del(.systemLog, .processManagement, .net, .security, .replication)' "$jsonConfigFile" > "$tempConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security, .replication, .sharding)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi return 1 } + +_isConfigServer() { + _mongod_hack_have_arg --configsvr "$@" || { + _parse_config "$@" \ + && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ + && [ "$clusterRole" = 'configsvr' ] + } +} + dbPath= _dbPath() { if [ -n "$dbPath" ]; then @@ -228,11 +237,7 @@ _dbPath() { fi if [ -z "$dbPath" ]; then - if _mongod_hack_have_arg --configsvr "$@" || { - _parse_config "$@" \ - && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ - && [ "$clusterRole" = 'configsvr' ] - }; then + if _isConfigServer "$@"; then # if running as config server, then the default dbpath is /data/configdb # https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr dbPath=/data/configdb @@ -316,6 +321,12 @@ if [ "$originalArgOne" = 'mongod' ]; then if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then _mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}" fi + # Setting sharding.clusterRole=configsvr requires the mongod instance to be running with replication + # disable configsvr for initial startup (https://github.com/docker-library/mongo/issues/509) + if _isConfigServer "$@"; then + _mongod_hack_ensure_no_arg '--configsvr' "${mongodHackedArgs[@]}" + _mongod_hack_ensure_arg_val '--dbpath' "$dbPath" "${mongodHackedArgs[@]}" + fi # "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters" tlsMode='disabled' diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index df4073d8cc..3ff06cad49 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -208,12 +208,21 @@ _parse_config() { cat >&2 "$jsonConfigFile" exit 1 fi - jq 'del(.systemLog, .processManagement, .net, .security, .replication)' "$jsonConfigFile" > "$tempConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security, .replication, .sharding)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi return 1 } + +_isConfigServer() { + _mongod_hack_have_arg --configsvr "$@" || { + _parse_config "$@" \ + && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ + && [ "$clusterRole" = 'configsvr' ] + } +} + dbPath= _dbPath() { if [ -n "$dbPath" ]; then @@ -228,11 +237,7 @@ _dbPath() { fi if [ -z "$dbPath" ]; then - if _mongod_hack_have_arg --configsvr "$@" || { - _parse_config "$@" \ - && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \ - && [ "$clusterRole" = 'configsvr' ] - }; then + if _isConfigServer "$@"; then # if running as config server, then the default dbpath is /data/configdb # https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr dbPath=/data/configdb @@ -316,6 +321,12 @@ if [ "$originalArgOne" = 'mongod' ]; then if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then _mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}" fi + # Setting sharding.clusterRole=configsvr requires the mongod instance to be running with replication + # disable configsvr for initial startup (https://github.com/docker-library/mongo/issues/509) + if _isConfigServer "$@"; then + _mongod_hack_ensure_no_arg '--configsvr' "${mongodHackedArgs[@]}" + _mongod_hack_ensure_arg_val '--dbpath' "$dbPath" "${mongodHackedArgs[@]}" + fi # "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters" tlsMode='disabled'