Skip to content

feat(ldap-auth): add hide_credentials - #13832

Open
nic-6443 wants to merge 2 commits into
apache:masterfrom
nic-6443:feat/ldap-auth-hide-credentials
Open

feat(ldap-auth): add hide_credentials#13832
nic-6443 wants to merge 2 commits into
apache:masterfrom
nic-6443:feat/ldap-auth-hide-credentials

Conversation

@nic-6443

@nic-6443 nic-6443 commented Aug 16, 2026

Copy link
Copy Markdown
Member

Description

ldap-auth decodes the username and password from the Authorization header, binds to the directory with them, and then forwards that header to the upstream as it arrived. LDAP credentials are usually the organisation-wide ones and reusable well beyond the API being called, so handing them to every upstream behind the gateway is worth being able to turn off — basic-auth, jwt-auth, key-auth and hmac-auth all have hide_credentials for exactly this.

This adds the same option to ldap-auth, defaulting to false so existing routes behave as before.

One unrelated line rides along in its own commit: the success path logged hit basic-auth access, a copy-paste from basic-auth, and it sits right below the code this PR touches. Happy to drop it if you'd rather keep the PR to one thing.

Which issue(s) this PR fixes:

N/A

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

The plugin decodes the LDAP username and password from the Authorization
header and, after a successful bind, forwards that header to the upstream
untouched. Directory credentials are usually reusable well beyond the API
being called, and the upstream may be a low trust or multi tenant service.

Add the `hide_credentials` option the other auth plugins already have
(`basic-auth`, `jwt-auth`, `key-auth`, `hmac-auth`), defaulting to false to
keep the current behaviour.
Copilot AI lite review requested due to automatic review settings August 16, 2026 14:53
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Aug 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a hide_credentials option to the ldap-auth plugin so operators can prevent forwarding the incoming Authorization header (which contains reusable LDAP credentials) to upstream services, while keeping default behavior unchanged for backward compatibility.

Changes:

  • Add hide_credentials (default false) to apisix/plugins/ldap-auth.lua and strip Authorization when enabled.
  • Add regression tests validating both the default forwarding behavior and the hiding behavior.
  • Document the new attribute in both English and Chinese plugin docs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
apisix/plugins/ldap-auth.lua Adds hide_credentials config and removes Authorization header when enabled.
t/plugin/ldap-auth.t Adds tests to verify Authorization is forwarded by default and removed when hide_credentials=true.
docs/en/latest/plugins/ldap-auth.md Documents the new hide_credentials attribute.
docs/zh/latest/plugins/ldap-auth.md Documents the new hide_credentials attribute in Chinese.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread apisix/plugins/ldap-auth.lua Outdated
core.request.set_header(ctx, "Authorization", nil)
end

core.log.info("hit basic-auth access")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, that line predates this PR but it is right below the code I touched, so fixed in eadc0da: it logs hit ldap-auth access now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Split off would have meant a second PR for a five-word log line, so I mentioned it in the description instead — it is its own commit if you would rather it went elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants