Skip to content

Commit a1208e2

Browse files
committed
localkdc: update demo to follow recent changes
Update the localkdc demo configuration to improve Kerberos and Samba integration, with changes to realm generation, user management, and authentication workflows New Features: - Dynamically generate unique Kerberos realm with UUID - Implement new user addition tool localkdc-useradd - Enhance Kerberos cross-realm authentication mechanism Enhancements: - Simplify Kerberos configuration generation - Improve Samba Kerberos integration - Update authentication workflow for remote Samba access Documentation: - Update README with new user addition and KDC configuration instructions Chores: - Update Samba and demo configuration templates - Modify Ansible playbook to support dynamic realm generation Signed-off-by: Alexander Bokovoy <[email protected]>
1 parent 37faf9b commit a1208e2

File tree

4 files changed

+102
-55
lines changed

4 files changed

+102
-55
lines changed

ipalab-config/localkdc/README.md

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Build the container images and containers:
1515
```
1616
ipalab-config ipalab-localkdc.yaml
1717
cd localkdc
18-
podman build -t fedora-localkdc containerfiles/Containerfile.localkdc .
18+
ansible-galaxy install -r requirements.yml
19+
podman build -t fedora-localkdc -f containerfiles/Containerfile.localkdc .
1920
podman-compose up -d
2021
```
2122

2223
Deploy the local KDC demo nodes:
2324

2425
```
25-
cd localkdc
2626
ansible-playbook -i inventory.yml playbooks/configure-localkdc.yaml
2727
```
2828

@@ -73,6 +73,20 @@ profile with following features enabled:
7373
- `with-gssapi`, to enable use of `pam_sss_gss` PAM module for GSSAPI
7474
authentication
7575

76+
### Configuring the local KDC
77+
78+
The playbook `playbooks/configure-localkdc.yaml` calls a tool named
79+
`localkdc-setup` to provision the local KDC configuration. It generates a
80+
Kerberos realm named `LOCALKDC.<SOME UUID>` and provisions well-known Kerberos
81+
principals in it. There are two individual service principals and a number of
82+
aliases for them:
83+
84+
- `host/...` principal is used by the SSH and SSSD services
85+
- `cifs/...` principal is used by the Samba services
86+
87+
Each service principal is added together with own aliases that correspond to
88+
the various versions of the machine hostname.
89+
7690
### Add a new user
7791

7892
Since authentication of the user accounts is handled with the help of local
@@ -81,14 +95,21 @@ the system-wide user store in `/etc/passwd`.
8195

8296
A new user account can be added with `useradd` tool. However, in order to set a
8397
password for this new account, a Kerberos principal needs to be added with
84-
`localkdc-kadmin` tool. `localkdc-kadmin` is a wrapper around `kadmin.local`
98+
`localkdc-useradd` tool. `localkdc-useradd` is a wrapper around `kadmin.local`
8599
tool to work on the local KDC database.
86100

87101
```
88102
# useradd newuser
89-
# localkdc-kadmin addprinc newuser
103+
# localkdc-useradd newuser
90104
```
91105

106+
It is important to use the wrapper tools for local KDC administration. In
107+
particular, in order to avoid dependency on the local KDC realm, all user
108+
principals created with a special, randomized, salt type for their Kerberos
109+
keys. The keys also stored in a special aliased entry (`userdb:...`) to allow
110+
local KDC database driver first to validate that a Kerberos principal does
111+
indeed exist on the system as a user and then return this entry.
112+
92113
### Use of Kerberos tools
93114

94115
MIT Kerberos library used in the local KDC demo is modified to support UNIX
@@ -108,22 +129,21 @@ module and produces an initial ticket granting ticket (TGT) in the Kerberos
108129
credentials cache which can be seen with the help of `klist` command:
109130

110131
```
111-
$ podman run -ti --network ipanet-localkdc registry.fedoraproject.org/fedora-toolbox:latest \
112-
ssh -l testuser ab.localkdc.test
132+
$ podman run -ti --network ipanet-localkdc fedora-toolbox:latest ssh -l testuser ab.localkdc.test
113133
The authenticity of host 'ab.localkdc.test (192.168.221.2)' can't be established.
114-
ED25519 key fingerprint is SHA256:DJEnxvJgd50csPmB3+bgHH2+Qfgr0y3Bnfrr7lEo1nA.
134+
ED25519 key fingerprint is SHA256:xDUKVLHsHC7T66Q6LERBL1PSzatKFZUuI56xvpOWyw8.
115135
This key is not known by any other names.
116136
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
117137
Warning: Permanently added 'ab.localkdc.test' (ED25519) to the list of known hosts.
118138
[email protected]'s password:
119-
Last login: Sat Jan 25 12:00:39 2025 from 192.168.221.8
139+
Last login: Sat May 3 10:12:21 2025 from 192.168.221.4
120140
[testuser@ab ~]$ klist
121-
Ticket cache: KCM:1000:81791
122-
Default principal: testuser@AB.LOCALKDC.SITE
141+
Ticket cache: KCM:1000:55628
142+
Default principal: testuser@LOCALKDC.2A1A0335-BF33-4B96-AC68-F98DCBF154A9
123143
124144
Valid starting Expires Service principal
125-
01/25/25 12:01:21 01/26/25 12:01:21 krbtgt/AB.LOCALKDC.SITE@AB.LOCALKDC.SITE
126-
renew until 02/01/25 12:01:21
145+
05/03/25 10:18:11 05/04/25 10:18:11 krbtgt/LOCALKDC.2A1A0335-BF33-4B96-AC68-F98DCBF154A9@LOCALKDC.2A1A0335-BF33-4B96-AC68-F98DCBF154A9
146+
renew until 05/10/25 10:18:11
127147
```
128148

129149
In a separate console obtained with the help of `podman exec -ti ab.localkdc.test`,
@@ -132,13 +152,13 @@ issued the Kerberos ticket, as recorded in the `/var/log/localkdc.log` (the
132152
output excerpt has been reformatted for convenience):
133153

134154
```
135-
Jan 25 12:01:21 ab.localkdc.test krb5kdc[781](info): AS_REQ
155+
May 03 10:18:11 ab.localkdc.test krb5kdc[1113](info): AS_REQ
136156
(6 etypes {aes256-cts-hmac-sha384-192(20), aes128-cts-hmac-sha256-128(19),
137157
aes256-cts-hmac-sha1-96(18), aes128-cts-hmac-sha1-96(17),
138158
camellia256-cts-cmac(26), camellia128-cts-cmac(25)})
139-
/run/localkdc/kdc.sock: ISSUE: authtime 1737806481,
159+
/run/localkdc/kdc.sock: ISSUE: authtime 1746267491,
140160
etypes {rep=aes256-cts-hmac-sha384-192(20), tkt=aes256-cts-hmac-sha384-192(20), ses=aes256-cts-hmac-sha384-192(20)},
141-
testuser@AB.LOCALKDC.SITE for krbtgt/AB.LOCALKDC.SITE@AB.LOCALKDC.SITE
161+
testuser@LOCALKDC.2A1A0335-BF33-4B96-AC68-F98DCBF154A9 for krbtgt/LOCALKDC.2A1A0335-BF33-4B96-AC68-F98DCBF154A9@LOCALKDC.2A1A0335-BF33-4B96-AC68-F98DCBF154A9
142162
```
143163

144164
After that, we can ask for a service ticket to a different service, in this
@@ -182,14 +202,14 @@ we can see that this connection has indeed been established:
182202
```
183203
$ podman exec -ti ab.localkdc.test smbstatus
184204
185-
Samba version 4.21.3
205+
Samba version 4.22.1
186206
PID Username Group Machine Protocol Version Encryption Signing
187207
----------------------------------------------------------------------------------------------------------------------------------------
188-
1091 testuser testuser 192.168.221.2 (ipv4:192.168.221.2:43092) SMB3_11 AES-128-GCM AES-128-GMAC
208+
1943 testuser testuser 192.168.221.2 (ipv4:192.168.221.2:43620) SMB3_11 partial(AES-128-GCM) AES-128-GMAC
189209
190210
Service pid Machine Connected at Encryption Signing
191211
---------------------------------------------------------------------------------------------
192-
testuser 1091 192.168.221.2 Sat Jan 25 12:17:22 PM 2025 UTC - -
212+
testuser 1943 192.168.221.2 Sat May 3 10:38:31 AM 2025 UTC AES-128-GCM AES-128-GMAC
193213
194214
No locked files
195215
```
@@ -199,18 +219,48 @@ No locked files
199219
We can connect to Samba also from the remote machine. In this case, the client
200220
system will not have access to the local KDC on the machine where Samba is
201221
running. However, `smbclient` will be able to use IAKerb protocol extension to
202-
proxy Kerberos requests to the local KDC.
222+
proxy Kerberos requests to the local KDC on the Samba server side.
203223

204224
```
205-
$ podman exec -ti asn.localkdc.test smbclient -U [email protected] //ab.localkdc.test/homes
206-
Password for [[email protected]]:
207-
....
225+
$ podman exec -ti asn.localkdc.test runuser -l testuser
226+
[testuser@asn ~]$ klist
227+
klist: Credentials cache 'KCM:1000' not found
228+
[testuser@asn ~]$ smbclient -U testuser --use-kerberos=required --use-krb5-ccache=KCM: --client-protection=encrypt //ab.localkdc.test/homes
229+
Password for [ASN\testuser]:
230+
Try "help" to get a list of possible commands.
231+
smb: \> dir
232+
. D 0 Sat May 3 09:50:07 2025
233+
.. D 0 Sat May 3 09:50:07 2025
234+
.bash_logout H 18 Fri Nov 8 00:00:00 2024
235+
.bash_profile H 144 Fri Nov 8 00:00:00 2024
236+
.bashrc H 522 Fri Nov 8 00:00:00 2024
237+
localkdc-demo.tape N 2604 Fri May 2 10:39:04 2025
238+
.cache DH 0 Sat May 3 09:48:53 2025
239+
.config DH 0 Sat May 3 09:47:28 2025
240+
.pki DH 0 Sat May 3 09:47:29 2025
241+
.local DH 0 Sat May 3 09:47:29 2025
242+
.ssh DH 0 Sat May 3 09:49:52 2025
243+
.bash_history H 1217 Sat May 3 10:18:23 2025
244+
localkdc-demo.webm N 2702801 Sat May 3 09:51:39 2025
245+
246+
998540288 blocks of size 1024. 805004744 blocks available
208247
smb: \>
248+
[testuser@asn ~]$ klist
249+
Ticket cache: KCM:1000:33341
250+
Default principal: [email protected]
251+
252+
Valid starting Expires Service principal
253+
05/03/25 10:46:41 05/04/25 10:46:41 krbtgt/LOCALKDC.2A1A0335-BF33-4B96-AC68-F98DCBF154A9@LOCALKDC.2A1A0335-BF33-4B96-AC68-F98DCBF154A9
254+
renew until 05/10/25 10:46:41
255+
05/03/25 10:46:41 05/04/25 10:46:41 cifs/ab.localkdc.test@
256+
renew until 05/10/25 10:46:41
257+
Ticket server: cifs/[email protected]
209258
```
210259

211-
An authentication in this case will use Kerberos mechanism but will require
212-
password to proxy the request to the local KDC on Samba server side over the
213-
SMB3 connection.
260+
An authentication in this case will use Kerberos mechanism. However, Samba client will require
261+
a password because there are no valid credentials (yet) to authenticate. On its
262+
side, Samba server will then proxy the request to the local KDC on Samba server
263+
side. This Kerberos exchange will happen completely over SMB3 connection.
214264

215265
## Recording video of the demo operations
216266

@@ -220,9 +270,7 @@ The lab also includes a tape to record a video. Ansible playbook
220270
Video recording is built upon excellent
221271
[VHS](https://github.com/charmbracelet/vhs) tool. A pre-built version for
222272
Fedora is provided in [COPR
223-
abbra/vhs](https://copr.fedorainfracloud.org/coprs/abbra/vhs/). This build also
224-
includes a fix from the upstream
225-
[PR#551](https://github.com/charmbracelet/vhs/pull/551).
273+
abbra/vhs](https://copr.fedorainfracloud.org/coprs/abbra/vhs/).
226274

227275
```
228276
[in the generated localkdc directory]
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
[libdefaults]
22
default_ccache_name = KCM:
3+
canonicalize = true
34
default_realm = %REALM%
45

56
[domain_realm]
6-
ab.localkdc.test = AB.LOCALKDC.SITE
7-
asn.localkdc.test = ASN.LOCALKDC.SITE
7+
ab.localkdc.test = %REALM_AB%
8+
asn.localkdc.test = %REALM_ASN%
89

9-
[capaths]
10-
AB.LOCALKDC.SITE = {
11-
ASN.LOCALKDC.SITE = .
12-
}
13-
ASN.LOCALKDC.SITE = {
14-
AB.LOCALKDC.SITE = .
15-
}

ipalab-config/localkdc/configs/00-samba-smb.conf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
# Limit number of forked processes to avoid SMBLoris attack
44
max smbd processes = 1000
55

6-
# Use dedicated Samba keytab. The key there must be synchronized
7-
# with Samba tdb databases or nothing will work
8-
dedicated keytab file = FILE:/etc/samba/localkdc.keytab
9-
kerberos method = dedicated keytab
6+
# Include localkdc configuration generated by localkdc-setup
7+
include = /etc/samba/localkdc.conf
108

119
# Set up logging per machine and Samba process
1210
log file = /var/log/samba/log.%m
@@ -15,8 +13,6 @@
1513
server role = standalone
1614
obey pam restrictions = yes
1715

18-
realm = %REALM%
19-
2016
netbios name = %WORKGROUP%
2117
workgroup = %WORKGROUP%
2218

ipalab-config/localkdc/playbooks/configure-localkdc.yaml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,31 @@
55
gather_facts: true
66

77
vars:
8-
ab_realm: AB.LOCALKDC.SITE
9-
asn_realm: ASN.LOCALKDC.SITE
8+
host_ab: ab.localkdc.test
9+
host_asn: asn.localkdc.test
10+
test_user: testuser
11+
test_pass: Secret123
1012

1113
tasks:
14+
- name: Configure Local KDC
15+
ansible.builtin.shell: |
16+
/usr/sbin/localkdc-setup
17+
18+
- name: Collect local KDC information
19+
shell: |
20+
grep default_realm /etc/krb5.conf.d/localkdc | cut -d= -f2
21+
register: localkdc_info
22+
1223
- name: Generate realm name based on the host name
1324
ansible.builtin.set_fact:
1425
workgroup_name: "{{ ansible_facts.fqdn.split('.')[0] | upper }}"
15-
realm_name: "{{ ansible_facts.fqdn.split('.')[0] | upper }}.LOCALKDC.SITE"
26+
realm_name: "{{ localkdc_info.stdout | trim }}"
1627

1728
- name: Modify configuration templates to apply realm name
1829
ansible.builtin.shell: |
1930
sed -i "s@%REALM%@{{ realm_name }}@g" /root/configs/00-*
31+
sed -i "s@%REALM_AB%@{{ hostvars[host_ab]['realm_name'] }}@g" /root/configs/00-*
32+
sed -i "s@%REALM_ASN%@{{ hostvars[host_asn]['realm_name'] }}@g" /root/configs/00-*
2033
sed -i "s@%WORKGROUP%@{{ workgroup_name }}@g" /root/configs/00-*
2134
2235
- name: Set local KDC configuration defaults
@@ -61,10 +74,6 @@
6174
enabled: true
6275
state: started
6376

64-
- name: Configure Local KDC
65-
ansible.builtin.shell: |
66-
/usr/sbin/localkdc-setup
67-
6877
- name: Enable LocalKDC socket
6978
ansible.builtin.systemd_service:
7079
name: localkdc.socket
@@ -89,19 +98,19 @@
8998
enabled: true
9099
state: started
91100

92-
- name: Create a user 'testuser' with a home directory
101+
- name: Create a user '{{ test_user }}' with a home directory
93102
ansible.builtin.user:
94-
name: testuser
103+
name: {{ test_user }}
95104
create_home: yes
96105
groups: wheel
97106
append: true
98107

99108
- name: Add local KDC credentials for user 'testuser'
100109
ansible.builtin.shell: |
101-
/usr/sbin/localkdc-kadmin addprinc -pw Secret123 testuser
110+
echo -e "{{ test_pass }}\n{{ test_pass }}\n" | /usr/sbin/localkdc-useradd "{{ test_user }}"
102111
103112
- name: Add local KDC cross-realm trust between machines
104113
ansible.builtin.shell: |
105-
/usr/sbin/localkdc-kadmin addprinc -pw Secret123 krbtgt/{{ ab_realm }}@{{ asn_realm }}
106-
/usr/sbin/localkdc-kadmin addprinc -pw Secret123 krbtgt/{{ asn_realm }}@{{ ab_realm }}
114+
/usr/sbin/localkdc-kadmin addprinc -pw Secret123 "krbtgt/{{ hostvars[host_ab]['realm_name'] }}@{{ hostvars[host_asn]['realm_name'] }}"
115+
/usr/sbin/localkdc-kadmin addprinc -pw Secret123 "krbtgt/{{ hostvars[host_asn]['realm_name'] }}@{{ hostvars[host_ab]['realm_name'] }}"
107116

0 commit comments

Comments
 (0)