Skip to content

Commit 7e98cd5

Browse files
zeripath6543
andauthored
Add SkipLocal2FA option to pam and smtp sources (#17078)
* Add SkipLocal2FA option to other pam and smtp sources Extend #16954 to allow setting skip local 2fa on pam and SMTP authentication sources Signed-off-by: Andrew Thornton <[email protected]> * make SkipLocal2FA omitempty Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 74542ad commit 7e98cd5

File tree

10 files changed

+48
-6
lines changed

10 files changed

+48
-6
lines changed

routers/web/admin/auths.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func parseSMTPConfig(form forms.AuthenticationForm) *smtp.Source {
161161
SkipVerify: form.SkipVerify,
162162
HeloHostname: form.HeloHostname,
163163
DisableHelo: form.DisableHelo,
164+
SkipLocalTwoFA: form.SkipLocalTwoFA,
164165
}
165166
}
166167

@@ -244,8 +245,9 @@ func NewAuthSourcePost(ctx *context.Context) {
244245
hasTLS = true
245246
case login.PAM:
246247
config = &pamService.Source{
247-
ServiceName: form.PAMServiceName,
248-
EmailDomain: form.PAMEmailDomain,
248+
ServiceName: form.PAMServiceName,
249+
EmailDomain: form.PAMEmailDomain,
250+
SkipLocalTwoFA: form.SkipLocalTwoFA,
249251
}
250252
case login.OAuth2:
251253
config = parseOAuth2Config(form)

services/auth/source/ldap/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type Source struct {
5353
GroupFilter string // Group Name Filter
5454
GroupMemberUID string // Group Attribute containing array of UserUID
5555
UserUID string // User Attribute listed in Group
56-
SkipLocalTwoFA bool // Skip Local 2fa for users authenticated with this source
56+
SkipLocalTwoFA bool `json:",omitempty"` // Skip Local 2fa for users authenticated with this source
5757

5858
// reference to the loginSource
5959
loginSource *login.Source

services/auth/source/oauth2/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Source struct {
2525
OpenIDConnectAutoDiscoveryURL string
2626
CustomURLMapping *CustomURLMapping
2727
IconURL string
28-
SkipLocalTwoFA bool
28+
SkipLocalTwoFA bool `json:",omitempty"`
2929

3030
// reference to the loginSource
3131
loginSource *login.Source

services/auth/source/pam/source.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import (
1919

2020
// Source holds configuration for the PAM login source.
2121
type Source struct {
22-
ServiceName string // pam service (e.g. system-auth)
23-
EmailDomain string
22+
ServiceName string // pam service (e.g. system-auth)
23+
EmailDomain string
24+
SkipLocalTwoFA bool `json:",omitempty"` // Skip Local 2fa for users authenticated with this source
2425

2526
// reference to the loginSource
2627
loginSource *login.Source

services/auth/source/pam/source_authenticate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,8 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
6969

7070
return user, nil
7171
}
72+
73+
// IsSkipLocalTwoFA returns if this source should skip local 2fa for password authentication
74+
func (source *Source) IsSkipLocalTwoFA() bool {
75+
return source.SkipLocalTwoFA
76+
}

services/auth/source/smtp/source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Source struct {
2727
SkipVerify bool
2828
HeloHostname string
2929
DisableHelo bool
30+
SkipLocalTwoFA bool `json:",omitempty"`
3031

3132
// reference to the loginSource
3233
loginSource *login.Source

services/auth/source/smtp/source_authenticate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,8 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
8585

8686
return user, nil
8787
}
88+
89+
// IsSkipLocalTwoFA returns if this source should skip local 2fa for password authentication
90+
func (source *Source) IsSkipLocalTwoFA() bool {
91+
return source.SkipLocalTwoFA
92+
}

templates/admin/auth/edit.tmpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@
215215
<input id="allowed_domains" name="allowed_domains" value="{{$cfg.AllowedDomains}}">
216216
<p class="help">{{.i18n.Tr "admin.auths.allowed_domains_helper"}}</p>
217217
</div>
218+
<div class="optional field">
219+
<div class="ui checkbox">
220+
<label for="skip_local_two_fa"><strong>{{.i18n.Tr "admin.auths.skip_local_two_fa"}}</strong></label>
221+
<input id="skip_local_two_fa" name="skip_local_two_fa" type="checkbox" {{if $cfg.SkipLocalTwoFA}}checked{{end}}>
222+
<p class="help">{{.i18n.Tr "admin.auths.skip_local_two_fa_helper"}}</p>
223+
</div>
224+
</div>
218225
{{end}}
219226

220227
<!-- PAM -->
@@ -228,6 +235,13 @@
228235
<label for="pam_email_domain">{{.i18n.Tr "admin.auths.pam_email_domain"}}</label>
229236
<input id="pam_email_domain" name="pam_email_domain" value="{{$cfg.EmailDomain}}">
230237
</div>
238+
<div class="optional field">
239+
<div class="ui checkbox">
240+
<label for="skip_local_two_fa"><strong>{{.i18n.Tr "admin.auths.skip_local_two_fa"}}</strong></label>
241+
<input id="skip_local_two_fa" name="skip_local_two_fa" type="checkbox" {{if $cfg.SkipLocalTwoFA}}checked{{end}}>
242+
<p class="help">{{.i18n.Tr "admin.auths.skip_local_two_fa_helper"}}</p>
243+
</div>
244+
</div>
231245
{{end}}
232246

233247
<!-- OAuth2 -->

templates/admin/auth/new.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
<label for="pam_email_domain">{{.i18n.Tr "admin.auths.pam_email_domain"}}</label>
4242
<input id="pam_email_domain" name="pam_email_domain" value="{{.pam_email_domain}}">
4343
</div>
44+
<div class="pam optional field {{if not (eq .type 4)}}hide{{end}}">
45+
<div class="ui checkbox">
46+
<label for="skip_local_two_fa"><strong>{{.i18n.Tr "admin.auths.skip_local_two_fa"}}</strong></label>
47+
<input id="skip_local_two_fa" name="skip_local_two_fa" type="checkbox" {{if .skip_local_two_fa}}checked{{end}}>
48+
<p class="help">{{.i18n.Tr "admin.auths.skip_local_two_fa_helper"}}</p>
49+
</div>
50+
</div>
4451

4552
<!-- OAuth2 -->
4653
{{ template "admin/auth/source/oauth" . }}

templates/admin/auth/source/smtp.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,11 @@
4949
<input id="allowed_domains" name="allowed_domains" value="{{.allowed_domains}}">
5050
<p class="help">{{.i18n.Tr "admin.auths.allowed_domains_helper"}}</p>
5151
</div>
52+
<div class="optional field">
53+
<div class="ui checkbox">
54+
<label for="skip_local_two_fa"><strong>{{.i18n.Tr "admin.auths.skip_local_two_fa"}}</strong></label>
55+
<input id="skip_local_two_fa" name="skip_local_two_fa" type="checkbox" {{if .skip_local_two_fa}}checked{{end}}>
56+
<p class="help">{{.i18n.Tr "admin.auths.skip_local_two_fa_helper"}}</p>
57+
</div>
58+
</div>
5259
</div>

0 commit comments

Comments
 (0)