Improve encfs cookbook

Fix some things, and prepare for path-based activation. Also, comment
the buggy initial dir creation and explain manual provisioning in README
for now.
This commit is contained in:
Basti 2020-06-07 12:45:33 +02:00
parent 8918452fc5
commit 353f2c13f1
No known key found for this signature in database
GPG Key ID: BE4634D632D39B67
6 changed files with 50 additions and 17 deletions

View File

@ -1,3 +1,15 @@
# kosmos_encfs # kosmos_encfs
Install encfs and set up encryption for a data directory Install encfs and set up encryption for a data directory.
## Provisioning a new machine
Add encfs to the run list and run chef before adding other cookbooks that
depends on the encfs mount.
Log into the system and create the data directory like so:
encfs /usr/local/lib/encrypted_data /mnt/data --public
When asked for config options, choose nothing (i.e. "standard"). Do NOT choose
paranoia mode, as it breaks some software, like e.g. PostgreSQL.

View File

@ -1,11 +1,9 @@
[Unit] [Unit]
Description=EncFS for data dir Description=EncFS for data dir
Before=postgresql@12-main.service
BindsTo=postgresql@12-main.service
[Service] [Service]
Type=oneshot Type=oneshot
RemainAfterExit=yes RemainAfterExit=yes
ExecStart=/usr/local/bin/mount_encfs ExecStart=/usr/local/bin/mount_encfs
ExecStop=/bin/umount /mnt/data ExecStop=/usr/local/bin/unmount_encfs
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -35,11 +35,17 @@ mount_directory = "/mnt/data"
template "/usr/local/bin/mount_encfs" do template "/usr/local/bin/mount_encfs" do
source "mount_encfs.erb" source "mount_encfs.erb"
mode "0700" mode "0755"
variables encrypted_directory: encrypted_directory, variables encrypted_directory: encrypted_directory,
mount_directory: mount_directory mount_directory: mount_directory
end end
template "/usr/local/bin/unmount_encfs" do
source "unmount_encfs.erb"
mode "0700"
variables mount_directory: mount_directory
end
execute "systemctl daemon-reload" do execute "systemctl daemon-reload" do
command "systemctl daemon-reload" command "systemctl daemon-reload"
action :nothing action :nothing
@ -50,19 +56,22 @@ directory mount_directory do
mode "0775" mode "0775"
end end
execute "create encrypted file system" do # FIXME the password that is stored using this script does not match the actual password
command <<-EOF # execute "create encrypted file system" do
echo "y\\\n # command <<-EOF
y\\\n # echo "y\\\n
p\\\n # y\\\n
#{encfs_password}\\\n # FIXME paranoia mode breaks hard links, which postgres relies on
#{encfs_password}\\\n # p\\\n
" | encfs #{encrypted_directory} #{mount_directory} --public --stdinpass # #{encfs_password}\\\n
EOF # #{encfs_password}\\\n
sensitive true # " | encfs #{encrypted_directory} #{mount_directory} --public --stdinpass
not_if { ::File.exist?(encrypted_directory) } # EOF
end # sensitive true
# not_if { ::File.exist?(encrypted_directory) }
# end
# FIXME there seems to be half a comment missing here
# The service will automatically # The service will automatically
cookbook_file "/lib/systemd/system/encfs.service" do cookbook_file "/lib/systemd/system/encfs.service" do
source "encfs.service" source "encfs.service"

View File

@ -1,3 +1,4 @@
#!/bin/sh #!/bin/sh
systemd-ask-password --echo "encfs password:" | encfs <%= @encrypted_directory %> <%= @mount_directory %> --public --stdinpass systemd-ask-password --echo "encfs password:" | encfs <%= @encrypted_directory %> <%= @mount_directory %> --public --stdinpass
echo "Encrypted data directory mounted as <%= @mount_directory %>" > /tmp/data-dir-mounted.txt

View File

@ -0,0 +1,9 @@
[Unit]
Description=Start <%= @service_unit %> when encrypted data directory is mounted
[Path]
PathExists=/tmp/data-dir-mounted.txt
Unit=<%= @service_unit %>
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,4 @@
#!/bin/sh
rm /tmp/data-dir-mounted.txt
/bin/umount <%= @mount_directory %>