Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UserContent mechanism #676

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions charts/jenkins/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Use the following links to reference issues, PRs, and commits prior to v2.6.0.
The change log until v1.5.7 was auto-generated based on git commits.
Those entries include a reference to the git commit to be able to get more details.

## 4.1.15

Add option to add custom data via `controller.userContents` and `controller.binaryUserContents` that will be hosted by the Server.

## 4.1.14

If `installPlugins` is disabled, don't create unused plugins volume.
Expand Down
2 changes: 1 addition & 1 deletion charts/jenkins/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: jenkins
home: https://jenkins.io/
version: 4.1.14
version: 4.1.15
appVersion: 2.346.2
description: Jenkins - Build great things at any scale! The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
sources:
Expand Down
20 changes: 20 additions & 0 deletions charts/jenkins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,26 @@ controller:
renew: 60
```

### User Content

The [User Content](https://www.jenkins.io/doc/book/managing/user-content/) mechanism allows to use the Jenkins server to host custom files under the `/userContent` prefix.

```yaml
controller:
userContents:
- name: foobar.txt
data: |
My
File
Content

binaryUserContents:
- name: foobar.bin
data: SGVsbG8gV29ybGQ= # Hello World
```

Will provide the content via the `http(s)://jenkins.example.com/userContent/foobar.txt` and `http(s)://jenkins.example.com/userContent/foobar.bin` URL. Be aware that ConfigMaps & Secrets are __limited to 1 MB__ in Kubernetes - so the mechanism only provides a way to host limited content.

### RBAC

RBAC is enabled by default. If you want to disable it you will need to set `rbac.create` to `false`.
Expand Down
25 changes: 25 additions & 0 deletions charts/jenkins/templates/config-usercontent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if or .Values.controller.userContents .Values.controller.binaryUserContents -}}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "jenkins.fullname" . }}-user-contents
namespace: {{ template "jenkins.namespace" . }}
labels:
"app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
{{- if .Values.renderHelmLabels }}
"helm.sh/chart": "{{ template "jenkins.label" .}}"
{{- end }}
"app.kubernetes.io/managed-by": "{{ .Release.Service }}"
"app.kubernetes.io/instance": "{{ .Release.Name }}"
"app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
data:
{{- range .Values.controller.userContents }}
{{ .name }}: |-
{{ .data | indent 4 }}
{{- end }}
binaryData:
{{- range .Values.controller.binaryUserContents }}
{{ .name }}: {{ .data }}
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/jenkins/templates/jenkins-controller-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,20 @@ spec:
mountPath: /run/secrets/additional
readOnly: true
{{- end }}
{{- if or .Values.controller.userContents .Values.controller.binaryUserContents }}
{{- range $content := .Values.controller.userContents }}
- name: jenkins-user-contents
mountPath: {{ $.Values.controller.jenkinsHome }}/userContent/{{ $content.name }}
subPath: {{ $content.name }}
readOnly: true
{{- end }}
{{- range $content := .Values.controller.binaryUserContents }}
- name: jenkins-user-contents
mountPath: {{ $.Values.controller.jenkinsHome }}/userContent/{{ $content.name }}
subPath: {{ $content.name }}
readOnly: true
{{- end }}
{{- end }}
Comment on lines +291 to +304
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why you are mounting files individually instead of mounting all at once?

      - name: jenkins-user-contents
        mountPath: {{ $.Values.controller.jenkinsHome }}/userContent/
        readOnly: true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mount the Configmap, K8S will create symlinks foobar.txt -> ..data/foobar.txt where ..data -> ..2020_03_03_16_40_36.675612011

Jenkins seems to be not supporting symlinks at this point - neither by displaying nor serving it:
image
Might be related to Jenkins Security Advisory 2021-01-13?

So you can not access userContent/foobar.txt directly but would need to go via something like userContent/..2020_03_03_16_40_36.675612011/foobar.txt - and this is an always changing URL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the clarification.

- name: jenkins-cache
mountPath: /var/jenkins_cache
- mountPath: /tmp
Expand Down Expand Up @@ -425,6 +439,11 @@ spec:
- key: jenkins-jks-file
path: {{ .Values.controller.httpsKeyStore.fileName }}
{{- end }}
{{- if or .Values.controller.userContents .Values.controller.binaryUserContents }}
- name: jenkins-user-contents
configMap:
name: {{ template "jenkins.fullname" . }}-user-contents
{{- end }}

{{- if .Values.controller.imagePullSecretName }}
imagePullSecrets:
Expand Down
9 changes: 9 additions & 0 deletions charts/jenkins/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ controller:
# imagePullPolicy: Always
# command: [ "uname", "-a" ]

# Provide files that will be served by the Jenkins via the User Content mechanism. Content can be either UTF-8 encoded or be base64 encoded
userContents: []
# - name: filename
# data: file content

binaryUserContents: []
# - name: filename
# data: base64 encoded file content

sidecars:
configAutoReload:
# If enabled: true, Jenkins Configuration as Code will be reloaded on-the-fly without a reboot. If false or not-specified,
Expand Down