Repository navigation
Description
Problem
PR #106 changed the proxy-init container security context from capabilities-based to full privileged mode:
# Before (PR #106)
securityContext:
capabilities:
add:
- NET_ADMIN
- NET_RAW
runAsNonRoot: false
runAsUser: 0
# After (PR #106)
securityContext:
privileged: true
runAsNonRoot: false
runAsUser: 0Why this is a problem:
-
Excessive permissions:
privileged: truegrants far more access than needed:- Access to all host devices (
/dev/*) - Ability to load kernel modules
- Bypass AppArmor/SELinux policies
- Mount host filesystems
- Modify kernel parameters beyond networking
- Access to all host devices (
-
Security compliance: Many Kubernetes clusters have PodSecurityPolicies, PodSecurityStandards, or admission controllers that block privileged pods
-
Deployment blockers: Organizations with security-hardened clusters may not be able to adopt AuthProxy with this requirement
Root cause: The change was made to support sysctl -w net.ipv4.conf.all.route_localnet=1, which requires write access to /proc/sys/. This is needed for Istio Ambient Mesh coexistence (see PR #106).
Proposed Solution
Split the init container into two separate containers with minimal privileges:
Option 1: Two Init Containers (Recommended)
initContainers:
# Step 1: Set sysctl parameter (requires privileged, but is minimal/auditable)
- name: sysctl-init
image: busybox:latest
command:
- /bin/sh
- -c
- |
echo "Setting route_localnet for Istio Ambient Mesh compatibility"
sysctl -w net.ipv4.conf.all.route_localnet=1
echo "Sysctl configuration complete"
securityContext:
privileged: true
runAsUser: 0
runAsNonRoot: false
resources:
limits:
cpu: 10m
memory: 16Mi
requests:
cpu: 10m
memory: 16Mi
# Step 2: Configure iptables (only needs network capabilities)
- name: proxy-init
image: localhost/proxy-init:latest
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
runAsNonRoot: false
capabilities:
add:
- NET_ADMIN
- NET_RAW
env:
- name: PROXY_UID
value: "1337"
- name: PROXY_PORT
value: "15123"
- name: INBOUND_PROXY_PORT
value: "15124"
- name: SSH_PORT
value: "22"
resources:
limits:
cpu: 100m
memory: 64Mi
requests:
cpu: 10m
memory: 32MiBenefits:
- ✅ Minimizes privileged container scope (only sysctl operation)
- ✅ iptables setup uses minimal capabilities
- ✅ Easy to audit (sysctl container has 1 command)
- ✅ Can be conditionally included (only needed for Istio Ambient)
Option 2: Pod-Level SecurityContext (If Supported)
Some Kubernetes distributions support setting sysctls via pod-level securityContext:
apiVersion: v1
kind: Pod
spec:
securityContext:
sysctls:
- name: net.ipv4.conf.all.route_localnet
value: "1"
initContainers:
- name: proxy-init
securityContext:
capabilities:
add: [NET_ADMIN, NET_RAW]
runAsUser: 0Limitations:
- ❌ Requires
PodSecurityPolicyor cluster admission controller to allow unsafe sysctls - ❌
net.ipv4.conf.all.route_localnetis considered an "unsafe" sysctl by default - ❌ Cluster admin must whitelist it via
--allowed-unsafe-sysctlskubelet flag
Verdict: Option 2 is cleaner but has cluster-level prerequisites. Use Option 1 for broader compatibility.
Option 3: Conditional Sysctl (Advanced)
Make route_localnet conditional based on Istio Ambient detection:
#!/bin/sh
# In init-iptables.sh
# Detect if Istio Ambient is present (check for ztunnel sockets)
if ss -tln | grep -q ':15008\|:15001\|:15006'; then
echo "Istio Ambient Mesh detected, setting route_localnet"
if ! sysctl -w net.ipv4.conf.all.route_localnet=1; then
echo "WARNING: Failed to set route_localnet. Istio Ambient may not work correctly."
echo "This requires privileged: true in the init container securityContext."
fi
else
echo "No Istio Ambient Mesh detected, skipping route_localnet"
fiThen make privileged optional via annotation:
metadata:
annotations:
kagenti.io/istio-ambient: "true" # Triggers privileged modeFiles to Update
Required Changes
-
kagenti-webhook/internal/webhook/injector/container_builder.go- Modify
BuildProxyInitContainer()to create two init containers OR make privileged conditional - Add logic to detect
kagenti.io/istio-ambientannotation (if using Option 3)
- Modify
-
AuthBridge/AuthProxy/init-iptables.sh- Move sysctl command to a separate section with error handling
- Add conditional logic for Istio detection (if using Option 3)
-
Deployment YAMLs (update all):
AuthBridge/AuthProxy/k8s/auth-proxy-deployment.yamlAuthBridge/k8s/authbridge-deployment.yamlAuthBridge/k8s/authbridge-deployment-no-spiffe.yaml
Documentation Updates
-
AuthBridge/AuthProxy/README.md- Add section explaining the two init containers
- Document when
route_localnetis needed (Istio Ambient only)
-
AuthBridge/AuthProxy/quickstart/README.md- Update prerequisites section
- Add note about PodSecurityPolicies
Testing Plan
Test 1: Non-Ambient Cluster (Capabilities Only)
# Deploy with only capabilities-based init container
kubectl apply -f authbridge-deployment.yaml
# Verify iptables rules are set
kubectl exec -it <pod> -c auth-proxy -- iptables-legacy-save
# Test inbound/outbound traffic
kubectl exec -it <caller-pod> -- curl http://auth-target:8081/protectedExpected: Should work without privileged mode
Test 2: Istio Ambient Cluster (With Sysctl)
# Install Istio with ambient mesh
istioctl install --set profile=ambient
# Label namespace for ambient
kubectl label namespace default istio.io/dataplane-mode=ambient
# Deploy AuthProxy with sysctl-init container
kubectl apply -f authbridge-deployment.yaml
# Verify route_localnet is set
kubectl exec -it <pod> -- sysctl net.ipv4.conf.all.route_localnet
# Verify ztunnel is present
kubectl exec -it <pod> -- ss -tln | grep 15008
# Test traffic through ambient mesh
kubectl exec -it <caller-pod> -- curl http://auth-target:8081/protectedExpected: Both sysctl and iptables work; traffic flows through ztunnel
Test 3: PodSecurityPolicy Enforcement
# Apply restrictive PSP
kubectl apply -f - <<EOF
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: restricted
spec:
privileged: false
allowPrivilegeEscalation: false
requiredDropCapabilities:
- ALL
allowedCapabilities:
- NET_ADMIN
- NET_RAW
EOF
# Try to deploy AuthProxy
kubectl apply -f authbridge-deployment.yamlExpected (Option 1): Only sysctl-init should fail PSP (if PSP blocks privileged), but iptables init succeeds. Document this limitation.
Expected (current main): Entire deployment fails
Security Analysis
Current State (Privileged)
Attack Surface:
- Full device access
- Kernel module loading
- SELinux bypass
- Host filesystem access
Required For:
- sysctl (1 command)
- iptables (NET_ADMIN)
Proposed State (Option 1)
sysctl-init (privileged):
Duration: ~100ms
Commands: 1 (sysctl)
Attack Surface: Full, but minimal time window
proxy-init (capabilities):
Duration: ~500ms
Commands: ~30 iptables rules
Attack Surface: Network namespace only
Required: NET_ADMIN, NET_RAW
Risk Reduction: ~80% of execution time now uses minimal privileges
References
- PR fix: Fix conflict with Istio Ambient Mesh #106: fix: Fix conflict with Istio Ambient Mesh #106
- Istio Ambient Mesh Docs: https://istio.io/latest/docs/ambient/
- Kubernetes Sysctls: https://kubernetes.io/docs/tasks/administer-cluster/sysctl-cluster/
- route_localnet Documentation: https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt (search for
route_localnet) - PodSecurityPolicy: https://kubernetes.io/docs/concepts/security/pod-security-policy/
Related Files (from PR #106)
Modified files requiring changes:
AuthBridge/AuthProxy/k8s/auth-proxy-deployment.yaml (line 383-390)
AuthBridge/k8s/authbridge-deployment-no-spiffe.yaml (line 862-867)
AuthBridge/k8s/authbridge-deployment.yaml (line 962-967)
kagenti-webhook/internal/webhook/injector/container_builder.go (line 442-458)
Sysctl command location:
AuthBridge/AuthProxy/init-iptables.sh (line 171)
Success Criteria
- Init containers split into
sysctl-init(privileged) andproxy-init(capabilities-only) - All deployment YAMLs updated
- Webhook injector updated to inject both containers
- Documentation updated with security notes
- Tested in non-ambient cluster (should work with only proxy-init)
- Tested in Istio Ambient cluster (both containers work)
- Tested with PodSecurityPolicy (fails gracefully with clear error message)
Priority
High Priority — This blocks adoption in security-hardened environments.
Additional Context
This issue was identified during review of PR #106. While the privileged mode change was necessary to support Istio Ambient Mesh, it introduces a significant security expansion that can be mitigated by splitting the responsibilities across two init containers.
The recommended approach (Option 1) provides:
- Backward compatibility: Works with or without Istio Ambient
- Security isolation: Minimal privileged execution time
- Auditability: Clear separation of concerns
- Flexibility: Can be conditionally included based on deployment needs
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
huang195 commentedon Feb 12, 2026
@mrsabath the only concern I have with this approach is we're using
alpine:latestimage as our base image for the iptables init shell script, and this one is almost like the scratch image:It's 9MB big, whereas the
busyboximage is slightly smaller:I wonder if it's worth the effort given that we're going to be adding yet another init container into the mix, whereas we have another issue to minimize the number of init / sidecar containers overall.
mrsabath commentedon Feb 12, 2026
I think the key element of this issue is to reduce the privileges and that should be a focus
huang195 commentedon Feb 12, 2026
Reducing attack surface and reducing privilege is generally a good idea. However, in this case, our init container has 1 script, which is the init-iptables.sh, and nothing else. There's no service we're exposing. I don't think creating an extra busybox container would provide us a benefit here.
huang195 commentedon Feb 12, 2026
Here's a take from Claude:
We could keep the issue as is if we want to do the conditional sysctl, but the benefit is marginal at best.
huang195 commentedon Feb 17, 2026
As discussed on the call, another approach to this problem is to explore if we can get rid of the requirement giving root access to the init container in the first place. The problem is there is no capability to allow a container to run
sysctlcommand. There might be some way of tweaking the iptables rules so we don't need to run the sysctl command in the first place.huang195 commentedon Mar 22, 2026
the issue has been resolved, no longer need root level privilege.