rbac.yaml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. {{ if .Values.rbac.create }}
  2. {{- $serviceName := include "jenkins.fullname" . -}}
  3. # This role is used to allow Jenkins scheduling of agents via Kubernetes plugin.
  4. apiVersion: rbac.authorization.k8s.io/v1
  5. kind: Role
  6. metadata:
  7. name: {{ $serviceName }}-schedule-agents
  8. namespace: {{ template "jenkins.agent.namespace" . }}
  9. labels:
  10. "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
  11. {{- if .Values.renderHelmLabels }}
  12. "helm.sh/chart": "{{ template "jenkins.label" .}}"
  13. {{- end }}
  14. "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
  15. "app.kubernetes.io/instance": "{{ .Release.Name }}"
  16. "app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
  17. rules:
  18. - apiGroups: [""]
  19. resources: ["pods", "pods/exec", "pods/log", "persistentvolumeclaims", "events"]
  20. verbs: ["get", "list", "watch"]
  21. - apiGroups: [""]
  22. resources: ["pods", "pods/exec", "persistentvolumeclaims"]
  23. verbs: ["create", "delete", "deletecollection", "patch", "update"]
  24. ---
  25. # We bind the role to the Jenkins service account. The role binding is created in the namespace
  26. # where the agents are supposed to run.
  27. apiVersion: rbac.authorization.k8s.io/v1
  28. kind: RoleBinding
  29. metadata:
  30. name: {{ $serviceName }}-schedule-agents
  31. namespace: {{ template "jenkins.agent.namespace" . }}
  32. labels:
  33. "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
  34. {{- if .Values.renderHelmLabels }}
  35. "helm.sh/chart": "{{ template "jenkins.label" .}}"
  36. {{- end }}
  37. "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
  38. "app.kubernetes.io/instance": "{{ .Release.Name }}"
  39. "app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
  40. roleRef:
  41. apiGroup: rbac.authorization.k8s.io
  42. kind: Role
  43. name: {{ $serviceName }}-schedule-agents
  44. subjects:
  45. - kind: ServiceAccount
  46. name: {{ template "jenkins.serviceAccountName" .}}
  47. namespace: {{ template "jenkins.namespace" . }}
  48. ---
  49. {{- if .Values.rbac.readSecrets }}
  50. # This is needed if you want to use https://jenkinsci.github.io/kubernetes-credentials-provider-plugin/
  51. # as it needs permissions to get/watch/list Secrets
  52. apiVersion: rbac.authorization.k8s.io/v1
  53. kind: Role
  54. metadata:
  55. name: {{ template "jenkins.fullname" . }}-read-secrets
  56. namespace: {{ template "jenkins.namespace" . }}
  57. labels:
  58. "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
  59. {{- if .Values.renderHelmLabels }}
  60. "helm.sh/chart": "{{ template "jenkins.label" .}}"
  61. {{- end }}
  62. "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
  63. "app.kubernetes.io/instance": "{{ .Release.Name }}"
  64. "app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
  65. rules:
  66. - apiGroups: [""]
  67. resources: ["secrets"]
  68. verbs: ["get", "watch", "list"]
  69. ---
  70. apiVersion: rbac.authorization.k8s.io/v1
  71. kind: RoleBinding
  72. metadata:
  73. name: {{ $serviceName }}-read-secrets
  74. namespace: {{ template "jenkins.namespace" . }}
  75. labels:
  76. "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
  77. {{- if .Values.renderHelmLabels }}
  78. "helm.sh/chart": "{{ template "jenkins.label" .}}"
  79. {{- end }}
  80. "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
  81. "app.kubernetes.io/instance": "{{ .Release.Name }}"
  82. "app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
  83. roleRef:
  84. apiGroup: rbac.authorization.k8s.io
  85. kind: Role
  86. name: {{ template "jenkins.fullname" . }}-read-secrets
  87. subjects:
  88. - kind: ServiceAccount
  89. name: {{ template "jenkins.serviceAccountName" . }}
  90. namespace: {{ template "jenkins.namespace" . }}
  91. ---
  92. {{- end}}
  93. {{- if .Values.controller.sidecars.configAutoReload.enabled }}
  94. # The sidecar container which is responsible for reloading configuration changes
  95. # needs permissions to watch ConfigMaps
  96. apiVersion: rbac.authorization.k8s.io/v1
  97. kind: Role
  98. metadata:
  99. name: {{ template "jenkins.fullname" . }}-casc-reload
  100. namespace: {{ template "jenkins.namespace" . }}
  101. labels:
  102. "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
  103. {{- if .Values.renderHelmLabels }}
  104. "helm.sh/chart": "{{ template "jenkins.label" .}}"
  105. {{- end }}
  106. "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
  107. "app.kubernetes.io/instance": "{{ .Release.Name }}"
  108. "app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
  109. rules:
  110. - apiGroups: [""]
  111. resources: ["configmaps"]
  112. verbs: ["get", "watch", "list"]
  113. ---
  114. apiVersion: rbac.authorization.k8s.io/v1
  115. kind: RoleBinding
  116. metadata:
  117. name: {{ $serviceName }}-watch-configmaps
  118. namespace: {{ template "jenkins.namespace" . }}
  119. labels:
  120. "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
  121. {{- if .Values.renderHelmLabels }}
  122. "helm.sh/chart": "{{ template "jenkins.label" .}}"
  123. {{- end }}
  124. "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
  125. "app.kubernetes.io/instance": "{{ .Release.Name }}"
  126. "app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
  127. roleRef:
  128. apiGroup: rbac.authorization.k8s.io
  129. kind: Role
  130. name: {{ template "jenkins.fullname" . }}-casc-reload
  131. subjects:
  132. - kind: ServiceAccount
  133. name: {{ template "jenkins.serviceAccountName" . }}
  134. namespace: {{ template "jenkins.namespace" . }}
  135. {{- end}}
  136. {{ end }}