Encrypt restic secrets

This commit is contained in:
Andreas Zweili 2022-11-04 16:49:46 +01:00
parent 89a55f792a
commit 4f1a2f6b45
18 changed files with 121 additions and 39 deletions

View File

@ -1,29 +1,30 @@
{ custom
, hostname
, inputs
, path ? "/home/${custom.username}"
{ inputs
, path
, tag ? "home-dir"
, time
}: { pkgs, ... }:
}: { config, pkgs, ... }:
{
imports = [
(import "${inputs.self}/modules/telegram-notifications" { inherit inputs; })
];
systemd.timers."restic-backups-${custom.username}" = {
age.secrets.resticKey.file = "${inputs.self}/scrts/restic.key.age";
systemd.timers."restic-backups" = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-backups-${custom.username}.service" ];
partOf = [ "restic-backups.service" ];
timerConfig = {
OnCalendar = time;
};
};
systemd.services."restic-backups-${custom.username}" = {
systemd.services."restic-backups" = {
serviceConfig = {
User = "root";
Type = "oneshot";
};
environment = {
RESTIC_PASSWORD_FILE = "/home/${custom.username}/.nixos/secrets/passwords/restic.key";
RESTIC_PASSWORD_FILE = config.age.secrets.resticKey.path;
RESTIC_REPOSITORY = "rest:http://10.7.89.30:8000";
};
onFailure = [ "unit-status-telegram@%n.service" ];
@ -34,7 +35,7 @@
${pkgs.restic}/bin/restic forget \
--tag home-dir \
--host ${hostname} \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \

View File

@ -1,29 +1,30 @@
{ custom
, hostname
, inputs
, path ? "/home/${custom.username}"
{ inputs
, path
, tag ? "home-dir"
, time
}: { pkgs, ... }:
}: { config, pkgs, ... }:
{
imports = [
(import "${inputs.self}/modules/telegram-notifications" { inherit inputs; })
];
systemd.timers."restic-backups-${custom.username}" = {
age.secrets.resticKey.file = "${inputs.self}/scrts/restic.key.age";
systemd.timers."restic-backups" = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-backups-${custom.username}.service" ];
partOf = [ "restic-backups.service" ];
timerConfig = {
OnCalendar = time;
};
};
systemd.services."restic-backups-${custom.username}" = {
systemd.services."restic-backups" = {
serviceConfig = {
User = "root";
Type = "oneshot";
};
environment = {
RESTIC_PASSWORD_FILE = "/home/${custom.username}/.nixos/secrets/passwords/restic.key";
RESTIC_PASSWORD_FILE = config.age.secrets.resticKey.path;
RESTIC_REPOSITORY = "rest:http://10.7.89.30:8000";
};
onFailure = [ "unit-status-telegram@%n.service" ];
@ -40,7 +41,7 @@
${pkgs.restic}/bin/restic forget \
--tag home-dir \
--host ${hostname} \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
@ -48,7 +49,7 @@
${pkgs.restic}/bin/restic forget \
--tag mariadb \
--host ${hostname} \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \

View File

@ -1,8 +1,10 @@
{ inputs, custom, pkgs, ... }:
{ inputs }: { config, pkgs, ... }:
let
repository = "/mnt/restic-server";
in
{
age.secrets.resticKey.file = "${inputs.self}/scrts/restic.key.age";
environment.systemPackages = with pkgs; [
restic
];
@ -27,7 +29,7 @@ in
script = ''
${pkgs.restic}/bin/restic \
--repo ${repository} \
--password-file "/etc/restic/restic.key" \
--password-file ${config.age.secrets.resticKey.path} \
prune \
'';
};

View File

@ -1,7 +1,7 @@
{ custom, hostname, inputs }: { pkgs, ... }:
{ custom, inputs }: { config, pkgs, ... }:
let
# TODO: encrypt key file with agenix
password_file = "/home/${custom.username}/.nixos/secrets/passwords/restic.key";
password_file = config.age.secrets.resticKey.path;
repository = "rest:http://10.7.89.30:8000";
restic-mount = pkgs.writeShellScriptBin "restic-mount" ''
@ -9,7 +9,7 @@ let
${pkgs.restic}/bin/restic \
--repo ${repository} \
--password-file ${password_file} \
--host ${hostname} \
--host ${config.networking.hostName} \
mount /tmp/restic'';
restic-mount-all = pkgs.writeShellScriptBin "restic-mount-all" ''
@ -20,7 +20,7 @@ let
mount /tmp/restic'';
# TODO: encrypt key file with agenix
infomaniak-env = "/home/${custom.username}/.nixos/secrets/passwords/infomaniak-env";
infomaniak-env = config.age.secrets.infomaniakEnv.path;
infomaniak-repo = "swift:default:/";
infomaniak-auth-url = "https://swiss-backup02.infomaniak.com/identity/v3";
@ -49,6 +49,19 @@ in
(import "${inputs.self}/modules/telegram-notifications" { inherit inputs; })
];
age.secrets.infomaniakEnv = {
file = "${inputs.self}/scrts/infomaniak_env.age";
mode = "600";
owner = custom.username;
group = "users";
};
age.secrets.resticKey = {
file = "${inputs.self}/scrts/restic.key.age";
mode = "600";
owner = custom.username;
group = "users";
};
systemd.timers."restic-backups-${custom.username}" = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-backups-${custom.username}.service" ];
@ -77,7 +90,7 @@ in
${pkgs.restic}/bin/restic \
forget \
--host ${hostname} \
--host ${config.networking.hostName} \
--tag home-dir \
--keep-hourly 25 \
--keep-daily 7 \
@ -92,7 +105,7 @@ in
${pkgs.restic}/bin/restic \
--repo ${repository} \
--password-file ${password_file} \
snapshots --host ${hostname}'';
snapshots --host ${config.networking.hostName}'';
restic-unlock = ''
${pkgs.restic}/bin/restic \
--repo ${repository} \

BIN
scrts/infomaniak_env.age Normal file

Binary file not shown.

50
scrts/restic.key.age Normal file
View File

@ -0,0 +1,50 @@
age-encryption.org/v1
-> ssh-rsa 7S8lxw
OzFzBC1L014yJHeHbcprvvHFrSGGVvDYbSGL0zhz9zU9QVdavrF1Vjiau8uqKw89
BWgGsxkgdalzb99kds21tpX2dW9oVUCC5Utb4WSsOzTD6YvbW8D+XlsNsTPTb9iG
LQAvfe3W7xGCVn1vk87e1lKk21VngsvivaAU1ZUfZLRGTAs16ES9aOQoPN5nmV8x
DqnoApkbxUa3MhM45ZTl6mFXzEJxyBdX6wTs8e2A2BKsdTKTFFSuOamMN1v2b/Et
rnYFSxVNaH/2/lVYcOm4cY9K3IY2T/pgeJXXehg02w0kaaULNh8IqNcLnRygj/XD
tyQdJ3Xgg3bgVAYo8YTeG9+e9CYgLvyxGN4sJ5pa1QE5qAebpy9okCzATxI4quVt
QF//zYPnnLxIw4V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 -34,8 +34,10 @@ let
in
{
"gitea_env.age".publicKeys = defaultKeys ++ [ git ];
"infomaniak_env.age".publicKeys = all;
"pihole_env.age".publicKeys = defaultKeys ++ [ pihole ];
"plex_claim.age".publicKeys = defaultKeys ++ [ plex ];
"restic.key.age".publicKeys = all;
"telegram_notify_env.age".publicKeys = all;
"ttrss_env.age".publicKeys = defaultKeys ++ [ ttrss ];
}

View File

@ -9,7 +9,8 @@ in
inherit hostname inputs;
})
(import "${inputs.self}/modules/restic-server-mysql-client" {
time = "03:00"; inherit custom hostname inputs;
path = "/home/andreas";
time = "03:00"; inherit inputs;
})
(import "${inputs.self}/modules/nginx-proxy" {
inherit domain inputs;

View File

@ -20,7 +20,7 @@
"${inputs.self}/modules/scripts"
"${inputs.self}/modules/tlp"
"${inputs.self}/modules/tmux"
(import "${inputs.self}/modules/restic" { inherit custom hostname inputs; })
(import "${inputs.self}/modules/restic" { inherit custom inputs; })
];
boot.initrd.availableKernelModules = [
"aesni_intel"

View File

@ -6,7 +6,9 @@
inherit hostname inputs;
})
(import "${inputs.self}/modules/restic-server-client" {
time = "04:30"; inherit custom hostname inputs;
path = "/home/andreas";
time = "04:30";
inherit inputs;
})
(import "${inputs.self}/modules/nginx-proxy" {
domain = "mail.zweili.org"; inherit inputs;

View File

@ -10,6 +10,12 @@ in
})
(import "${inputs.self}/modules/docker" { inherit custom; })
"${inputs.self}/modules/logs-share"
(import "${inputs.self}/modules/restic-server-client" {
path = "/home/andreas";
tag = "management";
time = "23:30";
inherit inputs;
})
"${inputs.self}/modules/tmux"
];
services.nginx.virtualHosts."${domain}".locations = {

View File

@ -6,7 +6,8 @@
inherit hostname inputs;
})
(import "${inputs.self}/modules/restic-server-mysql-client" {
time = "04:00"; inherit custom hostname inputs;
path = "/home/andreas";
time = "04:00"; inherit inputs;
})
(import "${inputs.self}/modules/docker" { inherit custom; })
"${inputs.self}/modules/mariadb"

View File

@ -8,7 +8,7 @@
(import "${inputs.self}/modules/restic-server-client" {
path = "/var/lib/pihole";
tag = "pihole";
time = "05:00"; inherit custom hostname inputs;
time = "05:00"; inherit inputs;
})
(import "${inputs.self}/modules/docker" { inherit custom; })
(import "${inputs.self}/modules/pihole" { inherit inputs; })

View File

@ -8,7 +8,8 @@
(import "${inputs.self}/modules/restic-server-client" {
path = "/var/lib/plex";
tag = "plex";
time = "03:30"; inherit custom hostname inputs;
time = "03:30";
inherit inputs;
})
(import "${inputs.self}/modules/docker" { inherit custom; })
"${inputs.self}/modules/media-share"

View File

@ -6,7 +6,9 @@
inherit hostname inputs;
})
(import "${inputs.self}/modules/restic-server-client" {
time = "00:00"; inherit custom hostname inputs;
path = "/home/andreas";
time = "00:00";
inherit inputs;
})
"${inputs.self}/modules/nginx-acme-base"
(import "${inputs.self}/modules/docker" { inherit custom; })

View File

@ -5,6 +5,6 @@
ip = "10.7.89.30";
inherit hostname inputs;
})
"${inputs.self}/modules/restic-server"
(import "${inputs.self}/modules/restic-server" { inherit inputs; })
];
}

View File

@ -10,7 +10,7 @@
(import "${inputs.self}/modules/droidcam" { inherit custom; })
(import "${inputs.self}/modules/espanso" { inherit custom; })
"${inputs.self}/modules/lockscreen"
(import "${inputs.self}/modules/restic" { inherit custom hostname inputs; })
(import "${inputs.self}/modules/restic" { inherit custom inputs; })
"${inputs.self}/modules/tlp"
"${inputs.self}/modules/tmux"
];

View File

@ -14,7 +14,7 @@ in
(import "${inputs.self}/modules/restic-server-mysql-client" {
path = "/var/lib/ttrss";
tag = "ttrss";
time = "23:00"; inherit custom hostname inputs;
time = "23:00"; inherit inputs;
})
(import "${inputs.self}/modules/ttrss" {
inherit domain inputs;