You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by "smolnar82 (via GitHub)" <gi...@apache.org> on 2026/06/22 21:44:08 UTC

[PR] KNOX-3358: Support configurable bind credentials for the embedded Knox LDAP service [knox]

smolnar82 opened a new pull request, #1275:
URL: https://github.com/apache/knox/pull/1275

     [KNOX-3358](https://issues.apache.org/jira/browse/KNOX-3358) - Support configurable bind credentials for the embedded Knox LDAP service
   
     ## What changes were proposed in this pull request?
   
     The embedded Knox LDAP service (`KnoxLDAPService` / `KnoxLDAPServerManager`) called `directoryService.setAllowAnonymousAccess(true)` unconditionally, so any client could query the server with no credentials:
   ```
     $ ldapsearch -x -H ldap://localhost:33390 -b "" "(uid=admin)" cn mail memberOf
   ```
   succeeds with no `-D` / `-W`.
   
   This PR lets operators put the embedded server behind a bind user:
     - **`gateway.ldap.bind.user`** (new `gateway-site.xml` property) — the full bind DN clients must authenticate as (e.g. `uid=knox,ou=people,dc=hadoop,dc=apache,dc=org`).
     - **`gateway.ldap.bind.password`** (credential store alias) — the bind password, resolved from the gateway credential store via `AliasService` rather than stored in plaintext.
     
   Behavior:
     - When a bind user is configured **and** the `gateway.ldap.bind.password` alias resolves to a non-blank value, anonymous access is disabled and a bind entry (`inetOrgPerson`) is created for the configured DN via the privileged admin session. Clients **must** then bind with those credentials.
     - Otherwise (the default), anonymous access remains enabled exactly as before — fully backward compatible.
     
   The bind DN's parent container must already exist: the server auto-creates `ou=people,{base.dn}` and `ou=groups,{base.dn}` (and `ou=system` always exists), so the bind DN must sit under one of those.
     
     Changes:
     - `GatewayConfig` / `GatewayConfigImpl` / `GatewayTestConfig`: new `gateway.ldap.bind.user` property and `getLDAPBindUser()` getter.
     - `KnoxLDAPService`: gains an `AliasService` dependency (`setAliasService(...)`), injected by `LdapServiceFactory`, and passes it to the server manager.
     - `KnoxLDAPServerManager`: reads the bind user from config and the bind password from the `gateway.ldap.bind.password` gateway alias; conditionally disables anonymous access; new `createBindUser(...)` adds the bind entry.
     - `LdapMessages`: new INFO log emitted when bind enforcement is enabled. 
     - Docs: `knox-site/docs/service_ldap_server.md` — new "Bind Credentials" section (including the base DN ↔ bind DN relationship and a worked example) plus an updated _Anonymous Access_ note.
    
   ## How was this patch tested?
     
     - Added unit tests in `KnoxLDAPServerManagerTest` that start a real embedded server and use `LdapNetworkConnection` (with a mocked `AliasService` resolving the bind password) to verify:
       - anonymous bind is rejected when bind credentials are configured;
       - binding with the configured DN/password succeeds and can search;
       - binding with a wrong password is rejected (`LdapAuthenticationException`);
       - anonymous access still works when no bind credentials are configured (backward compat).
     - Updated `KnoxLDAPServiceTest` for the new `AliasService` dependency and the `getLDAPBindUser()` lookup.
     - `mvn -pl gateway-server test -Dtest=KnoxLDAPServerManagerTest,KnoxLDAPServiceTest` → BUILD SUCCESS, 25 tests pass; Checkstyle and PMD clean.
     - Manual end-to-end with `gateway.ldap.enabled=true`, `gateway.ldap.port=33390`,
       `gateway.ldap.base.dn=dc=hadoop,dc=apache,dc=org`,
       `gateway.ldap.bind.user=uid=knox,ou=people,dc=hadoop,dc=apache,dc=org`, and the
       `gateway.ldap.bind.password` alias created via
       `knoxcli.sh create-alias gateway.ldap.bind.password --value <password>`:
       - `ldapsearch -x -H ldap://localhost:33390 -b "" "(uid=admin)" cn` → fails (anonymous denied) 
       - `ldapsearch -x -H ldap://localhost:33390 -D "uid=knox,ou=people,dc=hadoop,dc=apache,dc=org" -w <password> -b "" "(uid=admin)" cn mail memberOf` → succeeds
     
   ## Integration Tests
   
   No new workflow integration tests were added; the feature is covered by the unit tests above, which exercise a real embedded LDAP server over a live socket (bind + search).
     
   ## UI changes                                                                                                                                                                                                                   
   
   N/A


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3358: Support configurable bind credentials for the embedded Knox LDAP service [knox]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #1275:
URL: https://github.com/apache/knox/pull/1275#issuecomment-4773395516

   ## Test Results
   28 tests   28 ✅  2s ⏱️
    1 suites   0 💤
    1 files     0 ❌
   
   Results for commit 2b0e6f2e.
   
   [test-results]:data:application/gzip;base64,H4sIACmuOWoC/12Myw6CMBBFf4V07aJMeYg/Y9phmkwEavpYGf/dglrB3T3nJuchLE8UxKWqT5UIiWOBMXkd2S0ZIWM+4nrB+QvXkBD/zI3v2cgirObpIMh75z/Gp6UU130IvsWvt/Eut/G+hm6eOWYQYCR1Foi0AlIaySgDrSUcaejroUdp2q4xjXi+AFeuXd7/AAAA
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3358: Support configurable bind credentials for the embedded Knox LDAP service [knox]

Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 merged PR #1275:
URL: https://github.com/apache/knox/pull/1275


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3358: Support configurable bind credentials for the embedded Knox LDAP service [knox]

Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on PR #1275:
URL: https://github.com/apache/knox/pull/1275#issuecomment-4773417037

   Manual testing results:
   
   gateway-site.xml changes:
   ```
       <property>
           <name>gateway.ldap.bind.user</name>
           <value>uid=knox,ou=people,dc=hadoop,dc=apache,dc=org</value>
       </property>
   ```
   
   Saved the bind password:
   ```
   $ bin/knoxcli.sh create-alias gateway.ldap.bind.password --value knoxsecret
   gateway.ldap.bind.password has been successfully created.
   ```
   
   Restarted Knox.
   
   Logs:
   ```
   2026-06-22 23:50:17,073  INFO  services.ldap (KnoxLDAPServerManager.java:start(205)) - Anonymous access disabled; clients must bind as: uid=knox,ou=people,dc=hadoop,dc=apache,dc=org
   ```
   
   Anonymous access denied:
   ```
   $ ldapsearch -x -H ldap://localhost:33390 -b "" "(uid=admin)" cn
   ldap_bind: Invalid credentials (49)
   	additional info: INVALID_CREDENTIALS: Bind failed: org.apache.directory.api.ldap.model.exception.LdapAuthenticationException: ERR_229 Cannot authenticate user 
   ```
   
   Wrong password:
   ```
   $ ldapsearch -x -H ldap://localhost:33390 -D "uid=knox,ou=people,dc=hadoop,dc=apache,dc=org" -w wrongPassword -b "" "(uid=admin)" cn mail memberOf
   ldap_bind: Invalid credentials (49)
   	additional info: INVALID_CREDENTIALS: Bind failed: org.apache.directory.api.ldap.model.exception.LdapAuthenticationException: ERR_229 Cannot authenticate user uid=knox,ou=people,dc=hadoop,dc=apache,dc=org
   ```
   
   Happy path:
   ```
   $ ldapsearch -x -H ldap://localhost:33390 -D "uid=knox,ou=people,dc=hadoop,dc=apache,dc=org" -w knoxsecret -b "" "(uid=admin)" cn mail memberOf
   # extended LDIF
   #
   # LDAPv3
   # base <> with scope subtree
   # filter: (uid=admin)
   # requesting: cn mail memberOf 
   #
   
   # admin, people, hadoop.apache.org
   dn: uid=admin,ou=people,dc=hadoop,dc=apache,dc=org
   mail: admin@example.org
   cn: System Administrator
   memberOf: cn=admin,ou=groups,dc=hadoop,dc=apache,dc=org
   
   # search result
   search: 2
   result: 0 Success
   
   # numResponses: 2
   # numEntries: 1
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org