mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-12 02:24:21 -05:00
Cannot clone private repo from organization #2335
Closed
opened 2025-11-02 04:33:08 -06:00 by GiteaMirror
·
19 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2
v1.16.1
v1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
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
issue/stale
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#2335
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Governa on GitHub (Sep 15, 2018).
[x]):Description
I have two users and an organization:
Cloning an private repository with user_1 works.
Trying to clone an organization's private repository with user_2, fails with the following message:
If I simply make the repository public, user_2 is able to clone it.
@lafriks commented on GitHub (Sep 15, 2018):
Could be that same key has added multiple times?
@Governa commented on GitHub (Sep 17, 2018):
I don't think so. Would it cause this problem only on private repositories?
@stale[bot] commented on GitHub (Jan 9, 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.
@lunny commented on GitHub (Jan 9, 2019):
This maybe resolved? @Governa could you confirm that?
@jorgefuertes commented on GitHub (Jan 16, 2019):
Not resolved, I have the same problem at v1.7. I can't clone a private repo with a deploy (read-only) rsa key, auth works but clone is denied.
Making it public it works.
And yes, key is duped but I can't select an already uploaded key for a new repo, GUI makes you recreate the key for every repo you need to clone.
@jorgefuertes commented on GitHub (Jan 16, 2019):
Absolutely, duped key doesn't work in private repos, but there's no way to have no duplicated keys cause they are needed at every repo you need to clone.
@lunny commented on GitHub (Jan 18, 2019):
Could you run
Update the '.ssh/authorized_keys' file with Gitea SSH keys. (Not needed for the built-in SSH server.)on Admin UI before you do that?@lunny commented on GitHub (Jan 18, 2019):
Have you deleted some public keys? It seems https://github.com/go-gitea/gitea/pull/5684 resolved a key deleted issue.
@jorgefuertes commented on GitHub (Jan 18, 2019):
Did rebuild the Keys and it doesn't works. Its a bug, not happenning with internal ssh server, change to it and you can clone without problem.
@zeripath commented on GitHub (Jan 18, 2019):
Ok so that log message is coming from
cmd/serv.go:So it seems that in the original bug report the problem was that key 6 wasn't associated with repo 58.
@jorgefuertes is your error the same? That is it is basically:
If so could you check that you don't have two copies of the same key in the db and which repo key X is associated with. It shouldn't happen that two copies of the same keys end up with different IDs but I guess it's possible.
In terms of the difference between the builtin server vs. external they both use this code path in cmd/serv.go - the only difference is the determination of the keyid, so my suspicion is that this key has multiple IDs.
@jorgefuertes commented on GitHub (Jan 18, 2019):
Certenly, that's the error, an yes, key are duped across different repos, because you can't select a previously uploaded key from another repo.
Beside the bug (normal user doesn't need to know about internal or external SSH server, or duped keys), I think I would love to have a common pubkey store, system or organization wide, to choose deploy keys for a project.
Thanks everyone.
@zeripath commented on GitHub (Jan 18, 2019):
This isn't an internal external SSH issue. The problem is the duplicated key id for the same key.
It's just that the external SSH and the internal SSH just have slightly different orders for choosing which key id matches a particularly key. There will be repos you can access when using the internal that you can't when using the external and vice versa.
Now on master it shouldn't be possible for you to have two deploy key IDs for the same deploy key content so what version are you running?
@jorgefuertes commented on GitHub (Jan 19, 2019):
I'm running 1.7 right now but tried several versions before.
I don't have duped keys into the same repo, I want to make it clear. There are duped keys in a system wide view and that fails using external SSH server.
I have no issue with internal SSH server until now.
@zeripath commented on GitHub (Jan 19, 2019):
I wasn't saying that they're duped within the same repo.
It doesn't matter if the same key is used by different repos it should have the always have the same key id.
Somehow at least one repo with that key has got it to have a different key id (it may no longer have that wrong key id).
Now, according to the current master code that can't happen - so this must have happened in an earlier iteration. IIRC lunny may have committed a bug fix for this.
Now, it sounds like the majority of your repos are using the correct key id, so you're not seeing this in the internal SSH server case simply because of different ordering.
Ok, so how do fix this and interrogate this further?
Ok, if you're willing to look at the db. Go into your database and look at the
deploy_keytable.SELECT * FROM "deploy_key" WHERE repo_id=Y;should tell you what the key_id should be - one of these keys will have the correct fingerprint for your key X but will have a different id ZSELECT * FROM "deploy_key" WHERE key_id=X;should tell you which repos have the wrong key id attached. Similarly key_id=ZAssure yourself that the fingerprints and names for these deploy keys are the same.
Choose one of X or Z as the correct key_id K and wrong key_id W probably the lowest key_id should be K. Now you have two options:
You can try to get Gitea to clean up the situation itself. So if there are repos with the wrong key W attached, go in to Gitea and delete these keys, you should be able to add these again later. Don't re-add until all of the wrong ones are removed, probably you should remove all of the correct ones too to increase the chances that this is fixed once and for all. You should then be able to re add these keys once all of the old ones are removed. If that doesn't work then you'll have to do database hacking.
Hack the db. It's probably around a 50% chance that when you add the key back in to the repo, W instead of K will be written because I'm not sure how the public_key entry for W will get removed. If the above doesn't work or you're happy to just do some SQL hacking then...
SELECT * FROM public_key WHERE id = W OR id = K;UPDATE deploy_key SET key_id = K WHERE key_id = W;DELETE FROM public_key WHERE id = W;If you can't access your db, or you're unable to translate that SQL to your db. You can look at the
.ssh/authorized_keysyou should be able to compare the public key content for each line. In the command environment setting you will notice a key-X argument to the gitea serv command. That is the key id. If you compare you should see that there are likely two lines with the same public key content but different key ids. Now converting that key id back to the repository it's referring to is difficult without touching the db, but if there are two lines you definitely have a repository that is referring to the old key. You should be able to use the API to lookup the key, but even though I wrote that API I can't remember just now. But otherwise you should just delete all the deploy keys that match that public key from all repos. If you even miss one this will likely fail to fix your problem. That is I appreciate possibly a lot of work, hence the SQL I've provided.@jorgefuertes commented on GitHub (Jan 21, 2019):
Thank you very much for this complete explanation, I'll try it.
@lunny commented on GitHub (Feb 7, 2019):
@zeripath I think maybe one of your recent PRs has resolved this.
@zeripath commented on GitHub (Feb 7, 2019):
Hi @lunny yeah my recent PRs should prevent this from happening in future.
Unfortunately they won't fix the poor users who have been bitten by these bugs in the past.
@jorgefuertes I think my fixes above are still the way to fix your broken state - hopefully that fixed things for you. On master and the 1.7 branch are comprehensive fixes for deployment key and public key constraints which should prevent this from ever happening again.
@stale[bot] commented on GitHub (Apr 8, 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.
@Governa commented on GitHub (Apr 17, 2019):
I'm not able to reproduce this issue anymore. Solved