Skip to content

Commit

Permalink
Make 'fscrypt setup' offer a choice of directory modes
Browse files Browse the repository at this point in the history
World-writable directories are not appropriate for some systems, so
offer a choice of single-user-writable and world-writable modes, with
single-user-writable being the default.  Add a new documentation section
to help users decide which one to use.
  • Loading branch information
ebiggers committed Feb 23, 2022
1 parent 45599bd commit 6e35513
Show file tree
Hide file tree
Showing 22 changed files with 374 additions and 67 deletions.
53 changes: 48 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies](#runtime-dependencies).
- [Building and installing](#building-and-installing)
- [Runtime dependencies](#runtime-dependencies)
- [Configuration file](#configuration-file)
- [Setting up `fscrypt` on a filesystem](#setting-up-fscrypt-on-a-filesystem)
- [Setting up for login protectors](#setting-up-for-login-protectors)
- [Securing your login passphrase](#securing-your-login-passphrase)
- [Enabling the PAM module](#enabling-the-pam-module)
Expand Down Expand Up @@ -377,6 +378,44 @@ The fields are:
kernels, it's better to not use this setting and instead (re-)create your
encrypted directories with `"policy_version": "2"`.

## Setting up `fscrypt` on a filesystem

`fscrypt` needs some directories to exist on the filesystem on which encryption
will be used:

* `MOUNTPOINT/.fscrypt/policies`
* `MOUNTPOINT/.fscrypt/protectors`

(If login protectors are used, these must also exist on the root filesystem.)

To create these directories, run `fscrypt setup MOUNTPOINT`. If MOUNTPOINT is
owned by root, as is usually the case, then this command will require root.

There will be one decision you'll need to make: whether non-root users will be
allowed to create `fscrypt` metadata (policies and protectors).

If you say `y`, then these directories will be made world-writable, with the
sticky bit set so that users can't delete each other's files -- just like
`/tmp`. If you say `N`, then these directories will be writable only by root.

Saying `y` maximizes the usability of `fscrypt`, and on most systems it's fine
to say `y`. However, on some systems this may be inappropriate, as it will
allow malicious users to fill the entire filesystem unless filesystem quotas
have been configured -- similar to problems that have historically existed with
other world-writable directories, e.g. `/tmp`. If you are concerned about this,
say `N`. If you say `N`, then you'll only be able to run `fscrypt` as root to
set up encryption on users' behalf, unless you manually set custom permissions
on the metadata directories to grant write access to specific users or groups.

If you chose the wrong mode at `fscrypt setup` time, you can change the
directory permissions at any time. To enable single-user writable mode, run:

sudo chmod 0755 MOUNTPOINT/.fscrypt/*

To enable world-writable mode, run:

sudo chmod 1777 MOUNTPOINT/.fscrypt/*

## Setting up for login protectors

If you want any encrypted directories to be protected by your login passphrase,
Expand Down Expand Up @@ -646,11 +685,15 @@ MOUNTPOINT DEVICE FILESYSTEM ENCRYPTION FSCRYPT
Defaulting to policy_version 2 because kernel supports it.
Customizing passphrase hashing difficulty for this system...
Created global config file at "/etc/fscrypt.conf".
Metadata directories created at "/.fscrypt".
Allow users other than root to create fscrypt metadata on the root filesystem?
(See https://github.com/google/fscrypt#setting-up-fscrypt-on-a-filesystem) [y/N] y
Metadata directories created at "/.fscrypt", writable by everyone.

# Start using fscrypt with our filesystem
>>>>> fscrypt setup /mnt/disk
Metadata directories created at "/mnt/disk/.fscrypt".
>>>>> sudo fscrypt setup /mnt/disk
Allow users other than root to create fscrypt metadata on this filesystem? (See
https://github.com/google/fscrypt#setting-up-fscrypt-on-a-filesystem) [y/N] y
Metadata directories created at "/mnt/disk/.fscrypt", writable by everyone.

# Initialize encryption on a new empty directory
>>>>> mkdir /mnt/disk/dir1
Expand Down Expand Up @@ -678,8 +721,8 @@ POLICY UNLOCKED PROTECTORS

#### Quiet version
```bash
>>>>> sudo fscrypt setup --quiet --force
>>>>> fscrypt setup /mnt/disk --quiet
>>>>> sudo fscrypt setup --quiet --force --all-users
>>>>> sudo fscrypt setup /mnt/disk --quiet --all-users
>>>>> echo "hunter2" | fscrypt encrypt /mnt/disk/dir1 --quiet --source=custom_passphrase --name="Super Secret"
```

Expand Down
3 changes: 2 additions & 1 deletion actions/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"testing"
"time"

"github.com/google/fscrypt/filesystem"
"github.com/google/fscrypt/util"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -67,7 +68,7 @@ func setupContext() (ctx *Context, err error) {
return nil, err
}

return ctx, ctx.Mount.Setup()
return ctx, ctx.Mount.Setup(filesystem.WorldWritable)
}

// Cleans up the testing config file and testing filesystem data.
Expand Down
4 changes: 2 additions & 2 deletions cli-tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ setup_for_test()

# Give the tests their own fscrypt.conf.
export FSCRYPT_CONF="$TMPDIR/fscrypt.conf"
fscrypt setup --time=1ms > /dev/null
fscrypt setup --time=1ms --quiet --all-users > /dev/null

# The tests assume kernel support for v2 policies.
if ! grep -q '"policy_version": "2"' "$FSCRYPT_CONF"; then
Expand All @@ -171,7 +171,7 @@ EOF
fi

# Set up the test filesystems that aren't already set up.
fscrypt setup "$MNT" > /dev/null
fscrypt setup --quiet --all-users "$MNT" > /dev/null
}

run_test()
Expand Down
18 changes: 12 additions & 6 deletions cli-tests/t_encrypt.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

# Try to encrypt a nonexistent directory
[ERROR] fscrypt encrypt: no such file or directory
ext4 filesystem "MNT" has 0 protectors and 0 policies
ext4 filesystem "MNT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

[ERROR] fscrypt status: file or directory "MNT/dir" is not
encrypted
Expand All @@ -23,7 +24,8 @@ files into it, and securely delete the original directory. For example:
Caution: due to the nature of modern storage devices and filesystems, the
original data may still be recoverable from disk. It's much better to encrypt
your files from the start.
ext4 filesystem "MNT" has 0 protectors and 0 policies
ext4 filesystem "MNT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

[ERROR] fscrypt status: file or directory "MNT/dir" is not
encrypted
Expand All @@ -45,13 +47,15 @@ files into it, and securely delete the original directory. For example:
Caution: due to the nature of modern storage devices and filesystems, the
original data may still be recoverable from disk. It's much better to encrypt
your files from the start.
ext4 filesystem "MNT" has 0 protectors and 0 policies
ext4 filesystem "MNT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

[ERROR] fscrypt status: file or directory "MNT/dir" is not
encrypted

# Encrypt a directory as non-root user
ext4 filesystem "MNT" has 1 protector and 1 policy
ext4 filesystem "MNT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc1 No custom protector "prot"
Expand All @@ -67,7 +71,8 @@ Unlocked: Yes
Protected with 1 protector:
PROTECTOR LINKED DESCRIPTION
desc1 No custom protector "prot"
ext4 filesystem "MNT" has 1 protector and 1 policy
ext4 filesystem "MNT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc1 No custom protector "prot"
Expand All @@ -94,7 +99,8 @@ desc1 No custom protector "prot"

Encryption can only be enabled on a directory you own,
even if you have write access to the directory.
ext4 filesystem "MNT" has 0 protectors and 0 policies
ext4 filesystem "MNT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

[ERROR] fscrypt status: file or directory "MNT/dir" is not
encrypted
9 changes: 6 additions & 3 deletions cli-tests/t_encrypt_custom.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# Encrypt with custom passphrase protector
ext4 filesystem "MNT" has 1 protector and 1 policy
ext4 filesystem "MNT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc1 No custom protector "prot"
Expand Down Expand Up @@ -28,7 +29,8 @@ Enter a name for the new protector: prot
Enter custom passphrase for protector "prot":
Confirm passphrase:
"MNT/dir" is now encrypted, unlocked, and ready for use.
ext4 filesystem "MNT" has 1 protector and 1 policy
ext4 filesystem "MNT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc6 No custom protector "prot"
Expand All @@ -49,7 +51,8 @@ desc6 No custom protector "prot"
[ERROR] fscrypt encrypt: custom_passphrase protectors must be named

Use --name=PROTECTOR_NAME to specify a protector name.
ext4 filesystem "MNT" has 0 protectors and 0 policies
ext4 filesystem "MNT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

[ERROR] fscrypt status: file or directory "MNT/dir" is not
encrypted
42 changes: 28 additions & 14 deletions cli-tests/t_encrypt_login.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ IMPORTANT: See "MNT/dir/fscrypt_recovery_readme.txt" for
will lose access to this directory if you reinstall the operating
system or move this filesystem to another system.

ext4 filesystem "MNT" has 2 protectors and 1 policy
ext4 filesystem "MNT" has 2 protectors and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc1 Yes (MNT_ROOT) login protector for fscrypt-test-user
desc2 No custom protector "Recovery passphrase for dir"

POLICY UNLOCKED PROTECTORS
desc3 Yes desc1, desc2
ext4 filesystem "MNT_ROOT" has 1 protector and 0 policies
ext4 filesystem "MNT_ROOT" has 1 protector and 0 policies.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc1 No login protector for fscrypt-test-user
Expand Down Expand Up @@ -57,15 +59,17 @@ IMPORTANT: See "MNT/dir/fscrypt_recovery_readme.txt" for
system or move this filesystem to another system.

"MNT/dir" is now encrypted, unlocked, and ready for use.
ext4 filesystem "MNT" has 2 protectors and 1 policy
ext4 filesystem "MNT" has 2 protectors and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc10 Yes (MNT_ROOT) login protector for fscrypt-test-user
desc11 No custom protector "Recovery passphrase for dir"

POLICY UNLOCKED PROTECTORS
desc12 Yes desc10, desc11
ext4 filesystem "MNT_ROOT" has 1 protector and 0 policies
ext4 filesystem "MNT_ROOT" has 1 protector and 0 policies.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc10 No login protector for fscrypt-test-user
Expand All @@ -88,15 +92,17 @@ IMPORTANT: See "MNT/dir/fscrypt_recovery_readme.txt" for
will lose access to this directory if you reinstall the operating
system or move this filesystem to another system.

ext4 filesystem "MNT" has 2 protectors and 1 policy
ext4 filesystem "MNT" has 2 protectors and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc19 Yes (MNT_ROOT) login protector for fscrypt-test-user
desc20 No custom protector "Recovery passphrase for dir"

POLICY UNLOCKED PROTECTORS
desc21 Yes desc19, desc20
ext4 filesystem "MNT_ROOT" has 1 protector and 0 policies
ext4 filesystem "MNT_ROOT" has 1 protector and 0 policies.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc19 No login protector for fscrypt-test-user
Expand All @@ -114,14 +120,16 @@ desc20 No custom protector "Recovery passphras
Protector is owned by fscrypt-test-user:fscrypt-test-user

# Encrypt with login protector with --no-recovery
ext4 filesystem "MNT" has 1 protector and 1 policy
ext4 filesystem "MNT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc28 Yes (MNT_ROOT) login protector for fscrypt-test-user

POLICY UNLOCKED PROTECTORS
desc29 Yes desc28
ext4 filesystem "MNT_ROOT" has 1 protector and 0 policies
ext4 filesystem "MNT_ROOT" has 1 protector and 0 policies.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc28 No login protector for fscrypt-test-user
Expand All @@ -145,7 +153,8 @@ Unlocked: Yes
Protected with 1 protector:
PROTECTOR LINKED DESCRIPTION
desc35 No login protector for fscrypt-test-user
ext4 filesystem "MNT_ROOT" has 1 protector and 1 policy
ext4 filesystem "MNT_ROOT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc35 No login protector for fscrypt-test-user
Expand All @@ -159,18 +168,22 @@ desc34 Yes desc35
identified by user, not by name.

To fix this, don't specify the --name=PROTECTOR_NAME option.
ext4 filesystem "MNT" has 0 protectors and 0 policies
ext4 filesystem "MNT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

ext4 filesystem "MNT_ROOT" has 0 protectors and 0 policies
ext4 filesystem "MNT_ROOT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

[ERROR] fscrypt status: file or directory "MNT/dir" is not
encrypted

# Try to use the wrong login passphrase
[ERROR] fscrypt encrypt: incorrect login passphrase
ext4 filesystem "MNT" has 0 protectors and 0 policies
ext4 filesystem "MNT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

ext4 filesystem "MNT_ROOT" has 0 protectors and 0 policies
ext4 filesystem "MNT_ROOT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

[ERROR] fscrypt status: file or directory "MNT/dir" is not
encrypted
Expand All @@ -183,7 +196,8 @@ IMPORTANT: See "MNT/dir/fscrypt_recovery_readme.txt" for
will lose access to this directory if you reinstall the operating
system or move this filesystem to another system.

ext4 filesystem "MNT" has 2 protectors and 1 policy
ext4 filesystem "MNT" has 2 protectors and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc39 No custom protector "Recovery passphrase for dir"
Expand Down
15 changes: 10 additions & 5 deletions cli-tests/t_encrypt_raw_key.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# Encrypt with raw_key protector from file
ext4 filesystem "MNT" has 1 protector and 1 policy
ext4 filesystem "MNT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc1 No raw key protector "prot"
Expand All @@ -18,7 +19,8 @@ PROTECTOR LINKED DESCRIPTION
desc1 No raw key protector "prot"

# Encrypt with raw_key protector from stdin
ext4 filesystem "MNT" has 1 protector and 1 policy
ext4 filesystem "MNT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc6 No raw key protector "prot"
Expand All @@ -37,21 +39,24 @@ desc6 No raw key protector "prot"

# Try to encrypt with raw_key protector from file, using wrong key length
[ERROR] fscrypt encrypt: TMPDIR/raw_key: key file must be 32 bytes
ext4 filesystem "MNT" has 0 protectors and 0 policies
ext4 filesystem "MNT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

[ERROR] fscrypt status: file or directory "MNT/dir" is not
encrypted

# Try to encrypt with raw_key protector from stdin, using wrong key length
[ERROR] fscrypt encrypt: unexpected EOF
ext4 filesystem "MNT" has 0 protectors and 0 policies
ext4 filesystem "MNT" has 0 protectors and 0 policies.
All users can create fscrypt metadata on this filesystem.

[ERROR] fscrypt status: file or directory "MNT/dir" is not
encrypted

# Encrypt with raw_key protector from file, unlock from stdin
"MNT/dir" is now locked.
ext4 filesystem "MNT" has 1 protector and 1 policy
ext4 filesystem "MNT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc11 No raw key protector "prot"
Expand Down
6 changes: 4 additions & 2 deletions cli-tests/t_metadata.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ext4 filesystem "MNT" has 3 protectors and 1 policy
ext4 filesystem "MNT" has 3 protectors and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc1 No custom protector "foo"
Expand All @@ -7,7 +8,8 @@ desc3 No custom protector "baz"

POLICY UNLOCKED PROTECTORS
desc4 No desc1, desc2, desc3
ext4 filesystem "MNT" has 2 protectors and 1 policy
ext4 filesystem "MNT" has 2 protectors and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc1 No custom protector "foo"
Expand Down
Loading

0 comments on commit 6e35513

Please sign in to comment.