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
This commit is contained in:
Stavros Kois
2022-11-30 21:30:01 +02:00
committed by GitHub
parent 0ac0a66547
commit 664840a9e3
4 changed files with 32 additions and 11 deletions
+13
View File
@@ -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_
+9
View File
@@ -20,6 +20,7 @@ questions:
label: "username" label: "username"
schema: schema:
type: string type: string
valid_chars: '^(?!^admin$).*$'
required: true required: true
- variable: password - variable: password
label: "password" label: "password"
@@ -63,6 +64,14 @@ questions:
type: string type: string
default: "127.0.0.1" default: "127.0.0.1"
required: true 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 - variable: customConfig
group: "App Configuration" group: "App Configuration"
label: "Custom Configuration parameters" label: "Custom Configuration parameters"
+9 -11
View File
@@ -2,10 +2,12 @@
{{- define "gitea.secrets" -}} {{- 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) -}}
{{- if and ( .Values.ingress.main.enabled ) ( gt (len .Values.ingress.main.hosts) 0 ) -}} {{- $DOMAIN = (index .Values.ingress.main.hosts 0).host -}}
{{- $DOMAIN = (index .Values.ingress.main.hosts 0).host -}} {{- $URL = (printf "https://%s/" (index .Values.ingress.main.hosts 0).host) -}}
{{- end -}} {{- end -}}
apiVersion: v1 apiVersion: v1
@@ -86,11 +88,7 @@ stringData:
ENABLE_PPROF = false ENABLE_PPROF = false
HTTP_PORT = {{ .Values.service.main.ports.main.targetPort }} HTTP_PORT = {{ .Values.service.main.ports.main.targetPort }}
PROTOCOL = http PROTOCOL = http
{{- if and ( .Values.ingress.main.enabled ) ( gt (len .Values.ingress.main.hosts) 0 ) }} ROOT_URL = {{ $URL }}
ROOT_URL = {{ printf "https://%s" $DOMAIN }}
{{- else }}
ROOT_URL = {{ printf "http://%s" $DOMAIN }}
{{- end }}
SSH_DOMAIN = {{ $DOMAIN }} SSH_DOMAIN = {{ $DOMAIN }}
SSH_LISTEN_PORT = {{ .Values.service.ssh.ports.ssh.targetPort }} SSH_LISTEN_PORT = {{ .Values.service.ssh.ports.ssh.targetPort }}
SSH_PORT = {{ .Values.service.ssh.ports.ssh.port }} 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) }} {{- if or .Values.admin.existingSecret (and .Values.admin.username .Values.admin.password) }}
function configure_admin_user() { 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 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 gitea admin user create --admin --username "${GITEA_ADMIN_USERNAME}" --password "${GITEA_ADMIN_PASSWORD}" --email {{ .Values.admin.email | quote }} --must-change-password=false
echo '...created.' echo '...created.'
else 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}" gitea admin user change-password --username "${GITEA_ADMIN_USERNAME}" --password "${GITEA_ADMIN_PASSWORD}"
echo '...password sync done.' echo '...password sync done.'
fi fi
+1
View File
@@ -121,6 +121,7 @@ config:
APP_NAME: "Gitea: Git with a cup of tea" APP_NAME: "Gitea: Git with a cup of tea"
RUN_MODE: dev RUN_MODE: dev
ALLOWED_HOST_LIST: "127.0.0.1" ALLOWED_HOST_LIST: "127.0.0.1"
nodeIP: 127.0.0.1
customConfig: customConfig:
[] []