@@ -15,38 +15,60 @@ IRONIC_HTPASSWD_FILE=/etc/ironic/htpasswd
1515if [[ -f " /auth/ironic/htpasswd" ]]; then
1616 IRONIC_HTPASSWD=$( < /auth/ironic/htpasswd)
1717fi
18+ if [[ -f " /auth/ironic-rpc/htpasswd" ]]; then
19+ IRONIC_RPC_HTPASSWD=$( < /auth/ironic-rpc/htpasswd)
20+ fi
1821export 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
4164configure_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}
0 commit comments