Skip to content

Commit 5407382

Browse files
authored
Add cli flags LDAP group configuration (go-gitea#33933)
Add 7 new flags to ldap subcommands corresponding to UI options Closes CLI part of go-gitea#20716
1 parent a9e8ac0 commit 5407382

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

cmd/admin_auth_ldap.go

+49
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,34 @@ var (
127127
&cli.UintFlag{
128128
Name: "page-size",
129129
Usage: "Search page size.",
130+
},
131+
&cli.BoolFlag{
132+
Name: "enable-groups",
133+
Usage: "Enable LDAP groups",
134+
},
135+
&cli.StringFlag{
136+
Name: "group-search-base-dn",
137+
Usage: "The LDAP base DN at which group accounts will be searched for",
138+
},
139+
&cli.StringFlag{
140+
Name: "group-member-attribute",
141+
Usage: "Group attribute containing list of users",
142+
},
143+
&cli.StringFlag{
144+
Name: "group-user-attribute",
145+
Usage: "User attribute listed in group",
146+
},
147+
&cli.StringFlag{
148+
Name: "group-filter",
149+
Usage: "Verify group membership in LDAP",
150+
},
151+
&cli.StringFlag{
152+
Name: "group-team-map",
153+
Usage: "Map LDAP groups to Organization teams",
154+
},
155+
&cli.BoolFlag{
156+
Name: "group-team-map-removal",
157+
Usage: "Remove users from synchronized teams if user does not belong to corresponding LDAP group",
130158
})
131159

132160
ldapSimpleAuthCLIFlags = append(commonLdapCLIFlags,
@@ -273,6 +301,27 @@ func parseLdapConfig(c *cli.Context, config *ldap.Source) error {
273301
if c.IsSet("skip-local-2fa") {
274302
config.SkipLocalTwoFA = c.Bool("skip-local-2fa")
275303
}
304+
if c.IsSet("enable-groups") {
305+
config.GroupsEnabled = c.Bool("enable-groups")
306+
}
307+
if c.IsSet("group-search-base-dn") {
308+
config.GroupDN = c.String("group-search-base-dn")
309+
}
310+
if c.IsSet("group-member-attribute") {
311+
config.GroupMemberUID = c.String("group-member-attribute")
312+
}
313+
if c.IsSet("group-user-attribute") {
314+
config.UserUID = c.String("group-user-attribute")
315+
}
316+
if c.IsSet("group-filter") {
317+
config.GroupFilter = c.String("group-filter")
318+
}
319+
if c.IsSet("group-team-map") {
320+
config.GroupTeamMap = c.String("group-team-map")
321+
}
322+
if c.IsSet("group-team-map-removal") {
323+
config.GroupTeamMapRemoval = c.Bool("group-team-map-removal")
324+
}
276325
return nil
277326
}
278327

cmd/admin_auth_ldap_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ func TestAddLdapBindDn(t *testing.T) {
5151
"--attributes-in-bind",
5252
"--synchronize-users",
5353
"--page-size", "99",
54+
"--enable-groups",
55+
"--group-search-base-dn", "ou=group,dc=full-domain-bind,dc=org",
56+
"--group-member-attribute", "memberUid",
57+
"--group-user-attribute", "uid",
58+
"--group-filter", "(|(cn=gitea_users)(cn=admins))",
59+
"--group-team-map", `{"cn=my-group,cn=groups,dc=example,dc=org": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}`,
60+
"--group-team-map-removal",
5461
},
5562
source: &auth.Source{
5663
Type: auth.LDAP,
@@ -78,6 +85,13 @@ func TestAddLdapBindDn(t *testing.T) {
7885
AdminFilter: "(memberOf=cn=admin-group,ou=example,dc=full-domain-bind,dc=org)",
7986
RestrictedFilter: "(memberOf=cn=restricted-group,ou=example,dc=full-domain-bind,dc=org)",
8087
Enabled: true,
88+
GroupsEnabled: true,
89+
GroupDN: "ou=group,dc=full-domain-bind,dc=org",
90+
GroupMemberUID: "memberUid",
91+
UserUID: "uid",
92+
GroupFilter: "(|(cn=gitea_users)(cn=admins))",
93+
GroupTeamMap: `{"cn=my-group,cn=groups,dc=example,dc=org": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}`,
94+
GroupTeamMapRemoval: true,
8195
},
8296
},
8397
},
@@ -510,6 +524,13 @@ func TestUpdateLdapBindDn(t *testing.T) {
510524
"--bind-password", "secret-bind-full",
511525
"--synchronize-users",
512526
"--page-size", "99",
527+
"--enable-groups",
528+
"--group-search-base-dn", "ou=group,dc=full-domain-bind,dc=org",
529+
"--group-member-attribute", "memberUid",
530+
"--group-user-attribute", "uid",
531+
"--group-filter", "(|(cn=gitea_users)(cn=admins))",
532+
"--group-team-map", `{"cn=my-group,cn=groups,dc=example,dc=org": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}`,
533+
"--group-team-map-removal",
513534
},
514535
id: 23,
515536
existingAuthSource: &auth.Source{
@@ -545,6 +566,13 @@ func TestUpdateLdapBindDn(t *testing.T) {
545566
AdminFilter: "(memberOf=cn=admin-group,ou=example,dc=full-domain-bind,dc=org)",
546567
RestrictedFilter: "(memberOf=cn=restricted-group,ou=example,dc=full-domain-bind,dc=org)",
547568
Enabled: true,
569+
GroupsEnabled: true,
570+
GroupDN: "ou=group,dc=full-domain-bind,dc=org",
571+
GroupMemberUID: "memberUid",
572+
UserUID: "uid",
573+
GroupFilter: "(|(cn=gitea_users)(cn=admins))",
574+
GroupTeamMap: `{"cn=my-group,cn=groups,dc=example,dc=org": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}`,
575+
GroupTeamMapRemoval: true,
548576
},
549577
},
550578
},

0 commit comments

Comments
 (0)