aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2020-05-09Add cli-tests frameworkEric Biggers
Add a framework for writing automated tests of the fscrypt command-line tool. See cli-tests/README.md for details.
2020-05-09cmd/fscrypt: add FSCRYPT_CONSISTENT_OUTPUT environmental variableEric Biggers
Allow setting FSCRYPT_CONSISTENT_OUTPUT=1 in the environment to cause policies and protectors to sorted by last modification time. The CLI tests need this to make the output of 'fscrypt' ordered in a consistent way with regard to the operations performed.
2020-05-09cmd/fscrypt: add FSCRYPT_ROOT_MNT environmental variableEric Biggers
Allow overriding the mountpoint where login protectors are stored by setting the FSCRYPT_ROOT_MNT environmental variable. The CLI tests need this to avoid touching the real "/".
2020-05-09cmd/fscrypt: add FSCRYPT_CONF environmental variableEric Biggers
Allow overriding the location of fscrypt.conf by setting the FSCRYPT_CONF environmental variable. The CLI tests need this to avoid touching the real /etc/fscrypt.conf.
2020-05-09travis.yml: stop overriding e2fsprogs version (#222)Eric Biggers
There's no longer a need to override the Ubuntu version that the Travis CI builds install e2fsprogs from, since we now use "dist: bionic", and e2fsprogs in Bionic supports encryption.
2020-05-09keyring: cast FS_IOC_REMOVE_ENCRYPTION_KEY to uintptr (#221)Filip Stanis
Since v0.2.6, fscrypt only builds for 64-bit systems. E.g. trying to build on Raspbian fails with the following error: $ go get github.com/google/fscrypt/cmd/fscrypt # github.com/google/fscrypt/keyring go/src/github.com/google/fscrypt/keyring/fs_keyring.go:231:6: constant 3225445912 overflows int go/src/github.com/google/fscrypt/keyring/fs_keyring.go:235:7: constant 3225445913 overflows int Fix it by making the 'ioc' variable have type uintptr. [EB - removed the later cast to uintptr that became unnecessary, and added explanation to commit message.]
2020-04-16Allow fscrypt to work in containers (#213)Eric Biggers
Update the /proc/self/mountinfo parsing code to allow selecting a Mount with Subtree != "/", i.e. a Mount not of the full filesystem. This is needed to allow fscrypt to work in containers, where the root of the filesystem may not be mounted. See findMainMount() for details about the algorithm used. Resolves https://github.com/google/fscrypt/issues/211
2020-03-24Release version v0.2.7v0.2.7Joe Richey
Signed-off-by: Joe Richey <joerichey@google.com>
2020-03-24Makefile: Use trimpath if available (#208)Joseph Richey
Passing -trimpath makes the build entirely reproducible. Signed-off-by: Joe Richey <joerichey@google.com>
2020-03-23cmd: Simplify "fscrypt --version" output (#207)Joseph Richey
There's no need to include the build time, author, and copyright info in the output of "fscrypt --version". This information is: - Overly complex (the current string is hard to parse) - Inaccurate (there are other authors than just me) - Unnecessary (the Apache 2 license is for Source Code) - Makes reproducible builds impossible The default version string is just fine. Signed-off-by: Joe Richey <joerichey@google.com>
2020-03-23Merge pull request #205 from ebiggers/autoselect-v2Joseph Richey
Automatically enable policy_version 2 when kernel support is detected
2020-03-23README.md: update v2 policy-related documentationEric Biggers
- Mention that a v5.4+ kernel is recommended. - Mention that policy_version defaults to 1 when unset. - Emphasize that v2 policies are the recommended solution to the key visibility problems, and add some more information.
2020-03-23README.md: update examples to use v2 policiesEric Biggers
Since on new kernels v1 encryption policies are deprecated in favor of v2, update the examples to show v2. This mostly just consists of updating the output, as the commands are essentially the same with one notable difference in 'fscrypt lock'.
2020-03-23Improve error message when unlocking v2 policy is unsupportedEric Biggers
If trying to unlock a v2-encrypted directory fails because the kernel lacks support for v2 policies, show a better error message. This can happen if someone downgrades their kernel or tries to access encrypted directories on removable storage from a computer with an older kernel. Detecting this case is difficult since all we have to go with is EACCES when opening the directory. Implement a heuristic where if get EACCES, we actually have read access to the directory, and the kernel doesn't support v2 policies, we show the improved error message. Before: # fscrypt unlock dir [ERROR] fscrypt unlock: open dir: permission denied After: # fscrypt unlock dir [ERROR] fscrypt unlock: open dir: permission denied This may be caused by the directory using a v2 encryption policy and the current kernel not supporting it. If indeed the case, then this directory can only be used on kernel v5.4 and later. You can create directories accessible on older kernels by changing policy_version to 1 in /etc/fscrypt.conf.
2020-03-23Improve error message when setting v2 policy is unsupportedEric Biggers
If trying to encrypt a directory using a v2 policy fails due to the kernel lacking support for v2 policies, show a better error message. One way this can happen is if someone runs 'fscrypt setup' with a new kernel and then downgrades to an old kernel. Before: # echo -n hunter2 | fscrypt encrypt dir --source=custom_passphrase --name=foo --quiet [ERROR] fscrypt encrypt: inappropriate ioctl for device: system error: could not add key to the keyring After: # echo -n hunter2 | fscrypt encrypt dir --source=custom_passphrase --name=foo --quiet [ERROR] fscrypt encrypt: kernel is too old to support v2 encryption policies v2 encryption policies are only supported by kernel version 5.4 and later. Either use a newer kernel, or change policy_version to 1 in /etc/fscrypt.conf.
2020-03-23Create /etc/fscrypt.conf with policy_version 2 on kernel v5.4+Eric Biggers
v2 encryption policies are now recommended, due to various security and usability advantages over v1 policies. Many people have been running into the usability problems with v1, so it's desirable to get people onto v2 without having to manually opt-in. Therefore, when 'fscrypt setup' creates /etc/fscrypt.conf, enable policy_version 2 automatically if the kernel supports it. I decided to go with this solution over the policy_version "auto" I suggested originally because this way is simpler, it can still be changed to "auto" later if desired, and "auto" might require changing how we parse the config file (since currently the config file is mapped directly to a protobuf where policy_version is an 'int' and is shared with EncryptionOptions). Resolves https://github.com/google/fscrypt/issues/182
2020-03-23Simplify choosing the key description prefixEric Biggers
There's no real need to allow users to choose the key description prefix (a.k.a. the "service"), since on ext4 and f2fs we can just use "ext4" and "f2fs" for compatibility with all kernels both old and new, and on other filesystems we can just use "fscrypt". So, let's do that. Since this removes the point of the "--legacy" option to 'fscrypt setup' and the "compatibility" field in /etc/fscrypt.conf, remove those too. Specifically, we start ignoring the "compatibility" in existing config files and not writing it to new ones. The corresponding protobuf field number and name are reserved. We stop accepting the "--legacy" option at all, although since it was default true and there was no real reason for anyone to change it to false, probably no one will notice. If anyone does, they should just stop specifying the option. Note that this change only affects user keyrings and thus only affects v1 encryption policies, which are deprecated in favor of v2 anyway.
2020-03-19README.md: improve documentation for PAM configuration (#204)Eric Biggers
2020-02-22Makefile: clean up installation commands (#201)Eric Biggers
Improve the documentation for the installation-related Makefile variables, and update the commands to remove the forward slash after $(DESTDIR) in order to remove a duplicate forward slash and match the recommended usage.
2020-02-18Use DESTDIR for install prefix (#200)Anatol Pomozov
DESTDIR has a well established purpose https://www.gnu.org/prep/standards/html_node/DESTDIR.html It is a suffix for all the files to be installed. And it is used by package managers who installs the files into some $tmpdir before creating a package. Change the build commands to follow this convention. Add BINDIR that does the same what previous did $DESTDIR.
2020-02-10Release version v0.2.6 (#198)v0.2.6Joseph Richey
* Release version v0.2.6 Fixes #195 Also, update the encrypted API key. My person access token had expired, this one should work now. Signed-off-by: Joe Richey <joerichey@google.com>
2020-01-29cmd/fscrypt/commands: allow disabling recovery passphrase (#193)Eric Biggers
While it's important to generate a recovery passphrase in the linked protector case to avoid data loss if the system is reinstalled, some people really don't want it (even though it can be safely ignored as it almost certainly has far more entropy than the login passphrase). As a compromise, prompt for y/n before generating it, with default y. Also, to allow disabling the recovery passphrase during noninteractive use, add a --no-recovery command-line option. Update https://github.com/google/fscrypt/issues/186
2020-01-29Merge pull request #192 from ebiggers/cleanup-on-errorEric Biggers
Clean up policies and protectors on error
2020-01-28actions/policy: revert new protector links on failureEric Biggers
Ensure that when an encryption policy is reverted (e.g. due to encryptPath() failing after the policy was created), we also delete any new protector links that were created for the policy, as this is not handled by the logic that reverts new protectors.
2020-01-28filesystem: don't overwrite existing protector linksEric Biggers
When adding a protector to a policy, don't unconditionally overwrite the protector link, because it may already exist. Instead, if it already exists and points to the mount, just use it. If it already exists and points to the wrong place, return an error. Also add a bool to the return value of AddLinkedProtector() so that callers can check whether the link was newly created or not.
2020-01-28cmd/fscrypt/commands: clean up properly when encryptPath() failsEric Biggers
Move the deferred locking and deletion of the policy on failure to the correct places, so that it's done in all failure cases, including in the case where adding the recovery protector fails. Also make the recovery protector be locked and deleted on failure. Finally, put all the code to do deferred deprovisioning of the policy in the same place: right after it's provisioned.
2020-01-28actions/recovery: revert protector if it can't be added to policyEric Biggers
Ensure that a failed AddRecoveryPassphrase() doesn't leave around an unneeded protector file.
2020-01-28cmd/fscrypt/errors: explicitly mark error messages as errors (#191)Eric Biggers
When an fscrypt command fails and prints an error message, in some cases it isn't clear that the message is actually an error, e.g.: fscrypt encrypt: login protectors do not need a name Make it clear by always prefixing the message with "[ERROR] ", e.g. [ERROR] fscrypt encrypt: login protectors do not need a name Update https://github.com/google/fscrypt/issues/186
2020-01-28cmd/fscrypt/setup: don't prompt to create /etc/fscrypt.conf (#190)Eric Biggers
When 'fscrypt setup' sees that /etc/fscrypt.conf doesn't exist, don't ask for confirmation before creating it. Just do it. This is the normal use, and there's not a good reason to ask the user to confirm it.
2020-01-27actions/recovery: ensure recovery passphrase is really custom_passphraseEric Biggers
If the login protector was just created by the same 'fscrypt encrypt' command, then policy.Context.Config.Source will be pam_passphrase. This needs to be overridden to custom_passphrase when creating the protector for the recovery passphrase. This fixes the following error: fscrypt encrypt: login protectors do not need a name Resolves https://github.com/google/fscrypt/issues/187 Update https://github.com/google/fscrypt/issues/186
2020-01-23Document how to check for kernel config options (#183)ebiggers
Resolves https://github.com/google/fscrypt/issues/181
2020-01-23privileges.go: remove a stale comment (#184)ebiggers
The workaround for Go versions before 1.10 was already removed by commit 3022c1603d96 ("Ensure setting user privileges is reversible").
2020-01-23filesystem: remove canonicalizePath() (#185)ebiggers
canonicalizePath() is now only used by an error path in getMountFromLink(), which we can make use getDeviceName() instead.
2020-01-22Merge pull request #167 from ebiggers/recovery-passphraseebiggers
Automatically generate recovery passphrase when useful
2020-01-22Automatically generate recovery passphrase when usefulEric Biggers
If a user re-installs their system (or otherwise loses the /.fscrypt directory on the root filesystem) they also lose access to any login passphrase-protected directories on other filesystems, unless additional protectors were manually added. This can be unexpected, as it may be expected that the old login passphrase would still work. We can't really fix this by storing a login protector on every filesystem because: - If a user were to have N login protectors, it would take them N times longer to log in, as every login protector would need to be unlocked. - If a user were to change their login passphrase while any external volumes were unmounted, login protectors would get out of sync. - It's preferable that an external volume isn't unlockable by itself using only a login passphrase, as login passphrases are often weak. Instead, generate a recovery passphrase when creating a login passphrase-protected directory on a non-root filesystem. The recovery passphrase is added as a custom_passphrase protector, thus giving the policy two protectors: one pam_passphrase and one custom_passphrase. Then this passphrase is written to a file in the new encrypted directory. Writing the passphrase to a file here is okay since it's encrypted, but it's obviously useless by itself; it's up to the user to store this passphrase somewhere else if they need it. Use a recovery passphrase instead of a "recovery code" that encodes the policy key directly because a passphrase is more user-friendly: it can safely be made much shorter than a key, and it works just like any other fscrypt protector. Also, it's not as critical to allow recovery when the .fscrypt directory on the *same* filesystem is deleted. Resolves https://github.com/google/fscrypt/issues/164
2020-01-22Merge pull request #148 from ebiggers/fscrypt-key-mgmt-improvementsebiggers
Filesystem keyring and v2 encryption policy support
2020-01-05README.md: document new settings and troubleshooting key accessEric Biggers
Document the new /etc/fscrypt.conf settings for the filesystem keyring and v2 encryption policies, and add a new subsection for troubleshooting key access problems.
2020-01-05cmd/fscrypt, keyring: add --all-users option to 'fscrypt lock'Eric Biggers
Allow root to provide the --all-users option to 'fscrypt lock' to force an encryption key to be removed from the filesystem (i.e., force an encrypted directory to be locked), even if other users have added it. To implement this option, we just need to use the FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS ioctl rather than FS_IOC_REMOVE_ENCRYPTION_KEY. In theory this option could be implemented for the user keyrings case too, but it would be difficult and the user keyrings are being deprecated for fscrypt, so don't bother.
2020-01-05Keyring support for v2 encryption policiesEric Biggers
Implement adding/removing v2 encryption policy keys to/from the kernel. The kernel requires that the new ioctls FS_IOC_ADD_ENCRYPTION_KEY and FS_IOC_REMOVE_ENCRYPTION_KEY be used for this. Root is not required. However, non-root support brings an extra complication: the kernel keeps track of which users have called FS_IOC_ADD_ENCRYPTION_KEY for the same key. FS_IOC_REMOVE_ENCRYPTION_KEY only works as one of these users, and it only removes the calling user's claim to the key; the key is only truly removed when the last claim is removed. Implement the following behavior: - 'fscrypt unlock' and pam_fscrypt add the key for the user, even if other user(s) have it added already. This behavior is needed so that another user can't remove the key out from under the user. - 'fscrypt lock' and pam_fscrypt remove the key for the user. However, if the key wasn't truly removed because other users still have it added, 'fscrypt lock' prints a warning. - 'fscrypt status' shows whether the directory is unlocked for anyone.
2020-01-05Metadata support for v2 encryption policiesEric Biggers
Linux v5.4 and later supports v2 encryption policies. These have several advantages over v1 encryption policies: - Their encryption keys can be added/removed to/from the filesystem by non-root users, thus gaining the benefits of the filesystem keyring while also retaining support for non-root use. - They use a more standard, secure, and flexible key derivation function. Because of this, some future kernel-level fscrypt features will be implemented for v2 policies only. - They prevent a denial-of-service attack where a user could associate the wrong key with another user's encrypted files. Prepare the fscrypt tool to support v2 encryption policies by: - Adding a policy_version field to the EncryptionOptions, i.e. to the config file and to the policy metadata files. - Using the kernel-specified algorithm to compute the key descriptor for v2 policies. - Handling setting and getting v2 policies. Actually adding/removing the keys for v2 policies to/from the kernel is left for the next patch.
2020-01-05pam_fscrypt: update to handle filesystem keyringEric Biggers
FS_IOC_ADD_ENCRYPTION_KEY and FS_IOC_REMOVE_ENCRYPTION_KEY require root for v1 policy keys, so update the PAM module to re-acquire root privileges while provisioning/deprovisioning policies that need this. Also, only set up the user keyring if it will actually be used.
2020-01-05cmd/fscrypt: adjust user and keyring validation and preparationEric Biggers
Don't force the user to provide a --user argument when running fscrypt as root if they're doing something where the TargetUser isn't actually needed, such as provisioning/deprovisioning a v1 encryption policy to/from the filesystem keyring, or creating a non-login protector. Also don't set up the user keyring (or check for it being set up) if it won't actually be used. Finally, if we'll be provisioning/deprovisioning a v1 encryption policy to/from the filesystem keyring, make sure the command is running as root, since the kernel requires this.
2020-01-05cmd/fscrypt: add 'fscrypt lock' commandEric Biggers
Add support for 'fscrypt lock'. This command "locks" a directory, undoing 'fscrypt unlock'. When the filesystem keyring is used, 'fscrypt lock' also detects when a directory wasn't fully locked due to some files still being in-use. It can then be run again later to try to finish locking the files.
2020-01-05keyring: support filesystem keyring with v1 encryption policiesEric Biggers
Linux v5.4 and later allows fscrypt keys to be added/removed directly to/from the filesystem via the new ioctls FS_IOC_ADD_ENCRYPTION_KEY and FS_IOC_REMOVE_ENCRYPTION_KEY. Among other benefits, these fix the key visibility problems that many users have been running into, where system services and containers can't access encrypted files. Allow the user to opt-in to using these new ioctls for their existing encrypted directories by setting in their /etc/fscrypt.conf: "use_fs_keyring_for_v1_policies": true Note that it can't really be on by default, since for v1 policies the ioctls require root, whereas user keyrings don't. I.e., setting this to true means that users will need to use 'sudo fscrypt unlock', not 'fscrypt unlock'. v2 policies won't have this restriction.
2020-01-05Add keyring packageEric Biggers
In preparation for introducing support for the new filesystem-level keyrings, move the existing user keyring management code from security/keyring.go and crypto/crypto.go into a new package, 'keyring'. This package provides functions AddEncryptionKey, RemoveEncryptionKey, and GetEncryptionKeyStatus which delegate to either the filesystem keyring (added by a later patch) or to the user keyring. This provides a common interface to both types of keyrings, to the extent possible.
2020-01-05README.md: document /etc/fscrypt.confEric Biggers
2019-12-15keyring: fix permission denied accessing user keyring (#177)ebiggers
When userKeyringIDLookup() looks up a user keyring, it links it into the process keyring to ensure that the process retains the "possessor privileges" over the user keyring, then caches the user keyring's ID. Unfortunately, this use of the process keyring randomly fails because Go creates threads before even init() and main() are run, and then can run code on them later. Since the kernel doesn't create the process keyring until userspace requests it and the process keyring is actually a per-thread property that's only inherited by new threads, different threads in a Go process may see different process keyrings. Fix this by removing the user keyring cache, switching from the process keyring to the thread keyring, and using LockOSThread() to pin the goroutine to an OS thread while needed to perform a keyring operation. Resolves https://github.com/google/fscrypt/issues/176
2019-11-28README.md: update output to match realityEric Biggers
Update the example output in the README to match reality. Also make a few other updates to the examples to take into account that 'fscrypt purge' now drops caches by default, and that the root filesystem doesn't need to support encryption if the encrypted directories are being created on a different filesystem. Resolves https://github.com/google/fscrypt/issues/62
2019-11-28Merge pull request #172 from ebiggers/login-passphrase-doc-fixJoseph Richey
README.md: remove obsolete warning about changing login passphrase
2019-11-27README.md: remove obsolete warning about changing login passphraseEric Biggers
For some time now, fscrypt actually does re-wrap a user's login protector when their login passphrase changes, provided that the PAM configuration is correct. Remove the obsolete paragraph. Update https://github.com/google/fscrypt/issues/51