Injecting files with tmpfiles.d

I’m trying to bake in a file into my image using tmpfiles.d, but I’m having no luck, the resulting file appears but is empty. This method is described in bootc’s docs.

In a system running from my image I have a file /usr/lib/tmpfiles.d/backup-key.conf with contents:

f~ /var/home/backup/.ssh/backup.key 600 backup backup - SSBkb27igJl0IHdhbnQgdG8gdGFsayB0byB5b3Ugbm8gbW9yZSwgeW91IGVtcHR5LWhlYWRlZCBhbmltYWwgZm9vZCB0cm91Z2ggd2lwZXIuIEkgZmFydCBpbiB5b3VyIGdlbmVyYWwgZGlyZWN0aW9uLiBZb3VyIG1vdGhlciB3YXMgYSBoYW1zdGVyIGFuZCB5b3VyIGZhdGhlciBzbWVsdCBvZiBlbGRlcmJlcnJpZXMu

This does cause the file to appear, but it’s empty. Anyone have any idea what am I doing wrong?

root in ~
❯ ls -alsh /var/home/backup/.ssh/
total 0
0 drwxr-xr-x. 2 root   root   25 Feb 13 13:47 .
0 drwxr-xr-x. 3 root   root   18 Feb 13 13:47 ..
0 -rw-------. 1 backup backup  0 Feb 13 13:47 backup.key

root in ~
❯ cat /var/home/backup/.ssh/backup.key

root in ~
❯

I’m building the image for myself using my self-hosted Forgejo in my isolated homelab. Nothing is public so there’s no risk in baking SSH keys into my images.

What if you use f+ instead of f~ ?

Nevermind, I kept the empty file from earlier experiments and this mechanism doesn’t rewrite it once it is created. The contents do appear on redeploy.

1 Like