Skip to content

Commit

Permalink
[bitnami/jenkins] Move Jenkins to non-root (#2014)
Browse files Browse the repository at this point in the history
* [bitnami/jenkins] Move Jenkins to non-root

Signed-off-by: juan131 <juan@bitnami.com>
Signed-off-by: Bitnami Containers <containers@bitnami.com>
Co-authored-by: Bitnami Containers <containers@bitnami.com>
  • Loading branch information
Juan Ariza Toledano and bitnami-bot authored Mar 6, 2020
1 parent a9c2999 commit cf87f81
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 104 deletions.
2 changes: 1 addition & 1 deletion bitnami/jenkins/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: jenkins
version: 4.1.9
version: 5.0.0
appVersion: 2.204.4
description: The leading open source automation server
keywords:
Expand Down
209 changes: 136 additions & 73 deletions bitnami/jenkins/README.md

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions bitnami/jenkins/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ Also, we can't use a single if because lazy evaluation is not an option
{{- end -}}
{{- end -}}

{{/*
Return the proper image name (for the init container volume-permissions image)
*/}}
{{- define "jenkins.volumePermissions.image" -}}
{{- $registryName := .Values.volumePermissions.image.registry -}}
{{- $repositoryName := .Values.volumePermissions.image.repository -}}
{{- $tag := .Values.volumePermissions.image.tag | toString -}}
{{/*
Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
Also, we can't use a single if because lazy evaluation is not an option
*/}}
{{- if .Values.global }}
{{- if .Values.global.imageRegistry }}
{{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
{{- else -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}
{{- else -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end -}}
{{- end -}}

{{/*
Return the proper image name (for the metrics image)
*/}}
Expand Down Expand Up @@ -109,20 +132,26 @@ imagePullSecrets:
{{- range .Values.global.imagePullSecrets }}
- name: {{ . }}
{{- end }}
{{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets }}
{{- else if or .Values.image.pullSecrets .Values.volumePermissions.image.pullSecrets .Values.metrics.image.pullSecrets }}
imagePullSecrets:
{{- range .Values.image.pullSecrets }}
- name: {{ . }}
{{- end }}
{{- range .Values.volumePermissions.image.pullSecrets }}
- name: {{ . }}
{{- end }}
{{- range .Values.metrics.image.pullSecrets }}
- name: {{ . }}
{{- end }}
{{- end -}}
{{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets }}
{{- else if or .Values.image.pullSecrets .Values.volumePermissions.image.pullSecrets .Values.metrics.image.pullSecrets }}
imagePullSecrets:
{{- range .Values.image.pullSecrets }}
- name: {{ . }}
{{- end }}
{{- range .Values.volumePermissions.image.pullSecrets }}
- name: {{ . }}
{{- end }}
{{- range .Values.metrics.image.pullSecrets }}
- name: {{ . }}
{{- end }}
Expand Down
27 changes: 27 additions & 0 deletions bitnami/jenkins/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,37 @@ spec:
{{- if .Values.tolerations }}
tolerations: {{- include "jenkins.tplValue" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
{{- end }}
{{- if .Values.podSecurityContext }}
securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- end }}
{{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
initContainers:
- name: volume-permissions
image: {{ include "jenkins.volumePermissions.image" . }}
imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }}
command:
- /bin/bash
args:
- -ec
- |
mkdir -p /bitnami/jenkins
chown -R "{{ .Values.containerSecurityContext.runAsUser }}:{{ .Values.podSecurityContext.fsGroup }}" "/bitnami/jenkins"
securityContext:
runAsUser: 0
{{- if .Values.volumePermissions.resources }}
resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }}
{{- end }}
volumeMounts:
- name: jenkins-data
mountPath: /bitnami/jenkins
{{- end }}
containers:
- name: jenkins
image: {{ template "jenkins.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
{{- if .Values.containerSecurityContext }}
securityContext: {{- toYaml .Values.containerSecurityContext | nindent 12 }}
{{- end }}
env:
- name: JENKINS_USERNAME
value: {{ .Values.jenkinsUser | quote }}
Expand Down
20 changes: 14 additions & 6 deletions bitnami/jenkins/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ metadata:
{{- if .Values.ingress.certManager }}
kubernetes.io/tls-acme: "true"
{{- end }}
{{- range $key, $value := .Values.ingress.annotations }}
{{ $key }}: {{ $value | quote }}
{{- if .Values.ingress.annotations }}
{{- include "jenkins.tplValue" (dict "value" .Values.ingress.annotations "context" $) | nindent 4 }}
{{- end }}
spec:
rules:
Expand All @@ -19,10 +19,10 @@ spec:
paths:
- path: /
backend:
serviceName: {{ template "jenkins.fullname" $ }}
serviceName: {{ template "jenkins.fullname" . }}
servicePort: http
{{- end }}
{{- range .Values.ingress.hosts }}
{{- range .Values.ingress.extraHosts }}
- host: {{ .name }}
http:
paths:
Expand All @@ -31,7 +31,15 @@ spec:
serviceName: {{ template "jenkins.fullname" $ }}
servicePort: http
{{- end }}
{{- if .Values.ingress.tls }}
tls: {{- toYaml .Values.ingress.tls | nindent 4 }}
{{- if or .Values.ingress.tls .Values.ingress.extraTls }}
tls:
{{- if .Values.ingress.tls }}
- hosts:
- {{ .Values.ingress.hostname }}
secretName: {{ printf "%s-tls" .Values.ingress.hostname }}
{{- end }}
{{- if .Values.ingress.extraTls }}
{{- toYaml .Values.ingress.extraTls | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
23 changes: 23 additions & 0 deletions bitnami/jenkins/templates/metrics-svc .yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "jenkins.fullname" . }}-metrics
labels: {{- include "jenkins.labels" . | nindent 4 }}
{{- if .Values.metrics.service.annotations }}
annotations: {{ include "jenkins.tplValue" ( dict "value" .Values.metrics.service.annotations "context" $) | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.metrics.service.type }}
{{- if and (eq .Values.metrics.service.type "LoadBalancer") (not (empty .Values.metrics.service.loadBalancerIP)) }}
loadBalancerIP: {{ .Values.metrics.service.loadBalancerIP }}
{{- end }}
ports:
- name: metrics
port: {{ .Values.metrics.service.port }}
targetPort: metrics
{{- if (and (or (eq .Values.metrics.service.type "NodePort") (eq .Values.metrics.service.type "LoadBalancer")) (not (empty .Values.metrics.service.nodePort))) }}
nodePort: {{ .Values.metrics.service.nodePort }}
{{- else if eq .Values.metrics.service.type "ClusterIP" }}
nodePort: null
{{- end }}
selector: {{- include "jenkins.matchLabels" . | nindent 4 }}
28 changes: 28 additions & 0 deletions bitnami/jenkins/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "jenkins.fullname" . }}
{{- if .Values.metrics.serviceMonitor.namespace }}
namespace: {{ .Values.metrics.serviceMonitor.namespace }}
{{- end }}
labels: {{- include "jenkins.labels" . | nindent 4 }}
{{- range $key, $value := .Values.metrics.serviceMonitor.selector }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
selector:
matchLabels: {{ include "jenkins.matchLabels" . | nindent 6 }}
endpoints:
- port: http
path: "/metrics"
{{- if .Values.metrics.serviceMonitor.interval }}
interval: {{ .Values.metrics.serviceMonitor.interval }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }}
{{- end }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
{{- end }}
135 changes: 113 additions & 22 deletions bitnami/jenkins/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
image:
registry: docker.io
repository: bitnami/jenkins
tag: 2.204.4-debian-10-r0
tag: 2.204.4-debian-10-r3
## Specify a imagePullPolicy
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
Expand Down Expand Up @@ -111,6 +111,18 @@ nodeSelector: {}
##
tolerations: {}

## Jenkins pods' Security Context
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod
##
podSecurityContext:
fsGroup: 1001

## Jenkins containers' Security Context (only main container)
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container
##
containerSecurityContext:
runAsUser: 1001

## Enable persistence using Persistent Volume Claims
## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/
##
Expand Down Expand Up @@ -188,26 +200,23 @@ ingress:
## For a full list of possible ingress annotations, please see
## ref: https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/nginx-configuration/annotations.md
##
## If tls is set to true, annotation ingress.kubernetes.io/secure-backends: "true" will automatically be set
## If certManager is set to true, annotation kubernetes.io/tls-acme: "true" will automatically be set
##
annotations: {}
# kubernetes.io/ingress.class: nginx

## The list of additional hostnames to be covered with this ingress record.
## Most likely the hostname above will be enough, but in the event more hosts are needed, this is an array
## hosts:
## extraHosts:
## - name: jenkins.local
## path: /

## The tls configuration for the ingress
## ref: https://kubernetes.io/docs/concepts/services-networking/ingress/#tls
##
tls:
- hosts:
- example.local
secretName: example.local-tls
## The tls configuration for additional hostnames to be covered with this ingress record.
## see: https://kubernetes.io/docs/concepts/services-networking/ingress/#tls
## extraTls:
## - hosts:
## - jenkins.local
## secretName: jenkins.local-tls

secrets:
## If you're providing your own certificates, please use this to add the certificates as secrets
## key and certificate should start with -----BEGIN CERTIFICATE----- or
## -----BEGIN RSA PRIVATE KEY-----
Expand All @@ -217,9 +226,51 @@ ingress:
##
## It is also possible to create and manage the certificates outside of this helm chart
## Please see README.md for more information
# - name: apache.local-tls
# key:
# certificate:
##
secrets: []
## - name: jenkins.local-tls
## key:
## certificate:

## Init Container paramaters
## Change the owner and group of the persistent volume(s) mountpoint(s) to 'runAsUser:fsGroup' on each component
## values from the podSecurityContext section of the component
##
volumePermissions:
enabled: false
## Bitnami Minideb image
## ref: https://hub.docker.com/r/bitnami/minideb/tags/
##
image:
registry: docker.io
repository: bitnami/minideb
tag: buster
## Specify a imagePullPolicy
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
##
pullPolicy: Always
## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace)
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
## Example:
## pullSecrets:
## - myRegistryKeySecretName
##
pullSecrets: []
## Init Container resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
limits: {}
# cpu: 100m
# memory: 128Mi
requests: {}
# cpu: 100m
# memory: 128Mi

## Prometheus Exporter / Metrics
##
Expand All @@ -231,7 +282,7 @@ metrics:
image:
registry: docker.io
repository: bitnami/jenkins-exporter
tag: 0.20171225.0-debian-10-r34
tag: 0.20171225.0-debian-10-r37
pullPolicy: IfNotPresent
## Optionally specify an array of imagePullSecrets.
## Secrets must be manually created in the namespace.
Expand All @@ -242,12 +293,7 @@ metrics:
## Metrics exporter pod Annotation and Labels
## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
##
podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9118"
## Metrics exporter resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
podAnnotations: {}
## Jenkins Prometheus exporter resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
Expand All @@ -262,3 +308,48 @@ metrics:
requests: {}
# cpu: 100m
# memory: 128Mi
## Metrics exporter service configuration
##
service:
## Service type
##
type: ClusterIP
## Metrics exporter port
##
port: 9122
## Specify the nodePort value for the LoadBalancer and NodePort service types.
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
##
nodePort: ""
## Set the LoadBalancer service type to internal only.
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer
##
# loadBalancerIP:
## Annotations for the Prometheus metrics service
##
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "{{ .Values.metrics.service.port }}"
## Prometheus Operator ServiceMonitor configuration
##
serviceMonitor:
enabled: false
## Namespace in which Prometheus is running
##
# namespace: monitoring

## Interval at which metrics should be scraped.
## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#endpoint
##
# interval: 10s

## Timeout after which the scrape is ended
## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#endpoint
##
# scrapeTimeout: 10s

## ServiceMonitor selector labels
## ref: https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#prometheus-configuration
##
# selector:
# prometheus: my-prometheus

0 comments on commit cf87f81

Please sign in to comment.