Skip to content

Commit 029e05f

Browse files
authored
Merge branch 'master' into fix-13983-disable-ssh-editing-if-ldap
2 parents 4ca803f + e2aa701 commit 029e05f

File tree

10 files changed

+107
-19
lines changed

10 files changed

+107
-19
lines changed

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/repo/issue/view_content/pull.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@
363363
{{end}}
364364
</div>
365365
</div>
366-
<div class="dib ml-3">{{$.i18n.Tr "repo.pulls.merge_instruction_hint" | Safe}}</div>
367-
<div class="instruct" style="display:none">
366+
<div class="instruct-toggle ml-3">{{$.i18n.Tr "repo.pulls.merge_instruction_hint" | Safe}}</div>
367+
<div class="instruct-content" style="display:none">
368368
<div class="ui divider"></div>
369369
<div><h3 class="di">{{$.i18n.Tr "step1"}} </h3>{{$.i18n.Tr "repo.pulls.merge_instruction_step1_desc"}}</div>
370370
<div class="ui secondary segment">

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"

web_src/js/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,8 @@ async function initRepository() {
11201120
e.preventDefault();
11211121
$(`.${$(this).data('do')}-fields`).show();
11221122
$(this).parent().hide();
1123+
$('.instruct-toggle').hide();
1124+
$('.instruct-content').hide();
11231125
});
11241126
$('.merge-button > .dropdown').dropdown({
11251127
onChange(_text, _value, $choice) {
@@ -1133,6 +1135,7 @@ async function initRepository() {
11331135
e.preventDefault();
11341136
$(this).closest('.form').hide();
11351137
$mergeButton.parent().show();
1138+
$('.instruct-toggle').show();
11361139
});
11371140
initReactionSelector();
11381141
}
@@ -1199,7 +1202,7 @@ async function initRepository() {
11991202

12001203
function initPullRequestMergeInstruction() {
12011204
$('.show-instruction').on('click', () => {
1202-
$('.instruct').toggle();
1205+
$('.instruct-content').toggle();
12031206
});
12041207
}
12051208

web_src/less/_base.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101
--color-code-bg: #ffffff;
102102
--color-markdown-code-block: #00000010;
103103
--color-secondary-bg: #f4f4f4;
104+
/* backgrounds */
105+
--checkbox-mask-checked: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1 -1 18 18" width="16" height="16"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg>');
106+
--checkbox-mask-indeterminate: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2 7.75A.75.75 0 012.75 7h10a.75.75 0 010 1.5h-10A.75.75 0 012 7.75z"></path></svg>');
104107
}
105108

106109
:root:lang(ja) {

web_src/less/_markdown.less

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,19 @@
203203
pointer-events: none;
204204
background: var(--color-text);
205205
mask-size: cover;
206+
-webkit-mask-size: cover;
206207
}
207208

208209
input[type="checkbox"]:checked::after {
209210
content: "";
210-
mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1 -1 18 18" width="16" height="16"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg>');
211+
mask-image: var(--checkbox-mask-checked);
212+
-webkit-mask-image: var(--checkbox-mask-checked);
211213
}
212214

213215
input[type="checkbox"]:indeterminate::after {
214216
content: "";
215-
mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2 7.75A.75.75 0 012.75 7h10a.75.75 0 010 1.5h-10A.75.75 0 012 7.75z"></path></svg>');
217+
mask-image: var(--checkbox-mask-indeterminate);
218+
-webkit-mask-image: var(--checkbox-mask-indeterminate);
216219
}
217220

218221
ul ul,

web_src/less/_repository.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@
593593
}
594594

595595
&.view.issue {
596+
.instruct-toggle {
597+
display: inline-block;
598+
}
599+
596600
.title {
597601
padding-bottom: 0 !important;
598602

0 commit comments

Comments
 (0)