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

[WIP] Rootless docker #7129

Closed
wants to merge 3 commits into from
Closed

Conversation

sapk
Copy link
Member

@sapk sapk commented Jun 5, 2019

Following #4749

Currently work with the default user git pid (1000)

The main blocking adjustment to use the --user docker flag to adjust running user is various check of the user by gitea but also by sub process like ssh-keygen in #7128

@@ -1,5 +1,6 @@
#!/bin/bash

#TODO maybe /data/git/.ssh not needed anymore
Copy link
Member

Choose a reason for hiding this comment

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

If docker user internal SSH server, it's not needed

Copy link
Contributor

Choose a reason for hiding this comment

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

While it is not needed for the single process setup, removing it would break existing setups.

Copy link
Member Author

Choose a reason for hiding this comment

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

@das7pad yes but it is for the setup part so if we don't need it anymore we don't need to create it if it doesn't exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

For folks who backup the entire /data/git directory it is not a problem. But for those who just backup non-generated files, read only the repositories directory, the .ssh directory would be missing upon restore.

Copy link
Contributor

Choose a reason for hiding this comment

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

But the internal sshserver doesn't use the .ssh directory...

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about the third example in #7129 (review).
I know that the files in the .ssh directory are only needed to get the spawned sshd-childs talk with the correct gitea instance.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 5, 2019
@codecov-io
Copy link

Codecov Report

Merging #7129 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7129      +/-   ##
==========================================
- Coverage   41.57%   41.57%   -0.01%     
==========================================
  Files         446      446              
  Lines       60848    60841       -7     
==========================================
- Hits        25299    25295       -4     
+ Misses      32265    32264       -1     
+ Partials     3284     3282       -2
Impacted Files Coverage Δ
models/ssh_key.go 46.01% <100%> (+0.2%) ⬆️
modules/setting/setting.go 48.51% <100%> (+0.17%) ⬆️
modules/log/log.go 69.36% <0%> (-2.71%) ⬇️

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 5d3177d...ba98261. Read the comment docs.

@techknowlogick techknowlogick added topic/deployment topic/distribution This PR changes something about the packaging of Gitea labels Jun 9, 2019
Copy link
Contributor

@das7pad das7pad left a comment

Choose a reason for hiding this comment

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

This breaks almost every usage of the docker image.

Some broken usage examples:

  • all of the 'official' docker-compose configs
    https://docs.gitea.io/en-us/install-with-docker/
  • docker run -d -p 80:3000 -p 2222:22 gitea/gitea
  • running sshd in the container to get the gitea binary
    • run gitea with git user
    • run sshd with root

if ! [[ $(ls -ld /data/git | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git /data/git; fi
chmod 0755 /data/gitea /app/gitea /data/git
chmod 0755 /data/gitea /data/git
#chmod 0755 /app/gitea
Copy link
Contributor

Choose a reason for hiding this comment

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

/app/gitea is owned by root.

Suggested change
#chmod 0755 /app/gitea

Copy link
Member Author

@sapk sapk Jun 15, 2019

Choose a reason for hiding this comment

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

Yes and I don't think it is a problem. I will recheck but that a good point that the process inside the containre couldn't change content inside /app/gitea

return "", errors.New("not enough output for calculating fingerprint: " + stdout)
}
return strings.Split(stdout, " ")[1], nil
return ssh.FingerprintSHA256(pk), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be an unrelated change. Can we move the change into a new PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a needed change because openssh does un-needed system check (that fail in this configuration with --user flag) for calculating the fingerprint of the key. I allready separate this in an other PR #7128

Copy link
Contributor

Choose a reason for hiding this comment

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

What system check is failing for you?

I setup a test with alpine and the --user flag, but can not see any error.

https://gist.github.com/das7pad/62b58bfb67da516542992d8bf5744446

Copy link
Member Author

Choose a reason for hiding this comment

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

If you pass an uid/gid (numerical) that doesn't exist inside the container it should failed.

@@ -436,7 +436,7 @@ func forcePathSeparator(path string) {
// This check is ignored under Windows since SSH remote login is not the main
// method to login on Windows.
func IsRunUserMatchCurrentUser(runUser string) (string, bool) {
if IsWindows {
if IsWindows || SSH.StartBuiltinServer {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to be a bug fix? Let's move it into a new PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in #7215

@@ -1,5 +1,6 @@
#!/bin/bash

#TODO maybe /data/git/.ssh not needed anymore
Copy link
Contributor

Choose a reason for hiding this comment

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

While it is not needed for the single process setup, removing it would break existing setups.

@das7pad
Copy link
Contributor

das7pad commented Jun 15, 2019

How about adding a new image variant for the proposed changes?

For example gitea/gitea:root-less, gitea/gitea:1-root-less, gitea/gitea:1.8-root-less

This would allow any existing deployment to stay as is. And folks which require additional hardening of the container can use the new variant.

With a reasonable delay we can eventually swap the default tag: gitea/gitea:root-less-> gitea/gitea:latest.

@sapk
Copy link
Member Author

sapk commented Jun 15, 2019

@das7pad the docs will need to be updated to follow some changed needed to the run command in some cases but it should be able to reuse the same data folder.
I like the idea to have a transition tag to not enforce this rootless image at start.

Copy link
Contributor

@das7pad das7pad left a comment

Choose a reason for hiding this comment

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

Manual ownership changes to the ssh directory in the data volume are needed.


chown root:root /data/ssh/*
chmod 0700 /data/ssh
chmod 0600 /data/ssh/*
Copy link
Contributor

Choose a reason for hiding this comment

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

The ssh-hostkeys are owned by root and locked down to root only read access. The internal ssh-server will not be able to read them as git user.

@stale
Copy link

stale bot commented Aug 17, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions.

@stale stale bot added the issue/stale label Aug 17, 2019
@lunny lunny added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Aug 17, 2019
@stale stale bot removed the issue/stale label Aug 17, 2019
@westurner
Copy link

Rather than try and maintain/rebase this separate branch, would it be easier to:

  • leave the existing config in
  • check for an environment variable like GITEA_ROOTLESS in the setup and entrypoint scripts
  • create a templates/app_rootless.ini

@sapk
Copy link
Member Author

sapk commented Feb 4, 2020

@westurner I would suggest more to define a rootless tagged image that could become the main later but would ease the transition and allow us to break some pattern existing in the current image.

@alexanderadam
Copy link

@westurner I would suggest more to define a rootless tagged image that could become the main later but would ease the transition and allow us to break some pattern existing in the current image.

I like this idea.

When the rootless image is working (i.e. two months without new issues on the rootless image) the 'legacy root' image could show a warning in the frontend (i.e. Hey, we are now switching to a proper rootless image. You should migrate, too. Click here for more information on how to migrate).

@sapk
Copy link
Member Author

sapk commented Feb 4, 2020

Yes and this transition duration would help us write a migration guide (like changing owner, possible change of key signature of ssh server, ...)

@sapk
Copy link
Member Author

sapk commented Feb 5, 2020

I will send another PR that will replace this one for a image tagged rootless

@sapk sapk mentioned this pull request Feb 5, 2020
@sapk
Copy link
Member Author

sapk commented Feb 5, 2020

The fixes related to help remove external deps (openssh) are already merged (in separe PR) and the rootless part of this PR is moved to a new PR (non breaking by using an other tag -rootless)

@sapk sapk closed this Feb 5, 2020
@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
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. topic/deployment topic/distribution This PR changes something about the packaging of Gitea
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants