nametransform: make gocryptfs.diriv and gocryptfs.xxx.name files world-readable

Make `gocryptfs.diriv` and `gocryptfs.xxx.name` files world-readable to make encrypted backups easier
when mounting via fstab.

Having the files follow chmod/chown of their parent does not seem
to be worth the hassle. The content of the diriv files is not
secret, and both diriv and name files are protected by the
perms of the parent dir.

Fixes https://github.com/rfjakob/gocryptfs/issues/539
This commit is contained in:
Jakob Unterwurzacher 2021-01-10 08:06:09 +01:00
parent 6b492fdcb8
commit bed60101f4
4 changed files with 27 additions and 9 deletions

View File

@ -193,6 +193,8 @@ Changelog
vNEXT, in progress vNEXT, in progress
* MANPAGE: Split options into sections acc. to where they apply ([#517](https://github.com/rfjakob/gocryptfs/issues/517)) * MANPAGE: Split options into sections acc. to where they apply ([#517](https://github.com/rfjakob/gocryptfs/issues/517))
* `-idle`: count cwd inside the mount as busy ([#533](https://github.com/rfjakob/gocryptfs/issues/533)) * `-idle`: count cwd inside the mount as busy ([#533](https://github.com/rfjakob/gocryptfs/issues/533))
* Make `gocryptfs.diriv` and `gocryptfs.xxx.name` files world-readable to make encrypted backups easier
when mounting via [/etc/fstab](Documentation/MANPAGE.md#fstab) ([#539](https://github.com/rfjakob/gocryptfs/issues/539))
v2.0-beta2, 2020-11-14 v2.0-beta2, 2020-11-14
* Improve [performance](Documentation/performance.txt#L69) * Improve [performance](Documentation/performance.txt#L69)

View File

@ -239,6 +239,10 @@ func (n *Node) Setattr(ctx context.Context, f fs.FileHandle, in *fuse.SetAttrIn,
defer syscall.Close(dirfd) defer syscall.Close(dirfd)
// chmod(2) // chmod(2)
//
// gocryptfs.diriv & gocryptfs.longname.[sha256].name files do NOT get chmod'ed
// or chown'ed with their parent file/dir for simplicity.
// See nametransform/perms.go for details.
if mode, ok := in.GetMode(); ok { if mode, ok := in.GetMode(); ok {
errno = fs.ToErrno(syscallcompat.FchmodatNofollow(dirfd, cName, mode)) errno = fs.ToErrno(syscallcompat.FchmodatNofollow(dirfd, cName, mode))
if errno != 0 { if errno != 0 {

View File

@ -1,16 +1,26 @@
package nametransform package nametransform
const ( const (
// Permissions for gocryptfs.diriv files // Permissions for gocryptfs.diriv files.
// The gocryptfs.diriv files are created once, never modified,
// never chmod'ed or chown'ed.
// //
// It makes sense to have the diriv files group-readable so the FS can // Group-readable so the FS can be mounted by several users in the same group
// be mounted from several users from a network drive (see // (see https://github.com/rfjakob/gocryptfs/issues/387 ).
// https://github.com/rfjakob/gocryptfs/issues/387 ).
// //
// Note that gocryptfs.conf is still created with 0400 permissions so the // Note that gocryptfs.conf is still created with 0400 permissions so the
// owner must explicitly chmod it to permit access. // owner must explicitly chmod it to permit access.
dirivPerms = 0440 //
// World-readable so an encrypted directory can be copied by the non-root
// owner when gocryptfs is running as root
// ( https://github.com/rfjakob/gocryptfs/issues/539 ).
dirivPerms = 0444
// Permissions for gocryptfs.longname.[sha256].name files // Permissions for gocryptfs.longname.[sha256].name files.
namePerms = 0400 // The .name files are created once, never modified,
// never chmod'ed or chown'ed.
//
// Group- and world-readable for the same reasons as the gocryptfs.diriv
// files (see above).
namePerms = 0444
) )

View File

@ -59,8 +59,10 @@ func TestInitFilePerms(t *testing.T) {
syscall.Stat(dir+"/gocryptfs.diriv", &st) syscall.Stat(dir+"/gocryptfs.diriv", &st)
perms = st.Mode & 0777 perms = st.Mode & 0777
// From v1.7.1, these are created with 0440 permissions, see // From v1.7.1, these are created with 0440 permissions, see
// https://github.com/rfjakob/gocryptfs/issues/387 // https://github.com/rfjakob/gocryptfs/issues/387 .
if perms != 0440 { // From v2.0, created with 0444 perms, see
// https://github.com/rfjakob/gocryptfs/issues/539 .
if perms != 0444 {
t.Errorf("Wrong permissions for gocryptfs.diriv: %#o", perms) t.Errorf("Wrong permissions for gocryptfs.diriv: %#o", perms)
} }
} }