Skip to content

Commit b5b1018

Browse files
committed
Merge branch 'master' into fix-13984-multiple-keys-per-input
2 parents 328faed + b8c58ed commit b5b1018

File tree

6 files changed

+90
-14
lines changed

6 files changed

+90
-14
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ David Svantesson <[email protected]> (@davidsvantesson)
3939
CirnoT <[email protected]> (@CirnoT)
4040
a1012112796 <[email protected]> (@a1012112796)
4141
Karl Heinz Marbaise <[email protected]> (@khmarbaise)
42+
Norwin Roosen <[email protected]> (@noerw)

docs/content/doc/usage/fail2ban-setup.en-us.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,27 @@ on a bad authentication from the web or CLI using SSH or HTTP respectively:
2525
```log
2626
2018/04/26 18:15:54 [I] Failed authentication attempt for user from xxx.xxx.xxx.xxx
2727
```
28+
29+
```log
30+
2020/10/15 16:05:09 modules/ssh/ssh.go:143:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
31+
```
32+
33+
```log
34+
2020/10/15 16:05:09 modules/ssh/ssh.go:155:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
35+
```
36+
2837
```log
29-
2020/10/15 16:05:09 modules/ssh/ssh.go:188:publicKeyHandler() [E] SearchPublicKeyByContent: public key does not exist [id: 0] Failed authentication attempt from xxx.xxx.xxx.xxx
38+
2020/10/15 16:05:09 modules/ssh/ssh.go:198:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
3039
```
40+
41+
```log
42+
2020/10/15 16:05:09 modules/ssh/ssh.go:213:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
43+
```
44+
45+
```log
46+
2020/10/15 16:05:09 modules/ssh/ssh.go:227:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
47+
```
48+
3149
```log
3250
2020/10/15 16:08:44 ...s/context/context.go:204:HandleText() [E] invalid credentials from xxx.xxx.xxx.xxx
3351
```

modules/ssh/ssh.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,25 @@ func sessionHandler(session ssh.Session) {
134134
}
135135

136136
func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
137+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
138+
log.Debug("Handle Public Key: Fingerprint: %s from %s", gossh.FingerprintSHA256(key), ctx.RemoteAddr())
139+
}
140+
137141
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)
142+
log.Warn("Invalid SSH username %s - must use %s for all git operations via ssh", ctx.User(), setting.SSH.BuiltinServerUser)
143+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
139144
return false
140145
}
141146

142147
// check if we have a certificate
143148
if cert, ok := key.(*gossh.Certificate); ok {
149+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
150+
log.Debug("Handle Certificate: %s Fingerprint: %s is a certificate", ctx.RemoteAddr(), gossh.FingerprintSHA256(key))
151+
}
152+
144153
if len(setting.SSH.TrustedUserCAKeys) == 0 {
154+
log.Warn("Certificate Rejected: No trusted certificate authorities for this server")
155+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
145156
return false
146157
}
147158

@@ -151,7 +162,7 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
151162
pkey, err := models.SearchPublicKeyByContentExact(principal)
152163
if err != nil {
153164
if models.IsErrKeyNotExist(err) {
154-
log.Debug("Principal Rejected: Unknown Principal: %s", principal)
165+
log.Debug("Principal Rejected: %s Unknown Principal: %s", ctx.RemoteAddr(), principal)
155166
continue principalLoop
156167
}
157168
log.Error("SearchPublicKeyByContentExact: %v", err)
@@ -172,33 +183,58 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
172183

173184
// check the CA of the cert
174185
if !c.IsUserAuthority(cert.SignatureKey) {
175-
log.Debug("Principal Rejected: Untrusted Authority Signature Fingerprint %s for Principal: %s", gossh.FingerprintSHA256(cert.SignatureKey), principal)
186+
if log.IsDebug() {
187+
log.Debug("Principal Rejected: %s Untrusted Authority Signature Fingerprint %s for Principal: %s", ctx.RemoteAddr(), gossh.FingerprintSHA256(cert.SignatureKey), principal)
188+
}
176189
continue principalLoop
177190
}
178191

179192
// validate the cert for this principal
180193
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)
194+
// User is presenting an invalid certificate - STOP any further processing
195+
if log.IsError() {
196+
log.Error("Invalid Certificate KeyID %s with Signature Fingerprint %s presented for Principal: %s from %s", cert.KeyId, gossh.FingerprintSHA256(cert.SignatureKey), principal, ctx.RemoteAddr())
197+
}
198+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
199+
183200
return false
184201
}
185202

203+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
204+
log.Debug("Successfully authenticated: %s Certificate Fingerprint: %s Principal: %s", ctx.RemoteAddr(), gossh.FingerprintSHA256(key), principal)
205+
}
186206
ctx.SetValue(giteaKeyID, pkey.ID)
187207

188208
return true
189209
}
210+
211+
if log.IsWarn() {
212+
log.Warn("From %s Fingerprint: %s is a certificate, but no valid principals found", ctx.RemoteAddr(), gossh.FingerprintSHA256(key))
213+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
214+
}
215+
return false
216+
}
217+
218+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
219+
log.Debug("Handle Public Key: %s Fingerprint: %s is not a certificate", ctx.RemoteAddr(), gossh.FingerprintSHA256(key))
190220
}
191221

192222
pkey, err := models.SearchPublicKeyByContent(strings.TrimSpace(string(gossh.MarshalAuthorizedKey(key))))
193223
if err != nil {
194224
if models.IsErrKeyNotExist(err) {
195-
log.Warn("Permission Denied: Unknown public key : %s", gossh.FingerprintSHA256(key))
225+
if log.IsWarn() {
226+
log.Warn("Unknown public key: %s from %s", gossh.FingerprintSHA256(key), ctx.RemoteAddr())
227+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
228+
}
196229
return false
197230
}
198-
log.Error("SearchPublicKeyByContent: %v Failed authentication attempt from %s", err, ctx.RemoteAddr())
231+
log.Error("SearchPublicKeyByContent: %v", err)
199232
return false
200233
}
201234

235+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
236+
log.Debug("Successfully authenticated: %s Public Key Fingerprint: %s", ctx.RemoteAddr(), gossh.FingerprintSHA256(key))
237+
}
202238
ctx.SetValue(giteaKeyID, pkey.ID)
203239

204240
return true

modules/structs/issue.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ type Issue struct {
5050
Ref string `json:"ref"`
5151
Labels []*Label `json:"labels"`
5252
Milestone *Milestone `json:"milestone"`
53-
Assignee *User `json:"assignee"`
54-
Assignees []*User `json:"assignees"`
53+
// deprecated
54+
Assignee *User `json:"assignee"`
55+
Assignees []*User `json:"assignees"`
5556
// Whether the issue is open or closed
5657
//
5758
// type: string
@@ -83,7 +84,8 @@ type CreateIssueOption struct {
8384
// required:true
8485
Title string `json:"title" binding:"Required"`
8586
Body string `json:"body"`
86-
// username of assignee
87+
Ref string `json:"ref"`
88+
// deprecated
8789
Assignee string `json:"assignee"`
8890
Assignees []string `json:"assignees"`
8991
// swagger:strfmt date-time
@@ -97,8 +99,10 @@ type CreateIssueOption struct {
9799

98100
// EditIssueOption options for editing an issue
99101
type EditIssueOption struct {
100-
Title string `json:"title"`
101-
Body *string `json:"body"`
102+
Title string `json:"title"`
103+
Body *string `json:"body"`
104+
Ref *string `json:"ref"`
105+
// deprecated
102106
Assignee *string `json:"assignee"`
103107
Assignees []string `json:"assignees"`
104108
Milestone *int64 `json:"milestone"`

routers/api/v1/repo/issue.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
486486
PosterID: ctx.User.ID,
487487
Poster: ctx.User,
488488
Content: form.Body,
489+
Ref: form.Ref,
489490
DeadlineUnix: deadlineUnix,
490491
}
491492

@@ -625,6 +626,13 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
625626
if form.Body != nil {
626627
issue.Content = *form.Body
627628
}
629+
if form.Ref != nil {
630+
err = issue_service.ChangeIssueRef(issue, ctx.User, *form.Ref)
631+
if err != nil {
632+
ctx.Error(http.StatusInternalServerError, "UpdateRef", err)
633+
return
634+
}
635+
}
628636

629637
// Update or remove the deadline, only if set and allowed
630638
if (form.Deadline != nil || form.RemoveDeadline != nil) && canWrite {

templates/swagger/v1_json.tmpl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11937,7 +11937,7 @@
1193711937
],
1193811938
"properties": {
1193911939
"assignee": {
11940-
"description": "username of assignee",
11940+
"description": "deprecated",
1194111941
"type": "string",
1194211942
"x-go-name": "Assignee"
1194311943
},
@@ -11976,6 +11976,10 @@
1197611976
"format": "int64",
1197711977
"x-go-name": "Milestone"
1197811978
},
11979+
"ref": {
11980+
"type": "string",
11981+
"x-go-name": "Ref"
11982+
},
1197911983
"title": {
1198011984
"type": "string",
1198111985
"x-go-name": "Title"
@@ -12778,6 +12782,7 @@
1277812782
"type": "object",
1277912783
"properties": {
1278012784
"assignee": {
12785+
"description": "deprecated",
1278112786
"type": "string",
1278212787
"x-go-name": "Assignee"
1278312788
},
@@ -12802,6 +12807,10 @@
1280212807
"format": "int64",
1280312808
"x-go-name": "Milestone"
1280412809
},
12810+
"ref": {
12811+
"type": "string",
12812+
"x-go-name": "Ref"
12813+
},
1280512814
"state": {
1280612815
"type": "string",
1280712816
"x-go-name": "State"

0 commit comments

Comments
 (0)