mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-06 07:03:45 +09:00
feat(redis)!: issue the password through the credentials API
The chart generated the password of the default user itself, kept it readable by the tenant in <release>-auth, and shared it with replication, the Sentinels, the exporter and backups. It now renders a CredentialTemplate for the default account while authEnabled is on, and points the operator at that account's Secret, which the platform seeds and rewrites on a mint and which the tenant cannot read. The operator keeps replication, the Sentinels, the probes and the exporter on an internal account of its own, so the minted password reaches only the servers' default user and the backup Job, which is why the backup strategy reads the same Secret, and a mint restarts no pod. The ResourceDefinition no longer selects <release>-auth and excludes the internal account's Secret, which carries an ownerReference to the RedisFailover, so the tenant-visible set holds the trust anchor alone. The e2e mint step fails if a mint restarts a pod or moves the master. BREAKING CHANGE: <release>-auth is no longer rendered or readable; clients get the password by minting the default credential. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
This commit is contained in:
15 files changed
+248
-52
No files matched your search
@@ -44,11 +44,13 @@ load test_helper
|
||||
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
|
||||
CHART="$REPO_ROOT/packages/system/redis-rd"
|
||||
|
||||
# The complete tenant-visible Secret surface. The generated password by name;
|
||||
# the trust anchor by label. Nothing else. The two key-bearing Secrets are
|
||||
# The complete tenant-visible Secret surface: the trust anchor by label, and
|
||||
# nothing else. The password is issued through the credentials API, and its
|
||||
# account Secret is the platform's. The operator's internal account joins the
|
||||
# key-bearing Secrets in exclude. The two key-bearing Secrets are
|
||||
# named in exclude, which is evaluated before include and so backstops the
|
||||
# label-only entry against a mis-stamp.
|
||||
EXPECTED_SECRETS='{"exclude":[{"resourceNames":["redis-{{ .name }}.ca-tls","redis-{{ .name }}.tls","redis-{{ .name }}.ca-cert"]}],"include":[{"resourceNames":["redis-{{ .name }}-auth"]},{"matchLabels":{"internal.cozystack.io/tenant-ca":"true"}}]}'
|
||||
EXPECTED_SECRETS='{"exclude":[{"resourceNames":["redis-{{ .name }}.ca-tls","redis-{{ .name }}.tls","redis-{{ .name }}.ca-cert","rfr-redis-{{ .name }}-internal"]}],"include":[{"matchLabels":{"internal.cozystack.io/tenant-ca":"true"}}]}'
|
||||
|
||||
# Order within include is meaningless -- the matcher ORs across entries -- so
|
||||
# both arrays are sorted before comparing, and a missing exclude is normalized
|
||||
@@ -115,7 +117,7 @@ NORMALIZE='{exclude: ((.exclude // []) | sort), include: (.include | sort)}'
|
||||
|
||||
# Whole-structure comparison. Anything added to the tenant's Secret surface --
|
||||
# by name, by label, or by an unrestricted entry -- changes this string.
|
||||
@test "redis-rd exposes no Secret beyond the password and the trust anchor" {
|
||||
@test "redis-rd exposes no Secret beyond the trust anchor" {
|
||||
rendered=$(helm template redis-rd "$CHART") || return 1
|
||||
|
||||
if [ -z "$rendered" ]; then
|
||||
|
||||
@@ -81,6 +81,87 @@ spec:
|
||||
status:
|
||||
readyReplicas: 2
|
||||
|
||||
# The password is the platform's to issue: a mint reaches every running
|
||||
# server with CONFIG SET, restarts no pod and moves no master (replication,
|
||||
# the Sentinels, the probes and the exporter use the operator's internal
|
||||
# account, not this password), and a second mint replaces the first.
|
||||
- name: verify-minted-credential
|
||||
try:
|
||||
- assert:
|
||||
timeout: 2m
|
||||
resource:
|
||||
apiVersion: core.cozystack.io/v1alpha1
|
||||
kind: Credential
|
||||
metadata:
|
||||
name: redis-test.default
|
||||
spec:
|
||||
application:
|
||||
kind: Redis
|
||||
name: test
|
||||
user: default
|
||||
status:
|
||||
password:
|
||||
origin: NotIssued
|
||||
# bash for pipefail and process substitution; the sandbox's /bin/sh is dash.
|
||||
- script:
|
||||
timeout: 10m
|
||||
shell: bash
|
||||
content: |
|
||||
set -euo pipefail
|
||||
cred=redis-test.default
|
||||
mint() {
|
||||
kubectl create --raw "/apis/core.cozystack.io/v1alpha1/namespaces/$NAMESPACE/credentials/$cred/mint" \
|
||||
-f <(printf '{"apiVersion":"core.cozystack.io/v1alpha1","kind":"CredentialRequest"}') \
|
||||
| jq -r '.status.password'
|
||||
}
|
||||
# The password goes to redis-cli on stdin: exec arguments travel in
|
||||
# the request URI, which the audit log records at any level.
|
||||
cli() {
|
||||
local password=$1; shift
|
||||
local pod
|
||||
pod=$(kubectl -n "$NAMESPACE" get pod -l app.kubernetes.io/component=redis,app.kubernetes.io/instance=redis-test \
|
||||
--field-selector status.phase=Running -o name | head -n1)
|
||||
[ -n "$pod" ] || return 0
|
||||
printf '%s\n' "$password" | kubectl -n "$NAMESPACE" exec -i "$pod" -c redis -- \
|
||||
sh -c 'IFS= read -r REDISCLI_AUTH; export REDISCLI_AUTH; exec redis-cli -h rfrm-redis-test "$@"' sh \
|
||||
"$@" 2>/dev/null | tr -d '\r' || true
|
||||
}
|
||||
login() { cli "$1" ping; }
|
||||
# Every redis pod with its uid and restart count, and which one the
|
||||
# master label is on: a mint must change none of it.
|
||||
pods() {
|
||||
kubectl -n "$NAMESPACE" get pod -l app.kubernetes.io/component=redis,app.kubernetes.io/instance=redis-test \
|
||||
-o jsonpath='{range .items[*]}{.metadata.name} {.metadata.uid} {.status.containerStatuses[*].restartCount} {.metadata.labels.redisfailovers-role}{"\n"}{end}' | sort
|
||||
}
|
||||
before=$(pods)
|
||||
[ "$(printf '%s\n' "$before" | grep -c ' master$')" = 1 ] || { echo "no single master before the mint: $before" >&2; exit 1; }
|
||||
|
||||
first=$(mint)
|
||||
[ "${#first}" -eq 32 ] || { echo "minted password has ${#first} characters, want 32" >&2; exit 1; }
|
||||
# The operator applies the changed account Secret on its next
|
||||
# reconcile; a readiness wait on that, not a retry.
|
||||
until [ "$(login "$first")" = "PONG" ]; do sleep 5; done
|
||||
view=$(kubectl -n "$NAMESPACE" get credentials.core.cozystack.io "$cred" -o json)
|
||||
[ "$(printf '%s' "$view" | jq -r .status.password.origin)" = "Minted" ] || { echo "origin is not Minted: $view" >&2; exit 1; }
|
||||
if printf '%s' "$view" | grep -qF -- "$first"; then echo "the Credential carries the minted password" >&2; exit 1; fi
|
||||
|
||||
second=$(mint)
|
||||
[ "$second" != "$first" ] || { echo "a second mint returned the same password" >&2; exit 1; }
|
||||
until [ "$(login "$second")" = "PONG" ]; do sleep 5; done
|
||||
# The operator drops the replaced password once every server takes
|
||||
# the new one, a pass after it applies it.
|
||||
while [ "$(login "$first")" = "PONG" ]; do sleep 5; done
|
||||
# Replication outlived both rotations, and nothing restarted or
|
||||
# failed over to get there.
|
||||
until cli "$second" info replication | grep -qx 'connected_slaves:1'; do sleep 5; done
|
||||
after=$(pods)
|
||||
if [ "$after" != "$before" ]; then
|
||||
printf 'a mint restarted a pod or moved the master:\nbefore:\n%s\nafter:\n%s\n' "$before" "$after" >&2
|
||||
exit 1
|
||||
fi
|
||||
check:
|
||||
($error == null): true
|
||||
|
||||
# One replica runs one Sentinel with its PDB disabled. The PDB the operator
|
||||
# created for the three Sentinels of two replicas has to go with it, or its
|
||||
# minAvailable: 1 pins the only Sentinel against every eviction.
|
||||
@@ -267,20 +348,10 @@ spec:
|
||||
try:
|
||||
# Positive control, and it comes first: the negatives below are satisfied
|
||||
# by an ABSENT label, which is also what a webhook that stamped nothing
|
||||
# this run looks like. The auth Secret is chart-rendered, traces to the
|
||||
# Redis CR and is included by name, so it MUST be stamped.
|
||||
- assert:
|
||||
timeout: 2m
|
||||
resource:
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: redis-secure-auth
|
||||
labels:
|
||||
internal.cozystack.io/tenantresource: "true"
|
||||
# tenant-ca is stamped by the CA-extraction controller; tenantresource is
|
||||
# the lineage webhook's verdict from the redis ApplicationDefinition's
|
||||
# matchLabels include. Both true means the whole chain held.
|
||||
# this run looks like. tenant-ca is stamped by the CA-extraction
|
||||
# controller; tenantresource is the lineage webhook's verdict from the
|
||||
# redis ApplicationDefinition's matchLabels include. Both true means the
|
||||
# whole chain held.
|
||||
- assert:
|
||||
timeout: 2m
|
||||
resource:
|
||||
@@ -320,6 +391,15 @@ spec:
|
||||
metadata:
|
||||
name: redis-secure.ca-cert
|
||||
(metadata.labels."internal.cozystack.io/tenantresource" != 'true'): true
|
||||
# The account Secret holds the password itself and is the platform's.
|
||||
- assert:
|
||||
timeout: 2m
|
||||
resource:
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: redis-secure.default.account
|
||||
(metadata.labels."internal.cozystack.io/tenantresource" != 'true'): true
|
||||
# No retry around this script. The replica link it reads is settled by
|
||||
# none of the asserts above and carries its own bounded wait below. The
|
||||
# whole step measured 3.0s on run 34711755303, so link_wait is wide
|
||||
|
||||
@@ -20,7 +20,7 @@ make_stubs() {
|
||||
cat > "$stub/kubectl" <<'EOF'
|
||||
#!/bin/bash
|
||||
printf '%s\n' "$*" >> "$STUB_DIR/kubectl.argv"
|
||||
if [ "$*" = "-n tenant-root get secret redis-demo-auth --ignore-not-found -o jsonpath={.data.password}" ]; then
|
||||
if [ "$*" = "-n tenant-root get secret redis-demo.default.account --ignore-not-found -o jsonpath={.data.password}" ]; then
|
||||
printf '%s' "${STUB_PW_B64:-}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user