Repository navigation
Conversation
Signed-off-by: Alan Cha <[email protected]>
UID 1337 Standardization - File Permission FixThe ProblemDuring testing, the Root CauseThe sidecars were running as different UIDs:
When a file is written by one sidecar (e.g., The SolutionStandardized all AuthBridge sidecars to run as UID 1337:
Why UID 1337 SpecificallyEnvoy compatibility: Envoy's official base image runs as UID 1337 by default (industry standard from Istio/Linkerd). Changing Envoy's UID would require rebuilding the base image. iptables traffic interception: The Files Changedkagenti-extensions:
|
Signed-off-by: Alan Cha <[email protected]>
WIPLocal 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 TWO overlay files. The ansible installer will detect the existing # Go to kagenti repo
cd kagenti
# Install with base dev values + TWO overlays (federated-jwt + local images)
# --env dev → Loads dev_values.yaml (base Kind development config)
# --env-file ...federated-jwt → Enables JWT-SVID authentication (production-ready)
# --env-file ...local_images → Uses :local image tags (testing-only)
deployments/ansible/run-install.sh --env dev \
--env-file deployments/envs/dev_values_federated-jwt.yaml \
--env-file deployments/envs/dev_values_local_images.yamlAbout the values files:
This installation will:
The SPIFFE IdP setup job will:
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. 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" |
|
kagenti-extensions/local-build-and-test.sh #!/bin/bash
set -e
# Local Build and Test Script for JWT-SVID Authentication
# This script builds all necessary images locally and loads them into Kind
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
KAGENTI_DIR="/Users/alan/Documents/Work/kagenti"
CLUSTER_NAME="${CLUSTER_NAME:-kagenti-dev}"
# Auto-detect container runtime (Podman or Docker)
# If KIND_EXPERIMENTAL_PROVIDER is set to podman, use it regardless of what's installed
if [ "${KIND_EXPERIMENTAL_PROVIDER}" = "podman" ]; then
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-podman}"
elif ! command -v docker &> /dev/null && command -v podman &> /dev/null; then
# Docker not available but Podman is
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-podman}"
else
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-docker}"
fi
echo "Using container runtime: ${CONTAINER_RUNTIME}"
# Function to load image into Kind (handles Podman vs Docker)
load_image_to_kind() {
local image_name="$1"
if [ "${CONTAINER_RUNTIME}" = "podman" ]; then
# Podman: save to tar and load
# Replace colons and slashes to make valid filename
local tar_file="/tmp/$(echo ${image_name} | sed 's|[:/]|-|g').tar"
${CONTAINER_RUNTIME} save "${image_name}" -o "${tar_file}"
kind load image-archive "${tar_file}" --name "${CLUSTER_NAME}"
rm -f "${tar_file}"
else
# Docker: direct load
kind load docker-image "${image_name}" --name "${CLUSTER_NAME}"
fi
}
echo "=========================================="
echo "Building Local Images for JWT-SVID Testing"
echo "Cluster: ${CLUSTER_NAME}"
echo "=========================================="
# Check if cluster exists
if ! kind get clusters | grep -q "^${CLUSTER_NAME}$"; then
echo "❌ Kind cluster '${CLUSTER_NAME}' not found"
echo "Please create it first or set CLUSTER_NAME environment variable"
exit 1
fi
echo "✅ Found Kind cluster: ${CLUSTER_NAME}"
echo ""
# Build spiffe-idp-setup (NEW - from kagenti repo)
echo "=========================================="
echo "Building spiffe-idp-setup"
echo "=========================================="
cd "${KAGENTI_DIR}/kagenti/auth/spiffe-idp-setup"
${CONTAINER_RUNTIME} build -t ghcr.io/kagenti/kagenti/spiffe-idp-setup:local .
load_image_to_kind ghcr.io/kagenti/kagenti/spiffe-idp-setup:local
echo "✅ Built and loaded: spiffe-idp-setup:local"
echo ""
# Build client-registration (CHANGED - UID 1337)
echo "=========================================="
echo "Building client-registration"
echo "=========================================="
cd "${SCRIPT_DIR}/AuthBridge/client-registration"
${CONTAINER_RUNTIME} build -t ghcr.io/kagenti/kagenti-extensions/client-registration:local .
load_image_to_kind ghcr.io/kagenti/kagenti-extensions/client-registration:local
echo "✅ Built and loaded: client-registration:local"
echo ""
# Build kagenti-webhook (CHANGED - container_builder.go)
echo "=========================================="
echo "Building kagenti-webhook"
echo "=========================================="
cd "${SCRIPT_DIR}/kagenti-webhook"
make docker-build IMG=ghcr.io/kagenti/kagenti-extensions/kagenti-webhook:local CONTAINER_TOOL=${CONTAINER_RUNTIME}
load_image_to_kind ghcr.io/kagenti/kagenti-extensions/kagenti-webhook:local
echo "✅ Built and loaded: kagenti-webhook:local"
echo ""
# Build envoy-with-processor (verify UID 1337)
echo "=========================================="
echo "Building envoy-with-processor"
echo "=========================================="
cd "${SCRIPT_DIR}/AuthBridge/AuthProxy"
${CONTAINER_RUNTIME} build -f Dockerfile.envoy -t ghcr.io/kagenti/kagenti-extensions/envoy-with-processor:local .
load_image_to_kind ghcr.io/kagenti/kagenti-extensions/envoy-with-processor:local
echo "✅ Built and loaded: envoy-with-processor:local"
echo ""
# Build proxy-init
echo "=========================================="
echo "Building proxy-init"
echo "=========================================="
cd "${SCRIPT_DIR}/AuthBridge/AuthProxy"
${CONTAINER_RUNTIME} build -f Dockerfile.init -t ghcr.io/kagenti/kagenti-extensions/proxy-init:local .
load_image_to_kind ghcr.io/kagenti/kagenti-extensions/proxy-init:local
echo "✅ Built and loaded: proxy-init:local"
echo ""
echo "=========================================="
echo "✅ All images built and loaded successfully!"
echo "=========================================="
echo ""
echo "Images loaded into cluster '${CLUSTER_NAME}':"
echo " - ghcr.io/kagenti/kagenti/spiffe-idp-setup:local"
echo " - ghcr.io/kagenti/kagenti-extensions/client-registration:local"
echo " - ghcr.io/kagenti/kagenti-extensions/kagenti-webhook:local"
echo " - ghcr.io/kagenti/kagenti-extensions/envoy-with-processor:local"
echo " - ghcr.io/kagenti/kagenti-extensions/proxy-init:local"
echo ""
echo "Next steps:"
echo " 1. Update values files to use :local tag"
echo " 2. Run: cd ${KAGENTI_DIR} && deployments/ansible/run-install.sh --env dev"
echo " 3. Verify SPIRE and Keycloak are running"
echo " 4. Run the AuthBridge demo"
echo ""kagent/deployments/envs/dev_values_local_images.yaml # ============================================================================
# dev_values_local_images.yaml
# ============================================================================
# Local image overrides for testing with :local tags
#
# USAGE: Add this as an additional overlay for local testing:
# run-install.sh --env dev \
# --env-file deployments/envs/dev_values_federated-jwt.yaml \
# --env-file deployments/envs/dev_values_local_images.yaml
#
# ⚠️ DO NOT USE IN PRODUCTION - This file is for local testing only!
#
# This file overrides image tags to use :local and pullPolicy to Never,
# allowing testing with locally-built images loaded into Kind cluster.
# ============================================================================
# Override cluster creation for manual Kind cluster setup
create_kind_cluster: false
kind_cluster_name: kagenti-dev
charts:
kagenti:
values:
# Override SPIFFE IdP setup image
spiffeIdp:
image:
repository: ghcr.io/kagenti/kagenti/spiffe-idp-setup
tag: local
pullPolicy: Never
# Override AuthBridge sidecar images
authBridge:
images:
clientRegistration:
tag: local
pullPolicy: Never
envoyProxy:
tag: local
pullPolicy: Never
proxyInit:
tag: local
pullPolicy: Never
# Override webhook image
components:
platformWebhook:
image:
repository: ghcr.io/kagenti/kagenti-extensions/kagenti-webhook
tag: local
pullPolicy: Neverkagenti-extensions/verify-spire-keycloak.sh #!/bin/bash
set -e
# Verification script for SPIRE and Keycloak setup
echo "=========================================="
echo "Verifying SPIRE and Keycloak Setup"
echo "=========================================="
echo ""
# Check SPIRE
echo "1. Checking SPIRE server..."
if kubectl get pods -n spire-server -l app.kubernetes.io/name=server | grep -q "Running"; then
echo "✅ SPIRE server is running"
else
echo "❌ SPIRE server is not running"
kubectl get pods -n spire-server
exit 1
fi
echo ""
# Check SPIRE OIDC discovery provider
echo "2. Checking SPIRE OIDC discovery provider..."
if kubectl get pods -n spire-server -l app.kubernetes.io/name=spiffe-oidc-discovery-provider | grep -q "Running"; then
echo "✅ SPIRE OIDC discovery provider is running"
else
echo "❌ SPIRE OIDC discovery provider is not running"
kubectl get pods -n spire-server
exit 1
fi
echo ""
# Check SPIRE JWKS endpoint
echo "3. Checking SPIRE JWKS endpoint..."
JWKS_URL="http://spire-spiffe-oidc-discovery-provider.spire-server.svc.cluster.local/keys"
if kubectl run -it --rm --restart=Never curl-test --image=curlimages/curl:latest -- curl -s "${JWKS_URL}" | grep -q '"use"'; then
echo "✅ SPIRE JWKS has 'use' field"
else
echo "❌ SPIRE JWKS missing 'use' field"
exit 1
fi
echo ""
# Check Keycloak
echo "4. Checking Keycloak..."
if kubectl get pods -n keycloak -l app=keycloak | grep -q "Running"; then
echo "✅ Keycloak is running"
else
echo "❌ Keycloak is not running"
kubectl get pods -n keycloak
exit 1
fi
echo ""
# Check Keycloak admin secret
echo "5. Checking Keycloak admin secret..."
if kubectl get secret -n keycloak keycloak-initial-admin &>/dev/null; then
echo "✅ Keycloak admin secret exists"
echo "Username: $(kubectl get secret -n keycloak keycloak-initial-admin -o jsonpath='{.data.username}' | base64 -d)"
else
echo "❌ Keycloak admin secret not found"
exit 1
fi
echo ""
# Check SPIFFE IdP setup job
echo "6. Checking SPIFFE IdP setup job..."
if kubectl get job -n kagenti-system kagenti-spiffe-idp-setup-job &>/dev/null; then
JOB_STATUS=$(kubectl get job -n kagenti-system kagenti-spiffe-idp-setup-job -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}')
if [ "$JOB_STATUS" == "True" ]; then
echo "✅ SPIFFE IdP setup job completed successfully"
echo ""
echo "Job logs:"
kubectl logs -n kagenti-system job/kagenti-spiffe-idp-setup-job --tail=20
else
echo "⚠️ SPIFFE IdP setup job has not completed yet"
kubectl get job -n kagenti-system kagenti-spiffe-idp-setup-job
echo ""
echo "Job logs:"
kubectl logs -n kagenti-system job/kagenti-spiffe-idp-setup-job --tail=50
fi
else
echo "⚠️ SPIFFE IdP setup job not found (may not be deployed yet)"
fi
echo ""
echo "=========================================="
echo "✅ Verification Complete"
echo "=========================================="
echo ""
echo "To access Keycloak Admin Console:"
echo " 1. Open: http://keycloak.localtest.me:8080/admin"
echo " 2. Switch to the 'kagenti' realm"
echo " 3. Check Identity Providers → Should see 'spire-spiffe' (Type: SPIFFE)"
echo "" |
|
Replaced by #187 |
Thin serialization shell over check_policy_conflicts: any completed survey returns 200 with the ConflictReport JSON body (the controller's first JSON response body). Unlike the live /apply path, a found conflict is a recorded diagnosis and never 422; the resolver's pre-survey HTTPException(502/404) propagates unchanged as a bare non-2xx with no report body, and a missing policy_text is a FastAPI validation 422. The /apply routes and the PolicyContradictionError/PolicyRulesBuilderError -> 422 handlers are untouched. Refs #159. Part of #154. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Anatoly Koyfman <[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