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

migrate database if app.ini found #5290

Merged
merged 5 commits into from Jan 5, 2019

Conversation

pciavald
Copy link
Contributor

@pciavald pciavald commented Nov 7, 2018

Hi,

For my installation of gitea, I needed unattended initial config. @techknowlogick told me on Discord that it could be done using then new migrate command, gitea migrate -c /data/gitea/conf/app.ini.

I've added in the Docker entrypoint:

  • check if /data/gitea/conf/app.ini exists
  • change mode and owner
  • migrate database

It works correctly on my machine, in my docker-compose the data volume is mapped with only the config file and the platform auto-inits. However I can see in the logs this error which does not affect behaviour:

migrate: /data/gitea/conf/app.ini: Permission denied

@codecov-io
Copy link

codecov-io commented Nov 7, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@cbc14df). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #5290   +/-   ##
=========================================
  Coverage          ?   37.83%           
=========================================
  Files             ?      322           
  Lines             ?    47489           
  Branches          ?        0           
=========================================
  Hits              ?    17968           
  Misses            ?    26935           
  Partials          ?     2586

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbc14df...81be951. Read the comment docs.

@bkcsoft bkcsoft added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 7, 2018
chmod 644 /data/gitea/conf/app.ini
chown -R 1000:1000 /data/git /data/gitea
su - git -c gitea migrate -c /data/gitea/conf/app.ini
fi
Copy link
Member

Choose a reason for hiding this comment

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

Please use ${USER}, ${USER_UID}, and ${USER_GID} variables instead of hardcoding them.

Copy link
Contributor Author

@pciavald pciavald Nov 7, 2018

Choose a reason for hiding this comment

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

${USER_UID}, ${USER_GID}, $UID and $GID are undefined, i'll use $USER:$USER is that ok ?

Copy link
Contributor Author

@pciavald pciavald Nov 7, 2018

Choose a reason for hiding this comment

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

I see these variables (USER_UID and USER_GID) should be defined by default to 1000 if not specified by the docker-compose environment key, and they're not defined in my docker-compose.

So I don't understand why they are undefined, i've echoed them in the entrypoint and only USER was defined. Using $USER:$USER in the chown may create problems if a developer defines the USER_UID and USER_GID in their env.

Copy link
Contributor

Choose a reason for hiding this comment

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

The original entry point script just checks for the variables and if they're there does something. That's why they're undefined.

You may have to adjust it to define the variables if they're not there or empty.

if [ -z "${USER_GID}" ]; then
  USER_GID="`id -g ${USER}`"
fi

And similarly for UID. Otherwise I'd be suspicious that the chown could choose the wrong UID and GID in cases were they were set explicitly - but I'd happily defer to more expert opinion on this.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes. You are right @pciavald, I missed that they were undefined. I think that @zeripath's approach of setting a default for the values is a good one.

docker/usr/bin/entrypoint Outdated Show resolved Hide resolved
@techknowlogick techknowlogick added this to the 1.8.0 milestone Jan 5, 2019
@bkcsoft bkcsoft added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 5, 2019
@bkcsoft bkcsoft added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 5, 2019
@techknowlogick techknowlogick merged commit 0236856 into go-gitea:master Jan 5, 2019
Copy link
Contributor

@apricote apricote left a comment

Choose a reason for hiding this comment

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

I think there is a small security issue caused by this PR

@@ -22,6 +30,13 @@ for FOLDER in /data/gitea/conf /data/gitea/log /data/git /data/ssh; do
mkdir -p ${FOLDER}
done

if [ -f /data/gitea/conf/app.ini ]; then
echo "Found app.ini config file, migrating database"
chmod 644 /data/gitea/conf/app.ini
Copy link
Contributor

Choose a reason for hiding this comment

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

This will allow anyone with access to the server to read the app.ini, exposing any credentials (database, metrics, smtp).

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... I guess you're right. I guess this should be 600. In some ways this is not so bad because this for docker - you shouldn't have other users on it in any case, that's not the docker way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason to change the file permissions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly not. If you've not set the INSTALL_LOCK setting in your app.ini and you've got the wrong mode then you won't be able to use /install. However I guess we shouldn't be being preventing people from shooting themselves in the foot like that. Pop a PR on if you're able otherwise I can when I'm next at a dev box. @techknowlogick do you agree that perhaps we shouldn't changing the mode here?

Copy link
Contributor

Choose a reason for hiding this comment

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

@pciavald What was your reasoning for changing the mode?

@zeripath
Copy link
Contributor

zeripath commented Jan 14, 2019

@techknowlogick I think unfortunately there may still be problems with this.

The correct place for automigration is likely within the gitea script within the s6 folder. That would require a little refactoring of that to make it work.

However a simple improvement is that we should change the migrate line to:

(cd /app/gitea; exec su-exec $USER /app/gitea/gitea migrate)

as per my comment:

#5688 (comment)

Then this will more closely match how docker starts Gitea so if people have used relative paths etc in their app.ini we're not affected by these.

I won't have a chance to write a pr for this for several days so if you can or get a friendly minion please do.

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants