blob: 48ba8abb6172104be55a24cf729ea589f85a08d0 [file] [log] [blame]
Giorgi Lekveishvili35982662024-04-05 13:05:40 +04001{{ if .Values.rbac.create }}
2{{- $serviceName := include "jenkins.fullname" . -}}
3
4# This role is used to allow Jenkins scheduling of agents via Kubernetes plugin.
5apiVersion: rbac.authorization.k8s.io/v1
6kind: Role
7metadata:
8 name: {{ $serviceName }}-schedule-agents
9 namespace: {{ template "jenkins.agent.namespace" . }}
10 labels:
gio20157e82026-07-22 13:10:48 +040011 {{- include "jenkins.labels" . | nindent 4 }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040012rules:
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.
24apiVersion: rbac.authorization.k8s.io/v1
25kind: RoleBinding
26metadata:
27 name: {{ $serviceName }}-schedule-agents
28 namespace: {{ template "jenkins.agent.namespace" . }}
29 labels:
gio20157e82026-07-22 13:10:48 +040030 {{- include "jenkins.labels" . | nindent 4 }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040031roleRef:
32 apiGroup: rbac.authorization.k8s.io
33 kind: Role
34 name: {{ $serviceName }}-schedule-agents
35subjects:
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
45apiVersion: rbac.authorization.k8s.io/v1
46kind: Role
47metadata:
48 name: {{ template "jenkins.fullname" . }}-read-secrets
49 namespace: {{ template "jenkins.namespace" . }}
50 labels:
gio20157e82026-07-22 13:10:48 +040051 {{- include "jenkins.labels" . | nindent 4 }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040052rules:
53 - apiGroups: [""]
54 resources: ["secrets"]
55 verbs: ["get", "watch", "list"]
56
57---
58
59apiVersion: rbac.authorization.k8s.io/v1
60kind: RoleBinding
61metadata:
62 name: {{ $serviceName }}-read-secrets
63 namespace: {{ template "jenkins.namespace" . }}
64 labels:
gio20157e82026-07-22 13:10:48 +040065 {{- include "jenkins.labels" . | nindent 4 }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040066roleRef:
67 apiGroup: rbac.authorization.k8s.io
68 kind: Role
69 name: {{ template "jenkins.fullname" . }}-read-secrets
70subjects:
71 - kind: ServiceAccount
72 name: {{ template "jenkins.serviceAccountName" . }}
73 namespace: {{ template "jenkins.namespace" . }}
74
75---
76{{- end}}
77
gio20157e82026-07-22 13:10:48 +040078{{- 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.
82apiVersion: rbac.authorization.k8s.io/v1
83kind: Role
84metadata:
85 name: {{ $serviceName }}-use-nonroot-scc
86 namespace: {{ template "jenkins.namespace" . }}
87 labels:
88 {{- include "jenkins.labels" . | nindent 4 }}
89rules:
90 - apiGroups: ["security.openshift.io"]
91 resources: ["securitycontextconstraints"]
92 resourceNames: ["nonroot", "nonroot-v2"]
93 verbs: ["use"]
94---
95
96apiVersion: rbac.authorization.k8s.io/v1
97kind: RoleBinding
98metadata:
99 name: {{ $serviceName }}-use-nonroot-scc
100 namespace: {{ template "jenkins.namespace" . }}
101 labels:
102 {{- include "jenkins.labels" . | nindent 4 }}
103roleRef:
104 apiGroup: rbac.authorization.k8s.io
105 kind: Role
106 name: {{ template "jenkins.fullname" . }}-use-nonroot-scc
107subjects:
108 - kind: ServiceAccount
109 name: {{ template "jenkins.serviceAccountName" . }}
110 namespace: {{ template "jenkins.namespace" . }}
111
112---
113{{- end}}
114
Giorgi Lekveishvili35982662024-04-05 13:05:40 +0400115{{- if .Values.controller.sidecars.configAutoReload.enabled }}
116# The sidecar container which is responsible for reloading configuration changes
117# needs permissions to watch ConfigMaps
118apiVersion: rbac.authorization.k8s.io/v1
119kind: Role
120metadata:
121 name: {{ template "jenkins.fullname" . }}-casc-reload
122 namespace: {{ template "jenkins.namespace" . }}
123 labels:
gio20157e82026-07-22 13:10:48 +0400124 {{- include "jenkins.labels" . | nindent 4 }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +0400125rules:
126- apiGroups: [""]
127 resources: ["configmaps"]
128 verbs: ["get", "watch", "list"]
129
130---
131
132apiVersion: rbac.authorization.k8s.io/v1
133kind: RoleBinding
134metadata:
135 name: {{ $serviceName }}-watch-configmaps
136 namespace: {{ template "jenkins.namespace" . }}
137 labels:
gio20157e82026-07-22 13:10:48 +0400138 {{- include "jenkins.labels" . | nindent 4 }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +0400139roleRef:
140 apiGroup: rbac.authorization.k8s.io
141 kind: Role
142 name: {{ template "jenkins.fullname" . }}-casc-reload
143subjects:
144- kind: ServiceAccount
145 name: {{ template "jenkins.serviceAccountName" . }}
146 namespace: {{ template "jenkins.namespace" . }}
147
148{{- end}}
149
150{{ end }}