-
Notifications
You must be signed in to change notification settings - Fork 378
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: gittar remove skipAuth #1856
Merged
erda-bot
merged 2 commits into
erda-project:master
from
littlejiancc:feature/gittar-skip
Sep 15, 2021
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,50 +196,43 @@ func doAuth(c *webcontext.Context, repo *models.Repo, repoName string) { | |
var gitRepository = &gitmodule.Repository{} | ||
var err error | ||
var userInfo *ucauth.UserInfo | ||
//skip authentication | ||
host := c.Host() | ||
for _, skipUrl := range conf.SkipAuthUrls() { | ||
if skipUrl != "" && strings.HasSuffix(host, skipUrl) { | ||
logrus.Debugf("skip authenticate host: %s", host) | ||
gitRepository, err = openRepository(c, repo) | ||
if err != nil { | ||
c.AbortWithStatus(500, err) | ||
return | ||
} | ||
c.Set("repository", gitRepository) | ||
|
||
userIdStr := c.GetHeader(httputil.UserHeader) | ||
if userIdStr == "" { | ||
c.AbortWithStatus(500, errors.New("the userID is empty")) | ||
return | ||
} | ||
|
||
userInfoDto, err := uc.FindUserById(userIdStr) | ||
if err != nil { | ||
c.AbortWithStatus(500, err) | ||
return | ||
} | ||
logrus.Infof("repo: %s userId: %v, username: %s", repoName, userIdStr, userInfoDto.Username) | ||
//校验通过缓存5分钟结果 | ||
//校验失败每次都会请求 | ||
_, validateError := ValidaUserRepoWithCache(c, userIdStr, repo) | ||
if validateError != nil { | ||
logrus.Infof("openapi auth fail repo:%s user:%s", repoName, userInfoDto.Username) | ||
c.AbortWithStatus(403, validateError) | ||
return | ||
} | ||
c.Set("repository", gitRepository) | ||
//c.Set("lock", repoLock.Lock) | ||
if !isGitProtocolRequest(c) { | ||
gitRepository, err = openRepository(c, repo) | ||
if err != nil { | ||
c.AbortWithStatus(500, err) | ||
return | ||
} | ||
c.Set("repository", gitRepository) | ||
|
||
c.Set("user", &models.User{ | ||
Name: userInfoDto.Username, | ||
NickName: userInfoDto.NickName, | ||
Email: userInfoDto.Email, | ||
Id: userIdStr, | ||
}) | ||
c.Next() | ||
userIdStr := c.GetHeader(httputil.UserHeader) | ||
if userIdStr == "" { | ||
c.AbortWithStatus(500, errors.New("the userID is empty")) | ||
return | ||
} | ||
userInfoDto, err := uc.FindUserById(userIdStr) | ||
if err != nil { | ||
c.AbortWithStatus(500, err) | ||
return | ||
} | ||
logrus.Infof("repo: %s userId: %v, username: %s", repoName, userIdStr, userInfoDto.Username) | ||
//校验通过缓存5分钟结果 | ||
//校验失败每次都会请求 | ||
_, validateError := ValidaUserRepoWithCache(c, userIdStr, repo) | ||
if validateError != nil { | ||
logrus.Infof("openapi auth fail repo:%s user:%s", repoName, userInfoDto.Username) | ||
c.AbortWithStatus(403, validateError) | ||
return | ||
} | ||
|
||
c.Set("user", &models.User{ | ||
Name: userInfoDto.Username, | ||
NickName: userInfoDto.NickName, | ||
Email: userInfoDto.Email, | ||
Id: userIdStr, | ||
}) | ||
c.Next() | ||
return | ||
} | ||
|
||
userInfo, err = GetUserInfoByTokenOrBasicAuth(c, repo.ProjectID) | ||
|
@@ -453,3 +446,11 @@ func getOrgIDV3(c *webcontext.Context, orgName string) (int64, error) { | |
} | ||
return orgID, nil | ||
} | ||
|
||
// isGitProtocolRequest if request like git clone,git push... return true | ||
func isGitProtocolRequest(c *webcontext.Context) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add unit test for this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if c.GetHeader("Git-Protocol") != "" { | ||
return true | ||
} | ||
return false | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use english
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done