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

restic-rest-server module: init #39943

Merged
merged 1 commit into from May 4, 2018
Merged

Conversation

bachp
Copy link
Member

@bachp bachp commented May 3, 2018

Motivation for this change

Allow running the restic REST server as module.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

/cc @dotlambda as you added the binary

@xeji
Copy link
Contributor

xeji commented May 3, 2018

cc @Lassulus

preStart = ''
# Make sure directories exist with correct owner
mkdir -p ${cfg.dataDir}
chown restic:restic ${cfg.dataDir}
Copy link
Member

Choose a reason for hiding this comment

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

This can better be done using users.users.restic.createHome.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea thanks. I will update the PR.

privateRepos = mkOption {
default = false;
type = types.bool;
description = "Enable private repos.";
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could be a little more self-explanatory?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had a more comprehensice description here. But it turned out very long and in the end was more or less the same as was written in the readme of rest-server. So I think I can just copy that in here.

after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
PermissionsStartOnly = true;
Copy link
Member

Choose a reason for hiding this comment

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

This is no longer needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, will remove it.

${optionalString cfg.appendOnly "--append-only"} \
${optionalString cfg.privateRepos "--private-repos"} \
${optionalString cfg.prometheus "--prometheus"} \
${concatStringsSep " " cfg.extraFlags} \
Copy link
Member

Choose a reason for hiding this comment

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

You could use escapeShellArgs here.

serviceConfig = {
PermissionsStartOnly = true;
ExecStart = ''
${cfg.package}/bin/rest-server server \
Copy link
Member

Choose a reason for hiding this comment

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

The second server shouldn't be there, should it?

Copy link
Member Author

@bachp bachp May 4, 2018

Choose a reason for hiding this comment

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

I will check the command line, but I think you are right.

'';
Type = "simple";
User = "restic";
Group = "restic";
Copy link
Member

Choose a reason for hiding this comment

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

Did you think about using some of the hardening options like ProtectSystem = "strict" and ReadWritePaths?
You can also hava a look at the BorgBackup module.

Copy link
Member Author

Choose a reason for hiding this comment

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

No I haven't. This is just a minimal service atm. But I will take a look at the borg backup service and see if I can add some hardening here.

@bachp
Copy link
Member Author

bachp commented May 4, 2018

@dotlambda All comments addressed

@dotlambda
Copy link
Member

Right now, the user needs to put the .htaccess file in the dataDir themselves. That could be done via an option, too. However, I'm also fine with merging as is. (I won't use it myself anyway as a short test seemed to indicate that it doesn't work well/at all when put behind a Tor onion service.)

Another thing that would be nice to have is a combined test for the restic and rest-server modules. But that can be done in another PR.

@bachp
Copy link
Member Author

bachp commented May 4, 2018

@dotlambda I tought about adding an option to set the .htaccess file but decided against it for several reasons.

  1. I don't like to modify files in dataDir from nix and it seems rest-server currently doesn't allow to specify an alternative location.
  2. The user password (even with bcrypt) should probably not got into the nix store anyway.

Also they seem to have changed some things regarding authentication after 0.9.7 (like the --no-auth flag) so I might revisit this after the next version is released.

I also think a test might be good but as you said this can be done in a next PR.

@dotlambda dotlambda merged commit b051cdf into NixOS:master May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants