Skip to content

Commit bdf691a

Browse files
authored
Merge branch 'master' into vendor_bleve
2 parents 264f681 + e46a638 commit bdf691a

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

modules/repository/generate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ func generateGitContent(ctx models.DBContext, repo, templateRepo, generateRepo *
207207
}
208208

209209
repo.DefaultBranch = templateRepo.DefaultBranch
210+
gitRepo, err := git.OpenRepository(repo.RepoPath())
211+
if err != nil {
212+
return fmt.Errorf("openRepository: %v", err)
213+
}
214+
defer gitRepo.Close()
215+
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
216+
return fmt.Errorf("setDefaultBranch: %v", err)
217+
}
210218
if err = models.UpdateRepositoryCtx(ctx, repo, false); err != nil {
211219
return fmt.Errorf("updateRepository: %v", err)
212220
}

modules/repository/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func initRepository(ctx models.DBContext, repoPath string, u *models.User, repo
323323
if err != nil {
324324
return fmt.Errorf("openRepository: %v", err)
325325
}
326+
defer gitRepo.Close()
326327
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
327328
return fmt.Errorf("setDefaultBranch: %v", err)
328329
}

modules/ssh/ssh.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func sessionHandler(session ssh.Session) {
135135

136136
func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
137137
if ctx.User() != setting.SSH.BuiltinServerUser {
138+
log.Warn("Permission Denied: Invalid SSH username %s - must use %s for all git operations via ssh", ctx.User(), setting.SSH.BuiltinServerUser)
138139
return false
139140
}
140141

@@ -145,17 +146,18 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
145146
}
146147

147148
// look for the exact principal
149+
principalLoop:
148150
for _, principal := range cert.ValidPrincipals {
149151
pkey, err := models.SearchPublicKeyByContentExact(principal)
150152
if err != nil {
153+
if models.IsErrKeyNotExist(err) {
154+
log.Debug("Principal Rejected: Unknown Principal: %s", principal)
155+
continue principalLoop
156+
}
151157
log.Error("SearchPublicKeyByContentExact: %v", err)
152158
return false
153159
}
154160

155-
if models.IsErrKeyNotExist(err) {
156-
continue
157-
}
158-
159161
c := &gossh.CertChecker{
160162
IsUserAuthority: func(auth gossh.PublicKey) bool {
161163
for _, k := range setting.SSH.TrustedUserCAKeysParsed {
@@ -170,11 +172,14 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
170172

171173
// check the CA of the cert
172174
if !c.IsUserAuthority(cert.SignatureKey) {
173-
return false
175+
log.Debug("Principal Rejected: Untrusted Authority Signature Fingerprint %s for Principal: %s", gossh.FingerprintSHA256(cert.SignatureKey), principal)
176+
continue principalLoop
174177
}
175178

176179
// validate the cert for this principal
177180
if err := c.CheckCert(principal, cert); err != nil {
181+
// User is presenting an invalid cerficate - STOP any further processing
182+
log.Error("Permission Denied: Invalid Certificate KeyID %s with Signature Fingerprint %s presented for Principal: %s", cert.KeyId, gossh.FingerprintSHA256(cert.SignatureKey), principal)
178183
return false
179184
}
180185

@@ -186,6 +191,10 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
186191

187192
pkey, err := models.SearchPublicKeyByContent(strings.TrimSpace(string(gossh.MarshalAuthorizedKey(key))))
188193
if err != nil {
194+
if models.IsErrKeyNotExist(err) {
195+
log.Warn("Permission Denied: Unknown public key : %s", gossh.FingerprintSHA256(key))
196+
return false
197+
}
189198
log.Error("SearchPublicKeyByContent: %v Failed authentication attempt from %s", err, ctx.RemoteAddr())
190199
return false
191200
}

services/repository/push.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
9797
}
9898
var commits = &repo_module.PushCommits{}
9999
if opts.IsTag() { // If is tag reference {
100+
if pusher == nil || pusher.ID != opts.PusherID {
101+
var err error
102+
if pusher, err = models.GetUserByID(opts.PusherID); err != nil {
103+
return err
104+
}
105+
}
100106
tagName := opts.TagName()
101107
if opts.IsDelRef() {
102108
delTags = append(delTags, tagName)

0 commit comments

Comments
 (0)