Skip to content

Commit fbc6abf

Browse files
authored
Merge branch 'main' into feature/workflow-graph
2 parents 07094e1 + 19e1997 commit fbc6abf

File tree

15 files changed

+38
-14
lines changed

15 files changed

+38
-14
lines changed

cmd/admin_auth_ldap.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ func commonLdapCLIFlags() []cli.Flag {
9494
Name: "public-ssh-key-attribute",
9595
Usage: "The attribute of the user’s LDAP record containing the user’s public ssh key.",
9696
},
97+
&cli.BoolFlag{
98+
Name: "ssh-keys-are-verified",
99+
Usage: "Set to true to automatically flag SSH keys in LDAP as verified.",
100+
},
97101
&cli.BoolFlag{
98102
Name: "skip-local-2fa",
99103
Usage: "Set to true to skip local 2fa for users authenticated by this source",
@@ -294,6 +298,9 @@ func parseLdapConfig(c *cli.Command, config *ldap.Source) error {
294298
if c.IsSet("public-ssh-key-attribute") {
295299
config.AttributeSSHPublicKey = c.String("public-ssh-key-attribute")
296300
}
301+
if c.IsSet("ssh-keys-are-verified") {
302+
config.SSHKeysAreVerified = c.Bool("ssh-keys-are-verified")
303+
}
297304
if c.IsSet("avatar-attribute") {
298305
config.AttributeAvatar = c.String("avatar-attribute")
299306
}

models/asymkey/ssh_key.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func addKey(ctx context.Context, key *PublicKey) (err error) {
8484
}
8585

8686
// AddPublicKey adds new public key to database and authorized_keys file.
87-
func AddPublicKey(ctx context.Context, ownerID int64, name, content string, authSourceID int64) (*PublicKey, error) {
87+
func AddPublicKey(ctx context.Context, ownerID int64, name, content string, authSourceID int64, verified bool) (*PublicKey, error) {
8888
log.Trace(content)
8989

9090
fingerprint, err := CalcFingerprint(content)
@@ -115,6 +115,7 @@ func AddPublicKey(ctx context.Context, ownerID int64, name, content string, auth
115115
Mode: perm.AccessModeWrite,
116116
Type: KeyTypeUser,
117117
LoginSourceID: authSourceID,
118+
Verified: verified,
118119
}
119120
if err = addKey(ctx, key); err != nil {
120121
return nil, fmt.Errorf("addKey: %w", err)
@@ -298,7 +299,7 @@ func deleteKeysMarkedForDeletion(ctx context.Context, keys []string) (bool, erro
298299
}
299300

300301
// AddPublicKeysBySource add a users public keys. Returns true if there are changes.
301-
func AddPublicKeysBySource(ctx context.Context, usr *user_model.User, s *auth.Source, sshPublicKeys []string) bool {
302+
func AddPublicKeysBySource(ctx context.Context, usr *user_model.User, s *auth.Source, sshPublicKeys []string, verified bool) bool {
302303
var sshKeysNeedUpdate bool
303304
for _, sshKey := range sshPublicKeys {
304305
var err error
@@ -317,7 +318,7 @@ func AddPublicKeysBySource(ctx context.Context, usr *user_model.User, s *auth.So
317318
marshalled = marshalled[:len(marshalled)-1]
318319
sshKeyName := fmt.Sprintf("%s-%s", s.Name, ssh.FingerprintSHA256(out))
319320

320-
if _, err := AddPublicKey(ctx, usr.ID, sshKeyName, marshalled, s.ID); err != nil {
321+
if _, err := AddPublicKey(ctx, usr.ID, sshKeyName, marshalled, s.ID, verified); err != nil {
321322
if IsErrKeyAlreadyExist(err) {
322323
log.Trace("AddPublicKeysBySource[%s]: Public SSH Key %s already exists for user", sshKeyName, usr.Name)
323324
} else {
@@ -336,7 +337,7 @@ func AddPublicKeysBySource(ctx context.Context, usr *user_model.User, s *auth.So
336337
}
337338

338339
// SynchronizePublicKeys updates a user's public keys. Returns true if there are changes.
339-
func SynchronizePublicKeys(ctx context.Context, usr *user_model.User, s *auth.Source, sshPublicKeys []string) bool {
340+
func SynchronizePublicKeys(ctx context.Context, usr *user_model.User, s *auth.Source, sshPublicKeys []string, verified bool) bool {
340341
var sshKeysNeedUpdate bool
341342

342343
log.Trace("synchronizePublicKeys[%s]: Handling Public SSH Key synchronization for user %s", s.Name, usr.Name)
@@ -381,7 +382,7 @@ func SynchronizePublicKeys(ctx context.Context, usr *user_model.User, s *auth.So
381382
newKeys = append(newKeys, key)
382383
}
383384
}
384-
if AddPublicKeysBySource(ctx, usr, s, newKeys) {
385+
if AddPublicKeysBySource(ctx, usr, s, newKeys, verified) {
385386
sshKeysNeedUpdate = true
386387
}
387388

options/locale/locale_en-US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,6 +3067,7 @@
30673067
"admin.auths.attribute_mail": "Email Attribute",
30683068
"admin.auths.attribute_ssh_public_key": "Public SSH Key Attribute",
30693069
"admin.auths.attribute_avatar": "Avatar Attribute",
3070+
"admin.auths.ssh_keys_are_verified": "SSH keys in LDAP are considered as verified",
30703071
"admin.auths.attributes_in_bind": "Fetch Attributes in Bind DN Context",
30713072
"admin.auths.allow_deactivate_all": "Allow an empty search result to deactivate all users",
30723073
"admin.auths.use_paged_search": "Use Paged Search",

routers/api/v1/user/key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid
211211
return
212212
}
213213

214-
key, err := asymkey_model.AddPublicKey(ctx, uid, form.Title, content, 0)
214+
key, err := asymkey_model.AddPublicKey(ctx, uid, form.Title, content, 0, false)
215215
if err != nil {
216216
repo.HandleAddKeyError(ctx, err)
217217
return

routers/web/admin/auths.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func parseLDAPConfig(form forms.AuthenticationForm) *ldap.Source {
136136
AttributesInBind: form.AttributesInBind,
137137
AttributeSSHPublicKey: form.AttributeSSHPublicKey,
138138
AttributeAvatar: form.AttributeAvatar,
139+
SSHKeysAreVerified: form.SSHKeysAreVerified,
139140
SearchPageSize: pageSize,
140141
Filter: form.Filter,
141142
GroupsEnabled: form.GroupsEnabled,

routers/web/auth/oauth_signin_sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func oauth2UpdateSSHPubIfNeed(ctx *context.Context, authSource *auth.Source, got
8686
if err != nil {
8787
return err
8888
}
89-
if !asymkey_model.SynchronizePublicKeys(ctx, user, authSource, sshKeys) {
89+
if !asymkey_model.SynchronizePublicKeys(ctx, user, authSource, sshKeys, false) {
9090
return nil
9191
}
9292
return asymkey_service.RewriteAllPublicKeys(ctx)

routers/web/user/setting/keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func KeysPost(ctx *context.Context) {
187187
return
188188
}
189189

190-
if _, err = asymkey_model.AddPublicKey(ctx, ctx.Doer.ID, form.Title, content, 0); err != nil {
190+
if _, err = asymkey_model.AddPublicKey(ctx, ctx.Doer.ID, form.Title, content, 0, false); err != nil {
191191
ctx.Data["HasSSHError"] = true
192192
switch {
193193
case asymkey_model.IsErrKeyAlreadyExist(err):

services/asymkey/commit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestParseCommitWithSSHSignature(t *testing.T) {
3131
// AAAEDWqPHTH51xb4hy1y1f1VeWL/2A9Q0b6atOyv5fx8x5prpPrMXSg9qTx04jPNPWRcHs
3232
// utyxWjThIpzcaO68yWVnAAAAEXVzZXIyQGV4YW1wbGUuY29tAQIDBA==
3333
// -----END OPENSSH PRIVATE KEY-----
34-
sshPubKey, err := asymkey_model.AddPublicKey(t.Context(), 999, "user-ssh-key-any-name", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILpPrMXSg9qTx04jPNPWRcHsutyxWjThIpzcaO68yWVn", 0)
34+
sshPubKey, err := asymkey_model.AddPublicKey(t.Context(), 999, "user-ssh-key-any-name", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILpPrMXSg9qTx04jPNPWRcHsutyxWjThIpzcaO68yWVn", 0, false)
3535
require.NoError(t, err)
3636
_, err = db.GetEngine(t.Context()).ID(sshPubKey.ID).Cols("verified").Update(&asymkey_model.PublicKey{Verified: true})
3737
require.NoError(t, err)

services/asymkey/ssh_key_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ssh-dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x/DZuYAz3ib
6666

6767
for i, kase := range testCases {
6868
s.ID = int64(i) + 20
69-
asymkey_model.AddPublicKeysBySource(t.Context(), user, s, []string{kase.keyString})
69+
asymkey_model.AddPublicKeysBySource(t.Context(), user, s, []string{kase.keyString}, false)
7070
keys, err := db.Find[asymkey_model.PublicKey](t.Context(), asymkey_model.FindPublicKeyOptions{
7171
OwnerID: user.ID,
7272
LoginSourceID: s.ID,

services/auth/source/ldap/source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Source struct {
4444
AttributesInBind bool // fetch attributes in bind context (not user)
4545
AttributeSSHPublicKey string // LDAP SSH Public Key attribute
4646
AttributeAvatar string
47+
SSHKeysAreVerified bool // true if SSH keys in LDAP are verified
4748
SearchPageSize uint32 // Search with paging page size
4849
Filter string // Query filter to validate entry
4950
AdminFilter string // Query filter to check if user is admin

0 commit comments

Comments
 (0)