# The sandboxes' network on Claude Platform on AWS: the poller in, the
# Claude Platform on AWS endpoint out.
#
# It replaces ../egress-policy.yaml (same name) and differs in two rules: HTTPS goes
# to aws-external-anthropic.<AWS_REGION>.api.aws, where AnthropicAWS sends every
# request, instead of api.anthropic.com, which this path does not use; and egress is
# allowed to the Pod Identity credential address, 169.254.170.23, on TCP 80.
#
# The sandbox's ServiceAccount has a Pod Identity role on this path. A Nitro sandbox
# passes credential requests to 169.254.170.23 on to the Pod Identity Agent on the
# node, and this policy applies to them: without the rule they time out.
#
# DNS (port 53) is allowed to any IP address. While CoreDNS typically runs on a fixed
# cluster address, allowing any destination eliminates the need for address lookup and
# substitution. This simplifies the setup and avoids issues with missing or malformed
# cluster DNS addresses (#104).
# <AWS_REGION> is your workspace's Region.
apiVersion: networking.k8s.aws/v1alpha1
kind: ApplicationNetworkPolicy
metadata:
  name: claude-sandbox-worker-egress
spec:
  podSelector:
    matchLabels:
      app: claude-sandbox-worker
  policyTypes:
    - Ingress
    - Egress
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: claude-poller
      ports:
        - { protocol: TCP, port: 8080 }
  egress:
    - to:
        - ipBlock: { cidr: 0.0.0.0/0 }
      ports:
        - { protocol: UDP, port: 53 }
        - { protocol: TCP, port: 53 }
    - to:
        - ipBlock: { cidr: 169.254.170.23/32 }   # EKS Pod Identity credentials
      ports:
        - { protocol: TCP, port: 80 }
    - to:
        - domainNames:
            - aws-external-anthropic.<AWS_REGION>.api.aws
      ports:
        - { protocol: TCP, port: 443 }
