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

Add option to run borgmatic as root by another user #160

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ borg_user: "root"
borg_group: "root"
backup_user_info:
home: "/home/{{ borg_user }}"
borgmatic_run_as_root: false
...
4 changes: 4 additions & 0 deletions meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,7 @@ argument_specs:
type: str
required: false
description: Name of the SSH public and private key
borgmatic_run_as_root:
type: bool
required: false
description: If the variable is set, systemd will run borgmatic using sudo.
4 changes: 2 additions & 2 deletions templates/borgmatic.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ConditionACPower=true
[Service]
Type=oneshot
User={{ borg_user }}
ExecStart=borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}
ExecStart={{ 'sudo ' if borgmatic_run_as_root}}borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}

# Source: https://projects.torsion.org/borgmatic-collective/borgmatic/raw/branch/master/sample/systemd/borgmatic.service
# Security settings for systemd running as root, optional but recommended to improve security. You
Expand All @@ -22,7 +22,7 @@ LockPersonality=true
# Certain borgmatic features like Healthchecks integration need MemoryDenyWriteExecute to be off.
# But you can try setting it to "yes" for improved security if you don't use those features.
MemoryDenyWriteExecute=no
NoNewPrivileges=yes
NoNewPrivileges={{ 'no' if borgmatic_run_as_root else 'yes'}}
PrivateDevices=yes
PrivateTmp=yes
ProtectClock=yes
Expand Down
4 changes: 2 additions & 2 deletions templates/config.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ consistency:
# prevent potential shell injection or privilege escalation.
hooks:
{% for hook in borgmatic_hooks %}
{{ hook }}:
{{ borgmatic_hooks[hook] | to_nice_yaml(indent=4) | indent(4, first=true) }}
{{ hook }}:
{{ borgmatic_hooks[hook] | to_nice_yaml(indent=4) | indent(4, first=true) }}
{% endfor %}