Skip to content

Commit 0ed2e89

Browse files
authored
Merge branch 'main' into lunny/fix_hunk_missing_at
2 parents fdac8bd + 56eccb4 commit 0ed2e89

Some content is hidden

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

51 files changed

+708
-374
lines changed

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ RUN chmod 755 /tmp/local/usr/bin/entrypoint \
3939
/tmp/local/etc/s6/.s6-svscan/* \
4040
/go/src/code.gitea.io/gitea/gitea \
4141
/go/src/code.gitea.io/gitea/environment-to-ini
42-
RUN chmod 644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete
4342

4443
FROM docker.io/library/alpine:3.22
4544
LABEL maintainer="[email protected]"
@@ -83,4 +82,3 @@ CMD ["/usr/bin/s6-svscan", "/etc/s6"]
8382
COPY --from=build-env /tmp/local /
8483
COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
8584
COPY --from=build-env /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
86-
COPY --from=build-env /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh

Dockerfile.rootless

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ RUN chmod 755 /tmp/local/usr/local/bin/docker-entrypoint.sh \
3737
/tmp/local/usr/local/bin/gitea \
3838
/go/src/code.gitea.io/gitea/gitea \
3939
/go/src/code.gitea.io/gitea/environment-to-ini
40-
RUN chmod 644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete
4140

4241
FROM docker.io/library/alpine:3.22
4342
LABEL maintainer="[email protected]"
@@ -72,7 +71,6 @@ RUN chown git:git /var/lib/gitea /etc/gitea
7271
COPY --from=build-env /tmp/local /
7372
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
7473
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
75-
COPY --from=build-env /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh
7674

7775
# git:git
7876
USER 1000:1000

cmd/admin_auth_oauth.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func oauthCLIFlags() []cli.Flag {
8787
Value: nil,
8888
Usage: "Scopes to request when to authenticate against this OAuth2 source",
8989
},
90+
&cli.StringFlag{
91+
Name: "ssh-public-key-claim-name",
92+
Usage: "Claim name that provides SSH public keys",
93+
},
94+
&cli.StringFlag{
95+
Name: "full-name-claim-name",
96+
Usage: "Claim name that provides user's full name",
97+
},
9098
&cli.StringFlag{
9199
Name: "required-claim-name",
92100
Value: "",
@@ -177,6 +185,8 @@ func parseOAuth2Config(c *cli.Command) *oauth2.Source {
177185
RestrictedGroup: c.String("restricted-group"),
178186
GroupTeamMap: c.String("group-team-map"),
179187
GroupTeamMapRemoval: c.Bool("group-team-map-removal"),
188+
SSHPublicKeyClaimName: c.String("ssh-public-key-claim-name"),
189+
FullNameClaimName: c.String("full-name-claim-name"),
180190
}
181191
}
182192

@@ -268,6 +278,12 @@ func (a *authService) runUpdateOauth(ctx context.Context, c *cli.Command) error
268278
if c.IsSet("group-team-map-removal") {
269279
oAuth2Config.GroupTeamMapRemoval = c.Bool("group-team-map-removal")
270280
}
281+
if c.IsSet("ssh-public-key-claim-name") {
282+
oAuth2Config.SSHPublicKeyClaimName = c.String("ssh-public-key-claim-name")
283+
}
284+
if c.IsSet("full-name-claim-name") {
285+
oAuth2Config.FullNameClaimName = c.String("full-name-claim-name")
286+
}
271287

272288
// update custom URL mapping
273289
customURLMapping := &oauth2.CustomURLMapping{}

cmd/admin_auth_oauth_test.go

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func TestAddOauth(t *testing.T) {
8888
"--restricted-group", "restricted",
8989
"--group-team-map", `{"group1": [1,2]}`,
9090
"--group-team-map-removal=true",
91+
"--ssh-public-key-claim-name", "attr_ssh_pub_key",
92+
"--full-name-claim-name", "attr_full_name",
9193
},
9294
source: &auth_model.Source{
9395
Type: auth_model.OAuth2,
@@ -104,15 +106,17 @@ func TestAddOauth(t *testing.T) {
104106
EmailURL: "https://example.com/email",
105107
Tenant: "some_tenant",
106108
},
107-
IconURL: "https://example.com/icon",
108-
Scopes: []string{"scope1", "scope2"},
109-
RequiredClaimName: "claim_name",
110-
RequiredClaimValue: "claim_value",
111-
GroupClaimName: "group_name",
112-
AdminGroup: "admin",
113-
RestrictedGroup: "restricted",
114-
GroupTeamMap: `{"group1": [1,2]}`,
115-
GroupTeamMapRemoval: true,
109+
IconURL: "https://example.com/icon",
110+
Scopes: []string{"scope1", "scope2"},
111+
RequiredClaimName: "claim_name",
112+
RequiredClaimValue: "claim_value",
113+
GroupClaimName: "group_name",
114+
AdminGroup: "admin",
115+
RestrictedGroup: "restricted",
116+
GroupTeamMap: `{"group1": [1,2]}`,
117+
GroupTeamMapRemoval: true,
118+
SSHPublicKeyClaimName: "attr_ssh_pub_key",
119+
FullNameClaimName: "attr_full_name",
116120
},
117121
TwoFactorPolicy: "skip",
118122
},
@@ -223,15 +227,17 @@ func TestUpdateOauth(t *testing.T) {
223227
EmailURL: "https://old.example.com/email",
224228
Tenant: "old_tenant",
225229
},
226-
IconURL: "https://old.example.com/icon",
227-
Scopes: []string{"old_scope1", "old_scope2"},
228-
RequiredClaimName: "old_claim_name",
229-
RequiredClaimValue: "old_claim_value",
230-
GroupClaimName: "old_group_name",
231-
AdminGroup: "old_admin",
232-
RestrictedGroup: "old_restricted",
233-
GroupTeamMap: `{"old_group1": [1,2]}`,
234-
GroupTeamMapRemoval: true,
230+
IconURL: "https://old.example.com/icon",
231+
Scopes: []string{"old_scope1", "old_scope2"},
232+
RequiredClaimName: "old_claim_name",
233+
RequiredClaimValue: "old_claim_value",
234+
GroupClaimName: "old_group_name",
235+
AdminGroup: "old_admin",
236+
RestrictedGroup: "old_restricted",
237+
GroupTeamMap: `{"old_group1": [1,2]}`,
238+
GroupTeamMapRemoval: true,
239+
SSHPublicKeyClaimName: "old_ssh_pub_key",
240+
FullNameClaimName: "old_full_name",
235241
},
236242
TwoFactorPolicy: "",
237243
},
@@ -257,6 +263,8 @@ func TestUpdateOauth(t *testing.T) {
257263
"--restricted-group", "restricted",
258264
"--group-team-map", `{"group1": [1,2]}`,
259265
"--group-team-map-removal=false",
266+
"--ssh-public-key-claim-name", "new_ssh_pub_key",
267+
"--full-name-claim-name", "new_full_name",
260268
},
261269
authSource: &auth_model.Source{
262270
ID: 1,
@@ -274,15 +282,17 @@ func TestUpdateOauth(t *testing.T) {
274282
EmailURL: "https://example.com/email",
275283
Tenant: "new_tenant",
276284
},
277-
IconURL: "https://example.com/icon",
278-
Scopes: []string{"scope1", "scope2"},
279-
RequiredClaimName: "claim_name",
280-
RequiredClaimValue: "claim_value",
281-
GroupClaimName: "group_name",
282-
AdminGroup: "admin",
283-
RestrictedGroup: "restricted",
284-
GroupTeamMap: `{"group1": [1,2]}`,
285-
GroupTeamMapRemoval: false,
285+
IconURL: "https://example.com/icon",
286+
Scopes: []string{"scope1", "scope2"},
287+
RequiredClaimName: "claim_name",
288+
RequiredClaimValue: "claim_value",
289+
GroupClaimName: "group_name",
290+
AdminGroup: "admin",
291+
RestrictedGroup: "restricted",
292+
GroupTeamMap: `{"group1": [1,2]}`,
293+
GroupTeamMapRemoval: false,
294+
SSHPublicKeyClaimName: "new_ssh_pub_key",
295+
FullNameClaimName: "new_full_name",
286296
},
287297
TwoFactorPolicy: "skip",
288298
},

models/asymkey/gpg_key_commit_verification.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,15 @@ import (
1515
"github.com/ProtonMail/go-crypto/openpgp/packet"
1616
)
1717

18-
// __________________ ________ ____ __.
19-
// / _____/\______ \/ _____/ | |/ _|____ ___.__.
20-
// / \ ___ | ___/ \ ___ | <_/ __ < | |
21-
// \ \_\ \| | \ \_\ \ | | \ ___/\___ |
22-
// \______ /|____| \______ / |____|__ \___ > ____|
23-
// \/ \/ \/ \/\/
24-
// _________ .__ __
25-
// \_ ___ \ ____ _____ _____ |__|/ |_
26-
// / \ \/ / _ \ / \ / \| \ __\
27-
// \ \___( <_> ) Y Y \ Y Y \ || |
28-
// \______ /\____/|__|_| /__|_| /__||__|
29-
// \/ \/ \/
30-
// ____ ____ .__ _____.__ __ .__
31-
// \ \ / /___________|__|/ ____\__| ____ _____ _/ |_|__| ____ ____
32-
// \ Y // __ \_ __ \ \ __\| |/ ___\\__ \\ __\ |/ _ \ / \
33-
// \ /\ ___/| | \/ || | | \ \___ / __ \| | | ( <_> ) | \
34-
// \___/ \___ >__| |__||__| |__|\___ >____ /__| |__|\____/|___| /
35-
// \/ \/ \/ \/
36-
3718
// This file provides functions relating commit verification
3819

3920
// CommitVerification represents a commit validation of signature
4021
type CommitVerification struct {
4122
Verified bool
4223
Warning bool
4324
Reason string
44-
SigningUser *user_model.User
45-
CommittingUser *user_model.User
25+
SigningUser *user_model.User // if Verified, then SigningUser is non-nil
26+
CommittingUser *user_model.User // if Verified, then CommittingUser is non-nil
4627
SigningEmail string
4728
SigningKey *GPGKey
4829
SigningSSHKey *PublicKey

models/asymkey/ssh_key.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ func AddPublicKeysBySource(ctx context.Context, usr *user_model.User, s *auth.So
355355
return sshKeysNeedUpdate
356356
}
357357

358-
// SynchronizePublicKeys updates a users public keys. Returns true if there are changes.
358+
// SynchronizePublicKeys updates a user's public keys. Returns true if there are changes.
359359
func SynchronizePublicKeys(ctx context.Context, usr *user_model.User, s *auth.Source, sshPublicKeys []string) bool {
360360
var sshKeysNeedUpdate bool
361361

362362
log.Trace("synchronizePublicKeys[%s]: Handling Public SSH Key synchronization for user %s", s.Name, usr.Name)
363363

364-
// Get Public Keys from DB with current LDAP source
364+
// Get Public Keys from DB with the current auth source
365365
var giteaKeys []string
366366
keys, err := db.Find[PublicKey](ctx, FindPublicKeyOptions{
367367
OwnerID: usr.ID,

models/auth/oauth2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ func (err ErrOAuthApplicationNotFound) Unwrap() error {
612612
return util.ErrNotExist
613613
}
614614

615-
// GetActiveOAuth2SourceByName returns a OAuth2 AuthSource based on the given name
616-
func GetActiveOAuth2SourceByName(ctx context.Context, name string) (*Source, error) {
615+
// GetActiveOAuth2SourceByAuthName returns a OAuth2 AuthSource based on the given name
616+
func GetActiveOAuth2SourceByAuthName(ctx context.Context, name string) (*Source, error) {
617617
authSource := new(Source)
618618
has, err := db.GetEngine(ctx).Where("name = ? and type = ? and is_active = ?", name, OAuth2, true).Get(authSource)
619619
if err != nil {

models/auth/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func UpdateSource(ctx context.Context, source *Source) error {
334334

335335
err = registerableSource.RegisterSource()
336336
if err != nil {
337-
// restore original values since we cannot update the provider it self
337+
// restore original values since we cannot update the provider itself
338338
if _, err := db.GetEngine(ctx).ID(source.ID).AllCols().Update(originalSource); err != nil {
339339
log.Error("UpdateSource: Error while wrapOpenIDConnectInitializeError: %v", err)
340340
}

models/user/user.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,12 +1166,6 @@ func ValidateCommitsWithEmails(ctx context.Context, oldCommits []*git.Commit) ([
11661166

11671167
for _, c := range oldCommits {
11681168
user := emailUserMap.GetByEmail(c.Author.Email) // FIXME: why ValidateCommitsWithEmails uses "Author", but ParseCommitsWithSignature uses "Committer"?
1169-
if user == nil {
1170-
user = &User{
1171-
Name: c.Author.Name,
1172-
Email: c.Author.Email,
1173-
}
1174-
}
11751169
newCommits = append(newCommits, &UserCommit{
11761170
User: user,
11771171
Commit: c,
@@ -1195,12 +1189,14 @@ func GetUsersByEmails(ctx context.Context, emails []string) (*EmailUserMap, erro
11951189

11961190
needCheckEmails := make(container.Set[string])
11971191
needCheckUserNames := make(container.Set[string])
1192+
noReplyAddressSuffix := "@" + strings.ToLower(setting.Service.NoReplyAddress)
11981193
for _, email := range emails {
1199-
if strings.HasSuffix(email, "@"+setting.Service.NoReplyAddress) {
1200-
username := strings.TrimSuffix(email, "@"+setting.Service.NoReplyAddress)
1201-
needCheckUserNames.Add(strings.ToLower(username))
1194+
emailLower := strings.ToLower(email)
1195+
if noReplyUserNameLower, ok := strings.CutSuffix(emailLower, noReplyAddressSuffix); ok {
1196+
needCheckUserNames.Add(noReplyUserNameLower)
1197+
needCheckEmails.Add(emailLower)
12021198
} else {
1203-
needCheckEmails.Add(strings.ToLower(email))
1199+
needCheckEmails.Add(emailLower)
12041200
}
12051201
}
12061202

models/user/user_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func TestUserEmails(t *testing.T) {
8585
testGetUserByEmail(t, c.Email, c.UID)
8686
})
8787
}
88+
89+
t.Run("NoReplyConflict", func(t *testing.T) {
90+
setting.Service.NoReplyAddress = "example.com"
91+
testGetUserByEmail(t, "[email protected]", 1)
92+
})
8893
})
8994
}
9095

0 commit comments

Comments
 (0)