From 664840a9e3b0971a0b09e2068c7d0d9c39520ac4 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Wed, 30 Nov 2022 21:30:01 +0200 Subject: [PATCH] fix(gitea): default to nodeIP for DOMAIN and ROOT_URL (#5003) * fix(gitea): default to nodeIP for DOMAIN and ROOT_URL * fix issue #4118 * add regex validation --- charts/stable/gitea/docs/validation.md | 13 +++++++++++++ charts/stable/gitea/questions.yaml | 9 +++++++++ charts/stable/gitea/templates/_secrets.tpl | 20 +++++++++----------- charts/stable/gitea/values.yaml | 1 + 4 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 charts/stable/gitea/docs/validation.md diff --git a/charts/stable/gitea/docs/validation.md b/charts/stable/gitea/docs/validation.md new file mode 100644 index 00000000000..2df454e88ed --- /dev/null +++ b/charts/stable/gitea/docs/validation.md @@ -0,0 +1,13 @@ +# Input Validation + +**`username`** +Accepted formats are: + +- Any character except the word `admin` + +Regex used to match this: `^(?!^admin$).*$` +You can try live [here](https://regex101.com/r/n91qZM/1) + +--- + +_If you find a field that you think it needs validation, please open an issue on github_ diff --git a/charts/stable/gitea/questions.yaml b/charts/stable/gitea/questions.yaml index 05ef98f02a9..fb08574095e 100644 --- a/charts/stable/gitea/questions.yaml +++ b/charts/stable/gitea/questions.yaml @@ -20,6 +20,7 @@ questions: label: "username" schema: type: string + valid_chars: '^(?!^admin$).*$' required: true - variable: password label: "password" @@ -63,6 +64,14 @@ questions: type: string default: "127.0.0.1" required: true + - variable: nodeIP + label: Node IP + description: Used to generate configuration, when installed without ingress + schema: + type: string + required: true + $ref: + - "definitions/nodeIP" - variable: customConfig group: "App Configuration" label: "Custom Configuration parameters" diff --git a/charts/stable/gitea/templates/_secrets.tpl b/charts/stable/gitea/templates/_secrets.tpl index 37df8994b70..335581abe78 100644 --- a/charts/stable/gitea/templates/_secrets.tpl +++ b/charts/stable/gitea/templates/_secrets.tpl @@ -2,10 +2,12 @@ {{- define "gitea.secrets" -}} --- +{{ $DOMAIN := .Values.config.nodeIP | quote -}} +{{ $URL := (printf "http://%s/" .Values.config.nodeIP) }} -{{ $DOMAIN := ( printf "%s-gitea.%s.svc.%s" .Release.Name .Release.Namespace "cluster.local" | quote ) -}} -{{- if and ( .Values.ingress.main.enabled ) ( gt (len .Values.ingress.main.hosts) 0 ) -}} -{{- $DOMAIN = (index .Values.ingress.main.hosts 0).host -}} +{{- if and (.Values.ingress.main.enabled) (gt (len .Values.ingress.main.hosts) 0) -}} + {{- $DOMAIN = (index .Values.ingress.main.hosts 0).host -}} + {{- $URL = (printf "https://%s/" (index .Values.ingress.main.hosts 0).host) -}} {{- end -}} apiVersion: v1 @@ -86,11 +88,7 @@ stringData: ENABLE_PPROF = false HTTP_PORT = {{ .Values.service.main.ports.main.targetPort }} PROTOCOL = http - {{- if and ( .Values.ingress.main.enabled ) ( gt (len .Values.ingress.main.hosts) 0 ) }} - ROOT_URL = {{ printf "https://%s" $DOMAIN }} - {{- else }} - ROOT_URL = {{ printf "http://%s" $DOMAIN }} - {{- end }} + ROOT_URL = {{ $URL }} SSH_DOMAIN = {{ $DOMAIN }} SSH_LISTEN_PORT = {{ .Values.service.ssh.ports.ssh.targetPort }} SSH_PORT = {{ .Values.service.ssh.ports.ssh.port }} @@ -189,13 +187,13 @@ stringData: {{- if or .Values.admin.existingSecret (and .Values.admin.username .Values.admin.password) }} function configure_admin_user() { - local ACCOUNT_ID=$(gitea admin user list --admin | grep -e "\s\+${GITEA_ADMIN_USERNAME}\s\+" | awk -F " " "{printf \$1}") + local ACCOUNT_ID=$(gitea admin user list --admin | grep -e "\s\+${GITEA_ADMIN_USERNAME}\|{{ .Values.admin.email }}\s\+" | awk -F " " "{printf \$1}") if [[ -z "${ACCOUNT_ID}" ]]; then - echo "No admin user '${GITEA_ADMIN_USERNAME}' found. Creating now..." + echo "No admin user '${GITEA_ADMIN_USERNAME}' found, neither email '{{ .Values.admin.email }}' is assigned to an admin. Creating now..." gitea admin user create --admin --username "${GITEA_ADMIN_USERNAME}" --password "${GITEA_ADMIN_PASSWORD}" --email {{ .Values.admin.email | quote }} --must-change-password=false echo '...created.' else - echo "Admin account '${GITEA_ADMIN_USERNAME}' already exist. Running update to sync password..." + echo "Admin account '${GITEA_ADMIN_USERNAME}' or email {{ .Values.admin.email }} already exist. Running update to sync password..." gitea admin user change-password --username "${GITEA_ADMIN_USERNAME}" --password "${GITEA_ADMIN_PASSWORD}" echo '...password sync done.' fi diff --git a/charts/stable/gitea/values.yaml b/charts/stable/gitea/values.yaml index e3356b099d7..57c7618d0d0 100644 --- a/charts/stable/gitea/values.yaml +++ b/charts/stable/gitea/values.yaml @@ -121,6 +121,7 @@ config: APP_NAME: "Gitea: Git with a cup of tea" RUN_MODE: dev ALLOWED_HOST_LIST: "127.0.0.1" + nodeIP: 127.0.0.1 customConfig: []