Skip to content

Commit 1228de7

Browse files
author
Ivan Tkachev
committed
Add an option to automatically verify SSH keys from LDAP
1 parent e31f224 commit 1228de7

37 files changed

+60
-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_cs-CZ.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,6 +2950,7 @@ auths.attribute_surname=Atribut příjmení
29502950
auths.attribute_mail=Atribut e-mailové adresy
29512951
auths.attribute_ssh_public_key=Atribut veřejného SSH klíče
29522952
auths.attribute_avatar=Atributy avataru
2953+
auths.ssh_keys_are_verified=SSH klíče v LDAP jsou automaticky ověřovány.
29532954
auths.attributes_in_bind=Získat atributy v kontextu Bind DN
29542955
auths.allow_deactivate_all=Povolit prázdný výsledek hledání pro deaktivaci všech uživatelů
29552956
auths.use_paged_search=Použijte vyhledávání ve stránce

options/locale/locale_de-DE.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,7 @@ auths.attribute_surname=Nachnamensattribut
30003000
auths.attribute_mail=E-Mail-Attribut
30013001
auths.attribute_ssh_public_key=Öffentlicher-SSH-Schlüssel-Attribut
30023002
auths.attribute_avatar=Avatar-Attribut
3003+
auths.ssh_keys_are_verified=SSH-Schlüssel in LDAP werden automatisch überprüft
30033004
auths.attributes_in_bind=Hole Attribute im Bind-Kontext
30043005
auths.allow_deactivate_all=Erlaube ein leeres Suchergebnis, um alle Benutzer zu deaktivieren
30053006
auths.use_paged_search=Seitensuche verwenden

options/locale/locale_el-GR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,7 @@ auths.attribute_surname=Χαρακτηριστικό Επωνύμου
26922692
auths.attribute_mail=Χαρακτηριστικό Email
26932693
auths.attribute_ssh_public_key=Χαρακτηριστικό Δημόσιου Κλειδιού SSH
26942694
auths.attribute_avatar=Χαρακτηριστικό Εικόνας
2695+
auths.ssh_keys_are_verified=Οι κλειδιά SSH στο LDAP ελέγχονται αυτόματα
26952696
auths.attributes_in_bind=Λήψη χαρακτηριστικών μέσα στο πλαίσιο του Bind DN
26962697
auths.allow_deactivate_all=Επιτρέψτε σε ένα κενό αποτέλεσμα αναζήτησης να απενεργοποιήσει όλους τους χρήστες
26972698
auths.use_paged_search=Χρήση Σελιδοποιημένης Αναζήτησης

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,7 @@ auths.attribute_surname = Surname Attribute
32263226
auths.attribute_mail = Email Attribute
32273227
auths.attribute_ssh_public_key = Public SSH Key Attribute
32283228
auths.attribute_avatar = Avatar Attribute
3229+
auths.ssh_keys_are_verified = SSH keys in LDAP are automatically verified
32293230
auths.attributes_in_bind = Fetch Attributes in Bind DN Context
32303231
auths.allow_deactivate_all = Allow an empty search result to deactivate all users
32313232
auths.use_paged_search = Use Paged Search

options/locale/locale_es-ES.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,7 @@ auths.attribute_surname=Atributo apellido
26722672
auths.attribute_mail=Atributo correo electrónico
26732673
auths.attribute_ssh_public_key=Atributo Clave Pública SSH
26742674
auths.attribute_avatar=Atributo del avatar
2675+
auths.ssh_keys_are_verified=Las claves SSH en LDAP se verifican automáticamente
26752676
auths.attributes_in_bind=Obtener atributos en el contexto de Bind DN
26762677
auths.allow_deactivate_all=Permitir un resultado de búsqueda vacío para desactivar todos los usuarios
26772678
auths.use_paged_search=Usar búsqueda paginada

options/locale/locale_fa-IR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,7 @@ auths.attribute_surname=ویژگی نام خانوادگی
21112111
auths.attribute_mail=ویژگی ایمیل
21122112
auths.attribute_ssh_public_key=ویژگی های کلید SSH عمومی
21132113
auths.attribute_avatar=ویژگی آواتار
2114+
auths.ssh_keys_are_verified=کلیدهای SSH در LDAP به صورت خودکار تأیید می‌شوند.
21142115
auths.attributes_in_bind=واکشی ویژگی های DN متصل شده در متن زمینه
21152116
auths.allow_deactivate_all=به یک نتیجه جستجوی خالی اجازه دهید تا همه کاربران را غیرفعال کند
21162117
auths.use_paged_search=استفاده از جستجو ثبت شده

options/locale/locale_fr-FR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,7 @@ auths.attribute_surname=Attribut nom de famille
32263226
auths.attribute_mail=Attribut courriel
32273227
auths.attribute_ssh_public_key=Attribut clé SSH publique
32283228
auths.attribute_avatar=Attribut de l'avatar
3229+
auths.ssh_keys_are_verified=Les clés SSH dans LDAP sont vérifiées automatiquement
32293230
auths.attributes_in_bind=Aller chercher les attributs dans le contexte de liaison DN
32303231
auths.allow_deactivate_all=Permettre à un résultat de recherche vide de désactiver tous les utilisateurs
32313232
auths.use_paged_search=Utiliser la recherche paginée

options/locale/locale_ga-IE.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,7 @@ auths.attribute_surname=Tréith Sloinne
32263226
auths.attribute_mail=Tréith ríomhphoist
32273227
auths.attribute_ssh_public_key=Tréith Eochair SSH Phoiblí
32283228
auths.attribute_avatar=Tréith Avatar
3229+
auths.ssh_keys_are_verified=Tá eochracha SSH i LDAP agus déantar díriú orthu go huathoibríoch
32293230
auths.attributes_in_bind=Faigh tréithe i gComhthéacs Bind DN
32303231
auths.allow_deactivate_all=Lig do thoradh cuardaigh folamh gach úsáideoir a dhíghníomhachtú
32313232
auths.use_paged_search=Úsáid Cuardach Leathanaigh

0 commit comments

Comments
 (0)