Skip to content

Commit d1f8292

Browse files
committed
PUC-752: reading OIDCCryptoPassphrase from a secret
1 parent 2cebe8c commit d1f8292

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

Diff for: components/keystone/aio-values.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,18 @@ pod:
228228
- name: keystone-sso
229229
mountPath: /etc/keystone-sso
230230
readOnly: true
231+
- name: oidc-secret
232+
mountPath: /etc/oidc-secret
233+
readOnly: true
231234
volumes:
232235
- name: keystone-sso
233236
secret:
234237
secretName: keystone-sso
238+
- name: oidc-secret
239+
secret:
240+
secretName: sso-passphrase
241+
replicas:
242+
api: 1
235243
lifecycle:
236244
disruption_budget:
237245
api:
@@ -287,7 +295,7 @@ conf:
287295
OIDCProviderMetadataURL http://dex.dex.svc:5556/.well-known/openid-configuration
288296
OIDCClientID keystone
289297
OIDCClientSecret "exec:/bin/cat /etc/keystone-sso/client-secret"
290-
OIDCCryptoPassphrase "exec:/bin/cat /etc/keystone-sso/oidc-crypto-passphrase"
298+
OIDCCryptoPassphrase "exec:/bin/cat /etc/oidc-secret/password"
291299
OIDCClaimDelimiter ;
292300
293301
# avoid redirect issues per the following

Diff for: scripts/gitops-secrets-gen.sh

+25-3
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,12 @@ mkdir -p "${DEST_DIR}/dex/"
218218
for client in nautobot argo argocd keystone grafana; do
219219
if [ ! -f "${DEST_DIR}/dex/secret-${client}-sso-dex.yaml" ]; then
220220
SSO_SECRET=$("${SCRIPTS_DIR}/pwgen.sh")
221-
SSO_CRYPTO_PASSPHRASE=$("${SCRIPTS_DIR}/pwgen.sh")
222221
kubectl --namespace dex \
223222
create secret generic "${client}-sso" \
224223
--dry-run=client \
225224
-o yaml \
226225
--type Opaque \
227226
--from-literal=client-secret="$SSO_SECRET" \
228-
--from-literal=oidc-crypto-passphrase="$SSO_CRYPTO_PASSPHRASE" \
229227
--from-literal=client-id="${client}" \
230228
--from-literal=issuer="https://dex.${DNS_ZONE}" \
231229
| secret-seal-stdin "${DEST_DIR}/dex/secret-${client}-sso-dex.yaml"
@@ -263,10 +261,20 @@ convert_to_var_name() {
263261
convert_to_secret_name() {
264262
echo "$1" | tr '[:upper:]' '[:lower:]' | tr '_' '-'
265263
}
264+
# Default password generator using pwgen.sh
265+
default_pwgen() {
266+
"${SCRIPTS_DIR}/pwgen.sh" 2>/dev/null
267+
}
268+
269+
# Custom password generator with only alphabets
270+
alpha_only_pwgen() {
271+
head /dev/urandom | tr -dc A-Za-z | head -c 32
272+
}
266273

267274
load_or_gen_os_secret() {
268275
local data_var=$1
269276
local secret_var=$2
277+
local gen_func=${3:-default_pwgen}
270278

271279
if kubectl -n openstack get secret "${secret_var}" &>/dev/null; then
272280
data="$(kubectl -n openstack get secret "${secret_var}" -o jsonpath='{.data.password}' | base64 -d)"
@@ -276,7 +284,7 @@ load_or_gen_os_secret() {
276284
return 1
277285
else
278286
echo "Generating ${secret_var}"
279-
data="$("${SCRIPTS_DIR}/pwgen.sh" 2>/dev/null)"
287+
data="$(${gen_func})"
280288
# good ol' bash 3 compat for macOS
281289
eval "${data_var}=\"${data}\""
282290
# return 0 because we need to write this out
@@ -369,4 +377,18 @@ find "${DEST_DIR}" -maxdepth 1 -mindepth 1 -type d | while read -r component; do
369377
fi
370378
done
371379

380+
echo "Checking keystone oidc passphrase Sealed Secret"
381+
mkdir -p "${DEST_DIR}/keystone"
382+
383+
# Generate or retrieve passphrase
384+
VARNAME_PASSPHRASE="OS_SSO_PASSPHRASE"
385+
SECRET_PASSPHRASE="sso-passphrase"
386+
387+
load_or_gen_os_secret "${VARNAME_PASSPHRASE}" "${SECRET_PASSPHRASE}" alpha_only_pwgen && \
388+
create_os_secret "PASSPHRASE" "keystone" "passphrase"
389+
390+
# Export for Helm templating if needed
391+
export OS_SSO_PASSPHRASE
392+
393+
372394
exit 0

0 commit comments

Comments
 (0)