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

UpdatePublicKey: Failed to update public key: public key does not exist #2060

Closed
2 of 7 tasks
gsantner opened this issue Jun 25, 2017 · 21 comments · Fixed by #2185
Closed
2 of 7 tasks

UpdatePublicKey: Failed to update public key: public key does not exist #2060

gsantner opened this issue Jun 25, 2017 · 21 comments · Fixed by #2185
Labels
Milestone

Comments

@gsantner
Copy link

gsantner commented Jun 25, 2017

  • Gitea version (or commit ref): 7356762
  • Git version: 2.11.0
  • Operating system: Debian 9
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant - no access
  • Log gist:

Description

Sometimes i'm not able to pull from gitea because of anUpdatePublicKey error. As also the CI service pulls from gitea repos, this creates a lot of build errors every day. The keys are all added to the gitea account and do have access to repos. I also deleted, readded the keys and did a (gite admin)-ssh key rewrite.

gitea serv.log:

2017/06/25 19:04:18 [T] UpdatePublicKeyUpdated: http://localhost:5642/api/internal/ssh/20/update
2017/06/25 19:04:18 [...io/gitea/cmd/serv.go:329 runServ()] [F] UpdatePublicKey: Failed to update public key: public key does not exist [id: 20]

database entry (freshly added today):

INSERT INTO `public_key` (`id`, `owner_id`, `name`, `fingerprint`, `content`, `mode`, `type`, `created`, `updated`, `created_unix`, `updated_unix`) 
VALUES (20, 1, ' PubKeyName ', 'SHA256:arjdAAKEYAAAA COMMENT', 2, 1, NULL, NULL, 1498410219, 1498410258);

client:

Cloning the remote Git repository

Cloning repository gogs@SERVER:server/someone-wiki-jekyll.git

 > git init /var/lib/jenkins/workspace/someone-wiki-jekyll_master-ASIDHASDASF # timeout=10

Fetching upstream changes from gogs@SERVER:server/someone-wiki-jekyll.git

 > git --version # timeout=10

using GIT_SSH to set credentials Deploy jekyll wiki SSH

 > git fetch --tags --progress gogs@SERVER:server/someone-wiki-jekyll.git +refs/heads/*:refs/remotes/origin/*

ERROR: Error cloning remote repo 'origin'

hudson.plugins.git.GitException: Command "git fetch --tags --progress gogs@SERVER:server/someone-wiki-jekyll.git +refs/heads/*:refs/remotes/origin/*" returned status code 1:

stdout: 

stderr: remote: Zähle Objekte: 638, Fertig.        

remote: Komprimiere Objekte:   0% (1/286)           
remote: Komprimiere Objekte:   1% (3/286)          
....
remote: Komprimiere Objekte: 100% (286/286)           
remote: Komprimiere Objekte: 100% (286/286), Fertig.        

Empfange Objekte:   0% (1/638)   
Empfange Objekte:   1% (7/638)   
Empfange Objekte:   2% (13/638)   
...
Empfange Objekte:  46% (294/638)   
remote: Total 638 (delta 333), reused 610 (delta 322)        
....
Löse Unterschiede auf:  99% (332/333)   

Gitea: Internal error

UpdatePublicKey: Failed to update public key: public key does not exist [id: 20]


	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1903)

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1622)

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:71)

@lunny lunny added the type/bug label Jun 26, 2017
@lunny lunny added this to the 1.2.0 milestone Jun 26, 2017
@ethantkoenig
Copy link
Member

@gsantner The INSERT command you posted isn't valid; the column count doesn't match the value count, and created and updated are not columns in the public_key table.

Are you sure there is a key with id 20 in the database (i.e. SELECT * FROM public_key WHERE id=20 returns something)?

If for some reason you're not able to directly run the SELECT command, you could instead use the GET /api/v1/users/:username/keys API endpoint to double-check that the key does in fact exist in the database.

@gsantner
Copy link
Author

gsantner commented Jun 26, 2017

Sorry maybe I accidentally removed one during pasting to github. below is the export again.
Yes, the query gets exactly this line, so I'm sure theres ID 20 in there.

API: tried https://DOMAIN/gitea/api/v1/users/gregor/keys and it just shows me a white page without any error (accessed via browser). Theres also no error or other message in the log from this api query.
Did tail -f *.log inside code.gitea.io/gitea/log

in fact exist in the database.

It does, I directly accessed the database gitea is using.

As said above, I can access/clone/push. But sometimes (multiple times a day, and often at CI) it just gives this error. The keys are correctly setted up at my clients.

--
-- Tabellenstruktur für Tabelle `public_key`
--

CREATE TABLE `public_key` (
  `id` bigint(20) NOT NULL,
  `owner_id` bigint(20) NOT NULL,
  `name` varchar(255) NOT NULL,
  `fingerprint` varchar(255) NOT NULL,
  `content` text NOT NULL,
  `mode` int(11) NOT NULL DEFAULT '2',
  `type` int(11) NOT NULL DEFAULT '1',
  `created` datetime DEFAULT NULL,
  `updated` datetime DEFAULT NULL,
  `created_unix` bigint(20) DEFAULT NULL,
  `updated_unix` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Daten für Tabelle `public_key`
--

INSERT INTO `public_key` (`id`, `owner_id`, `name`, `fingerprint`, `content`, `mode`, `type`, `created`, `updated`, `created_unix`, `updated_unix`) VALUES
(20, 1, ' laptop gregor ', 'SHA256:arjdRrafsdfsdfadsfsd', 'ssh-rsa AAAasdfadsfadsfadsfadsfjr9F gregor@somewhere', 2, 1, NULL, NULL, 1498410219, 1498468069);

@ethantkoenig
Copy link
Member

@gsantner What is the value of setting.LocalURL in your setup (specifically inside the serv subcommand)?

The request POST {setting.LocalURL}/api/internal/ssh/20/update (made here) is returning a 500, because whatever gitea instance is running at that URL is talking to a different database than the one that contains your key.

@gsantner
Copy link
Author

I dont have any debugging tools or like that installed on the system. What shall I do, and where I can find the piece of information then?

@gsantner
Copy link
Author

Btw: There is just one Gitea instance running on the system

@ethantkoenig
Copy link
Member

@gsantner From looking at the logs you've posted, setting.LocalURL is http://localhost:5642. Can do you the following:

  1. Can you double-check that the gitea config (default location is custom/conf/app.ini) is correct? Specifically the database config?
  2. Can you go to http://localhost:5642/user/settings/keys (authenticated as the user with id 1), and confirm that you see the key you inserted (SHA256:arjdRrafsdfsdfadsfsd)

If neither of these reveal anything, then I'm stuck 😕

@gsantner
Copy link
Author

1 ) Well, it's localhost at a port yes, but apache is serving in front. (Which shouldn't matter anyway as I'm cloning via SSH)

[server]
SSH_DOMAIN   =  MY.DOMAIN.EXT
DOMAIN       = MY.DOMAIN.EXT
HTTP_PORT    = 5642    
ROOT_URL     = https://MY.DOMAIN.EXT/gitea
OFFLINE_MODE = false
ENABLE_GZIP  = false

[database]
DB_TYPE  = mysql
HOST     = 127.0.0.1:3306
NAME     = gitea
USER     = gitea
PASSWD   = PASS
  1. Of course, yeah, the right key (hash) is there (I pasted some short random text in the issue). And in the database too. With the correct text and description.

@lafriks
Copy link
Member

lafriks commented Jul 2, 2017

Does in your app.ini config file has INTERNAL_TOKEN value?

@gsantner
Copy link
Author

gsantner commented Jul 3, 2017

@lafriks Yep, under [security]

@lafriks
Copy link
Member

lafriks commented Jul 3, 2017

and it is not empty, right? (do not post it here just confirm it is not empty)

@gsantner
Copy link
Author

gsantner commented Jul 3, 2017

of course it is there

@lunny
Copy link
Member

lunny commented Jul 13, 2017

Could you reproduce that? Maybe take a look at the xorm.log?

@gsantner
Copy link
Author

gsantner commented Jul 13, 2017

Yes, reproducible. serv.log.txt / xorm.log.txt. I deleted all logs before starting the script.

Maybe some kind of race condition? Maybe related to a timestamp?

#!/bin/bash
for i in `seq 1 100` ; do 
        git clone gogs@myhost:me/somerepo.git   CloneNr$i 2>&1 | grep "key" &
done
ls | wc -l

outputs: (59 clones out of 100 worked actually / loaded repo fully).

$
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
UpdatePublicKey: Failed to update public key: public key does not exist [id: 19]
59

@lafriks
Copy link
Member

lafriks commented Jul 13, 2017

Thanks for detailed info, I will look into this

@gsantner
Copy link
Author

gsantner commented Jul 20, 2017

@lafriks
Thanks for your fixes! Tried the script above again, and there are no warnings/erorrs anymore now. But still about half of the clones do not work.

[gregor@gregor-desktop aatmp]$ bash clonestuff.sh ; sleep 5 ; rmFolderWithGit clone
83
[gregor@gregor-desktop aatmp]$ bash clonestuff.sh ; sleep 5 ; rmFolderWithGit clone
80
[gregor@gregor-desktop aatmp]$ 
[gregor@gregor-desktop aatmp]$ bash clonestuff.sh ; sleep 5 ; rmFolderWithGit clone
22
[gregor@gregor-desktop aatmp]$ bash clonestuff.sh ; sleep 5 ; rmFolderWithGit clone
30
[gregor@gregor-desktop aatmp]$ bash clonestuff.sh ; sleep 5 ; rmFolderWithGit clone
88
[gregor@gregor-desktop aatmp]$ bash clonestuff.sh ; sleep 5 ; rmFolderWithGit clone
50
[gregor@gregor-desktop aatmp]$ bash clonestuff.sh ; sleep 5 ; rmFolderWithGit clone
40
[gregor@gregor-desktop aatmp]$ bash clonestuff.sh ; sleep 5 ; rmFolderWithGit clone
67

In the Logs I can find
2017/07/20 16:15:08 [T] UpdatePublicKeyUpdated: http://localhost:PORT/api/internal/ssh/19/update lines, but no public key error anymore. I don't know where the problem lies now, but there is still a bug.
The problem may not occur so often when using it with one time push/pull for code updates, but if theres e.g. jenkins behind who does pull and make checks

@lafriks
Copy link
Member

lafriks commented Jul 20, 2017

@gsantner It works correctly wait before bash script finishes to execute and than check cloned repository count. Because at the end of git clone you have & so ls executes faster than git commands are finished cloning repositories that's way you get wrong count. If you will wait a bit longer and run ls manually you will see correct count

@gsantner
Copy link
Author

gsantner commented Jul 20, 2017

Thats what I tried too (before multiple script execution). fail2ban turned off. heres a log. I did check if some git is running too

log.txt

I tried the script too with 10 clones, that works. 100 may be a little heavy and unnatural, I'm just somewhat suprised it cannot be handled even if cloning is running from/to localhost. From the log: maybe an upstream bug in openssh?

@lafriks
Copy link
Member

lafriks commented Jul 20, 2017

@gsantner try adding sleep before ls, might be that when scripts exits it child processes are also killed

@gsantner
Copy link
Author

gsantner commented Jul 20, 2017 via email

@lafriks
Copy link
Member

lafriks commented Jul 22, 2017

@gsantner I found out why are you having problem with 100 parallel clones. It is actually not a gitea fault but ssh servers anti ddos protection. By default ssh configuration has MaxStartups 10:30:60 that means that it will start drop connections at rate 30% after it has 10 parallel yet unauthorized connections or more than 60 connections in total. When setting MaxStartups 100:30:120 in /etc/ssh/sshd_config and restarting ssh server I had no problems and all 100 copies get cloned without errors.

@gsantner
Copy link
Author

@lafriks Wow, thanks for finding that out 👍, and of course for fixing the bug

@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants