pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


nfskrb5test1.ksh - KDC test script for Windows NFS krb5 setup test #001
Posted by Anonymous on Wed 26th Aug 2026 17:56
raw | new post
view followups (newest first): nfskrb5test1.ksh - KDC test script for Windows NFS krb5 setup test #001 by Anonymous

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

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