gogs / gogs/gogs

"Public key content has been used." on mssql after first key

Open
#4,509 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

💊 bug 🙇‍♂️ help wanted
Dominant language
Go
Stars
47.8k
Forks
5.1k
Avg merge
7h 23m
Merged PRs (30d)
5

Description

  • Gogs version (or commit ref): 0.11.4.0405
  • Git version: ~2.7
  • Operating system: ~Ubuntu Server 16.04.2 LTS
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gogs.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist (usually found in log/gogs.log):

Description

  • If I try to add a ssh key the error message "Public key content has been used." is displayd. User does not matter.
  • The very first ssh-key for the first user is added.
  • If I manually add a key to the Database and "Rewrite '.ssh/authorized_keys' file" the key is written and working

SQL Profiler yields the following statements (User-ID: 3):

exec sp_executesql N'SELECT "id", "owner_id", "name", "fingerprint", "content", "mode", "type", "created_unix", "updated_unix" FROM "public_key" WHERE owner_id = @p1',N'@p1 bigint',@p1=3

=> yields 2 records for 2 keys

exec sp_executesql N'SELECT  TOP 1 "id", "owner_id", "name", "fingerprint", "content", "mode", "type", "created_unix", "updated_unix" FROM "public_key" WHERE "type"=@p1',N'@p1 bigint',@p1=1

=> yields 1 record for 2 keys

I guess this is the function that checks if the key exists: https://github.com/gogits/gogs/blob/63598688e454274da53fea1d072d60dd0e783c4b/models/ssh_key.go#L368

if yes, could it be that the content is missing in the last sql query generated?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked function in models/ssh_key.go and compare it with the MSSQL queries captured in the SQL Profiler output. Reproduce the first-key and second-key cases on MSSQL, then verify that adding another distinct SSH key no longer reports it as already used.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.