| Giorgi Lekveishvili | 3598266 | 2024-04-05 13:05:40 +0400 | [diff] [blame] | 1 | {{ if .Values.rbac.create }} |
| 2 | {{- $serviceName := include "jenkins.fullname" . -}} |
| 3 | |
| 4 | # This role is used to allow Jenkins scheduling of agents via Kubernetes plugin. |
| 5 | apiVersion: rbac.authorization.k8s.io/v1 |
| 6 | kind: Role |
| 7 | metadata: |
| 8 | name: {{ $serviceName }}-schedule-agents |
| 9 | namespace: {{ template "jenkins.agent.namespace" . }} |
| 10 | labels: |
| gio | 20157e8 | 2026-07-22 13:10:48 +0400 | [diff] [blame^] | 11 | {{- include "jenkins.labels" . | nindent 4 }} |
| Giorgi Lekveishvili | 3598266 | 2024-04-05 13:05:40 +0400 | [diff] [blame] | 12 | rules: |
| 13 | - apiGroups: [""] |
| 14 | resources: ["pods", "pods/exec", "pods/log", "persistentvolumeclaims", "events"] |
| 15 | verbs: ["get", "list", "watch"] |
| 16 | - apiGroups: [""] |
| 17 | resources: ["pods", "pods/exec", "persistentvolumeclaims"] |
| 18 | verbs: ["create", "delete", "deletecollection", "patch", "update"] |
| 19 | |
| 20 | --- |
| 21 | |
| 22 | # We bind the role to the Jenkins service account. The role binding is created in the namespace |
| 23 | # where the agents are supposed to run. |
| 24 | apiVersion: rbac.authorization.k8s.io/v1 |
| 25 | kind: RoleBinding |
| 26 | metadata: |
| 27 | name: {{ $serviceName }}-schedule-agents |
| 28 | namespace: {{ template "jenkins.agent.namespace" . }} |
| 29 | labels: |
| gio | 20157e8 | 2026-07-22 13:10:48 +0400 | [diff] [blame^] | 30 | {{- include "jenkins.labels" . | nindent 4 }} |
| Giorgi Lekveishvili | 3598266 | 2024-04-05 13:05:40 +0400 | [diff] [blame] | 31 | roleRef: |
| 32 | apiGroup: rbac.authorization.k8s.io |
| 33 | kind: Role |
| 34 | name: {{ $serviceName }}-schedule-agents |
| 35 | subjects: |
| 36 | - kind: ServiceAccount |
| 37 | name: {{ template "jenkins.serviceAccountName" .}} |
| 38 | namespace: {{ template "jenkins.namespace" . }} |
| 39 | |
| 40 | --- |
| 41 | |
| 42 | {{- if .Values.rbac.readSecrets }} |
| 43 | # This is needed if you want to use https://jenkinsci.github.io/kubernetes-credentials-provider-plugin/ |
| 44 | # as it needs permissions to get/watch/list Secrets |
| 45 | apiVersion: rbac.authorization.k8s.io/v1 |
| 46 | kind: Role |
| 47 | metadata: |
| 48 | name: {{ template "jenkins.fullname" . }}-read-secrets |
| 49 | namespace: {{ template "jenkins.namespace" . }} |
| 50 | labels: |
| gio | 20157e8 | 2026-07-22 13:10:48 +0400 | [diff] [blame^] | 51 | {{- include "jenkins.labels" . | nindent 4 }} |
| Giorgi Lekveishvili | 3598266 | 2024-04-05 13:05:40 +0400 | [diff] [blame] | 52 | rules: |
| 53 | - apiGroups: [""] |
| 54 | resources: ["secrets"] |
| 55 | verbs: ["get", "watch", "list"] |
| 56 | |
| 57 | --- |
| 58 | |
| 59 | apiVersion: rbac.authorization.k8s.io/v1 |
| 60 | kind: RoleBinding |
| 61 | metadata: |
| 62 | name: {{ $serviceName }}-read-secrets |
| 63 | namespace: {{ template "jenkins.namespace" . }} |
| 64 | labels: |
| gio | 20157e8 | 2026-07-22 13:10:48 +0400 | [diff] [blame^] | 65 | {{- include "jenkins.labels" . | nindent 4 }} |
| Giorgi Lekveishvili | 3598266 | 2024-04-05 13:05:40 +0400 | [diff] [blame] | 66 | roleRef: |
| 67 | apiGroup: rbac.authorization.k8s.io |
| 68 | kind: Role |
| 69 | name: {{ template "jenkins.fullname" . }}-read-secrets |
| 70 | subjects: |
| 71 | - kind: ServiceAccount |
| 72 | name: {{ template "jenkins.serviceAccountName" . }} |
| 73 | namespace: {{ template "jenkins.namespace" . }} |
| 74 | |
| 75 | --- |
| 76 | {{- end}} |
| 77 | |
| gio | 20157e8 | 2026-07-22 13:10:48 +0400 | [diff] [blame^] | 78 | {{- if .Values.rbac.useOpenShiftNonRootSCC }} |
| 79 | # This is needed if you are running on OpenShift and using the default |
| 80 | # containerSecurityContext in the chart. It grants the Jenkins service account |
| 81 | # permission to use the "nonroot" and "nonroot-v2" SecurityContextConstraints. |
| 82 | apiVersion: rbac.authorization.k8s.io/v1 |
| 83 | kind: Role |
| 84 | metadata: |
| 85 | name: {{ $serviceName }}-use-nonroot-scc |
| 86 | namespace: {{ template "jenkins.namespace" . }} |
| 87 | labels: |
| 88 | {{- include "jenkins.labels" . | nindent 4 }} |
| 89 | rules: |
| 90 | - apiGroups: ["security.openshift.io"] |
| 91 | resources: ["securitycontextconstraints"] |
| 92 | resourceNames: ["nonroot", "nonroot-v2"] |
| 93 | verbs: ["use"] |
| 94 | --- |
| 95 | |
| 96 | apiVersion: rbac.authorization.k8s.io/v1 |
| 97 | kind: RoleBinding |
| 98 | metadata: |
| 99 | name: {{ $serviceName }}-use-nonroot-scc |
| 100 | namespace: {{ template "jenkins.namespace" . }} |
| 101 | labels: |
| 102 | {{- include "jenkins.labels" . | nindent 4 }} |
| 103 | roleRef: |
| 104 | apiGroup: rbac.authorization.k8s.io |
| 105 | kind: Role |
| 106 | name: {{ template "jenkins.fullname" . }}-use-nonroot-scc |
| 107 | subjects: |
| 108 | - kind: ServiceAccount |
| 109 | name: {{ template "jenkins.serviceAccountName" . }} |
| 110 | namespace: {{ template "jenkins.namespace" . }} |
| 111 | |
| 112 | --- |
| 113 | {{- end}} |
| 114 | |
| Giorgi Lekveishvili | 3598266 | 2024-04-05 13:05:40 +0400 | [diff] [blame] | 115 | {{- if .Values.controller.sidecars.configAutoReload.enabled }} |
| 116 | # The sidecar container which is responsible for reloading configuration changes |
| 117 | # needs permissions to watch ConfigMaps |
| 118 | apiVersion: rbac.authorization.k8s.io/v1 |
| 119 | kind: Role |
| 120 | metadata: |
| 121 | name: {{ template "jenkins.fullname" . }}-casc-reload |
| 122 | namespace: {{ template "jenkins.namespace" . }} |
| 123 | labels: |
| gio | 20157e8 | 2026-07-22 13:10:48 +0400 | [diff] [blame^] | 124 | {{- include "jenkins.labels" . | nindent 4 }} |
| Giorgi Lekveishvili | 3598266 | 2024-04-05 13:05:40 +0400 | [diff] [blame] | 125 | rules: |
| 126 | - apiGroups: [""] |
| 127 | resources: ["configmaps"] |
| 128 | verbs: ["get", "watch", "list"] |
| 129 | |
| 130 | --- |
| 131 | |
| 132 | apiVersion: rbac.authorization.k8s.io/v1 |
| 133 | kind: RoleBinding |
| 134 | metadata: |
| 135 | name: {{ $serviceName }}-watch-configmaps |
| 136 | namespace: {{ template "jenkins.namespace" . }} |
| 137 | labels: |
| gio | 20157e8 | 2026-07-22 13:10:48 +0400 | [diff] [blame^] | 138 | {{- include "jenkins.labels" . | nindent 4 }} |
| Giorgi Lekveishvili | 3598266 | 2024-04-05 13:05:40 +0400 | [diff] [blame] | 139 | roleRef: |
| 140 | apiGroup: rbac.authorization.k8s.io |
| 141 | kind: Role |
| 142 | name: {{ template "jenkins.fullname" . }}-casc-reload |
| 143 | subjects: |
| 144 | - kind: ServiceAccount |
| 145 | name: {{ template "jenkins.serviceAccountName" . }} |
| 146 | namespace: {{ template "jenkins.namespace" . }} |
| 147 | |
| 148 | {{- end}} |
| 149 | |
| 150 | {{ end }} |