Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable admin to decide group access to repository files #3419

Merged
merged 1 commit into from Apr 30, 2022

Conversation

DanielG
Copy link
Contributor

@DanielG DanielG commented Jun 7, 2021

This fixes #2351, see also #2351 (comment)

Since the directory mode doesn't allow the execute bit (search permission)
to be set regardless of umask the files don't need to have empty group
permissions to disallow group access. By default the missing group execute
access on the containing directory will block any read/write attempt on the
files.

The upside of this is that the sysadmin can choose to change the directory
permissions to allow group execute access since all repo directories are
created at init time and not touched again after that. This will then allow
the group access to the files.

Checklist

  • I have read the Contribution Guidelines
  • I have enabled maintainer edits for this PR
  • I have added tests for all changes in this PR
  • I have added documentation for the changes (in the manual)
  • There's a new file in changelog/unreleased/ that describes the changes for our users (template here)
  • I have run gofmt on the code in all commits
  • All commit messages are formatted in the same style as the other commits in the repo
  • I'm done, this Pull Request is ready for review

@DanielG DanielG force-pushed the relax-file-modes branch 2 times, most recently from a0d7e83 to dc91575 Compare June 7, 2021 10:34
@greatroar
Copy link
Contributor

greatroar commented Jul 2, 2021

This new mode applies also to the SFTP backend, which does not (cannot, at least not portably) honor the local umask.

@DanielG
Copy link
Contributor Author

DanielG commented Jul 15, 2021

Indeed the sftp backend handles this by chmod'ing instead:

internal/backend/sftp/sftp.go:277:

	// pkg/sftp doesn't allow creating with a mode.
	// Chmod while the file is still empty.
	if err == nil {
		err = f.Chmod(backend.Modes.File)
	}

@beewoolie
Copy link

This makes me wonder a bit. If I understand the change correctly, the init of the repo requires an extra step, after creation, to change the permissions in the repo directories. If that's true, I'd say it is likely to be more evident to users if an option is added to the init subfunction that allows local and sftp to backends to manage permissions in a way that permits multiple users explicitly. It might need to have a group name, for example, so that it will, at a minimum, make the directories sticky for this group.

Making this an option for the repo means that it can be queried as part of the configuration. Inspection of the setup further enables validation of the expected configuration.

That said, this is something that blocks an expected use case for restic, multiple contributing users to the backup data store with a local store.

@DanielG
Copy link
Contributor Author

DanielG commented Feb 2, 2022 via email

@beewoolie
Copy link

I'd certainly be happy to have this wee change applied. The lack of a willing member of the team to review the change is, well, disapointing.

My point with the options is that it daylights what could be a hidden detail. When it comes to permissions, IMHO, I'd rather give a little extra boost to make the effect apparent. It adds some noise to be sure.

And, on the other hand, we seldom run these systems with shared groups (e.g.) such that the likely impact of this change is harmless.

@MichaelEischer
Copy link
Member

The change look like a big hack, that will cause problems if restic ever has to create a new directory. I'd rather propose a different approach:

Use the current permissions of the config file to let the local backend (and probably sftp too) detect whether the repository should be accessible only to the current user or also to the group. A file permission of 0400 would mean user-only and 0440 would allow group access. To switch between both variants, just run chmod on the repository.

@DanielG DanielG force-pushed the relax-file-modes branch 2 times, most recently from 8103d9b to 6ad146e Compare February 27, 2022 01:17
@DanielG
Copy link
Contributor Author

DanielG commented Feb 27, 2022

@MichaelEischer Good idea. I've implemented it.

@beewoolie
Copy link

Interesting strategy. Makes me wonder how it will be documented. IMHO, it seems discrete to use the file mode of a configuration file created by restic to determine file modes for files created within the repo.

Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the comments I've added, the PR also should add a short notice to the documentation (probably to doc/030_preparing_a_new_repo.rst) that a repository can be made user/group accessible depending on the config file permissions and how to switch.

internal/backend/paths.go Outdated Show resolved Hide resolved
changelog/unreleased/pull-3419 Outdated Show resolved Hide resolved
changelog/unreleased/pull-3419 Outdated Show resolved Hide resolved
changelog/unreleased/pull-3419 Outdated Show resolved Hide resolved
@MichaelEischer
Copy link
Member

Interesting strategy. Makes me wonder how it will be documented. IMHO, it seems discrete to use the file mode of a configuration file created by restic to determine file modes for files created within the repo.

The config file is part of the repository and not some external configuration file. So, I don't really understand what should be a problem here?

Copy link
Contributor Author

@DanielG DanielG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes:

  • Address review comments
  • Rewrite changelog
  • Add docs

internal/backend/paths.go Outdated Show resolved Hide resolved
@DanielG DanielG force-pushed the relax-file-modes branch 3 times, most recently from 95137db to ee5704b Compare March 6, 2022 17:19
@DanielG
Copy link
Contributor Author

DanielG commented Mar 31, 2022

@MichaelEischer ping, I'd appreciate another review.

Changes:

  • Improve wording in docs

@DanielG
Copy link
Contributor Author

DanielG commented Mar 31, 2022

Ok, so it looks like this can't work as-is yet because the config file is created not as part of the backend Create function but rather by the repository Init/init functions.

@MichaelEischer
Copy link
Member

Ok, so it looks like this can't work as-is yet because the config file is created not as part of the backend Create function but rather by the repository Init/init functions.

My suggestion would to ignore the stat error in Open if the config file does not exist (yet).

@DanielG DanielG force-pushed the relax-file-modes branch 2 times, most recently from 292e4b7 to b898fb7 Compare April 3, 2022 21:40
@DanielG
Copy link
Contributor Author

DanielG commented Apr 3, 2022

Oh yeah, another good idea. Implemented.

@MichaelEischer MichaelEischer force-pushed the relax-file-modes branch 2 times, most recently from 0577041 to a24e53b Compare April 9, 2022 20:49
Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rebased to PR to fix merge conflicts with the current master. Besides the few comments on the documentation entry, the code seems fine.

doc/030_preparing_a_new_repo.rst Outdated Show resolved Hide resolved
doc/030_preparing_a_new_repo.rst Outdated Show resolved Hide resolved
doc/030_preparing_a_new_repo.rst Outdated Show resolved Hide resolved
doc/030_preparing_a_new_repo.rst Outdated Show resolved Hide resolved
@DanielG DanielG force-pushed the relax-file-modes branch 2 times, most recently from 3d2e31c to 7e9d5ab Compare April 26, 2022 17:07
@DanielG
Copy link
Contributor Author

DanielG commented Apr 26, 2022

I've reworked the docs a bit and (hopefully) properly resolved the conflict with cd78335 by undoing the merging of code from Open/Create into open. @MichaelEischer I think your conflict resolution would have failed to work in the Create code path as the config file wouldn't exist there yet so stat would fail. EDIT: nvm. I forgot we handle the error case in DeriveModesFromFileInfo now.

Copy link
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

I've rebased the PR to fix the merge conflict in doc/030_preparing_a_new_repo.rst .

@MichaelEischer MichaelEischer merged commit 9c047f1 into restic:master Apr 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow default umask to be overridden
4 participants