Skip to content

environment-to-ini does not work with INSTALL_LOCK #25924

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

Closed
codello opened this issue Jul 17, 2023 · 4 comments · Fixed by #25926
Closed

environment-to-ini does not work with INSTALL_LOCK #25924

codello opened this issue Jul 17, 2023 · 4 comments · Fixed by #25926
Assignees
Labels

Comments

@codello
Copy link

codello commented Jul 17, 2023

Description

Running environment-to-ini on a partial config file will not apply environment variables if the source file has INSTALL_LOCK = true. This is a change in behavior to previous versions of the Gitea docker image.

Reproducable Example

Given this example.ini

[security]
INSTALL_LOCK = true

run

export GITEA__database__DB_TYPE=postgres
environment-to-ini --config=example.init --out=out.ini
cat out.ini

Actual result:

[security]
INSTALL_LOCK = true

Expected result:

[security]
INSTALL_LOCK = true

[database]
DB_TYPE = postgres

Workaround

For Gitea v1.20.0 a possible workaround is to set GITEA__security__INSTALL_LOCK=true in the environment and have INSTALL_LOCK = false (or absent) in the source config. This results in the desired configuration.

Additional Details

As mentioned above this behavior is new in Gitea v1.20.0. Previous versions produced the expected result. I suspect that #25330 caused the change of behavior but haven't checked thoroughly.

The issue seems to be caused by setting.InitWorkPathAndCfgProvider(…) which is called by environment-to-ini to load the existing config file. That function then clears the environment, causing environment-to-ini not to perform any changes.

if HasInstallLock(CfgProvider) {
ClearEnvConfigKeys() // if the instance has been installed, do not pass the environment variables to sub-processes
}


This bug report is specific to environment-to-ini so the rest of this form only partially applies.

Gitea Version

v1.20.0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

no logs produced / does not apply

Screenshots

No response

Git Version

2.40.1

Operating System

Alpine Linux v3.18 (official docker image) on Fedora 38 (host)

How are you running Gitea?

This bug is specific to environment-from-ini and occurs before Gitea actually starts.

I run Gitea via the official docker image gitea/gitea:1.20.0-rootless. Starting this image with an interactive shell allows you to reproduce the issue.

Alternatively run

docker run --rm -i gitea/gitea:1.20.0-rootless bash <<-EOF
mkdir /tmp/test
cd /tmp/test
export GITEA__database__DB_TYPE=postgres
echo "[security]
INSTALL_LOCK = true
" > example.ini
environment-to-ini --config=example.ini --out=out.ini
cat out.ini
EOF

Database

PostgreSQL

@wxiaoguang wxiaoguang self-assigned this Jul 17, 2023
@wxiaoguang
Copy link
Contributor

Thank you for the detailed report. Will fix it soon.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jul 17, 2023

(Regression of Make "install page" respect environment config #25648)

-> Make environment-to-ini work with INSTALL_LOCK=true #25926

silverwind pushed a commit that referenced this issue Jul 17, 2023
Regression of #25648, fix #25924

Test:

```bash
rm -f /tmp/example.ini /tmp/out.ini && \
echo "[security]" > /tmp/example.ini && \
echo "INSTALL_LOCK = true" >> /tmp/example.ini && \
GITEA__foo__bar=1 go run contrib/environment-to-ini/environment-to-ini.go --config=/tmp/example.ini --out=/tmp/out.ini && \
echo "==== example:" && \
cat /tmp/example.ini && \
echo "==== out:" && \
cat /tmp/out.ini
```

Output:

```
2023/07/17 17:40:51 ...nvironment-to-ini.go:99:runEnvironmentToIni() [I] Settings saved to: "/tmp/out.ini"
==== example:
[security]
INSTALL_LOCK = true
==== out:
[security]
INSTALL_LOCK = true

[foo]
bar = 1

```
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Jul 17, 2023
Regression of go-gitea#25648, fix go-gitea#25924

Test:

```bash
rm -f /tmp/example.ini /tmp/out.ini && \
echo "[security]" > /tmp/example.ini && \
echo "INSTALL_LOCK = true" >> /tmp/example.ini && \
GITEA__foo__bar=1 go run contrib/environment-to-ini/environment-to-ini.go --config=/tmp/example.ini --out=/tmp/out.ini && \
echo "==== example:" && \
cat /tmp/example.ini && \
echo "==== out:" && \
cat /tmp/out.ini
```

Output:

```
2023/07/17 17:40:51 ...nvironment-to-ini.go:99:runEnvironmentToIni() [I] Settings saved to: "/tmp/out.ini"
==== example:
[security]
INSTALL_LOCK = true
==== out:
[security]
INSTALL_LOCK = true

[foo]
bar = 1

```
@wxiaoguang
Copy link
Contributor

Could you try the nightly build (tag: 1.20-nightly and 1.20-nightly-rootless)? I think it should have been fixed.

@codello
Copy link
Author

codello commented Jul 19, 2023

Thanks a lot. I can confirm that the issue is fixed in both 1.20-nightly and 1.20-nightly-rootless.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2023
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this issue Jan 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants