# The brain's identity, and the whole of what it may do on the Kubernetes API.
#
# The brain claims a pod from the pool and reads the Sandbox the claim adopted,
# which is where the pod's IP is. That is all. Commands and files go to sandboxd
# in that pod over the pod network, so the brain needs no pods/exec, no
# pods/log, no pods/portforward and no read on pods at all: it cannot exec into
# any pod in this namespace, its own included, and the Kubernetes API carries
# none of the session's traffic.
#
# The verbs are the ones the agent-sandbox MCP server's documentation lists for
# the sandboxd in-cluster connection: the SDK creates a claim, watches it until
# it names a Sandbox, reads that Sandbox's status, lists the session's own
# claims by label to check a claim name belongs to it, and deletes the claim.
#
# <NAMESPACE> is filled in at apply time by ./scripts/setup.sh from the
# NAMESPACE variable. Never apply this file with the placeholder in place.
apiVersion: v1
kind: ServiceAccount
metadata:
  name: brain
  namespace: <NAMESPACE>
  labels:
    app.kubernetes.io/part-of: brain-and-hands
# automountServiceAccountToken stays at its default, true: the MCP server in the
# brain authenticates to the Kubernetes API with this ServiceAccount's token,
# through the SDK's in-cluster configuration. Its Bedrock credentials arrive
# separately, through the EKS Pod Identity association ./scripts/setup.sh
# creates for this same ServiceAccount. The two are unrelated.
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: brain
  namespace: <NAMESPACE>
  labels:
    app.kubernetes.io/part-of: brain-and-hands
rules:
  - apiGroups: ["extensions.agents.x-k8s.io"]
    resources: ["sandboxclaims"]
    verbs: ["create", "get", "list", "watch", "delete"]
  - apiGroups: ["agents.x-k8s.io"]
    resources: ["sandboxes"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: brain
  namespace: <NAMESPACE>
  labels:
    app.kubernetes.io/part-of: brain-and-hands
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: brain
subjects:
  - kind: ServiceAccount
    name: brain
    namespace: <NAMESPACE>
