I am using systemd to mount a Windows share using Kerberos. To make this work, I first run kinit
in a .service file to create a Kerberos credential cache (ccache). The .service runs as root as the ccache needs to be owned by root (journalctl -xe
helped me with that), as mount.cifs requires root. The .mount (and .automount) use the ccache to do the Kerberized mount. When I create the ccache interactively, this works well. However, when run inside the service unit, the ccache is quickly deleted and the (auto)mount fails. It does not matter if I save it to /tmp or /run/user/0.
- Why are files in /tmp or /run automatically deleted?
- What is the preferred location for these ccache files? Is
PrivateTmp
a better solution? If so, how do I refer to that private tmp dir inside the service file? I tried%T/krb5cc_root.ccache
, but systemctl generates an error. IsJoinsNamespaceOf
the way to use the same private tmp in the mount file?
I am using systemd 219 on linux CentOS 7. Below is my .service unit. Thanks in advance!
[Unit]
Description=Kinit keytab for /mnt/windows_staging
After=network.target
Requires=network.target
[Service]
Restart=always
RestartSec=30
PrivateTmp=yes
User=root
Group=users
ExecStartPre=-/bin/mkdir -p /mnt/windows_staging
ExecStartPre=-/bin/mkdir -p /run/user/0
Environment=KRB5_KTNAME=/home/albertjan@domain/myproject/etc/keytabs/albertjan.keytab
Environment=KRB5CCNAME=/run/user/0/krb5cc_root.ccache
ExecStart=/bin/kinit albertjan -kt ${KRB5_KTNAME} -c ${KRB5CCNAME}
ExecStartPost=/bin/sleep 2
ExecStop=-/bin/kdestroy -c ${KRB5CCNAME}
[Install]
WantedBy=multi-user.target