I want to setup a cron job with AD user. What is the potential risk if I setup cron job by AD user credential? What is prerequisite to do so? Can you list out the detail steps?
There is security risk when you setup cron job with AD user credential. The keytab file contains kerberos password hash for AD user that can be read by root.
DirectControl 4.4.1 ensures crond starts after adclient ready, so that ensure the crond job can be run as AD user.
Steps for setup cronjob for AD user with kerberos credential:
(1) create SPN for the AD user:
(a) on windows side,
setspn -A cron/<aduser> <aduser>
(b) on a joined Linux/Unix machine, run as root,
adkeytab -a -u <ad-admin> -P cron/<aduser> <aduser>
(2) create keytab for <aduser>:
on Unix/Linux side, as root,
adkeytab -A -K /etc/<aduser>.keytab -u <ad-admin> -p <ad-admin-pswd> --local –w <aduser-passwd> <aduser>
e.g. adkeytab -A -K /etc/test113.keytab -u administrator -p <admin-pwd> --local –w <test113-pwd> test113
(3) chown <aduser>:<adgroup> /etc/<aduser>.keytab
(4) to verify content, run as <aduser>,
/usr/share/centrifydc/kerberos/bin/klist -kt /etc/<aduser>.keytab
/etc/<aduser>.keytab now contains the password hash for kinit to obtain kerberos credential as <aduser>.
Add in cron job script:
/usr/share/centrifydc/kerberos/bin/kinit -kt /etc/<aduser>.keytab <aduser>
This create kerberos ticket cache for the AD user - that can be used to do SSO ssh with, from inside the cron script, for example.
To verify user kerberos credential is present, add line in cron script to see:
(A) /etc/<aduser>.keytab needs to be re-created after <aduser> password change. so, simply:
rm /etc/<aduser>/keytab, and redo step (2) and (3).
(B) the keytab file /etc/<aduser>.keytab can be copied from host to host - this is tied to the AD user, not to the machine.