Skip to content

Commit ecb82f3

Browse files
authored
CP-311020: Design for enabling ldaps for external auth (#6837)
2 parents 46d16f1 + ed593d5 commit ecb82f3

File tree

1 file changed

+323
-0
lines changed

1 file changed

+323
-0
lines changed
Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
---
2+
title: Secure LDAP (LDAPS) Support for External Authentication
3+
layout: default
4+
design_doc: true
5+
revision: 1
6+
status: draft
7+
---
8+
9+
## Terminology
10+
11+
| Term | Meaning |
12+
|------|---------|
13+
| AD | Windows Active Directory |
14+
| samba/winbind | Client used in xapi to talk to AD |
15+
| DC | Windows AD domain controller |
16+
| ldap/ldaps | Lightweight Directory Access Protocol / over SSL |
17+
| Joining host | The host joining to a pool |
18+
19+
## 1. Background
20+
21+
To integrate XenServer with AD, XenServer performs LDAP queries in the following use cases:
22+
23+
- **Enable external authentication/Join domain**: Samba LDAP queries DC details
24+
- **Session revalidation**: xapi queries user details (e.g., whether user is still valid, password expired, etc.) to decide whether to destroy a session
25+
26+
Currently XenServer uses plain LDAP queries, which is a concern for some enterprise customers.
27+
28+
## 2. Xapi Database
29+
30+
### 2.1 External Auth Configuration
31+
32+
External auth details are stored in the `host` (table) → `external_auth_configuration` (field). For example:
33+
34+
```
35+
external_auth_configuration: {
36+
domain: xenrt16718.local,
37+
user: Administrator,
38+
workgroup: XENRTXENRT16718,
39+
netbios_name: genus-35-103d,
40+
machine_pwd_last_change_time: 1767508709
41+
}
42+
```
43+
44+
A new field `ldaps` (bool, optional) will be added to `external_auth_configuration` field to state whether LDAPS should be used instead of LDAP. If not set, LDAP will be used for backward compatibility.
45+
46+
So the field will look like:
47+
48+
```
49+
external_auth_configuration: {
50+
domain: xenrt16718.local,
51+
user: Administrator,
52+
workgroup: XENRTXENRT16718,
53+
netbios_name: genus-35-103d,
54+
machine_pwd_last_change_time: 1767508709,
55+
ldaps: true
56+
}
57+
```
58+
59+
### 2.2 Certificate
60+
61+
To enforce security, if customer uses self-signed certificate, they need to upload the root CA certificate to XenServer, so XenServer can verify the certificate/public key used talking to DC for LDAPS.
62+
63+
The [trusted-certificates.md](https://github.com/xapi-project/xen-api/blob/master/doc/content/design/trusted-certificates.md) design enhanced the `Certificate` table and introduced a new field `purpose` for security, which limits the certificate only for specific purpose. `ldaps` will be added to `purpose` field as a value for LDAPS.
64+
65+
## 3. Interfaces
66+
67+
### 3.1 pool.enable_external_auth
68+
69+
To enable external auth, the current API arguments are as follows:
70+
71+
- `pool` (Ref _pool): The pool whose external authentication should be enabled
72+
- `config` (Map (String, String)): A list of key-values containing the configuration data
73+
- `service_name` (String): The name of the service
74+
- `auth_type` (String): The type of authentication (e.g., AD for Active Directory)
75+
76+
For example:
77+
78+
```bash
79+
xe pool-enable-external-auth uuid=<uuid> auth-type=AD service-name=<domain> config:user=<user> config:pass=<pwd>
80+
```
81+
82+
This API signature does not change. Regarding the config map, one new option is added:
83+
84+
- `config:ldaps`: whether LDAPS is required, default to `false`
85+
- Set `client ldap sasl wrapping` to `ldaps` if true, `seal` otherwise
86+
- This item will be stored in database in section 2.1
87+
88+
Given `ldaps` default to `false`, this feature is **NOT** enabled until explicitly set.
89+
90+
### 3.2 Set/Get Pool LDAPS Status
91+
92+
#### 3.2.1 pool.external_auth_set_ldaps
93+
94+
User can specify LDAPS during join domain as in 3.1.
95+
96+
For the existing joined domain, user can switch between LDAP and LDAPS with this new API. Args as follows:
97+
98+
- `pool` (Ref _pool): pool to set LDAPS
99+
- `ldaps` (Bool): whether LDAPS is required
100+
101+
This API will set the `ldaps` in database (Refer to 2.1).
102+
103+
This API performs following sanity check and rejects update if check fails:
104+
105+
- AD has already been enabled
106+
- Find proper certificate (Refer to 4.1 for the details)
107+
- Do a `ldaps` query to embedded user `krbtgt` for the joined domain
108+
109+
**Note:**
110+
- This API allow en-entry for debug purpose
111+
- Will not do the LDAPS query on the trusted domains, as xapi does not have trusted domain details
112+
- The joined domain likely has multiple DCs. LDAPS query tries every DC of the domain. Check pass if LDAPS query succeeds on any DC of the domain. This implies iterate and locate a DC supporting LDAPS (with proper certificate trust setup) before LDAPS query. However, this does not introduce performance problems as the LDAPS query happens in backend and refreshes result into XAPI DB
113+
- Pool coordinator dispatches this API request to every host, and only succeeds if all hosts pass the check
114+
- This API needs to be synced with other APIs. For example, `authenticate_username_password` should fail if this API is performing checking and configuration
115+
116+
This API will refresh `winbind` configuration (Refer to 4.1).
117+
118+
So following xe command can be used to switch between LDAP and LDAPS:
119+
120+
```bash
121+
xe pool-external-auth-set-ldaps uuid=<uuid> ldaps=<true|false>
122+
```
123+
124+
#### 3.2.2 Get Pool LDAPS Status
125+
126+
xapi generates a get message for each field automatically. To query the LDAPS status, client only needs to query the get method of `host` (class) → `external-auth-configuration` (field), and parse the result. The example as follows:
127+
128+
```bash
129+
xe host-param-get uuid=<uuid> param-name=external-auth-configuration
130+
```
131+
132+
### 3.3 Install Certificate
133+
134+
If the certificate for LDAPS in DC is signed by a private CA (vs a trusted public CA), user needs to import their Root or Intermediate CA certificate into XenServer.
135+
136+
`pool.install_trusted_certificate` can install the certificate with following parameters, refer to [trusted-certificates.md](https://github.com/xapi-project/xen-api/blob/master/doc/content/design/trusted-certificates.md) for the details:
137+
138+
- `session` (ref session_id): reference to a valid session
139+
- `self` (ref Pool): reference to the pool
140+
- `ca` (boolean): should always be `true` for `ldaps`. xapi should reject this CA otherwise
141+
- `cert` (string): the trusted certificate in PEM format
142+
- `purpose` (string list): the purposes of this cert. It can be one of following:
143+
- contain `ldaps` if for specific this specific purpose
144+
- empty set, thus would take as general purpose CA. It will be used for `ldaps` if no `ldaps` specific purpose found
145+
146+
**Note:** If the DCs (of joining domain and trusted domain in use) are signed by different CAs, all the CAs need to be uploaded to XenServer.
147+
148+
## 4. Configuration Item
149+
150+
To enforce LDAPS, following are required:
151+
152+
- Samba needs to be updated to 4.21+ (Already done)
153+
- LDAPS needs to be enabled in smb.conf
154+
155+
### 4.1 Samba Configuration
156+
157+
#### 4.1.1 smb.conf
158+
159+
To enforce LDAPS, xapi just passthrough the configuration to winbind. Following configuration needs to be updated to `/etc/samba/smb.conf`, details refer to [smb.conf](https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html):
160+
161+
```ini
162+
client ldap sasl wrapping = <ldaps | seal>
163+
tls verify peer = ca_and_name_if_available
164+
tls trust system cas = yes
165+
tls cafile = /etc/trusted-certs/ca-bundle-[ldaps|general].pem
166+
```
167+
168+
- Switch between `ldap` and `ldaps` will flip `client ldap sasl wrapping` between `seal` and `ldaps`
169+
- `tls cafile` points to a CA bundle used to verify DC certs. Details refer to 4.1.2
170+
171+
#### 4.1.2 Certificate Selection
172+
173+
This design is following [trusted-certificates.md](https://github.com/xapi-project/xen-api/blob/master/doc/content/design/trusted-certificates.md):
174+
175+
- Use `/etc/trusted-certs/ca-bundle-ldaps.pem` if exists
176+
- Fall back to `/etc/trusted-certs/ca-bundle-general.pem` if exists and previous not match
177+
- Report error if none of above match
178+
179+
**Note:** The selection/configuration is only refreshed on following cases:
180+
181+
- xapi (re)start
182+
- `pool.external_auth_set_ldaps` API
183+
- (Re)join domain
184+
185+
### 4.2 Xapi Configuration
186+
187+
#### 4.2.1 winbind-tls-verify-peer
188+
189+
For security, xapi asks winbind to verify CA certificate. `ca_and_name_if_available` is the default.
190+
191+
However, user may want to disable this verification for debug purpose.
192+
193+
`winbind-tls-verify-peer` is introduced for xapi configuration, and the possible values are `no_check`, `ca_only`, `ca_and_name_if_available`, `ca_and_name` and `as_strict_as_possible`.
194+
The configured value will override `tls verify peer` value in xapi generated samba configuration. Refer to [smb.conf](https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html) for the details.
195+
196+
197+
**Note:** This item is not intended for public documentation. This is only for debug purpose, or system tuning for specific scenarios from engineering/support team.
198+
199+
#### 4.2.2 ad-warning-message-interval
200+
201+
xapi sends warning message to user with this interval on LDAP query failure. Default to 1 week. Refer to section "Session revalidate" for the details.
202+
203+
## 5. Session Revalidate
204+
205+
xapi LDAP queries domain user status (if user has been added to manage XenServer) at configurable interval, and destroys the session created by domain user if user no longer in healthy status.
206+
207+
However, the LDAP query may fail due to various issues as follows:
208+
209+
- Temporary network issues
210+
- CA certificate is not properly configured, or expired, etc.
211+
212+
Instead of destroying user session for stability, a warning message will be sent to user with the details at configurable interval `ad-warning-message-interval`.
213+
214+
- If no LDAP error, do nothing
215+
- If error happens, send the warning message if:
216+
- first time see the error through xapi start up (so no need to persist last send time) or
217+
- `current_time - last_sent_time > winbind_warning_message_interval`
218+
219+
The message is defined as follows:
220+
- name: AD_DC_LDAP_CHECK
221+
- priority: Warning
222+
- cls: `Host
223+
- Body: LDAP(S) query check to `<DC>` of `<domain>` failed from `<host>` of `<pool>`
224+
225+
Note:
226+
- The backend session revalidate check only performs on pool coordinator, thus the backend LDAP(S) query check only on coordinator
227+
- `external_auth_set_ldaps` perform LDAP(S) query check on every host
228+
- All previous AD_DC_LDAP_CHECK warning of a host will be cleaned on a successful LDAP(s) query from that host
229+
230+
## 6. Pool Join/Leave
231+
232+
### 6.1 pool.join
233+
234+
#### 6.1.1 AD Pre-checks
235+
236+
Currently the pool.join pre-check checks the following:
237+
238+
- `external_auth_type`: whether joined AD
239+
- `external_auth_service_name`: whether joined the same domain
240+
241+
The pre-check is good enough, no matter whether `ldaps` is in use, as this ensures host can talk to AD. There are following cases:
242+
243+
- pool with AD, joining host with same AD: check pass as before this design
244+
- pool without AD, joining host without AD: check pass as before this design
245+
- pool without AD, joining host with AD: check failed as before this design
246+
- pool with AD, joining host without AD:
247+
- LDAPS not enabled: joining host needs to join to same AD as before this design
248+
- LDAPS enabled: joining host needs to enable AD without certificate check, details refer to 6.1.2
249+
250+
#### 6.1.2 Join Host to Pool with LDAPS Enabled
251+
252+
When joining a host without AD to a pool with LDAPS enabled, the host may not have the (CA) certificate for the domain. It can be trivial to enforce customer to upload the CA certificate to every joining host, thus client would help to orchestrate certificates.
253+
254+
The workflow:
255+
256+
~~~mermaid
257+
258+
sequenceDiagram
259+
participant user as User
260+
participant client as Client
261+
participant join as Joining host
262+
participant coor as Pool Coordinator
263+
participant dc as AD/DC
264+
265+
user->>client: pool.join
266+
Note over client: precheck
267+
alt precheck failed
268+
client-->>user: precheck failed
269+
end
270+
271+
Note over client,coor: sync all ldaps certs
272+
client->>coor: pool.download_trusted_certificate
273+
coor-->>client:
274+
client->>join: pool.install_trusted_certificate
275+
join-->>client:
276+
277+
user->>client: join domain username/password
278+
client->>join: join domain username/password
279+
join->>dc: join domain
280+
dc-->>join:
281+
join-->>client:
282+
283+
client->>join: pool.join
284+
Note over join,coor: join pool ops<br/>certs sync
285+
join-->>client:
286+
client-->>user: pool.join succeed
287+
288+
~~~
289+
290+
**Detailed Steps:**
291+
292+
1. Client find proper `ldaps certs` from pool coordinator as `certs_pool`
293+
- a. find all certs `ldaps in purpose`
294+
- b. if no LDAPS certs, find all `general` certs
295+
2. Client find all certs in joining host as `certs_joining_host`
296+
3. Client identify the certs needs to be synced to joining host as `certs_to_sync = certs_pool - certs_joining_host` (certs in `certs_pool`, but not in `certs_joining_host`), the certs fingerprint should be used to identify the certs
297+
4. Client download all `certs_to_sync`, `pool.download_trusted_certificate` from coordinator
298+
5. Client upload all certs to joining pool, `pool.install_trusted_certificate` to joining pool, with the same purpose
299+
6. Client trigger `pool.join` again with domain username and password
300+
7. After pool.join:
301+
- If pool.join failed, Client call `pool.uninstall_trusted_certificate` on joining host to revert the certs
302+
- If pool.join succeed, do nothing as pool.join would sync the certs anyway
303+
304+
### 6.2 pool.leave
305+
306+
`pool.disable_external_auth` is called during pool leave, thus the `ldaps` status is cleaned.
307+
308+
This design does not change it.
309+
310+
## 7. Telemetry Support
311+
312+
### 7.1 External Auth Enabled
313+
314+
`host` (table) → `external_auth_type` (field) = `AD`
315+
316+
### 7.2 LDAPS Enabled
317+
318+
`host` (table) → `external_auth_configuration` (field) → `ldaps` (key) = `true`
319+
320+
## References
321+
322+
- [trusted-certificates.md](https://github.com/xapi-project/xen-api/blob/master/doc/content/design/trusted-certificates.md)
323+
- [Samba smb.conf manual](https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html)

0 commit comments

Comments
 (0)