-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Keys API changes #4960
Keys API changes #4960
Conversation
3e2fa1f
to
8685618
Compare
5fe2483
to
de460f2
Compare
717a03e
to
2e0d315
Compare
I've made a few more changes/improvements to this pull-request.
The main benefit of allowing searching by fingerprint is that it makes it possible to implement an SSH AuthorizedKeysCommand à la #1870. I would have implemented searching by key content but the simplest naïve implementation would allow listing of all keys due to the way Gitea stores the content of keys - it may not be needed in any case. |
22ff5e2
to
f27d469
Compare
Heya, any thoughts about this request? It should be possible to implement searching by key content if it was required. |
Need to wait for one more maintainer to approve sdk PR |
3cfab3b
to
f792b6c
Compare
Ugh. It seems that I got go-gitea/go-sdk#121 out of sync with this request so another change to the SDK is needed. I've put another request in for that go-gitea/go-sdk#125 - if that's pulled I can adjust the first changeset and this might finally build! |
f792b6c
to
20f2ccd
Compare
SDK PR is merged, please update |
20f2ccd
to
e366f75
Compare
Codecov Report
@@ Coverage Diff @@
## master #4960 +/- ##
==========================================
+ Coverage 37.48% 37.62% +0.13%
==========================================
Files 310 310
Lines 45923 46039 +116
==========================================
+ Hits 17213 17320 +107
- Misses 26236 26240 +4
- Partials 2474 2479 +5
Continue to review full report at Codecov.
|
368ecb5
to
e822116
Compare
@sapk I just had to remove my first commit as the dependencies had already been updated. Is there anything else to be done for this request? I can remove the content searching if the query is thought to be too complex. |
To be honest I don't quite like that key searching by content. What is use case for that? |
Hi @lafriks ! The main use case for searching by key-content is creating a SSH AuthorizedKeysCommand [1][2] but you can do that using the fingerprint without the using the content. I'm happy to drop that bit or stick it behind an admin lock. (This is why the commits are separated rather than squashed in to one.) I can create an AuthorizedKeysCommand command for the main gitea if you'd like. [1] https://man.openbsd.org/sshd_config#AuthorizedKeysCommand |
e822116
to
96fce9f
Compare
I think it's fine to leave search by key in because keys are already available publicly (especially because they are "public keys"). I don't see this as a problem leaving in, and am supportive of the |
@lafriks was referring to the search by key content+/-type code in zeripath@e822116 I don't know if you saw that. It's a little awkward due to the way Gitea stores key content at present, so in order to make it not possible to just list all the keys and their comments I put some more logic in. The main reason for me putting in this PR is so that I can take a key-id and map it back to a user without having to iterate across all the users. I want to use that functionality to provide svn+ssh support for git-as-svn. That doesn't need the searching by key fingerprint or content, but putting that support in would allow me to write a separate AuthorizedKeysCommand rather than for me to have to parse and strip the authorized_keys files. Once you can create a AuthorizedKeysCommand you can provide other ssh based services on your own Gitea server. For plain old gitea you can create an AuthorizedKeysCommand without this PR and I've just put a pull request in for an AuthorizedKeysCommand #5236 that doesn't need this (although if you pull this request we can add the fingerprint stuff in.) |
Does searching by content really requires searching by part of it or searching by equal value wouldn't be enough? |
@lafriks Gitea is storing key type, content and comment as a single content string. You don't get given the comment when you login from ssh so you can't just use equality. The function SearchPublicKeyByContent(content string) overloads the meaning of content in slightly different way by combining key type and content as a single string so it then uses a simplistic like, but if you just use that method you can retrieve all keys by passing in an empty content or 'ssh'. It also does no escaping of '%' or '_' in the like statement. (It's safe to use that function in the AuthorizedKeysCommand PR #5236 because SSHD will still match the keys individually.) |
I would prefer to content searching be done in other PR right by spliting content out to different fields with migration to convert existing data |
@lafriks yeah that's fair enough. It's no longer in this PR. |
96fce9f
to
0aa0898
Compare
This adjusts the keys API to give out private information to user keys if the current user is the owner or an admin. Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit adds more information to the deploy keys to allow for back reference in to the main keys list. It also adds information about the repository that the key is referring to. Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit adds the functionality to search ssh-keys by fingerprint of the ssh-key. Deploy keys per repository can also be searched. There is no current clear API point to allow search of all deploy keys by fingerprint or keyID. Signed-off-by: Andrew Thornton <art27@cantab.net>
0aa0898
to
a1baff5
Compare
@zeripath seems my email reply to the comment above didn't make it through, but it was just thanking your for clarifying. |
The results of the API for both the repo ssh keys and the user ssh keys lacks several important features.
This pull request adjusts the API to allow reporting of the key id for the keys reported by
/repos/{owner}/{repo}/keys
and the owner, keytype and read_only type for the keys reported by/user/keys
.(Of note
/user/keys
does not only just return user keys but also deploy keys.)NB: This pull request requires: go-gitea/go-sdk#121