Skip to content

Commit ed34981

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix some dropdown problems on the issue sidebar (go-gitea#34308) [skip ci] Updated translations via Crowdin Fix button alignments (go-gitea#34307) fix go version (go-gitea#34299) Fix the ci build (go-gitea#34309) support the open-icon of folder (go-gitea#34168) Fix wrong review requests when updating the pull request (go-gitea#34286) Enforce two-factor auth (2FA: TOTP or WebAuthn) (go-gitea#34187) actions artifacts api list/download check status upload confirmed (go-gitea#34273)
2 parents de715eb + ba5c3f8 commit ed34981

File tree

91 files changed

+672
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+672
-410
lines changed

cmd/admin_auth_ldap.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"code.gitea.io/gitea/models/auth"
12+
"code.gitea.io/gitea/modules/util"
1213
"code.gitea.io/gitea/services/auth/source/ldap"
1314

1415
"github.com/urfave/cli/v2"
@@ -210,8 +211,8 @@ func newAuthService() *authService {
210211
}
211212
}
212213

213-
// parseAuthSource assigns values on authSource according to command line flags.
214-
func parseAuthSource(c *cli.Context, authSource *auth.Source) {
214+
// parseAuthSourceLdap assigns values on authSource according to command line flags.
215+
func parseAuthSourceLdap(c *cli.Context, authSource *auth.Source) {
215216
if c.IsSet("name") {
216217
authSource.Name = c.String("name")
217218
}
@@ -227,6 +228,7 @@ func parseAuthSource(c *cli.Context, authSource *auth.Source) {
227228
if c.IsSet("disable-synchronize-users") {
228229
authSource.IsSyncEnabled = !c.Bool("disable-synchronize-users")
229230
}
231+
authSource.TwoFactorPolicy = util.Iif(c.Bool("skip-local-2fa"), "skip", "")
230232
}
231233

232234
// parseLdapConfig assigns values on config according to command line flags.
@@ -298,9 +300,6 @@ func parseLdapConfig(c *cli.Context, config *ldap.Source) error {
298300
if c.IsSet("allow-deactivate-all") {
299301
config.AllowDeactivateAll = c.Bool("allow-deactivate-all")
300302
}
301-
if c.IsSet("skip-local-2fa") {
302-
config.SkipLocalTwoFA = c.Bool("skip-local-2fa")
303-
}
304303
if c.IsSet("enable-groups") {
305304
config.GroupsEnabled = c.Bool("enable-groups")
306305
}
@@ -376,7 +375,7 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
376375
},
377376
}
378377

379-
parseAuthSource(c, authSource)
378+
parseAuthSourceLdap(c, authSource)
380379
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
381380
return err
382381
}
@@ -398,7 +397,7 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
398397
return err
399398
}
400399

401-
parseAuthSource(c, authSource)
400+
parseAuthSourceLdap(c, authSource)
402401
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
403402
return err
404403
}
@@ -427,7 +426,7 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
427426
},
428427
}
429428

430-
parseAuthSource(c, authSource)
429+
parseAuthSourceLdap(c, authSource)
431430
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
432431
return err
433432
}
@@ -449,7 +448,7 @@ func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
449448
return err
450449
}
451450

452-
parseAuthSource(c, authSource)
451+
parseAuthSourceLdap(c, authSource)
453452
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
454453
return err
455454
}

cmd/admin_auth_oauth.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010

1111
auth_model "code.gitea.io/gitea/models/auth"
12+
"code.gitea.io/gitea/modules/util"
1213
"code.gitea.io/gitea/services/auth/source/oauth2"
1314

1415
"github.com/urfave/cli/v2"
@@ -156,7 +157,6 @@ func parseOAuth2Config(c *cli.Context) *oauth2.Source {
156157
OpenIDConnectAutoDiscoveryURL: c.String("auto-discover-url"),
157158
CustomURLMapping: customURLMapping,
158159
IconURL: c.String("icon-url"),
159-
SkipLocalTwoFA: c.Bool("skip-local-2fa"),
160160
Scopes: c.StringSlice("scopes"),
161161
RequiredClaimName: c.String("required-claim-name"),
162162
RequiredClaimValue: c.String("required-claim-value"),
@@ -185,10 +185,11 @@ func runAddOauth(c *cli.Context) error {
185185
}
186186

187187
return auth_model.CreateSource(ctx, &auth_model.Source{
188-
Type: auth_model.OAuth2,
189-
Name: c.String("name"),
190-
IsActive: true,
191-
Cfg: config,
188+
Type: auth_model.OAuth2,
189+
Name: c.String("name"),
190+
IsActive: true,
191+
Cfg: config,
192+
TwoFactorPolicy: util.Iif(c.Bool("skip-local-2fa"), "skip", ""),
192193
})
193194
}
194195

@@ -294,6 +295,6 @@ func runUpdateOauth(c *cli.Context) error {
294295

295296
oAuth2Config.CustomURLMapping = customURLMapping
296297
source.Cfg = oAuth2Config
297-
298+
source.TwoFactorPolicy = util.Iif(c.Bool("skip-local-2fa"), "skip", "")
298299
return auth_model.UpdateSource(ctx, source)
299300
}

cmd/admin_auth_stmp.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
117117
if c.IsSet("disable-helo") {
118118
conf.DisableHelo = c.Bool("disable-helo")
119119
}
120-
if c.IsSet("skip-local-2fa") {
121-
conf.SkipLocalTwoFA = c.Bool("skip-local-2fa")
122-
}
123120
return nil
124121
}
125122

@@ -156,10 +153,11 @@ func runAddSMTP(c *cli.Context) error {
156153
}
157154

158155
return auth_model.CreateSource(ctx, &auth_model.Source{
159-
Type: auth_model.SMTP,
160-
Name: c.String("name"),
161-
IsActive: active,
162-
Cfg: &smtpConfig,
156+
Type: auth_model.SMTP,
157+
Name: c.String("name"),
158+
IsActive: active,
159+
Cfg: &smtpConfig,
160+
TwoFactorPolicy: util.Iif(c.Bool("skip-local-2fa"), "skip", ""),
163161
})
164162
}
165163

@@ -195,6 +193,6 @@ func runUpdateSMTP(c *cli.Context) error {
195193
}
196194

197195
source.Cfg = smtpConfig
198-
196+
source.TwoFactorPolicy = util.Iif(c.Bool("skip-local-2fa"), "skip", "")
199197
return auth_model.UpdateSource(ctx, source)
200198
}

custom/conf/app.example.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,10 @@ INTERNAL_TOKEN =
524524
;;
525525
;; On user registration, record the IP address and user agent of the user to help identify potential abuse.
526526
;; RECORD_USER_SIGNUP_METADATA = false
527+
;;
528+
;; Set the two-factor auth behavior.
529+
;; Set to "enforced", to force users to enroll into Two-Factor Authentication, users without 2FA have no access to repositories via API or web.
530+
;TWO_FACTOR_AUTH =
527531

528532
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
529533
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module code.gitea.io/gitea
22

3-
go 1.24
3+
go 1.24.2
44

55
// rfc5280 said: "The serial number is an integer assigned by the CA to each certificate."
66
// But some CAs use negative serial number, just relax the check. related:
@@ -325,6 +325,8 @@ replace github.com/charmbracelet/git-lfs-transfer => gitea.com/gitea/git-lfs-tra
325325
// TODO: This could be removed after https://github.com/mholt/archiver/pull/396 merged
326326
replace github.com/mholt/archiver/v3 => github.com/anchore/archiver/v3 v3.5.2
327327

328+
replace git.sr.ht/~mariusor/go-xsd-duration => gitea.com/gitea/go-xsd-duration v0.0.0-20220703122237-02e73435a078
329+
328330
exclude github.com/gofrs/uuid v3.2.0+incompatible
329331

330332
exclude github.com/gofrs/uuid v4.0.0+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
1414
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
1515
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
1616
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
17-
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4HHsCo6xi2oWZYKWW4bly/Ory9FuTpFPRxj/mAg=
18-
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
1917
gitea.com/gitea/act v0.261.4 h1:Tf9eLlvsYFtKcpuxlMvf9yT3g4Hshb2Beqw6C1STuH8=
2018
gitea.com/gitea/act v0.261.4/go.mod h1:Pg5C9kQY1CEA3QjthjhlrqOC/QOT5NyWNjOjRHw23Ok=
2119
gitea.com/gitea/git-lfs-transfer v0.2.0 h1:baHaNoBSRaeq/xKayEXwiDQtlIjps4Ac/Ll4KqLMB40=
2220
gitea.com/gitea/git-lfs-transfer v0.2.0/go.mod h1:UrXUCm3xLQkq15fu7qlXHUMlrhdlXHoi13KH2Dfiits=
21+
gitea.com/gitea/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:BAFmdZpRW7zMQZQDClaCWobRj9uL1MR3MzpCVJvc5s4=
22+
gitea.com/gitea/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
2323
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed h1:EZZBtilMLSZNWtHHcgq2mt6NSGhJSZBuduAlinMEmso=
2424
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed/go.mod h1:E3i3cgB04dDx0v3CytCgRTTn9Z/9x891aet3r456RVw=
2525
gitea.com/go-chi/cache v0.2.1 h1:bfAPkvXlbcZxPCpcmDVCWoHgiBSBmZN/QosnZvEC0+g=

models/actions/artifact.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ const (
3030
ArtifactStatusDeleted // 6, ArtifactStatusDeleted is the status of an artifact that is deleted
3131
)
3232

33+
func (status ArtifactStatus) ToString() string {
34+
switch status {
35+
case ArtifactStatusUploadPending:
36+
return "upload is not yet completed"
37+
case ArtifactStatusUploadConfirmed:
38+
return "upload is completed"
39+
case ArtifactStatusUploadError:
40+
return "upload failed"
41+
case ArtifactStatusExpired:
42+
return "expired"
43+
case ArtifactStatusPendingDeletion:
44+
return "pending deletion"
45+
case ArtifactStatusDeleted:
46+
return "deleted"
47+
default:
48+
return "unknown"
49+
}
50+
}
51+
3352
func init() {
3453
db.RegisterModel(new(ActionArtifact))
3554
}

models/auth/source.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ var Names = map[Type]string{
5858
// Config represents login config as far as the db is concerned
5959
type Config interface {
6060
convert.Conversion
61+
SetAuthSource(*Source)
62+
}
63+
64+
type ConfigBase struct {
65+
AuthSource *Source
66+
}
67+
68+
func (p *ConfigBase) SetAuthSource(s *Source) {
69+
p.AuthSource = s
6170
}
6271

6372
// SkipVerifiable configurations provide a IsSkipVerify to check if SkipVerify is set
@@ -104,19 +113,15 @@ func RegisterTypeConfig(typ Type, exemplar Config) {
104113
}
105114
}
106115

107-
// SourceSettable configurations can have their authSource set on them
108-
type SourceSettable interface {
109-
SetAuthSource(*Source)
110-
}
111-
112116
// Source represents an external way for authorizing users.
113117
type Source struct {
114-
ID int64 `xorm:"pk autoincr"`
115-
Type Type
116-
Name string `xorm:"UNIQUE"`
117-
IsActive bool `xorm:"INDEX NOT NULL DEFAULT false"`
118-
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
119-
Cfg convert.Conversion `xorm:"TEXT"`
118+
ID int64 `xorm:"pk autoincr"`
119+
Type Type
120+
Name string `xorm:"UNIQUE"`
121+
IsActive bool `xorm:"INDEX NOT NULL DEFAULT false"`
122+
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
123+
TwoFactorPolicy string `xorm:"two_factor_policy NOT NULL DEFAULT ''"`
124+
Cfg Config `xorm:"TEXT"`
120125

121126
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
122127
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
@@ -140,9 +145,7 @@ func (source *Source) BeforeSet(colName string, val xorm.Cell) {
140145
return
141146
}
142147
source.Cfg = constructor()
143-
if settable, ok := source.Cfg.(SourceSettable); ok {
144-
settable.SetAuthSource(source)
145-
}
148+
source.Cfg.SetAuthSource(source)
146149
}
147150
}
148151

@@ -200,6 +203,10 @@ func (source *Source) SkipVerify() bool {
200203
return ok && skipVerifiable.IsSkipVerify()
201204
}
202205

206+
func (source *Source) TwoFactorShouldSkip() bool {
207+
return source.TwoFactorPolicy == "skip"
208+
}
209+
203210
// CreateSource inserts a AuthSource in the DB if not already
204211
// existing with the given name.
205212
func CreateSource(ctx context.Context, source *Source) error {
@@ -223,9 +230,7 @@ func CreateSource(ctx context.Context, source *Source) error {
223230
return nil
224231
}
225232

226-
if settable, ok := source.Cfg.(SourceSettable); ok {
227-
settable.SetAuthSource(source)
228-
}
233+
source.Cfg.SetAuthSource(source)
229234

230235
registerableSource, ok := source.Cfg.(RegisterableSource)
231236
if !ok {
@@ -320,9 +325,7 @@ func UpdateSource(ctx context.Context, source *Source) error {
320325
return nil
321326
}
322327

323-
if settable, ok := source.Cfg.(SourceSettable); ok {
324-
settable.SetAuthSource(source)
325-
}
328+
source.Cfg.SetAuthSource(source)
326329

327330
registerableSource, ok := source.Cfg.(RegisterableSource)
328331
if !ok {

models/auth/source_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
)
2020

2121
type TestSource struct {
22+
auth_model.ConfigBase
23+
2224
Provider string
2325
ClientID string
2426
ClientSecret string

models/auth/twofactor.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,13 @@ func DeleteTwoFactorByID(ctx context.Context, id, userID int64) error {
164164
}
165165
return nil
166166
}
167+
168+
func HasTwoFactorOrWebAuthn(ctx context.Context, id int64) (bool, error) {
169+
has, err := HasTwoFactorByUID(ctx, id)
170+
if err != nil {
171+
return false, err
172+
} else if has {
173+
return true, nil
174+
}
175+
return HasWebAuthnRegistrationsByUID(ctx, id)
176+
}

models/fixtures/action_artifact.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111
content_encoding: ""
1212
artifact_path: "abc.txt"
1313
artifact_name: "artifact-download"
14+
status: 2
15+
created_unix: 1712338649
16+
updated_unix: 1712338649
17+
expired_unix: 1720114649
18+
19+
-
20+
id: 2
21+
run_id: 791
22+
runner_id: 1
23+
repo_id: 4
24+
owner_id: 1
25+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
26+
storage_path: ""
27+
file_size: 1024
28+
file_compressed_size: 1024
29+
content_encoding: "30/20/1712348022422036662.chunk"
30+
artifact_path: "abc.txt"
31+
artifact_name: "artifact-download-incomplete"
1432
status: 1
1533
created_unix: 1712338649
1634
updated_unix: 1712338649

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ func prepareMigrationTasks() []*migration {
381381
newMigration(317, "Add new index for action for heatmap", v1_24.AddNewIndexForUserDashboard),
382382
newMigration(318, "Add anonymous_access_mode for repo_unit", v1_24.AddRepoUnitAnonymousAccessMode),
383383
newMigration(319, "Add ExclusiveOrder to Label table", v1_24.AddExclusiveOrderColumnToLabelTable),
384+
newMigration(320, "Migrate two_factor_policy to login_source table", v1_24.MigrateSkipTwoFactor),
384385
}
385386
return preparedMigrations
386387
}

0 commit comments

Comments
 (0)