# services/hermes-triage-demo/rbac.yaml
# Two scoped grants, both least-privilege:
# 1. Jenkins agent pods (SA jenkins/jenkins) create and observe the demo
#    test-runner Job and manage the fixture ConfigMap (ensure + seed).
# 2. Ariadne's own service account patches the fixture ConfigMap back to
#    healthy. The repair runs in-process inside Ariadne, so there is no
#    repair Job and no separate repair service account.
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: demo-test-runner
  namespace: hermes-triage-demo
  labels:
    app.kubernetes.io/part-of: hermes-triage-demo
rules:
  - apiGroups: ["batch"]
    resources: ["jobs"]
    verbs: ["create", "get", "list", "watch"]
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["pods/log"]
    verbs: ["get"]
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["create"]
  - apiGroups: [""]
    resources: ["configmaps"]
    resourceNames: ["hermes-triage-demo-fixture"]
    verbs: ["get", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: demo-test-runner-jenkins
  namespace: hermes-triage-demo
  labels:
    app.kubernetes.io/part-of: hermes-triage-demo
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: demo-test-runner
subjects:
  - kind: ServiceAccount
    name: jenkins
    namespace: jenkins
---
# The fixture repair runs in-process inside Ariadne rather than as a spawned
# Kubernetes Job, so Ariadne's own service account needs to patch exactly one
# ConfigMap in this namespace — nothing else.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: ariadne-fixture-repair
  namespace: hermes-triage-demo
  labels:
    app.kubernetes.io/part-of: hermes-triage-demo
rules:
  - apiGroups: [""]
    resources: ["configmaps"]
    resourceNames: ["hermes-triage-demo-fixture"]
    verbs: ["get", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: ariadne-fixture-repair
  namespace: hermes-triage-demo
  labels:
    app.kubernetes.io/part-of: hermes-triage-demo
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: ariadne-fixture-repair
subjects:
  - kind: ServiceAccount
    name: ariadne
    namespace: maintenance
