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
| 1 | 1 | #!/bin/ksh | |
| 2 | 2 | ||
| 3 | 3 | # | |
| 4 | 4 | # nfskrb5test1.ksh - KDC test script for Windows NFS krb5 setup test #001 | |
| 5 | 5 | # | |
| 6 | 6 | # Written by Roland Mainz <roland.mainz@nrubsig.org> | |
| 7 | 7 | # | |
| 8 | 8 | ||
| 9 | 9 | # | |
| 10 | 10 | # This is a very simple *TEST* script which sets up a Kerberos5 KDC and | |
| 11 | 11 | # NFSv4.1 server with GSSAPI on the same machine | |
| 12 | 12 | # | |
| 13 | + | # This script requires the following Debian 11/13 packages: | |
| 13 | 16 | # setup Windows machine | |
| 14 | 17 | # On Windows machine use (via Cygwin bash/ksh93 shell): | |
| 15 | 18 | # --- snip --- | |
| 16 | 19 | # # KDC and NFS server must have entries in "/cygdrive/c/Windows/System32/drivers/etc/hosts" | |
| 17 | 20 | # printf '10.49.202.233\t\tdebnfskrb5001.nfschicken.test\n' >>/cygdrive/c/Windows/System32/drivers/etc/hosts | |
| 18 | 21 | # printf '10.49.202.233\t\tdebnfskrb5001\n' >>/cygdrive/c/Windows/System32/drivers/etc/hosts | |
| 19 | 22 | # ksetup /setrealm NFSCHICKEN.TEST | |
| 20 | 23 | # ksetup /addkdc NFSCHICKEN.TEST debnfskrb5001.nfschicken.test | |
| 21 | 24 | # ksetup /setrealmflags NFSCHICKEN.TEST tcpsupported | |
| 22 | 25 | # ksetup /mapuser rmainz@NFSCHICKEN.TEST roland_mainz | |
| 23 | 26 | # ksetup /setcomputerpassword myhorriblepassword12 | |
| 24 | 27 | # # user has to do the Windows logon as user "rmainz@NFSCHICKEN.TEST", NOT as "roland_mainz" | |
| 25 | 28 | # # mount with | |
| 26 | 29 | # nfs_mount -o sec=krb5,rw 'K' nfs://10.49.202.233//nfsdata | |
| 27 | 30 | # --- snip --- | |
| 28 | 31 | # | |
| 29 | 32 | # | |
| 30 | 33 | ||
| 31 | 34 | export PATH='/usr/bin:/bin:/sbin' | |
| 32 | 35 | ||
| 33 | 36 | builtin mkdir | |
| 34 | 37 | #builtin rm | |
| 35 | 38 | ||
| 36 | 39 | set -o xtrace | |
| 37 | 40 | set -o nounset | |
| 38 | 41 | set -o errexit | |
| 39 | 42 | ||
| 40 | 43 | kdctestdir='/tmp/kdctest1' | |
| 41 | 44 | compound config=( | |
| 42 | 45 | hostname="$(hostname --fqdn)" | |
| 43 | 46 | kdcport=88 | |
| 44 | 47 | kadmindport=749 | |
| 45 | 48 | # nfsdomain must be LOWERCASE! | |
| 46 | 49 | nfsdomain='nfschicken.test' | |
| 47 | 50 | # realmname must be UPPERCASE! | |
| 48 | 51 | realmname='NFSCHICKEN.TEST' | |
| 49 | 52 | ) | |
| 50 | 53 | ||
| 51 | 54 | ||
| 52 | 55 | rm -Rfv -- "$kdctestdir" | |
| 53 | 56 | rm -Rfv "/tmp/krb5cc_dir_$(id -u)" | |
| 54 | 57 | mkdir -p -- "$kdctestdir" | |
| 55 | 58 | ||
| 56 | 59 | ||
| 57 | 60 | export KRB5_KDC_PROFILE="${kdctestdir}/kdc.conf" | |
| 58 | 61 | export KRB5_CONFIG="${kdctestdir}/krb5.conf" | |
| 59 | 62 | ||
| 60 | 63 | if [[ ! -d '/nfsdata' ]] ; then | |
| 61 | 64 | mkdir /nfsdata | |
| 62 | 65 | chmod a+rwxt /nfsdata | |
| 63 | 66 | ||
| 64 | 67 | printf '/nfsdata\tgss/krb5(rw,no_subtree_check) gss/krb5i(rw,no_subtree_check) gss/krb5p(rw,no_subtree_check)\n' >>'/etc/exports' | |
| 65 | 68 | fi | |
| 66 | 69 | ||
| 67 | 70 | ||
| 68 | 71 | printf 'NEED_SVCGSSD="yes"\n' >>/etc/default/nfs-kernel-server | |
| 69 | 72 | ||
| 70 | 73 | cat >'/etc/idmapd.conf' <<EOF | |
| 71 | 74 | # Verbosity = 8 logs all idmapper lookups | |
| 72 | 75 | Verbosity = 8 | |
| 73 | 76 | Pipefs-Directory = /run/rpc_pipefs | |
| 74 | 77 | # set your own domain here, if it differs from FQDN minus hostname | |
| 75 | 78 | # Domain = localdomain | |
| 76 | 79 | # Value for "Domain" must be lowercase, value for "Local-Realms" uppercase | |
| 77 | 80 | Domain = ${config.nfsdomain} | |
| 78 | 81 | Local-Realms = ${config.realmname} | |
| 79 | 82 | ||
| 80 | 83 | [Mapping] | |
| 81 | 84 | Nobody-User = nobody | |
| 82 | 85 | Nobody-Group = nogroup | |
| 83 | 86 | EOF | |
| 84 | 87 | ||
| 85 | 88 | cat >"${KRB5_CONFIG}" <<EOF | |
| 86 | 89 | [libdefaults] | |
| 87 | 90 | default_realm = ${config.realmname} | |
| 88 | 91 | default_ccache_name = DIR:/tmp/krb5cc_dir_%{uid} | |
| 89 | 92 | ||
| 90 | 93 | [realms] | |
| 91 | 94 | ${config.realmname} = { | |
| 92 | 95 | kdc = ${config.hostname}:${config.kdcport} | |
| 93 | 96 | admin_server = ${config.hostname}:${config.kadmindport} | |
| 94 | 97 | } | |
| 95 | 98 | EOF | |
| 96 | 99 | ||
| 97 | 100 | ||
| 98 | 101 | cat >"${KRB5_KDC_PROFILE}" <<EOF | |
| 99 | 102 | [kdcdefaults] | |
| 100 | 103 | kdc_ports = ${config.kdcport} | |
| 101 | 104 | kdc_tcp_ports = ${config.kdcport} | |
| 102 | 105 | ||
| 103 | 106 | [realms] | |
| 104 | 107 | ${config.realmname} = { | |
| 105 | 108 | kadmind_port = ${config.kadmindport} | |
| 106 | 109 | acl_file = ${kdctestdir}/kadm5.acl | |
| 107 | 110 | admin_keytab = ${kdctestdir}/kadm5.keytab | |
| 108 | 111 | database_name = ${kdctestdir}/principal | |
| 109 | 112 | key_stash_file = ${kdctestdir}/.k5.${config.realmname} | |
| 110 | 113 | ||
| 111 | 114 | max_life = 12h 0m 0s | |
| 112 | 115 | max_renewable_life = 7d 0h 0m 0s | |
| 113 | 116 | master_key_type = aes256-cts-hmac-sha1-96 | |
| 114 | 117 | supported_enctypes = aes256-cts-hmac-sha1-96:normal aes128-cts-hmac-sha1-96:normal arcfour-hmac:normal | |
| 115 | 118 | } | |
| 116 | 119 | ||
| 117 | 120 | [logging] | |
| 118 | 121 | kdc = FILE:${kdctestdir}/kdc.log | |
| 119 | 122 | admin_server = FILE:${kdctestdir}/kadmin.log | |
| 120 | 123 | default = FILE:${kdctestdir}/default.log | |
| 121 | 124 | ||
| 122 | 125 | EOF | |
| 123 | 126 | ||
| 124 | 127 | { | |
| 125 | 128 | printf '%s\n' 'myhorriblepassword12' | |
| 126 | 129 | printf '%s\n' 'myhorriblepassword12' | |
| 127 | 130 | } | kdb5_util create -r "${config.realmname}" -s | |
| 128 | 131 | ||
| 129 | 132 | ||
| 130 | 133 | ||
| 131 | 134 | # | |
| 132 | 135 | # add principals | |
| 133 | 136 | # | |
| 134 | 137 | compound -A principal_list=( | |
| 135 | 138 | # add admin user | |
| 136 | 139 | ['admin']=( | |
| 137 | 140 | principal="admin/admin@${config.realmname}" | |
| 138 | 141 | password='myhorriblepassword12' | |
| 139 | 142 | ) | |
| 140 | 143 | ||
| 141 | 144 | # add plain (Windows) user | |
| 142 | 145 | ['user1']=( | |
| 143 | 146 | principal="rmainz@${config.realmname}" | |
| 144 | 147 | password='myhorriblepassword12' | |
| 145 | 148 | ) | |
| 146 | 149 | ||
| 147 | 150 | # add Linux host | |
| 148 | 151 | ['linuxhost1']=( | |
| 149 | 152 | principal="host/debnfskrb5001@${config.realmname}" | |
| 150 | 153 | password='myhorriblepassword12' | |
| 151 | 154 | ) | |
| 152 | 155 | ['linuxhost1_fqdn']=( | |
| 153 | 156 | principal="host/debnfskrb5001.nfschicken.test@${config.realmname}" | |
| 154 | 157 | password='myhorriblepassword12' | |
| 155 | 158 | ) | |
| 156 | 159 | ||
| 157 | 160 | # add NFS service on Linux host | |
| 158 | 161 | ['linuxhost1_nfs_service']=( | |
| 159 | 162 | principal="nfs/debnfskrb5001@${config.realmname}" | |
| 160 | 163 | password='myhorriblepassword12' | |
| 161 | 164 | ) | |
| 162 | 165 | ['linuxhost1_nfs_service_fqdn']=( | |
| 163 | 166 | principal="nfs/debnfskrb5001.nfschicken.test@${config.realmname}" | |
| 164 | 167 | password='myhorriblepassword12' | |
| 165 | 168 | ) | |
| 166 | 169 | ||
| 167 | 170 | # add Windows machine | |
| 168 | 171 | ['win1']=( | |
| 169 | 172 | principal="host/wingrendel02@${config.realmname}" | |
| 170 | 173 | password='myhorriblepassword12' | |
| 171 | 174 | ) | |
| 172 | 175 | ['win1_fqdn']=( | |
| 173 | 176 | principal="host/wingrendel02.nfschicken.test@${config.realmname}" | |
| 174 | 177 | password='myhorriblepassword12' | |
| 175 | 178 | ) | |
| 176 | 179 | ) | |
| 177 | 180 | ||
| 178 | 181 | for pi in "${!principal_list[@]}" ; do | |
| 179 | 182 | nameref pie="principal_list[$pi]" | |
| 180 | 183 | ||
| 181 | 184 | { | |
| 182 | 185 | printf "addprinc %s\n" "${pie.principal}" | |
| 183 | 186 | printf '%s\n' "${pie.password}" | |
| 184 | 187 | printf '%s\n' "${pie.password}" | |
| 185 | 188 | } | kadmin.local | |
| 186 | 189 | done | |
| 187 | 190 | ||
| 188 | 191 | # | |
| 189 | 192 | # create /etc/krb5.keytab for NFS server | |
| 190 | 193 | # | |
| 191 | 194 | rm -f /tmp/nfs01.keytab | |
| 192 | 195 | { | |
| 193 | 196 | printf 'ktadd -k /tmp/nfs01.keytab nfs/debnfskrb5001.nfschicken.test@NFSCHICKEN.TEST\n' | |
| 194 | 197 | } | kadmin.local | |
| 195 | 198 | mv -f /tmp/nfs01.keytab /etc/krb5.keytab | |
| 196 | 199 | ||
| 197 | 200 | # | |
| 198 | 201 | # start KDC | |
| 199 | 202 | # | |
| 200 | 203 | krb5kdc -n & | |
| 201 | 204 | (( kdc_pid=$! )) | |
| 202 | 205 | ||
| 203 | 206 | # wait for KDC to start | |
| 204 | 207 | sleep 10 | |
| 205 | 208 | ||
| 206 | 209 | # | |
| 207 | 210 | # simple function test | |
| 208 | 211 | # | |
| 209 | 212 | { | |
| 210 | 213 | printf '%s\n' 'myhorriblepassword12' | |
| 211 | 214 | } | kinit "admin/admin@${config.realmname}" | |
| 212 | 215 | { | |
| 213 | 216 | printf '%s\n' 'myhorriblepassword12' | |
| 214 | 217 | } | kinit "rmainz@${config.realmname}" | |
| 215 | 218 | ||
| 216 | 219 | klist -A | |
| 217 | 220 | ||
| 218 | 221 | # | |
| 219 | 222 | # restart NFS server to pickup changes in /etc/exports and KRB5 changes | |
| 220 | 223 | # | |
| 221 | 224 | systemctl restart nfs-idmapd.service | |
| 222 | 225 | sleep 5 | |
| 223 | 226 | systemctl restart nfs-kernel-server | |
| 224 | 227 | ||
| 225 | 228 | # | |
| 226 | 229 | # sleep for two weeks | |
| 227 | 230 | # | |
| 228 | 231 | sleep $((60*60*24*7*2)) | |
| 229 | 232 | ||
| 230 | 233 | kill $kdc_pid | |
| 231 | 234 | wait $kdc_pid | |
| 232 | 235 | ||
| 233 | 236 | # EOF. | |
| 234 | 237 |
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.
nrubsig.kpaste.net RSS