Skip to content

feat: Add ability to load secrets from files #276

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions 2.3.1-ubi/resources/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ if [ "$1" = 'couchdb' ]; then
set -- /opt/couchdb/bin/couchdb "$@"
fi

# This function will populate the admin user in the docker.ini file using the first argument, the second argument is the password.
function set_admin_credentials {
adminUser="$1"
adminPassword="$2"
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$adminUser =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[admins]\n%s = %s\n" "$adminUser" "$adminPassword" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

# This function populates the chttpd_auth secret in the docker.ini file using the first argument.
function set_http_secret {
chttpSecret="$1"
if ! grep -Pzoqr "\[chttpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[chttpd_auth]\nsecret = %s\n" "$chttpSecret" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
# this is where runtime configuration changes will be written.
# we need to explicitly touch it here in case /opt/couchdb/etc has
Expand Down Expand Up @@ -64,17 +82,29 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
fi

if [ "$COUCHDB_USER" ] && [ "$COUCHDB_PASSWORD" ]; then
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$COUCHDB_USER =" /opt/couchdb/etc/local.d/*.ini; then
printf "\n[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_PASSWORD" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_admin_credentials "$COUCHDB_USER" "$COUCHDB_PASSWORD"
elif [ "$COUCHDB_USER_FILE" ] && [ "$COUCHDB_PASSWORD_FILE" ]; then
if [ -f "$COUCHDB_USER_FILE" ] && [ -f "$COUCHDB_PASSWORD_FILE" ]; then
adminUser=$(<"$COUCHDB_USER_FILE")
adminPassword=$(<"$COUCHDB_PASSWORD_FILE")
set_admin_credentials "$adminUser" "$adminPassword"
else
echo "ERROR: COUCHDB_USER_FILE or COUCHDB_PASSWORD_FILE does not exist." >&2
exit 1
fi
fi

if [ "$COUCHDB_SECRET" ]; then
# Set secret only if not already present
if ! grep -Pzoqr "\[couch_httpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini; then
printf "\n[couch_httpd_auth]\nsecret = %s\n" "$COUCHDB_SECRET" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_http_secret "$COUCHDB_SECRET"
elif [ "$COUCHDB_SECRET_FILE" ]; then
if [ -f "$COUCHDB_SECRET_FILE" ]; then
chttpSecret=$(<"$COUCHDB_SECRET_FILE")
set_http_secret "$chttpSecret"
else
echo "ERROR: COUCHDB_SECRET_FILE does not exist." >&2
exit 1
fi
fi

if [ "$(id -u)" = '0' ]; then
Expand Down
44 changes: 37 additions & 7 deletions 2.3.1/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ if [ "$1" = 'couchdb' ]; then
set -- /opt/couchdb/bin/couchdb "$@"
fi

# This function will populate the admin user in the docker.ini file using the first argument, the second argument is the password.
function set_admin_credentials {
adminUser="$1"
adminPassword="$2"
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$adminUser =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[admins]\n%s = %s\n" "$adminUser" "$adminPassword" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

# This function populates the chttpd_auth secret in the docker.ini file using the first argument.
function set_http_secret {
chttpSecret="$1"
if ! grep -Pzoqr "\[chttpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[chttpd_auth]\nsecret = %s\n" "$chttpSecret" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
# this is where runtime configuration changes will be written.
# we need to explicitly touch it here in case /opt/couchdb/etc has
Expand Down Expand Up @@ -64,17 +82,29 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
fi

if [ "$COUCHDB_USER" ] && [ "$COUCHDB_PASSWORD" ]; then
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$COUCHDB_USER =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_PASSWORD" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_admin_credentials "$COUCHDB_USER" "$COUCHDB_PASSWORD"
elif [ "$COUCHDB_USER_FILE" ] && [ "$COUCHDB_PASSWORD_FILE" ]; then
if [ -f "$COUCHDB_USER_FILE" ] && [ -f "$COUCHDB_PASSWORD_FILE" ]; then
adminUser=$(<"$COUCHDB_USER_FILE")
adminPassword=$(<"$COUCHDB_PASSWORD_FILE")
set_admin_credentials "$adminUser" "$adminPassword"
else
echo "ERROR: COUCHDB_USER_FILE or COUCHDB_PASSWORD_FILE does not exist." >&2
exit 1
fi
fi

if [ "$COUCHDB_SECRET" ]; then
# Set secret only if not already present
if ! grep -Pzoqr "\[couch_httpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[couch_httpd_auth]\nsecret = %s\n" "$COUCHDB_SECRET" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_http_secret "$COUCHDB_SECRET"
elif [ "$COUCHDB_SECRET_FILE" ]; then
if [ -f "$COUCHDB_SECRET_FILE" ]; then
chttpSecret=$(<"$COUCHDB_SECRET_FILE")
set_http_secret "$chttpSecret"
else
echo "ERROR: COUCHDB_SECRET_FILE does not exist." >&2
exit 1
fi
fi

if [ "$(id -u)" = '0' ]; then
Expand Down
44 changes: 37 additions & 7 deletions 3.1.2-ubi-clouseau/resources/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ if [ "$1" = 'couchdb' ]; then
set -- /opt/couchdb/bin/couchdb "$@"
fi

# This function will populate the admin user in the docker.ini file using the first argument, the second argument is the password.
function set_admin_credentials {
adminUser="$1"
adminPassword="$2"
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$adminUser =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[admins]\n%s = %s\n" "$adminUser" "$adminPassword" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

# This function populates the chttpd_auth secret in the docker.ini file using the first argument.
function set_http_secret {
chttpSecret="$1"
if ! grep -Pzoqr "\[chttpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[chttpd_auth]\nsecret = %s\n" "$chttpSecret" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
# this is where runtime configuration changes will be written.
# we need to explicitly touch it here in case /opt/couchdb/etc has
Expand Down Expand Up @@ -93,17 +111,29 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
fi

if [ "$COUCHDB_USER" ] && [ "$COUCHDB_PASSWORD" ]; then
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$COUCHDB_USER =" /opt/couchdb/etc/local.d/*.ini; then
printf "\n[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_PASSWORD" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_admin_credentials "$COUCHDB_USER" "$COUCHDB_PASSWORD"
elif [ "$COUCHDB_USER_FILE" ] && [ "$COUCHDB_PASSWORD_FILE" ]; then
if [ -f "$COUCHDB_USER_FILE" ] && [ -f "$COUCHDB_PASSWORD_FILE" ]; then
adminUser=$(<"$COUCHDB_USER_FILE")
adminPassword=$(<"$COUCHDB_PASSWORD_FILE")
set_admin_credentials "$adminUser" "$adminPassword"
else
echo "ERROR: COUCHDB_USER_FILE or COUCHDB_PASSWORD_FILE does not exist." >&2
exit 1
fi
fi

if [ "$COUCHDB_SECRET" ]; then
# Set secret only if not already present
if ! grep -Pzoqr "\[couch_httpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini; then
printf "\n[couch_httpd_auth]\nsecret = %s\n" "$COUCHDB_SECRET" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_http_secret "$COUCHDB_SECRET"
elif [ "$COUCHDB_SECRET_FILE" ]; then
if [ -f "$COUCHDB_SECRET_FILE" ]; then
chttpSecret=$(<"$COUCHDB_SECRET_FILE")
set_http_secret "$chttpSecret"
else
echo "ERROR: COUCHDB_SECRET_FILE does not exist." >&2
exit 1
fi
fi

if [ "$(id -u)" = '0' ]; then
Expand Down
44 changes: 37 additions & 7 deletions 3.1.2-ubi/resources/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ if [ "$1" = 'couchdb' ]; then
set -- /opt/couchdb/bin/couchdb "$@"
fi

# This function will populate the admin user in the docker.ini file using the first argument, the second argument is the password.
function set_admin_credentials {
adminUser="$1"
adminPassword="$2"
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$adminUser =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[admins]\n%s = %s\n" "$adminUser" "$adminPassword" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

# This function populates the chttpd_auth secret in the docker.ini file using the first argument.
function set_http_secret {
chttpSecret="$1"
if ! grep -Pzoqr "\[chttpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[chttpd_auth]\nsecret = %s\n" "$chttpSecret" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
# this is where runtime configuration changes will be written.
# we need to explicitly touch it here in case /opt/couchdb/etc has
Expand Down Expand Up @@ -63,17 +81,29 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
fi

if [ "$COUCHDB_USER" ] && [ "$COUCHDB_PASSWORD" ]; then
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$COUCHDB_USER =" /opt/couchdb/etc/local.d/*.ini; then
printf "\n[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_PASSWORD" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_admin_credentials "$COUCHDB_USER" "$COUCHDB_PASSWORD"
elif [ "$COUCHDB_USER_FILE" ] && [ "$COUCHDB_PASSWORD_FILE" ]; then
if [ -f "$COUCHDB_USER_FILE" ] && [ -f "$COUCHDB_PASSWORD_FILE" ]; then
adminUser=$(<"$COUCHDB_USER_FILE")
adminPassword=$(<"$COUCHDB_PASSWORD_FILE")
set_admin_credentials "$adminUser" "$adminPassword"
else
echo "ERROR: COUCHDB_USER_FILE or COUCHDB_PASSWORD_FILE does not exist." >&2
exit 1
fi
fi

if [ "$COUCHDB_SECRET" ]; then
# Set secret only if not already present
if ! grep -Pzoqr "\[couch_httpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini; then
printf "\n[couch_httpd_auth]\nsecret = %s\n" "$COUCHDB_SECRET" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_http_secret "$COUCHDB_SECRET"
elif [ "$COUCHDB_SECRET_FILE" ]; then
if [ -f "$COUCHDB_SECRET_FILE" ]; then
chttpSecret=$(<"$COUCHDB_SECRET_FILE")
set_http_secret "$chttpSecret"
else
echo "ERROR: COUCHDB_SECRET_FILE does not exist." >&2
exit 1
fi
fi

if [ "$(id -u)" = '0' ]; then
Expand Down
44 changes: 37 additions & 7 deletions 3.1.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ if [ "$1" = 'couchdb' ]; then
set -- /opt/couchdb/bin/couchdb "$@"
fi

# This function will populate the admin user in the docker.ini file using the first argument, the second argument is the password.
function set_admin_credentials {
adminUser="$1"
adminPassword="$2"
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$adminUser =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[admins]\n%s = %s\n" "$adminUser" "$adminPassword" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

# This function populates the chttpd_auth secret in the docker.ini file using the first argument.
function set_http_secret {
chttpSecret="$1"
if ! grep -Pzoqr "\[chttpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[chttpd_auth]\nsecret = %s\n" "$chttpSecret" >> /opt/couchdb/etc/local.d/docker.ini
fi
}

if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
# this is where runtime configuration changes will be written.
# we need to explicitly touch it here in case /opt/couchdb/etc has
Expand Down Expand Up @@ -64,17 +82,29 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
fi

if [ "$COUCHDB_USER" ] && [ "$COUCHDB_PASSWORD" ]; then
# Create admin only if not already present
if ! grep -Pzoqr "\[admins\]\n$COUCHDB_USER =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_PASSWORD" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_admin_credentials "$COUCHDB_USER" "$COUCHDB_PASSWORD"
elif [ "$COUCHDB_USER_FILE" ] && [ "$COUCHDB_PASSWORD_FILE" ]; then
if [ -f "$COUCHDB_USER_FILE" ] && [ -f "$COUCHDB_PASSWORD_FILE" ]; then
adminUser=$(<"$COUCHDB_USER_FILE")
adminPassword=$(<"$COUCHDB_PASSWORD_FILE")
set_admin_credentials "$adminUser" "$adminPassword"
else
echo "ERROR: COUCHDB_USER_FILE or COUCHDB_PASSWORD_FILE does not exist." >&2
exit 1
fi
fi

if [ "$COUCHDB_SECRET" ]; then
# Set secret only if not already present
if ! grep -Pzoqr "\[couch_httpd_auth\]\nsecret =" /opt/couchdb/etc/local.d/*.ini /opt/couchdb/etc/local.ini; then
printf "\n[couch_httpd_auth]\nsecret = %s\n" "$COUCHDB_SECRET" >> /opt/couchdb/etc/local.d/docker.ini
fi
set_http_secret "$COUCHDB_SECRET"
elif [ "$COUCHDB_SECRET_FILE" ]; then
if [ -f "$COUCHDB_SECRET_FILE" ]; then
chttpSecret=$(<"$COUCHDB_SECRET_FILE")
set_http_secret "$chttpSecret"
else
echo "ERROR: COUCHDB_SECRET_FILE does not exist." >&2
exit 1
fi
fi

if [ "$(id -u)" = '0' ]; then
Expand Down
Loading