Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for max_page_size in the vault_ldap_auth_backend #1878

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions vault/resource_ldap_auth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func ldapAuthBackendResource() *schema.Resource {
Optional: true,
Computed: true,
},
"max_page_size": {
Type: schema.TypeInt,
Default: -1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Vault API returns a default for this field then we should not set a Default in the provider. We can instead set this field to Computed: true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that currently Vault API returns the wrong value (0) instead of (-1), which breaks most LDAP implementations, as it causes no results to be sent. They have their own PR with a fix being made, but this change makes it backwards compatible.

https://developer.hashicorp.com/vault/api-docs/auth/ldap#max_page_size

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks for the explanation. I think in this case we can set the Default then.

Optional: true,
},
"userdn": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -266,6 +271,11 @@ func ldapAuthBackendUpdate(ctx context.Context, d *schema.ResourceData, meta int
if v, ok := d.GetOkExists("case_sensitive_names"); ok {
data["case_sensitive_names"] = v.(bool)
}

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

if v, ok := d.GetOk("userdn"); ok {
data["userdn"] = v.(string)
}
Expand Down Expand Up @@ -381,6 +391,7 @@ func ldapAuthBackendRead(_ context.Context, d *schema.ResourceData, meta interfa
d.Set("certificate", resp.Data["certificate"])
d.Set("binddn", resp.Data["binddn"])
d.Set("case_sensitive_names", resp.Data["case_sensitive_names"])
d.Set("max_page_size", resp.Data["max_page_size"])
d.Set("userdn", resp.Data["userdn"])
d.Set("userattr", resp.Data["userattr"])
d.Set("userfilter", resp.Data["userfilter"])
Expand Down
2 changes: 2 additions & 0 deletions vault/resource_ldap_auth_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func testLDAPAuthBackendCheck_attrs(resourceName string, name string) resource.T
"url": "url",
"starttls": "starttls",
"case_sensitive_names": "case_sensitive_names",
"max_page_size": "max_page_size",
"tls_min_version": "tls_min_version",
"tls_max_version": "tls_max_version",
"insecure_tls": "insecure_tls",
Expand Down Expand Up @@ -260,6 +261,7 @@ resource "vault_ldap_auth_backend" "test" {
url = "ldaps://example.org"
starttls = true
case_sensitive_names = false
max_page_size = -1
tls_min_version = "tls11"
tls_max_version = "tls12"
insecure_tls = false
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 @@ -40,6 +40,8 @@ The following arguments are supported:

* `case_sensitive_names` - (Optional) Control case senstivity of objects fetched from LDAP, this is used for object matching in vault

* `max_page_size` - (Optional) Sets the max page size for LDAP lookups, by default it's set to -1

* `tls_min_version` - (Optional) Minimum acceptable version of TLS

* `tls_max_version` - (Optional) Maximum acceptable version of TLS
Expand Down