factotumをsystemdで管理する
もともと factotum 自体はsystemdで管理できていたが、factotum の起動時に secstore からシークレットを読むことができなかった。オリジナルのPlan 9版では -S オプションによって、nvram に入れておいた secstore のパスワードを起動時に読むことができたが、plan9portでは閉じられていたので使えない。
ユーザー権限でsystemd-credsを使うと、シークレットをsystemdが安全に管理してくれるので、これを使うとよい。
[Unit]Description=factotumAfter=default.target
[Service]Type=forkingEnvironment=PLAN9=/usr/local/plan9LoadCredentialEncrypted=secstore.secret:%h/lib/secstore.keyExecStart=/usr/local/plan9/bin/factotumExecStartPost=bash -c 'secstore -iG factotum <%d/secstore.secret | 9p write -l factotum/ctl'
[Install]WantedBy=default.targetこのとき、ファイルが存在しない場合はエラーになってしまうので plan9port-systemd-units では設定していない。なので自動的に読み込みたい場合は個別にオーバーライドして使う。
[Service]LoadCredentialEncrypted=secstore.secret:%h/lib/secstore.keyExecStartPost=bash -c 'secstore -iG factotum <%d/secstore.secret | 9p write -l factotum/ctl'ただし注意点がいくつかあって、factotum 自身が secstore のパスワードを扱うことはできないので、ExecStartPost ディレクティブで後から追加する。また、 9p write コマンドは1行しか扱えない。secstore に複数のシークレットが入っていると以下のエラーが発生する。
9p: write error: multiline write not allowed
なので、9p コマンドに -l オプションを与えて複数行を扱えるようにする必要があった。
あとはログイン時に実行させればいいが、以前はWaylandバックエンドだと DISPLAY 環境変数がなくて動かなかった。今はどうだろうか。
systemctl --user enable --now factotum.service