Skip to content

Commit

Permalink
Support LDAP username_as_alias Attribute (#1460)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Ash <32777270+benashz@users.noreply.github.com>
  • Loading branch information
in0rdr and benashz committed Jun 1, 2022
1 parent ac99471 commit 7205d99
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions vault/resource_ldap_auth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func ldapAuthBackendResource() *schema.Resource {
Optional: true,
Computed: true,
},
"username_as_alias": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Force the auth method to use the username passed by the user as the alias name.",
},
"use_token_groups": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -273,6 +279,10 @@ func ldapAuthBackendUpdate(ctx context.Context, d *schema.ResourceData, meta int
data["groupattr"] = v.(string)
}

if v, ok := d.GetOkExists("username_as_alias"); ok {
data["username_as_alias"] = v.(bool)
}

if v, ok := d.GetOkExists("use_token_groups"); ok {
data["use_token_groups"] = v.(bool)
}
Expand Down Expand Up @@ -354,6 +364,7 @@ func ldapAuthBackendRead(_ context.Context, d *schema.ResourceData, meta interfa
d.Set("groupfilter", resp.Data["groupfilter"])
d.Set("groupdn", resp.Data["groupdn"])
d.Set("groupattr", resp.Data["groupattr"])
d.Set("username_as_alias", resp.Data["username_as_alias"])
d.Set("use_token_groups", resp.Data["use_token_groups"])

// `bindpass`, `client_tls_cert` and `client_tls_key` cannot be read out from the API
Expand Down
4 changes: 3 additions & 1 deletion vault/resource_ldap_auth_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func testLDAPAuthBackendCheck_attrs(path string) resource.TestCheckFunc {
"deny_null_bind": "deny_null_bind",
"upndomain": "upndomain",
"groupfilter": "groupfilter",
"username_as_alias": "username_as_alias",
"groupdn": "groupdn",
"groupattr": "groupattr",
"use_token_groups": "use_token_groups",
Expand Down Expand Up @@ -284,7 +285,8 @@ resource "vault_ldap_auth_backend" "test" {
discoverdn = false
deny_null_bind = true
description = "example"
userfilter = "({{.UserAttr}}={{.Username}})"
userfilter = "({{.UserAttr}}={{.Username}})"
username_as_alias = true
use_token_groups = %s
}
`, path, local, use_token_groups)
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/ldap_auth_backend.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ The following arguments are supported:

* `groupattr` - (Optional) LDAP attribute to follow on objects returned by groupfilter

* `username_as_alias` - (Optional) Force the auth method to use the username passed by the user as the alias name.

* `use_token_groups` - (Optional) Use the Active Directory tokenGroups constructed attribute of the user to find the group memberships

* `path` - (Optional) Path to mount the LDAP auth backend under
Expand Down

0 comments on commit 7205d99

Please sign in to comment.