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

Fix SSH auth lfs locks #3152

Merged
merged 7 commits into from
Jan 27, 2018
Merged

Conversation

sapk
Copy link
Member

@sapk sapk commented Dec 11, 2017

Mostly don't reinvent the wheel to fix #3084 by re-using func of lfs.

@sapk sapk force-pushed the fix-ssh-auth-lfs-locks branch 3 times, most recently from a1f9481 to 7205109 Compare December 11, 2017 22:55
@sapk sapk changed the title [WIP] Fix SSH auth lfs locks Fix SSH auth lfs locks Dec 11, 2017
@sapk
Copy link
Member Author

sapk commented Dec 11, 2017

I extract a function parseToken of original authenticateToken and add user reference to token claim to be able to fill ctx.User if needed for creating or deleting locks.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 11, 2017
@codecov-io
Copy link

codecov-io commented Dec 11, 2017

Codecov Report

Merging #3152 into master will decrease coverage by 0.08%.
The diff coverage is 42.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3152      +/-   ##
==========================================
- Coverage   35.66%   35.57%   -0.09%     
==========================================
  Files         281      281              
  Lines       40552    40579      +27     
==========================================
- Hits        14463    14437      -26     
- Misses      23957    24001      +44     
- Partials     2132     2141       +9
Impacted Files Coverage Δ
cmd/serv.go 0% <0%> (ø) ⬆️
modules/lfs/server.go 39.07% <26.47%> (+1.4%) ⬆️
modules/lfs/locks.go 47.73% <58.53%> (-8%) ⬇️
models/lfs_lock.go 63.21% <65%> (-6.55%) ⬇️
models/error.go 32.73% <85.71%> (+0.3%) ⬆️
modules/indexer/indexer.go 70% <0%> (-7.5%) ⬇️
models/repo_indexer.go 41.15% <0%> (-5.76%) ⬇️
models/repo_list.go 65.62% <0%> (-1.57%) ⬇️
models/repo.go 43.25% <0%> (-0.19%) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 97fe773...2036540. Read the comment docs.

@lafriks lafriks added this to the 1.4.0 milestone Dec 11, 2017
@lafriks
Copy link
Member

lafriks commented Dec 11, 2017

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 11, 2017
@flozz
Copy link

flozz commented Dec 12, 2017

The authentication seems to work for the lock feature, but I am not able to push LFS object anymore:

$ git lfs push origin master
Git LFS: (0 of 1 files) 0 B / 8 B                                                                        
batch response: Fatal error: Server error: http:https://git2.XXX.YYY/ZZZ/test-lfs.git/info/lfs/objects/batch

Errors logged to /tmp/test-lfs/.git/lfs/objects/logs/20171212T112833.900447349.log
Use `git lfs logs last` to view the log.

From gitea log:

Dec 12 11:28:33 XXX gitea[44851]: [Macaron] 2017-12-12 11:28:33: Completed POST /ZZZ/test-lfs.git/info/lfs/objects/batch 500 Internal Server Error in 1.880036ms

Copy link
Member

@lafriks lafriks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above :)

@sapk
Copy link
Member Author

sapk commented Dec 12, 2017

@flozz thanks for the testing. Will look at it

l.Path = cleanPath(l.Path)
}

// AfterLoad is invoked from XORM after setting the values of all fields of this object.
func (l *LFSLock) AfterLoad() {
l.Owner, _ = GetUserByID(l.OwnerID)
l.Repo, _ = GetRepositoryByID(l.RepoID)
Copy link
Member

@ethantkoenig ethantkoenig Dec 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two thoughts:

  1. We shouldn't ignore errors here; we should at least log them.
  2. We should double-check that loading the Owner and Repo every time we read from the database is necessary. IMO, it seems a bit wasteful

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added repo during dev because I needed it at one time but this could be revert to only use repoID if it to much additional workload.

@@ -71,15 +74,15 @@ func CreateLFSLock(lock *LFSLock) (*LFSLock, error) {
}

// GetLFSLock returns release by given path.
func GetLFSLock(repoID int64, path string) (*LFSLock, error) {
func GetLFSLock(repo *Repository, path string) (*LFSLock, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Is it really worth passing the repository if the only thing we care about it the id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I remember it is to use HasAccess that need a repo reference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I could make a func accessLevel and hasAccess that use repoID more generally for better perf ? (I think in a other PR ?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I must have missed the call to CheckLFSAccessForRepo. Yes, perhaps in another PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact after reviewing code of accessLevel, it use repo.IsPrivate that need a repo reference so.

)

func checkRequest(req macaron.Request, post bool) int {
func checkRequest(ctx *context.Context, post bool) int {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be cleaner to write responses to ctx, instead of returning the response status? Right now, the person calling this function needs to know that 200 is a special return value (which isn't documented anywhere)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have wrote the method.

@@ -123,24 +126,20 @@ func DeleteLFSLockByID(id int64, u *User, force bool) (*LFSLock, error) {
}

//CheckLFSAccessForRepo check needed access mode base on action
func CheckLFSAccessForRepo(u *User, repoID int64, action string) error {
func CheckLFSAccessForRepo(u *User, repo *Repository, reqWrt bool) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's cleaner to pass the AccessMode directly, instead of a bool?

@sapk sapk changed the title Fix SSH auth lfs locks [WIP] Fix SSH auth lfs locks Dec 18, 2017
@sapk sapk force-pushed the fix-ssh-auth-lfs-locks branch 2 times, most recently from 32caa14 to 2155d57 Compare December 20, 2017 22:50
@@ -26,7 +26,8 @@ SSH_DOMAIN = localhost
HTTP_PORT = 3002
ROOT_URL = http:https://localhost:3002/
DISABLE_SSH = false
SSH_PORT = 22
SSH_LISTEN_HOST = localhost
SSH_PORT = 2222
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use same port for multiple database tests as they are run in parallel

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@lafriks
Copy link
Member

lafriks commented Dec 22, 2017

seems that ssh port change requires update in tests

@@ -12,27 +12,38 @@ import (
"time"

api "code.gitea.io/sdk/gitea"
"github.com/ngaut/log"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethantkoenig sorry I pass it as WIP seen I want to setup test for various git access to make that I don't break anything in future. It is my editor that setup this import, I will review my code once it works and remove WIP when ready. Sorry for the distrurb.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@sapk sapk force-pushed the fix-ssh-auth-lfs-locks branch 2 times, most recently from 71eb418 to 8116752 Compare December 30, 2017 16:49
@sapk
Copy link
Member Author

sapk commented Dec 30, 2017

@flozz can you re-test? It should be good now

@sapk sapk changed the title [WIP] Fix SSH auth lfs locks Fix SSH auth lfs locks Dec 30, 2017
@sapk
Copy link
Member Author

sapk commented Dec 30, 2017

Ok found my mistake in 2723ca5d82dee097e8fa4c0080a5492ec0bb44b8
This PR add integration test from git cli for http and ssh url for normal clone/commit but also lfs file and lfs lock.

@sapk sapk force-pushed the fix-ssh-auth-lfs-locks branch 2 times, most recently from 31c8e64 to 5d8d6c6 Compare December 30, 2017 18:55
@sapk
Copy link
Member Author

sapk commented Jan 16, 2018

Wait for #3377 to have tests before

lafriks pushed a commit that referenced this pull request Jan 16, 2018
* test: integration add git cli tests

Extracted form for easing review process and debug #3152

* test: integration add git cli big file commit

* fix:  Don't rewrite key if internal server
@sapk sapk force-pushed the fix-ssh-auth-lfs-locks branch 4 times, most recently from cfbd6e3 to e658af2 Compare January 16, 2018 20:39
@sapk sapk changed the title [WIP] Fix SSH auth lfs locks Fix SSH auth lfs locks Jan 16, 2018
@sapk
Copy link
Member Author

sapk commented Jan 16, 2018

All is working now. What fix pgsql tests should be inside #3377 or #3346.

@lafriks
Copy link
Member

lafriks commented Jan 17, 2018

@ethantkoenig need your approval

@lafriks
Copy link
Member

lafriks commented Jan 20, 2018

@ethantkoenig we need to release 1.4.0 soon, can you please review this?

Copy link
Member

@ethantkoenig ethantkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for delay

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 20, 2018
l.Path = cleanPath(l.Path)
}

// AfterLoad is invoked from XORM after setting the values of all fields of this object.
func (l *LFSLock) AfterLoad() {
l.Owner, _ = GetUserByID(l.OwnerID)
var err error
l.Owner, err = GetUserByID(l.OwnerID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will performing database queries inside AfterLoad lead to deadlock problems if the query that triggered AfterLoad is part of a transaction? See #1813

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethantkoenig queries should not be affected by locking and will load last committed data even if update/insert is in progress

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. In #1813 the offending SQL was a write which blocked on an ongoing transaction, but if you're sure that reading won't block on ongoing transactions then this is okay.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use

func (l *LFSLock) AfterLoad(sess *xorm.Session) {

}

to avoid that.

Copy link
Member

@lunny lunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow my suggestion.

@lafriks
Copy link
Member

lafriks commented Jan 26, 2018

@lunny need your approval

@lafriks lafriks merged commit 9e842c8 into go-gitea:master Jan 27, 2018
@sapk sapk deleted the fix-ssh-auth-lfs-locks branch May 19, 2018 23:56
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git LFS Lock: credential issue when using SSH
7 participants