Skip to content

Commit d1e3637

Browse files
Merge pull request #518 from dtantsur/json-rpc-cred
✨ Allow independent credentials for JSON RPC
2 parents 1a5d36b + 7978e68 commit d1e3637

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

scripts/auth-common.sh

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,60 @@ IRONIC_HTPASSWD_FILE=/etc/ironic/htpasswd
1515
if [[ -f "/auth/ironic/htpasswd" ]]; then
1616
IRONIC_HTPASSWD=$(</auth/ironic/htpasswd)
1717
fi
18+
if [[ -f "/auth/ironic-rpc/htpasswd" ]]; then
19+
IRONIC_RPC_HTPASSWD=$(</auth/ironic-rpc/htpasswd)
20+
fi
1821
export IRONIC_HTPASSWD=${IRONIC_HTPASSWD:-${HTTP_BASIC_HTPASSWD:-}}
22+
export IRONIC_RPC_HTPASSWD=${IRONIC_RPC_HTPASSWD:-${IRONIC_HTPASSWD}}
23+
24+
IRONIC_CONFIG=/etc/ironic/ironic.conf
25+
1926

20-
configure_client_basic_auth()
27+
configure_json_rpc_auth()
2128
{
22-
local auth_config_file="/auth/$1/auth-config"
23-
local dest="${2:-/etc/ironic/ironic.conf}"
24-
if [[ -f "${auth_config_file}" ]]; then
29+
if [[ "${IRONIC_EXPOSE_JSON_RPC}" != "true" ]]; then
30+
return
31+
fi
32+
33+
local auth_config_file="/auth/ironic-rpc/auth-config"
34+
local username_file="/auth/ironic-rpc/username"
35+
local password_file="/auth/ironic-rpc/password"
36+
if [[ -f "${username_file}" ]] && [[ -f "${password_file}" ]]; then
37+
crudini --set "${IRONIC_CONFIG}" json_rpc username "$(<${username_file})"
38+
set +x
39+
crudini --set "${IRONIC_CONFIG}" json_rpc password "$(<${password_file})"
40+
set -x
41+
elif [[ -f "${auth_config_file}" ]]; then
42+
echo "WARNING: using auth-config is deprecated, mount a secret directly"
2543
# Merge configurations in the "auth" directory into the default ironic configuration file
26-
crudini --merge "${dest}" < "${auth_config_file}"
44+
crudini --merge "${IRONIC_CONFIG}" < "${auth_config_file}"
45+
else
46+
echo "FATAL: no client-side credentials provided for JSON RPC"
47+
echo "HINT: mount a secret with username and password fields under /auth/ironic-rpc"
48+
exit 1
2749
fi
28-
}
2950

30-
configure_json_rpc_auth()
31-
{
32-
if [[ "${IRONIC_EXPOSE_JSON_RPC}" == "true" ]]; then
33-
if [[ -z "${IRONIC_HTPASSWD}" ]]; then
51+
if [[ -z "${IRONIC_RPC_HTPASSWD}" ]]; then
52+
if [[ -f "${username_file}" ]] && [[ -f "${password_file}" ]]; then
53+
htpasswd -c -i -B "${IRONIC_HTPASSWD_FILE}-rpc" "$(<${username_file})" <"${password_file}"
54+
else
3455
echo "FATAL: enabling JSON RPC requires authentication"
56+
echo "HINT: mount a secret with either username and password or htpasswd under /auth/ironic-rpc"
3557
exit 1
3658
fi
37-
printf "%s\n" "${IRONIC_HTPASSWD}" > "${IRONIC_HTPASSWD_FILE}-rpc"
59+
else
60+
printf "%s\n" "${IRONIC_RPC_HTPASSWD}" > "${IRONIC_HTPASSWD_FILE}-rpc"
3861
fi
3962
}
4063

4164
configure_ironic_auth()
4265
{
43-
local config=/etc/ironic/ironic.conf
4466
# Configure HTTP basic auth for API server
4567
if [[ -n "${IRONIC_HTPASSWD}" ]]; then
4668
printf "%s\n" "${IRONIC_HTPASSWD}" > "${IRONIC_HTPASSWD_FILE}"
4769
if [[ "${IRONIC_REVERSE_PROXY_SETUP}" == "false" ]]; then
48-
crudini --set "${config}" DEFAULT auth_strategy http_basic
49-
crudini --set "${config}" DEFAULT http_basic_auth_user_file "${IRONIC_HTPASSWD_FILE}"
70+
crudini --set "${IRONIC_CONFIG}" DEFAULT auth_strategy http_basic
71+
crudini --set "${IRONIC_CONFIG}" DEFAULT http_basic_auth_user_file "${IRONIC_HTPASSWD_FILE}"
5072
fi
5173
fi
5274
}

scripts/configure-ironic.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ env | grep "^OS_" || true
8484
mkdir -p /shared/html
8585
mkdir -p /shared/ironic_prometheus_exporter
8686

87-
configure_json_rpc_auth
88-
8987
if [[ -f /proc/sys/crypto/fips_enabled ]]; then
9088
ENABLE_FIPS_IPA=$(cat /proc/sys/crypto/fips_enabled)
9189
export ENABLE_FIPS_IPA
@@ -94,7 +92,7 @@ fi
9492
# The original ironic.conf is empty, and can be found in ironic.conf_orig
9593
render_j2_config /etc/ironic/ironic.conf.j2 /etc/ironic/ironic.conf
9694

97-
configure_client_basic_auth ironic-rpc
95+
configure_json_rpc_auth
9896

9997
# Make sure ironic traffic bypasses any proxies
10098
export NO_PROXY="${NO_PROXY:-},$IRONIC_IP"

0 commit comments

Comments
 (0)