# EN: RBAC for Gitea act_runner to deploy to staging namespace
# VI: RBAC cho Gitea act_runner deploy vao namespace staging
#
# The act_runner ServiceAccount (in gitea namespace) needs permissions to:
#   - Create Kaniko Jobs for building Docker images
#   - Apply manifests (deployments, services, configmaps, secrets, ingress, hpa, networkpolicies, pvc)
#   - Patch deployments (set image, rollout restart)
#   - Read pods/logs (rollout status)
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: act-runner-staging
  namespace: staging
rules:
  - apiGroups: ["apps"]
    resources: ["deployments"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
  - apiGroups: ["batch"]
    resources: ["jobs"]
    verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
  - apiGroups: [""]
    resources: ["services", "configmaps", "secrets", "persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
  - apiGroups: [""]
    resources: ["pods", "pods/log"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["networking.k8s.io"]
    resources: ["ingresses", "networkpolicies"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
  - apiGroups: ["autoscaling"]
    resources: ["horizontalpodautoscalers"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
  - apiGroups: [""]
    resources: ["namespaces"]
    verbs: ["get", "list", "create", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: act-runner-staging-binding
  namespace: staging
subjects:
  - kind: ServiceAccount
    name: act-runner
    namespace: gitea
roleRef:
  kind: Role
  name: act-runner-staging
  apiGroup: rbac.authorization.k8s.io
