Repository navigation
Conversation
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Local Testing Guide for JWT-SVID AuthenticationThis guide walks you through testing JWT-SVID authentication using local images (no push to ghcr.io). Prerequisites
Step 0: Create Kind ClusterThe Kagenti ansible installer can create a Kind cluster automatically, but for local image testing, it's better to create it manually first: # Create a Kind cluster with the correct name
kind create cluster --name kagenti-dev --config - <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30080
hostPort: 8080
protocol: TCP
- containerPort: 30443
hostPort: 8443
protocol: TCP
EOF
# Verify cluster is running
kubectl cluster-info --context kind-kagenti-devStep 1: Build and Load Local Imagescd kagenti-extensions
# Make the script executable
chmod +x local-build-and-test.sh
# Build all images and load into Kind cluster
# For Podman users: set KIND_EXPERIMENTAL_PROVIDER
export KIND_EXPERIMENTAL_PROVIDER=podman # Only needed for Podman
./local-build-and-test.sh
# If using a different cluster name:
# CLUSTER_NAME=my-cluster ./local-build-and-test.shThis builds and loads:
Note for Podman users: The script automatically detects Podman and uses tar archives to load images into Kind, since Step 2: Update Hardcoded Image TagsThe webhook's default image tags are hardcoded in cd kagenti-extensions/kagenti-webhook
# Replace image tags (these sed commands modify defaults.go in-place)
sed -i '' 's|envoy-with-processor:latest|envoy-with-processor:local|g' internal/webhook/config/defaults.go
sed -i '' 's|proxy-init:latest|proxy-init:local|g' internal/webhook/config/defaults.go
sed -i '' 's|client-registration:latest|client-registration:local|g' internal/webhook/config/defaults.go
# Also update PullPolicy to Never (don't pull from registry)
sed -i '' 's|PullPolicy:.*corev1.PullIfNotPresent|PullPolicy: corev1.PullNever|g' internal/webhook/config/defaults.go
# Verify changes
grep -E "envoy-with-processor|proxy-init|client-registration|PullPolicy" internal/webhook/config/defaults.go
# Rebuild the webhook image with updated tags
make docker-build IMG=ghcr.io/kagenti/kagenti-extensions/kagenti-webhook:local
# Load into Kind cluster
# For Docker users:
kind load docker-image ghcr.io/kagenti/kagenti-extensions/kagenti-webhook:local --name kagenti-dev
# For Podman users (use tar archive method):
# podman save ghcr.io/kagenti/kagenti-extensions/kagenti-webhook:local -o /tmp/webhook-local.tar
# kind load image-archive /tmp/webhook-local.tar --name kagenti-dev
# rm /tmp/webhook-local.tarStep 3: Install Kagenti with AnsibleIMPORTANT: For federated-JWT testing with local images, use the unified The ansible installer will detect the existing # Go to kagenti repo
cd kagenti
# Install with dev base values + TWO overlays (deps local images + extensions federated-jwt)
# --env dev → Loads dev_values.yaml (base Kind development config)
# --env-file deployments/envs/... → Local images for kagenti-deps (SPIRE, Keycloak, etc.)
# --env-file ../kagenti-extensions/... → Federated-jwt + local images for kagenti-extensions
deployments/ansible/run-install.sh --env dev \
--env-file deployments/envs/dev_values_local_images.yaml \
--env-file ../kagenti-extensions/federated-jwt-values.yamlAbout the values files:
This installation will:
How SPIFFE IdP setup works:
Expected behavior:
Step 4: Verify SPIRE and Keycloakcd kagenti-extensions
chmod +x verify-spire-keycloak.sh
./verify-spire-keycloak.shExpected output:
Step 5: Run AuthBridge DemoOption A: Manual Demo (Recommended First)Follow AuthBridge/demos/github-issue/demo-manual.md: cd /Users/alan/Documents/Work/kagenti-extensions/AuthBridge/demos/github-issue
# 1. Create namespace
kubectl create namespace team1
kubectl label namespace team1 kagenti-enabled=true
# 2. Deploy ConfigMaps (use the updated ones with kagenti-webhook-config)
kubectl apply -f k8s/configmaps.yaml
# 3. Deploy demo workload
kubectl apply -f k8s/deployment.yaml
# 4. Check client-registration sidecar logs
kubectl logs -n team1 deployment/weather-service -c kagenti-client-registration -f
# Expected (Phase 1 - client-secret):
# "Configuring client for client-secret authentication"
# Expected (Phase 2 - federated-jwt):
# "Configuring client for JWT-SVID authentication (federated-jwt)"Option B: Webhook-Based DemoFollow AuthBridge/demos/webhook/README.md for automatic sidecar injection testing. Appendix: Standalone Helm Install (Without Ansible)If you want to install kagenti-deps directly with Helm instead of using the Ansible installer, you must manually configure SPIFFE IdP support due to a bug in the SPIRE Helm chart that prevents Step 1: Install kagenti-depshelm install kagenti-deps ./charts/kagenti-deps/ \
-n kagenti-system \
--create-namespace \
--set spire.enabled=true \
--set keycloak.enabled=true \
--waitStep 2: Patch SPIRE ConfigMapThe SPIRE Helm chart doesn't render # Get the SPIRE namespace (may vary)
SPIRE_NAMESPACE=zero-trust-workload-identity-manager
# Patch the ConfigMap
kubectl get configmap spire-spiffe-oidc-discovery-provider \
-n $SPIRE_NAMESPACE -o json | \
jq '.data["oidc-discovery-provider.conf"] |= (fromjson | .set_key_use = true | tojson)' | \
kubectl apply -f -
# Restart OIDC provider to apply changes
kubectl rollout restart deployment/spire-spiffe-oidc-discovery-provider -n $SPIRE_NAMESPACE
# Wait for rollout to complete
kubectl rollout status deployment/spire-spiffe-oidc-discovery-provider -n $SPIRE_NAMESPACE --timeout=2mStep 3: Create SPIFFE IdP Setup JobThe job is not included in the Helm chart to avoid race conditions. Create it manually after the patch: kubectl apply -f - <<'EOF'
apiVersion: v1
kind: ServiceAccount
metadata:
name: kagenti-spiffe-idp-setup
namespace: kagenti-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kagenti-spiffe-idp-reader
rules:
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["keycloak-admin-secret"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: kagenti-spiffe-idp-keycloak-reader
namespace: keycloak
subjects:
- kind: ServiceAccount
name: kagenti-spiffe-idp-setup
namespace: kagenti-system
roleRef:
kind: ClusterRole
name: kagenti-spiffe-idp-reader
apiGroup: rbac.authorization.k8s.io
---
apiVersion: batch/v1
kind: Job
metadata:
name: kagenti-spiffe-idp-setup-job
namespace: kagenti-system
spec:
backoffLimit: 10
template:
spec:
serviceAccountName: kagenti-spiffe-idp-setup
restartPolicy: OnFailure
initContainers:
- name: wait-for-spire
image: bitnami/kubectl:latest
command:
- sh
- -c
- |
echo "Waiting for SPIRE server..."
kubectl wait --for=condition=ready pod -l app=spire-server \
-n zero-trust-workload-identity-manager --timeout=300s
echo "Waiting for SPIRE OIDC provider..."
kubectl wait --for=condition=ready pod \
-l app.kubernetes.io/name=spire-spiffe-oidc-discovery-provider \
-n zero-trust-workload-identity-manager --timeout=300s
containers:
- name: setup-spiffe-idp
image: ghcr.io/kagenti/kagenti/spiffe-idp-setup:latest
env:
- name: KEYCLOAK_BASE_URL
value: "http://keycloak-service.keycloak.svc:8080"
- name: KEYCLOAK_REALM
value: "kagenti"
- name: KEYCLOAK_NAMESPACE
value: "keycloak"
- name: KEYCLOAK_ADMIN_SECRET_NAME
value: "keycloak-admin-secret"
- name: KEYCLOAK_ADMIN_USERNAME_KEY
value: "username"
- name: KEYCLOAK_ADMIN_PASSWORD_KEY
value: "password"
- name: SPIFFE_TRUST_DOMAIN
value: "spiffe://localtest.me"
- name: SPIFFE_BUNDLE_ENDPOINT
value: "http://spire-spiffe-oidc-discovery-provider.zero-trust-workload-identity-manager.svc.cluster.local/keys"
- name: SPIFFE_IDP_ALIAS
value: "spire-spiffe"
EOF
# Wait for job to complete
kubectl wait --for=condition=complete job/kagenti-spiffe-idp-setup-job \
-n kagenti-system --timeout=5m
# Check job logs
kubectl logs job/kagenti-spiffe-idp-setup-job -n kagenti-systemStep 4: Verify# Check job status
kubectl get job kagenti-spiffe-idp-setup-job -n kagenti-system
# Verify JWKS has "use" field
kubectl run test-curl --rm -i --image=curlimages/curl --restart=Never -- \
curl -s http://spire-spiffe-oidc-discovery-provider.zero-trust-workload-identity-manager.svc.cluster.local/keys | \
jq '.keys[] | select(.use)'
# Should return keys with "use": "sig"Why these manual steps are needed:
Recommendation: Use the Ansible installer (Step 3 in main guide) instead of standalone Helm - it handles all of this automatically! Verify Federated-JWT ConfigurationSince you installed with # 1. Verify authBridge.clientAuthType is set to federated-jwt
kubectl get configmap kagenti-webhook-config -n team1 -o jsonpath='{.data.CLIENT_AUTH_TYPE}'
# Expected: federated-jwt
# 2. Deploy an agent and check client-registration logs
# (After deploying an agent in Step 6)
kubectl logs -n team1 deployment/<your-agent> -c kagenti-client-registration -f
# Expected: "Configuring client for JWT-SVID authentication (federated-jwt)"
# 3. Verify Keycloak client uses federated-jwt authenticator
# (After agent deployment creates a Keycloak client)
kubectl run test-curl --rm -i --image=curlimages/curl --restart=Never -- sh -c "
ADMIN_TOKEN=\$(curl -s 'http://keycloak-service.keycloak.svc:8080/realms/master/protocol/openid-connect/token' \
-d 'grant_type=password' -d 'client_id=admin-cli' -d 'username=admin' -d 'password=admin' | jq -r '.access_token')
curl -s -H 'Authorization: Bearer \$ADMIN_TOKEN' \
'http://keycloak-service.keycloak.svc:8080/admin/realms/kagenti/clients' | \
jq '.[] | select(.clientId | contains(\"spiffe\")) | {clientId, clientAuthenticatorType}'
"
# Expected: "clientAuthenticatorType": "federated-jwt" |
Signed-off-by: Alan Cha <[email protected]>
| @@ -18,10 +18,10 @@ COPY requirements.txt . | |||
| RUN pip install --no-cache-dir -r requirements.txt | |||
|
|
|||
| # Ensure non-root user owns application directory | |||
| RUN chown -R 1000:1000 /app | |||
| RUN chown -R 1337:1337 /app | |||
|
|
|||
| # Switch to non-root user | |||
| USER 1000:1000 | |||
| USER 1337:1337 | |||
|
|
|||
| # Register client | |||
| CMD ["python", "client_registration.py"] No newline at end of file | |||
There was a problem hiding this comment.
I'm not certain if this UID modification is required anymore. I had issues with the spiffe-helper, client-registration, envoy-proxy all reading from the shared volume to extract the JWT-SVID and this was recommended to me by Claude. 1337 was selected because of Envoy or Istio?
But later, I added ensureFSGroup() so these should all be able to read the JWT-SVID even if they are not the same UID.
TODO: verify this
| # Demo/development only: do NOT use hardcoded admin credentials in production. | ||
| # For production deployments, these values come from values.yaml in the Helm chart. | ||
| KEYCLOAK_ADMIN_USERNAME: "admin" | ||
| KEYCLOAK_ADMIN_PASSWORD: "admin" |
There was a problem hiding this comment.
This is a demo but I think the Keycloak admin username/password should come from a secret. I think there might already be a secret.
Doesn't the kagenti-client-registration sidecar already read the username/password from a secret in order to register clients?
TODO: verify this.
| # use kustomize) accordingly, and adjust the service account if needed. | ||
|
|
||
| --- | ||
| # kagenti-webhook-config ConfigMap - Used by kagenti-client-registration sidecar |
There was a problem hiding this comment.
Shouldn't this just be renamed to kagenti-client-registration-config instead of kagenti-webhook-config if it's only being used by kagenti-client-registration? But perhaps it won't be clear from the name that it's part of kagenti webhook?
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
Summary
Enable SPIRE in Keycloak by enabling federated client authentication in Keycloak and setting up SPIRE as an IdP.
Some important notes are that:
client-secretorfederated-jwt. That means that client-registration cannot dynamically switch between creating clients using secrets and JWT-SVID. It may be possible to do so but that would increase complexity and double the number clients (because Keycloak clients cannot both support secrets and JWT-SVID.1. Client Registration - JWT-SVID Support
File:
AuthBridge/client-registration/client_registration.pyCLIENT_AUTH_TYPEenvironment variable (client-secretorfederated-jwt)federated-jwt, configures Keycloak clients with:clientAuthenticatorType: "federated-jwt"jwt.credential.issuerandjwt.credential.subattributes2. Webhook Sidecar Injection Updates
File:
kagenti-webhook/internal/webhook/injector/container_builder.goenvironmentstokagenti-webhook-configKEYCLOAK_NAMESPACE,KEYCLOAK_ADMIN_SECRET_NAMEKEYCLOAK_ADMIN_USERNAME_KEY,KEYCLOAK_ADMIN_PASSWORD_KEYCLIENT_AUTH_TYPE,SPIFFE_IDP_ALIASagent-oauth-secret-job(reads credentials from Secret via K8s API)3. UID 1337 Standardization
File:
AuthBridge/client-registration/Dockerfileproxy-initiptables rules exclude UID 1337 from traffic redirection to prevent routing loops/opt/jwt_svid.token,/shared/*)4. Demo Configuration Updates
File:
AuthBridge/demos/github-issue/k8s/configmaps.yamlkagenti-webhook-config: Webhook-specific configuration (SPIRE, Keycloak, auth type)environments: Agent-facing configuration (kept minimal)Related issue(s)
Fix #82