2023-09-21 05:06:27 +01:00
|
|
|
{pkgs, ...}: {
|
2022-11-15 14:52:49 +00:00
|
|
|
services.secrets = {
|
|
|
|
enable = true;
|
|
|
|
|
2023-09-18 03:56:58 +01:00
|
|
|
vaultLogin = {
|
|
|
|
enable = true;
|
2023-09-21 05:06:27 +01:00
|
|
|
loginUsername = "hetzner-arm-container-storage";
|
2023-09-18 03:56:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
requiredVaultPaths = [
|
2024-11-08 20:50:43 +00:00
|
|
|
"api-keys/data/backblaze/Backblaze"
|
|
|
|
|
|
|
|
#"api-keys/data/storage/webdav/Main"
|
2023-10-10 22:22:54 +01:00
|
|
|
"api-keys/data/storage/webdav/Public"
|
2023-10-14 13:51:03 +01:00
|
|
|
"api-keys/data/storage/webdav/Uploads"
|
2024-04-26 19:55:22 +01:00
|
|
|
"api-keys/data/storage/webdav/Notes"
|
2024-05-09 08:19:31 +01:00
|
|
|
|
|
|
|
"private-public-keys/data/rclone/Chaos-Notes-Crypt"
|
2023-09-18 03:56:58 +01:00
|
|
|
];
|
|
|
|
|
2023-09-11 23:22:18 +01:00
|
|
|
packages = with pkgs; [
|
2022-11-15 14:52:49 +00:00
|
|
|
# for music & mail passwd files
|
|
|
|
apacheHttpd
|
|
|
|
# for rclone obscure config file
|
|
|
|
rclone
|
|
|
|
];
|
|
|
|
|
|
|
|
extraFunctions = ''
|
2022-11-29 10:08:44 +00:00
|
|
|
replace_slash_for_sed() {
|
|
|
|
sed "s#/#\\\/#"
|
|
|
|
}
|
|
|
|
|
2022-11-15 14:52:49 +00:00
|
|
|
simple_get_obscure() {
|
|
|
|
rclone obscure "$(simple_get "$@")"
|
2022-11-02 11:32:03 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 14:52:49 +00:00
|
|
|
simple_get_replace_b2() {
|
2022-11-29 10:08:44 +00:00
|
|
|
api_account=$(simple_get "$1" .keyID | replace_slash_for_sed)
|
|
|
|
api_key=$(simple_get "$1" .applicationKey | replace_slash_for_sed)
|
2022-11-15 14:52:49 +00:00
|
|
|
|
|
|
|
replace_account=''${2}_ACCOUNT
|
|
|
|
replace_key=''${2}_KEY
|
|
|
|
|
|
|
|
sed -i "s/$replace_account/$api_account/" "$3"
|
|
|
|
sed -i "s/$replace_key/$api_key/" "$3"
|
2022-11-02 11:32:03 +00:00
|
|
|
}
|
2022-12-03 13:16:22 +00:00
|
|
|
|
2022-11-29 10:08:44 +00:00
|
|
|
simple_get_replace_crypt() {
|
2023-09-21 16:59:51 +01:00
|
|
|
password=$(simple_get_obscure "$1" .password)
|
|
|
|
salt=$(simple_get_obscure "$1" .salt)
|
2022-11-29 10:08:44 +00:00
|
|
|
|
2023-09-21 16:59:51 +01:00
|
|
|
replace_password=''${2}_PASSWORD
|
|
|
|
replace_salt=''${2}_SALT
|
2022-11-29 10:08:44 +00:00
|
|
|
|
|
|
|
sed -i "s/$replace_password/$password/" "$3"
|
|
|
|
sed -i "s/$replace_salt/$salt/" "$3"
|
|
|
|
}
|
2023-10-10 22:22:54 +01:00
|
|
|
|
|
|
|
simple_get_htpasswd() {
|
|
|
|
if [ -f "$2" ]; then
|
|
|
|
rm "$2"
|
|
|
|
fi
|
2023-10-14 13:51:03 +01:00
|
|
|
|
2023-10-10 22:22:54 +01:00
|
|
|
touch "$2"
|
|
|
|
|
|
|
|
data=$(kv_get "$1" | base64)
|
|
|
|
for username in $(echo "$data" | base64 -d | jq -r ".data.data | keys | .[]"); do
|
|
|
|
password=$(echo "$data" | base64 -d | jq -r ".data.data.\"$username\"")
|
|
|
|
htpasswd -b "$2" "$username" "$password" 2>/dev/null
|
|
|
|
done
|
|
|
|
}
|
2022-11-15 14:52:49 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
secrets = {
|
2023-10-10 22:22:54 +01:00
|
|
|
vault_password = {
|
|
|
|
manual = true;
|
|
|
|
};
|
2022-11-15 14:52:49 +00:00
|
|
|
|
2024-11-08 21:01:43 +00:00
|
|
|
#webdav_main_htpasswd = {
|
|
|
|
# user = "storage";
|
|
|
|
# group = "storage";
|
|
|
|
# fetchScript = ''
|
|
|
|
# simple_get_htpasswd "/api-keys/storage/webdav/Main" "$secretFile"
|
|
|
|
# '';
|
|
|
|
#};
|
2023-10-10 22:22:54 +01:00
|
|
|
webdav_uploads_htpasswd = {
|
|
|
|
user = "storage";
|
|
|
|
group = "storage";
|
|
|
|
fetchScript = ''
|
|
|
|
simple_get_htpasswd "/api-keys/storage/webdav/Uploads" "$secretFile"
|
2022-11-20 10:34:55 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-04-26 19:55:22 +01:00
|
|
|
webdav_notes_htpasswd = {
|
|
|
|
user = "storage";
|
|
|
|
group = "storage";
|
|
|
|
fetchScript = ''
|
|
|
|
simple_get_htpasswd "/api-keys/storage/webdav/Notes" "$secretFile"
|
|
|
|
'';
|
|
|
|
};
|
2024-05-09 08:19:31 +01:00
|
|
|
|
2022-11-15 14:52:49 +00:00
|
|
|
rclone_config = {
|
|
|
|
user = "storage";
|
|
|
|
group = "storage";
|
|
|
|
fetchScript = ''
|
2024-02-08 20:21:35 +00:00
|
|
|
cp ${./data/rclone_config.template} "$secretFile"
|
2022-11-15 14:52:49 +00:00
|
|
|
|
2024-11-08 20:50:43 +00:00
|
|
|
simple_get_replace_b2 "/api-keys/backblaze/Backblaze" "B2" "$secretFile"
|
|
|
|
|
2024-04-26 19:55:22 +01:00
|
|
|
simple_get_replace_crypt "/private-public-keys/rclone/Chaos-Notes-Crypt" "STORAGE_NOTES_CRYPT" "$secretFile"
|
2022-11-15 14:52:49 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-11-02 11:32:03 +00:00
|
|
|
}
|