[Close #1077] fix!: protect secrets and enforce config precedence
Bash / bash-unittest (push) Successful in 19s
Bash / shellcheck (push) Successful in 26s
changelog / changelog (push) Successful in 12s
Helm / helm-lint (push) Successful in 16s
Helm / helm-unittest (push) Successful in 16s
Markdown linter / markdown-lint (push) Successful in 15s
Markdown linter / markdown-link-checker (push) Successful in 53s

Equivalent environment variable encodings could overwrite existing
secrets or make configuration precedence depend on environment order.

BREAKING CHANGE: Duplicate preset environment variables targeting the
same setting now cause initialization to fail. Remove duplicates.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
volker.raschekandCopilot committed 2026-12-04 22:37:36 +01:00
1 parent ccb53fca3f
commit a5579c167e
3 files changed
+163 -11

No files matched your search

@@ -120,6 +120,33 @@ function write_mounted_file() {
refute_line '+GITEA__SERVER__LFS_JWT_SECRET=mocked-lfs-jwt-secret'
}
@test "protects existing secrets from file and encoded environment variables" {
expect_gitea_config_edit_ini_call
touch "$GITEA_APP_INI"
export GITEA__SECURITY__SECRET_KEY__FILE="/tmp/secret"
export GITEA__SEC_0X55_RITY__INTERNAL_TOKEN="override"
export GITEA__OAUTH2__JWT_0X5F_SECRET__FILE="/tmp/jwt"
export GITEA__SERVER__LFS_JWT_SECRET="override"
export GITEA__SECURITY__OTHER__FILE="/tmp/other"
export GITEA___0x7365637572697479____0x5345435245545f4b4559_="encoded"
export GITEA__SECURITY__secret_key="other-case"
for GITEA_REBUILD_APP_INI in false true; do
export GITEA_REBUILD_APP_INI
run execute_test_script
assert_success
assert_line '-GITEA__SECURITY__SECRET_KEY__FILE=/tmp/secret'
assert_line '-GITEA__SEC_0X55_RITY__INTERNAL_TOKEN=override'
assert_line '-GITEA__OAUTH2__JWT_0X5F_SECRET__FILE=/tmp/jwt'
assert_line '-GITEA__SERVER__LFS_JWT_SECRET=override'
assert_line '-GITEA___0x7365637572697479____0x5345435245545f4b4559_=encoded'
refute_line '+GITEA___0X7365637572697479____0x5345435245545f4b4559_=encoded'
refute_line '-GITEA__SECURITY__OTHER__FILE=/tmp/other'
refute_line '-GITEA__SECURITY__secret_key=other-case'
done
}
@test "rebuilds an existing app.ini while preserving secret keys" {
expect_gitea_config_edit_ini_call
export GITEA_REBUILD_APP_INI=true
@@ -169,6 +196,32 @@ function write_mounted_file() {
refute_line '+GITEA__OAUTH2__JWT_SECRET=mocked-jwt-secret'
}
@test "preset encoded file variables override generated and mounted settings" {
expect_gitea_config_edit_ini_call
export GITEA___0x6f6175746832___JWT_0x5f_SECRET__FILE="/tmp/jwt"
write_mounted_file "inlines" "oauth2" "JWT_SECRET=inline"
write_mounted_file "additionals" "oauth2" "JWT_SECRET=additional"
run execute_test_script
assert_success
refute_line '+GITEA__OAUTH2__JWT_SECRET=mocked-jwt-secret'
refute_line '+GITEA__OAUTH2__JWT_SECRET=inline'
refute_line '+GITEA__OAUTH2__JWT_SECRET=additional'
assert_line '+GITEA___0X6F6175746832___JWT_0x5f_SECRET__FILE=/tmp/jwt'
}
@test "rejects conflicting preset variables for the same setting" {
expect_gitea_config_edit_ini_call
export GITEA__OAUTH2__JWT_SECRET="first"
export GITEA__oauth2__JWT_0X5F_SECRET__FILE="/tmp/jwt"
run "$PROJECT_ROOT/scripts/init-containers/config/config_environment.sh"
assert_failure
assert_output --partial 'conflicting preset environment variables'
}
@test "ensures that preset environment variables take precedence over mounted ones" {
expect_gitea_config_edit_ini_call
export GITEA__OAUTH2__JWT_SECRET="pre-defined-jwt-secret"