pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS

Difference between
modified post c17320d by Anonymous on Wed 26th Aug 2026 18:15
original post 0243a8 by Anonymous on Wed 26th Aug 2026 17:56
Download diff
Show old version | new version | both versions

    
11
#!/bin/ksh
22
33
#
44
# nfskrb5test1.ksh - KDC test script for Windows NFS krb5 setup test #001
55
#
66
# Written by Roland Mainz <roland.mainz@nrubsig.org>
77
#
88
99
#
1010
# This is a very simple *TEST* script which sets up a Kerberos5 KDC and
1111
# NFSv4.1 server with GSSAPI on the same machine
1212
#
13+
# This script requires the following Debian 11/13 packages:
1316
# setup Windows machine
1417
# On Windows machine use (via Cygwin bash/ksh93 shell):
1518
# --- snip ---
1619
# # KDC and NFS server must have entries in "/cygdrive/c/Windows/System32/drivers/etc/hosts"
1720
# printf '10.49.202.233\t\tdebnfskrb5001.nfschicken.test\n' >>/cygdrive/c/Windows/System32/drivers/etc/hosts
1821
# printf '10.49.202.233\t\tdebnfskrb5001\n' >>/cygdrive/c/Windows/System32/drivers/etc/hosts
1922
# ksetup /setrealm NFSCHICKEN.TEST
2023
# ksetup /addkdc NFSCHICKEN.TEST debnfskrb5001.nfschicken.test
2124
# ksetup /setrealmflags NFSCHICKEN.TEST tcpsupported
2225
# ksetup /mapuser rmainz@NFSCHICKEN.TEST roland_mainz
2326
# ksetup /setcomputerpassword myhorriblepassword12
2427
# # user has to do the Windows logon as user "rmainz@NFSCHICKEN.TEST", NOT as "roland_mainz"
2528
# # mount with
2629
# nfs_mount -o sec=krb5,rw 'K' nfs://10.49.202.233//nfsdata
2730
# --- snip ---
2831
#
2932
#
3033
3134
export PATH='/usr/bin:/bin:/sbin'
3235
3336
builtin mkdir
3437
#builtin rm
3538
3639
set -o xtrace
3740
set -o nounset
3841
set -o errexit
3942
4043
kdctestdir='/tmp/kdctest1'
4144
compound config=(
4245
	hostname="$(hostname --fqdn)"
4346
	kdcport=88
4447
	kadmindport=749
4548
	# nfsdomain must be LOWERCASE!
4649
	nfsdomain='nfschicken.test'
4750
	# realmname must be UPPERCASE!
4851
	realmname='NFSCHICKEN.TEST'
4952
)
5053
5154
5255
rm -Rfv -- "$kdctestdir"
5356
rm -Rfv "/tmp/krb5cc_dir_$(id -u)"
5457
mkdir -p -- "$kdctestdir"
5558
5659
5760
export KRB5_KDC_PROFILE="${kdctestdir}/kdc.conf"
5861
export KRB5_CONFIG="${kdctestdir}/krb5.conf"
5962
6063
if [[ ! -d '/nfsdata' ]] ; then
6164
	mkdir /nfsdata
6265
	chmod a+rwxt /nfsdata
6366
6467
	printf '/nfsdata\tgss/krb5(rw,no_subtree_check) gss/krb5i(rw,no_subtree_check) gss/krb5p(rw,no_subtree_check)\n' >>'/etc/exports'
6568
fi
6669
6770
6871
printf 'NEED_SVCGSSD="yes"\n' >>/etc/default/nfs-kernel-server
6972
7073
cat >'/etc/idmapd.conf' <<EOF
7174
# Verbosity = 8 logs all idmapper lookups
7275
Verbosity = 8
7376
Pipefs-Directory = /run/rpc_pipefs
7477
# set your own domain here, if it differs from FQDN minus hostname
7578
# Domain = localdomain
7679
# Value for "Domain" must be lowercase, value for "Local-Realms" uppercase
7780
Domain = ${config.nfsdomain}
7881
Local-Realms = ${config.realmname}
7982
8083
[Mapping]
8184
Nobody-User = nobody
8285
Nobody-Group = nogroup
8386
EOF
8487
8588
cat >"${KRB5_CONFIG}" <<EOF
8689
[libdefaults]
8790
    default_realm = ${config.realmname}
8891
    default_ccache_name = DIR:/tmp/krb5cc_dir_%{uid}
8992
9093
[realms]
9194
    ${config.realmname} = {
9295
        kdc = ${config.hostname}:${config.kdcport}
9396
        admin_server = ${config.hostname}:${config.kadmindport}
9497
    }
9598
EOF
9699
97100
98101
cat >"${KRB5_KDC_PROFILE}" <<EOF
99102
[kdcdefaults]
100103
    kdc_ports = ${config.kdcport}
101104
    kdc_tcp_ports = ${config.kdcport}
102105
103106
[realms]
104107
    ${config.realmname} = {
105108
	kadmind_port = ${config.kadmindport}
106109
	acl_file = ${kdctestdir}/kadm5.acl
107110
	admin_keytab = ${kdctestdir}/kadm5.keytab
108111
	database_name = ${kdctestdir}/principal
109112
	key_stash_file = ${kdctestdir}/.k5.${config.realmname}
110113
111114
	max_life = 12h 0m 0s
112115
	max_renewable_life = 7d 0h 0m 0s
113116
	master_key_type = aes256-cts-hmac-sha1-96
114117
	supported_enctypes = aes256-cts-hmac-sha1-96:normal aes128-cts-hmac-sha1-96:normal arcfour-hmac:normal
115118
    }
116119
117120
[logging]
118121
    kdc = FILE:${kdctestdir}/kdc.log
119122
    admin_server = FILE:${kdctestdir}/kadmin.log
120123
    default = FILE:${kdctestdir}/default.log
121124
122125
EOF
123126
124127
{
125128
	printf '%s\n' 'myhorriblepassword12'
126129
	printf '%s\n' 'myhorriblepassword12'
127130
} | kdb5_util create -r "${config.realmname}" -s
128131
129132
130133
131134
#
132135
# add principals
133136
#
134137
compound -A principal_list=(
135138
	# add admin user
136139
	['admin']=(
137140
		principal="admin/admin@${config.realmname}"
138141
		password='myhorriblepassword12'
139142
	)
140143
141144
	# add plain (Windows) user
142145
	['user1']=(
143146
		principal="rmainz@${config.realmname}"
144147
		password='myhorriblepassword12'
145148
	)
146149
147150
	# add Linux host
148151
	['linuxhost1']=(
149152
		principal="host/debnfskrb5001@${config.realmname}"
150153
		password='myhorriblepassword12'
151154
	)
152155
	['linuxhost1_fqdn']=(
153156
		principal="host/debnfskrb5001.nfschicken.test@${config.realmname}"
154157
		password='myhorriblepassword12'
155158
	)
156159
157160
	# add NFS service on Linux host
158161
	['linuxhost1_nfs_service']=(
159162
		principal="nfs/debnfskrb5001@${config.realmname}"
160163
		password='myhorriblepassword12'
161164
	)
162165
	['linuxhost1_nfs_service_fqdn']=(
163166
		principal="nfs/debnfskrb5001.nfschicken.test@${config.realmname}"
164167
		password='myhorriblepassword12'
165168
	)
166169
167170
	# add Windows machine
168171
	['win1']=(
169172
		principal="host/wingrendel02@${config.realmname}"
170173
		password='myhorriblepassword12'
171174
	)
172175
	['win1_fqdn']=(
173176
		principal="host/wingrendel02.nfschicken.test@${config.realmname}"
174177
		password='myhorriblepassword12'
175178
	)
176179
)
177180
178181
for pi in "${!principal_list[@]}" ; do
179182
	nameref pie="principal_list[$pi]"
180183
181184
	{
182185
		printf "addprinc %s\n" "${pie.principal}"
183186
		printf '%s\n' "${pie.password}"
184187
		printf '%s\n' "${pie.password}"
185188
	} | kadmin.local
186189
done
187190
188191
#
189192
# create /etc/krb5.keytab for NFS server
190193
#
191194
rm -f /tmp/nfs01.keytab
192195
{
193196
	printf 'ktadd -k /tmp/nfs01.keytab nfs/debnfskrb5001.nfschicken.test@NFSCHICKEN.TEST\n'
194197
} | kadmin.local
195198
mv -f /tmp/nfs01.keytab /etc/krb5.keytab
196199
197200
#
198201
# start KDC
199202
#
200203
krb5kdc -n &
201204
(( kdc_pid=$! ))
202205
203206
# wait for KDC to start
204207
sleep 10
205208
206209
#
207210
# simple function test
208211
#
209212
{
210213
	printf '%s\n' 'myhorriblepassword12'
211214
} | kinit "admin/admin@${config.realmname}"
212215
{
213216
	printf '%s\n' 'myhorriblepassword12'
214217
} | kinit "rmainz@${config.realmname}"
215218
216219
klist -A
217220
218221
#
219222
# restart NFS server to pickup changes in /etc/exports and KRB5 changes
220223
#
221224
systemctl restart nfs-idmapd.service
222225
sleep 5
223226
systemctl restart nfs-kernel-server
224227
225228
#
226229
# sleep for two weeks
227230
#
228231
sleep $((60*60*24*7*2))
229232
230233
kill $kdc_pid
231234
wait $kdc_pid
232235
233236
# EOF.
234237

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at