Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit c328cec

Browse files
authored
Add LDAP auth tests (#864)
* Add ldap service to testing setup * Remove open admin registration from ldap auth * Add ldap tests * test name consistencty * Add documentation for LDAP roles
1 parent af6bcbf commit c328cec

7 files changed

Lines changed: 354 additions & 14 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ jobs:
5252
- name: Start redis
5353
run: docker-compose -f server/docker-compose.yml up -d redis &
5454

55+
- name: Start ldap
56+
run: docker-compose -f server/docker-compose.yml up -d ldap &
57+
5558
- name: Start service for backend server
5659
if: ${{ matrix.backendtype }}
5760
run: docker-compose -f server/docker-compose.yml up -d ${{ matrix.backendtype }} &

DEVELOPER-GUIDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ Tests are located under `server/test` directory, and use `mocha` as a test runne
123123
cd server
124124
# if dependencies have not yet been installed (build.sh will do this)
125125
npm ci
126+
126127
# If test fixture has not yet been generated (build.sh will do this)
127128
node generate-test-db-fixture.js
129+
130+
# Start backend services if desired. (-d runs in background)
131+
docker-compose up -d redis
132+
docker-compose up -d ldap
133+
128134
# Run tests
129135
npm test
130136

docs/authentication.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ SQLPad users do not need to be added ahead of time, and may be created on the fl
131131

132132
## LDAP (Experimental)
133133

134+
?> Available as of 5.8.0
135+
136+
!> LDAP does not honor "open admin registration" for initial log in. Use `SQLPAD_ADMIN` to set initial admin email address if necessary
137+
134138
LDAP-based authentication can be enabled by setting the necessary environment variables:
135139

136140
- `SQLPAD_LDAP_AUTH_ENABLED` - Set to TRUE if LDAP enable, FALSE if LDAP disable.
@@ -145,7 +149,9 @@ LDAP-based authentication can be enabled by setting the necessary environment va
145149
- `SQLPAD_LDAP_ROLE_EDITOR_FILTER` - LDAP filter used to determine if a user should be assigned SQLPad editor role
146150
- `SQLPAD_LDAP_DEFAULT_ROLE`- Default role for users that do not match LDAP role filters. May be either `admin`, `editor`, `denied`, or empty. If `denied` or empty, a user _must_ match an LDAP role filter to be admitted into SQLPad, unless they are previously created as a SQLPad user in advanced.
147151

148-
To assign roles via LDAP-RBAC, you may specify a profile attribute and value to look to for a particular role.
152+
To assign roles via LDAP-RBAC, you may specify additional LDAP user filters to ensure the user fits a particular role or group.
153+
154+
?> Roles assigned via LDAP will sync on every login.
149155

150156
For example, if your LDAP implementation supports `memberOf`, you may decide to use group DN values. In this case two groups are needed, one for editors and one for admins.
151157

server/auth-strategies/ldap.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,7 @@ function enableLdap(config) {
212212
}
213213
}
214214

215-
let [openAdminRegistration, user] = await Promise.all([
216-
models.users.adminRegistrationOpen(),
217-
models.users.findOneByEmail(email),
218-
]);
215+
let user = await models.users.findOneByEmail(email);
219216

220217
if (user) {
221218
if (user.disabled) {
@@ -234,21 +231,16 @@ function enableLdap(config) {
234231
return done(null, user);
235232
}
236233

237-
// At this point user was not found, and a decision needs to be made to either create or reject the user
238-
239-
// If openAdminRegistration is enabled, this is the initial user
240-
// The users role should be admin
241-
if (openAdminRegistration) {
242-
role = 'admin';
243-
}
234+
// At this point user was not found
235+
// A decision needs to be made to either create or reject the user
244236

245237
// If role is still not set, and default is provided, use that
246238
if (!role) {
247239
role = ldapDefaultRole;
248240
}
249241

250-
// Finally, if role is set, and open admin registration or ldap auto sign up, create user
251-
if (role && (openAdminRegistration || config.get('ldapAutoSignUp'))) {
242+
// If role is set and ldap auto sign up is turned on, create user
243+
if (role && config.get('ldapAutoSignUp')) {
252244
appLog.debug(`adding user ${profileUsername} to role ${role}`);
253245
const newUser = await models.users.create({
254246
email,

server/docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ services:
55
ports:
66
- 6379:6379
77

8+
ldap:
9+
image: rroemhild/test-openldap
10+
ports:
11+
- 389:389
12+
privileged: true
13+
814
mssql:
915
image: 'mcr.microsoft.com/mssql/server:2017-latest'
1016
hostname: 'mssql'

0 commit comments

Comments
 (0)