RBAC & Security
RBAC & Security
Section titled “RBAC & Security”This guide covers security best practices and RBAC configuration for TRIGRA.
RBAC Overview
Section titled “RBAC Overview”TRIGRA requires cluster-level permissions to deploy resources across namespaces.
Default RBAC Configuration
Section titled “Default RBAC Configuration”apiVersion: v1kind: ServiceAccountmetadata: name: trigra namespace: default---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: trigrarules:- apiGroups: ["*"] resources: ["*"] verbs: ["*"]---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: trigrasubjects:- kind: ServiceAccount name: trigra namespace: defaultroleRef: kind: ClusterRole name: trigra apiGroup: rbac.authorization.k8s.ioLeast Privilege RBAC
Section titled “Least Privilege RBAC”For production environments, limit permissions to only what’s needed:
apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: trigrarules:# Core resources- apiGroups: [""] resources: - configmaps - secrets - services - pods - persistentvolumeclaims verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
# Deployments, StatefulSets, DaemonSets- apiGroups: ["apps"] resources: - deployments - statefulsets - daemonsets - replicasets verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
# Ingress- apiGroups: ["networking.k8s.io"] resources: - ingresses verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
# Jobs and CronJobs- apiGroups: ["batch"] resources: - jobs - cronjobs verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]Namespace-Scoped Access
Section titled “Namespace-Scoped Access”To restrict TRIGRA to specific namespaces:
# Use Role instead of ClusterRoleapiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata: name: trigra namespace: production # Only this namespacerules:- apiGroups: ["*"] resources: ["*"] verbs: ["*"]---apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata: name: trigra namespace: productionsubjects:- kind: ServiceAccount name: trigra namespace: defaultroleRef: kind: Role name: trigra apiGroup: rbac.authorization.k8s.ioWebhook Security
Section titled “Webhook Security”Signature Validation
Section titled “Signature Validation”TRIGRA validates all incoming webhooks using HMAC-SHA256:
- GitHub signs each webhook with your secret
- TRIGRA computes expected signature
- Request is rejected if signatures don’t match
// Validation logicmac := hmac.New(sha256.New, []byte(webhookSecret))mac.Write(body)expectedSig := "sha256=" + hex.EncodeToString(mac.Sum(nil))
if !hmac.Equal([]byte(expectedSig), []byte(receivedSig)) { // Reject request}Strong Secrets
Section titled “Strong Secrets”Always use cryptographically secure secrets:
# Good: 256-bit random keyopenssl rand -hex 32
# Bad: Weak password# webhook-secret-123Network Security
Section titled “Network Security”Network Policies
Section titled “Network Policies”Restrict network access to TRIGRA:
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: trigra-network-policyspec: podSelector: matchLabels: app: trigra policyTypes: - Ingress - Egress ingress: # Allow webhook traffic from anywhere (GitHub) - from: [] ports: - protocol: TCP port: 8080 egress: # Allow DNS - to: [] ports: - protocol: UDP port: 53 # Allow Kubernetes API - to: - namespaceSelector: {} ports: - protocol: TCP port: 443 # Allow GitHub API - to: [] ports: - protocol: TCP port: 443TLS/HTTPS
Section titled “TLS/HTTPS”For production, use HTTPS:
- Cloudflare Tunnel - Automatic TLS
- Ingress with cert-manager - Let’s Encrypt certificates
- Service Mesh - mTLS between services
# Ingress with TLSapiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: trigra annotations: cert-manager.io/cluster-issuer: letsencrypt-prodspec: tls: - hosts: - webhook.yourdomain.com secretName: trigra-tls rules: - host: webhook.yourdomain.com http: paths: - path: /webhook pathType: Prefix backend: service: name: trigra port: number: 80Pod Security
Section titled “Pod Security”Security Context
Section titled “Security Context”Run TRIGRA with restricted privileges:
spec: template: spec: securityContext: runAsNonRoot: true runAsUser: 1000 fsGroup: 1000 containers: - name: trigra securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true capabilities: drop: - ALLPod Security Standards
Section titled “Pod Security Standards”Apply Pod Security Standards:
apiVersion: v1kind: Namespacemetadata: name: trigra-system labels: pod-security.kubernetes.io/enforce: restricted pod-security.kubernetes.io/audit: restricted pod-security.kubernetes.io/warn: restrictedSecret Management
Section titled “Secret Management”External Secrets
Section titled “External Secrets”Use external secret management:
# With External Secrets OperatorapiVersion: external-secrets.io/v1beta1kind: ExternalSecretmetadata: name: trigra-secretspec: refreshInterval: 1h secretStoreRef: kind: ClusterSecretStore name: vault target: name: trigra-secret data: - secretKey: WEBHOOK_SECRET remoteRef: key: trigra/webhook-secretSecret Rotation
Section titled “Secret Rotation”Rotate secrets regularly:
- Generate new secret
- Update GitHub webhook with new secret
- Update Kubernetes secret
- Restart TRIGRA pods
# Rotation scriptNEW_SECRET=$(openssl rand -hex 32)kubectl create secret generic trigra-secret \ --from-literal=WEBHOOK_SECRET="$NEW_SECRET" \ --dry-run=client -o yaml | kubectl apply -f -kubectl rollout restart deployment/trigraecho "Update GitHub webhook with: $NEW_SECRET"Audit Logging
Section titled “Audit Logging”Enable Kubernetes audit logging for TRIGRA actions:
# Audit policyapiVersion: audit.k8s.io/v1kind: Policyrules:- level: Metadata users: ["system:serviceaccount:default:trigra"] verbs: ["create", "update", "patch", "delete"]Security Checklist
Section titled “Security Checklist”- Use strong, randomly generated webhook secret
- Enable HTTPS (Cloudflare Tunnel or Ingress)
- Apply least privilege RBAC
- Enable network policies
- Run as non-root user
- Use external secret management for production
- Rotate secrets periodically
- Enable audit logging
- Monitor for suspicious activity