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

Deploy key does not have access to private repository #2441

Closed
1 of 7 tasks
TheAssassin opened this issue Aug 31, 2017 · 17 comments
Closed
1 of 7 tasks

Deploy key does not have access to private repository #2441

TheAssassin opened this issue Aug 31, 2017 · 17 comments
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/question Issue needs no code to be fixed, only a description on how to fix it yourself.

Comments

@TheAssassin
Copy link

  • Gitea version (or commit ref): 1.2 (Docker image 3e606f47a47e)
  • Git version: not relevant
  • Operating system: not relevant
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant

Description

I tried to use a deploy key with a private repository on a private instance of Gitea running in a Docker container. Apparently, for private Git repositories, the deploy key doesn't have permission to read the repository, though.

Cloning into '.'...
Gitea: Invalid key ID
Invalid key ID[key-1]: public key does not exist [id: 1]
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

As soon as I publish the repository, the key works as expected.

It's a bit disruptive to have to switch the state of a repository for every deployment. I'd propose to allow deploy keys to clone the relevant repository even if it's private.

(I think a workaround might be to add a "machine user" or something like that, and add that to the repository.)

Oh, and please, improve that error message a bit. I'm not even sure whether the current behavior is intended, the message in the log extract I posted actually implies it might be an error.

@lunny
Copy link
Member

lunny commented Sep 1, 2017

see https://github.com/go-gitea/gitea/blob/master/cmd/serv.go#L208, I have checked the code. It seems it's right. Maybe you can check whether your key [id=1] is exist?

@lunny lunny added the type/question Issue needs no code to be fixed, only a description on how to fix it yourself. label Sep 1, 2017
@TheAssassin
Copy link
Author

Dump from deploy_key:

----+--------+---------+----------+----------------------------------------------------+--------------+--------------
  3 |      4 |      10 | abcdefgh | SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |   1504190000 |            0

I was pretty sure that the key ID is not 1, as I deleted and recreated that deploy key for that repository a few times before trying it at first.

The repo ID is correct. The key is in the public_key database, and the fingerprints are equal. Mode is 1 and type is 2. All this appears valid to me.

What I don't understand is this error message about key 1. Why does Gitea show it when going private, and work fine when going public with the repository?

@lafriks
Copy link
Member

lafriks commented Sep 2, 2017

Check authorized keys file is there key id 1 gitea command

@TheAssassin
Copy link
Author

@lafriks the key with the ID 4 that I re-added a few times is in there more than once (1, 2, 4). The problem now appears to be that the keys are not purged from this file, even when they're deleted from the database. The SSH key apparently matches the key with ID 1 first, thus, Gitea checks this ID. Since the key does not exist (and is therefore not authorized to access the repository), the client is denied access. (The key is by the way just once in the database).

#1870 should fix such issues and also implements a superior alternative to the authorized_keys file. But as the people mentioned in there, it might break compatibility for some people. I guess the appropriate fix for this bug is to fix the code generating this file.

@lafriks
Copy link
Member

lafriks commented Sep 2, 2017

You should regenerate it from admin interface and check if that helps

@TheAssassin
Copy link
Author

Well, that obviously fixes the problem. Though, I assume something in the process of deleting deploy keys doesn't trigger that function. I'd suggest to fix this issue by doing exactly that.

@lunny
Copy link
Member

lunny commented Sep 3, 2017

I think the regenerate should be called when a key delete from the UI. see https://github.com/go-gitea/gitea/blob/master/models/ssh_key.go#L406

@TheAssassin
Copy link
Author

Yes. But, thinking about it, it was not regenerated either when adding the key again. I'd say, the best way is to do it in both places to be on the safe side.

@bkcsoft
Copy link
Member

bkcsoft commented Sep 4, 2017

#1870 would fix this by not using the generated file at all :)

@lafriks
Copy link
Member

lafriks commented Sep 4, 2017

@bkcsoft but that requires special openssh server configuration and is it possible to configure it only for single user?

@bkcsoft
Copy link
Member

bkcsoft commented Sep 4, 2017

@lafriks

AuthorizedKeysCommand
Specifies a program to be used for lookup of the user's public keys. The program will be invoked with its first argument the name of the user being authorized, and should produce on standard output AuthorizedKeys lines (see AUTHORIZED_KEYS in sshd(8)). By default (or when set to the empty string) there is no AuthorizedKeysCommand run. If the AuthorizedKeysCommand does not successfully authorize the user, authorization falls through to the AuthorizedKeysFile. Note that this option has an effect only with PubkeyAuthentication turned on.

https://linux.die.net/man/5/sshd_config

@TheAssassin
Copy link
Author

IIRC from Phabricator (which I cited in the other issue by the way) this requires a second instance of OpenSSH. Also, as stated in that other issue, Dropbear etc. don't provide this option. I guess it's still mandatory to provide this as a fallback solution unless support for anything but OpenSSH 6.2+ is dropped.

@TheAssassin
Copy link
Author

Any ETA for #2441 (comment)?

@stale
Copy link

stale bot commented Jan 25, 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 stale bot added the issue/stale label Jan 25, 2019
@TheAssassin
Copy link
Author

So, the key file is still not re-generated when a key is deleted?

@stale stale bot removed the issue/stale label Jan 25, 2019
@stale
Copy link

stale bot commented Mar 26, 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 stale bot added the issue/stale label Mar 26, 2019
@lunny lunny added issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented and removed issue/stale labels Mar 26, 2019
@zeripath
Copy link
Contributor

This is fixed since PR #5939

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
6543 pushed a commit to 6543-forks/gitea that referenced this issue Feb 26, 2024
For small, personal self-hosted instances with no user signups, the fork
button is just a noise. This patch allows disabling them like stars can
be disabled too.

Disabling forks does not only remove the buttons from the web UI, it
also disables the routes that could be used to create forks.

Fixes go-gitea#2441.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
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 type/question Issue needs no code to be fixed, only a description on how to fix it yourself.
Projects
None yet
Development

No branches or pull requests

5 participants