Compare commits

..

2 Commits

2 changed files with 28 additions and 18 deletions

View File

@ -52,15 +52,31 @@ in
] ++ (map (org: "gitea-web-secret-provider@${org}") organizations); ] ++ (map (org: "gitea-web-secret-provider@${org}") organizations);
}; };
systemd.tmpfiles.settings."10-gitea-web-secret-provider"."/var/lib/gitea-web/authorized_keys.d".d = { systemd.tmpfiles.settings."10-gitea-web-secret-provider" = {
"/var/lib/gitea-web/authorized_keys.d".d = {
user = "gitea"; user = "gitea";
group = "gitea"; group = "gitea";
mode = "700"; mode = "700";
}; };
"/var/lib/gitea-web/web".d = {
user = "gitea";
group = "nginx";
mode = "750";
};
} //
(builtins.listToAttrs (map (org: {
name = "/var/lib/gitea-web/web/${org}";
value = {
d = {
user = "gitea";
group = "nginx";
mode = "750";
};
};
}) organizations));
systemd.slices.system-giteaweb = { systemd.slices.system-giteaweb = {
description = "Gitea web directories"; description = "Gitea web directories";
wantedBy = [ "multi-user.target" ];
}; };
# https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Specifiers # https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Specifiers
@ -79,7 +95,7 @@ in
org = "%i"; org = "%i";
token-path = "%d/token"; token-path = "%d/token";
api-url = "${cfg.settings.server.ROOT_URL}api/v1"; api-url = "${cfg.settings.server.ROOT_URL}api/v1";
key-dir = "%S/%i/keys"; key-dir = "%S/gitea-web/keys/%i";
authorized-keys-path = "%S/gitea-web/authorized_keys.d/%i"; authorized-keys-path = "%S/gitea-web/authorized_keys.d/%i";
rrsync-path = "${pkgs.rrsync}/bin/rrsync"; rrsync-path = "${pkgs.rrsync}/bin/rrsync";
web-dir = "%S/gitea-web/web"; web-dir = "%S/gitea-web/web";
@ -95,18 +111,11 @@ in
}; };
"gitea-web-chown@" = { "gitea-web-chown@" = {
description = "Ensure all gitea-web content is owned by the gitea user"; description = "Ensure all gitea-web content has correct ownership";
serviceConfig = { serviceConfig = {
Slice = "system-giteaweb.slice"; Slice = "system-giteaweb.slice";
Type = "oneshot"; Type = "oneshot";
ExecStart = "${pkgs.coreutils}/bin/chown -R gitea:gitea '%S/gitea-web'"; ExecStart = "${pkgs.coreutils}/bin/chown -R gitea:nginx '%S/gitea-web/web/%i'";
StateDirectory = "%i";
LoadCredential = [
"token:${config.sops.secrets."gitea/web-secret-provider/token".path}"
];
PrivateNetwork = true; PrivateNetwork = true;
} // commonHardening; } // commonHardening;
}; };

View File

@ -43,7 +43,7 @@ def get_org_repo_list(args: argparse.Namespace, token: str):
def generate_ssh_key(args: argparse.Namespace, repository: str): def generate_ssh_key(args: argparse.Namespace, repository: str):
keyname = hashlib.sha256(args.org.encode() + repository.encode()).hexdigest() keyname = hashlib.sha256(args.org.encode() + repository.encode()).hexdigest()
key_path = args.key_dir / keyname key_path = args.key_dir / keyname
if not key_path.exists() or args.force: if not key_path.is_file() or args.force:
subprocess.run( subprocess.run(
[ [
"ssh-keygen", "ssh-keygen",
@ -63,7 +63,8 @@ def generate_ssh_key(args: argparse.Namespace, repository: str):
with open(key_path, "r") as f: with open(key_path, "r") as f:
private_key = f.read() private_key = f.read()
with open(key_path.append_suffix('.pub'), "r") as f: pub_key_path = args.key_dir / (keyname + '.pub')
with open(pub_key_path, "r") as f:
public_key = f.read() public_key = f.read()
return private_key, public_key return private_key, public_key