Skip to content

KNOX-3364: New loadAliasesFromK8sSecrets method in entrypoint.sh to l…#1282

Merged
hanicz merged 1 commit into
apache:masterfrom
hanicz:KNOX-3364
Jun 29, 2026
Merged

KNOX-3364: New loadAliasesFromK8sSecrets method in entrypoint.sh to l…#1282
hanicz merged 1 commit into
apache:masterfrom
hanicz:KNOX-3364

Conversation

@hanicz

@hanicz hanicz commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

…oad aliases from k8s secrets. Install jq in the container as well.

KNOX-3364 - Bootstrap Knox aliases from labeled Kubernetes Secrets on container startup

What changes were proposed in this pull request?

Helper function to load Knox aliases from labeled Kubernetes Secrets. Uses the pod's mounted ServiceAccount token to list Secrets in the pod's namespace that carry KNOX_ALIAS_LABEL and feeds the names to knoxcli create-k8s-alias, so aliases are restored on every pod restart. Skips silently when no ServiceAccount token is mounted (non-k8s runs); logs a warning and continues on API errors so Knox startup isn't blocked by transient cluster issues. Requires: jq in the image; the pod's ServiceAccount must have list on Secrets in its namespace.

  • Installs jq on the container

How was this patch tested?

Tested on a local kind cluster, tested by just running without k8s, tested with no secrets, tested with different labels

Secrets:

---
apiVersion: v1
kind: Secret
metadata:
  name: stringdatasecret
  namespace: knox
  labels:
    knox.apache.org/alias: "true"
type: Opaque
stringData:
  alias.name: my-alias2
  topology: sandbox
  alias.value: s3cr3t
---
apiVersion: v1
kind: Secret
metadata:
  name: datasecret
  namespace: knox
  labels:
    knox.apache.org/alias: "true"
type: Opaque
data:
  alias.name: bXktYWxpYXM=
  alias.value: czNjcjN0

./bin/knoxcli.sh list-alias --cluster __gateway,sandbox

…oad aliases from k8s secrets. Install jq in the container as well.
@github-actions

Copy link
Copy Markdown

Test Results

28 tests   28 ✅  3s ⏱️
 1 suites   0 💤
 1 files     0 ❌

Results for commit 9651977.

@smolnar82 smolnar82 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor observation on the curl command, it's not a blocker...

Comment on lines +115 to +119
http_code=$(curl -sS \
--cacert "${sa_ca_file}" \
-H "Authorization: Bearer ${token}" \
-o "${resp_file}" -w "%{http_code}" \
"https://kubernetes.default.svc/api/v1/namespaces/${namespace}/secrets?labelSelector=${label}") || http_code="000"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there's no explicit timeout on the curl call. If the k8s API is slow or unreachable, this could stall container startup. Adding --max-time 10 or similar would make the failure path faster.

@hanicz hanicz merged commit 2fdbda0 into apache:master Jun 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants