authorized_keys inconsistency when using "admin regenerate keys" #3927

Closed
opened 2025-11-02 05:30:51 -06:00 by GiteaMirror · 8 comments
Owner

Originally created by @NiklasRosenstein on GitHub (Sep 10, 2019).

  • Gitea version (or commit ref): 1.10.0+dev-271-g7eacdcf39
  • Git version: 2.22.0
  • Operating system: Alpine Linux 3.10.2
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

Adding an SSH key to your account adds an entry in authorized_keys with command="/app/gitea/gitea serv key-X ..." .... Using the gitea admin regenerate keys command, those entries will be turned into command="/usr/local/bin/gitea serv key-X ..." ....

Originally created by @NiklasRosenstein on GitHub (Sep 10, 2019). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.10.0+dev-271-g7eacdcf39 - Git version: 2.22.0 - Operating system: Alpine Linux 3.10.2 - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description Adding an SSH key to your account adds an entry in `authorized_keys` with `command="/app/gitea/gitea serv key-X ..." ...`. Using the `gitea admin regenerate keys` command, those entries will be turned into `command="/usr/local/bin/gitea serv key-X ..." ...`.
GiteaMirror added the type/questionissue/stale labels 2025-11-02 05:30:51 -06:00
Author
Owner

@techknowlogick commented on GitHub (Sep 11, 2019):

Are you passing the same configuration to the CLI command as you have gitea web (the -c flag is helpful in this case)?

Are you running gitea inside Docker?

@techknowlogick commented on GitHub (Sep 11, 2019): Are you passing the same configuration to the CLI command as you have `gitea web` (the `-c` flag is helpful in this case)? Are you running gitea inside Docker?
Author
Owner

@stale[bot] commented on GitHub (Nov 10, 2019):

This issue 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 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Nov 10, 2019): This issue 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 weeks. Thank you for your contributions.
Author
Owner

@NiklasRosenstein commented on GitHub (Nov 10, 2019):

Hey @techknowlogick,

I am using Gitea from a Docker container. I do not pass a -c flag to gitea web.

@NiklasRosenstein commented on GitHub (Nov 10, 2019): Hey @techknowlogick, I am using Gitea from a Docker container. I do not pass a `-c` flag to `gitea web`.
Author
Owner

@zeripath commented on GitHub (Nov 10, 2019):

The inconsistency is because when docker runs Gitea it runs Gitea from the /app/gitea/gitea path directly whereas when you run it from the command line you're running it from the symlink /usr/local/bin/gitea

Gitea just puts whatever is in $0 when it's run.

It won't have any effects as far as I can tell.

We could change our docker to just put /app/gitea on the path and drop the symlink? Or replace the symlink with a script.

@zeripath commented on GitHub (Nov 10, 2019): The inconsistency is because when docker runs Gitea it runs Gitea from the /app/gitea/gitea path directly whereas when you run it from the command line you're running it from the symlink /usr/local/bin/gitea Gitea just puts whatever is in $0 when it's run. It won't have any effects as far as I can tell. We could change our docker to just put /app/gitea on the path and drop the symlink? Or replace the symlink with a script.
Author
Owner

@lunny commented on GitHub (Nov 11, 2019):

I think gitea has been the PATH in the docker.

@lunny commented on GitHub (Nov 11, 2019): I think `gitea` has been the `PATH` in the docker.
Author
Owner

@zeripath commented on GitHub (Nov 11, 2019):

Docker runs /app/gitea/gitea directly from the /app/gitea directory:

273a24f226/docker/root/etc/s6/gitea/run (L4-L6)

There is no PATH change in Dockerfile.

The final step in Dockerfile is to create a symlink:

273a24f226/Dockerfile (L64)

This has two effects:

  • When running Gitea from the command line in docker the $0 will not be the same as the docker run Gitea. Hence the /usr vs /app
  • The AppWorkDir and hence custom will not be the same when running from docker command line compared with running from the docker. entry point

There are three possible solutions to the first part:

  • Run as /usr in the s6 run
  • Add /app to the path and drop the symlink
  • Make /usr a script shim which runs /app

The second has the following options:

  • Change the docker build to use the LDFLAGS trick as I previously suggested. (Needed for the first two cases)
  • Set these in the script.
@zeripath commented on GitHub (Nov 11, 2019): Docker runs /app/gitea/gitea directly from the /app/gitea directory: https://github.com/go-gitea/gitea/blob/273a24f22676b73a648fd2a5467e385ec41e84e2/docker/root/etc/s6/gitea/run#L4-L6 There is no PATH change in Dockerfile. The final step in Dockerfile is to create a symlink: https://github.com/go-gitea/gitea/blob/273a24f22676b73a648fd2a5467e385ec41e84e2/Dockerfile#L64 This has two effects: * When running Gitea from the command line in docker the $0 will not be the same as the docker run Gitea. Hence the /usr vs /app * The AppWorkDir and hence custom will not be the same when running from docker command line compared with running from the docker. entry point There are three possible solutions to the first part: * Run as /usr in the s6 run * Add /app to the path and drop the symlink * Make /usr a script shim which runs /app The second has the following options: * Change the docker build to use the LDFLAGS trick as I previously suggested. (Needed for the first two cases) * Set these in the script.
Author
Owner

@stale[bot] commented on GitHub (Jan 10, 2020):

This issue 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 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Jan 10, 2020): This issue 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 weeks. Thank you for your contributions.
Author
Owner

@stale[bot] commented on GitHub (Jan 24, 2020):

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale[bot] commented on GitHub (Jan 24, 2020): This issue has been automatically closed because of inactivity. You can re-open it if needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#3927