zitadel #2

Merged
jsw merged 14 commits from zitadel into master 2025-07-24 21:45:32 +00:00
4 changed files with 110 additions and 54 deletions
Showing only changes of commit fa35e153c6 - Show all commits

View file

@ -41,5 +41,9 @@ in {
file = ./immich-oidc.age;
owner = abstrServiceUser "immich";
};
seafile-oidc = mkIf server {
file = ./seafile-oidc.age;
owner = abstrServiceUser "seafile";
};
};
}

16
secrets/seafile-oidc.age Normal file
View file

@ -0,0 +1,16 @@
age-encryption.org/v1
-> ssh-ed25519 GQzYWA bJyIAsI/6hAeQQ9gFYIEY3bYkSZ/1aC+8w3rBYWVHCU
H38Px7xdB/MFhXdBZxu016/7tuzuk7+mRTv1wyQT+d4
-> ssh-ed25519 MfR7VA +iGb3WpMd0LbGj8wLBWJOHtiDAcuhxNaKboABUJjqlk
y6Q1+lV4Zg3Bzz4VvTW+/4SxAy5A5tzOL7O/ra9V0ns
-> ssh-ed25519 +cvRTg sFXk188eoPOlJdh2LicBCwTvgRerU+Ou5JNvAawfPmU
elcMDCCJWkPWpmGMHTNgOMoZIAGqZmw3V4J2Q1opyU0
-> ssh-ed25519 WCPLrA mQMjG0AtKkKIQlSV5FDMhKiLovREAvFmEAye3pfAbSg
GK8mibNENVSXiQjmKqVuuyAe7b3VpPQ5tqbj/70vwOk
-> ssh-ed25519 7/ziYw U61nqCBxz9bH4aljZqD2zPd7kJxBQlK8O8eH0QD+8Cc
CCrpXNbLeNkRSeMmMjlEQK4ffyWm/bTozNZ5yfnXssw
-> ssh-ed25519 VQy60Q CiiIktgZ0Q5KPSGu/jwPHwNAVaD7dA7T/FKw8H0K3ws
ZeTiGA0sSeGS1IJrQMBIh28vUnHupYUrnZBsz+9I4yM
--- qMzO4grI7h5bkEI4d/ruuyMS7RVvZtFsfJT07M8W9W0
è€Í>q@|6bŸ1<yQ6<51>çÙM¼E; (o2WÓ³
ת¬¸æj<C3A6>UEÖ<45>è§ÿÝ)ý7JX|;â?.dˆ#iÌ ekw¯q¿Q¹Kú§¦¶©¼ì

View file

@ -22,4 +22,5 @@ in {
"zitadel-key.age".publicKeys = keys;
"forgejo-mailpass.age".publicKeys = keys;
"immich-oidc.age".publicKeys = keys;
"seafile-oidc.age".publicKeys = keys;
}

View file

@ -2,68 +2,20 @@
config,
inputs,
pkgs,
lib,
...
}: let
inherit (lib) mkIf mkForce;
cfg = config.niksos.server;
url = "files.jsw.tf";
httpsUrl = "https://" + url;
authUrl = config.services.zitadel.settings.ExternalDomain;
httpsAuthUrl = "https://" + authUrl;
oidcSubstitute = "*@#OPENIDCLIENTSECRET#@*";
config-dir = "/run/immich-conf";
in {
services.seafile = {
enable = config.niksos.server;
seahubPackage = inputs.nixpkgs-stable.legacyPackages.${pkgs.system}.seahub;
adminEmail = "jsw@jsw.tf";
initialAdminPassword = "ChangeMeTheFuckNow!";
gc.enable = true;
ccnetSettings.General.SERVICE_URL = httpsUrl;
seahubExtraConf = ''
ALLOWED_HOSTS = ['.${url}']
CSRF_COOKIE_SECURE = True
CSRF_COOKIE_SAMESITE = 'Strict'
CSRF_TRUSTED_ORIGINS = ['${httpsUrl}']
SITE_NAME = "JSW Cloud"
SITE_TITLE = "JSW Cloud"
ENABLE_OAUTH = True
OAUTH_CREATE_UNKNOWN_USER = True
OAUTH_ACTIVATE_USER_AFTER_CREATION = True
OAUTH_ENABLE_INSECURE_TRANSPORT = False
OAUTH_CLIENT_ID = "329743411726844274"
OAUTH_CLIENT_SECRET = "${oidcSubstitute}"
OAUTH_REDIRECT_URL = '${httpsUrl}/oauth/callback/'
OAUTH_PROVIDER_DOMAIN = '${authUrl}'
OAUTH_PROVIDER = 'JSW Auth'
OAUTH_AUTHORIZATION_URL = '${httpsAuthUrl}/oauth/v2/authorize'
OAUTH_TOKEN_URL = '${httpsAuthUrl}/oauth/v2/token'
OAUTH_USER_INFO_URL = '${httpsAuthUrl}/oidc/v1/userinfo'
OAUTH_SCOPE = ["user",]
OAUTH_ATTRIBUTE_MAP = {
"id": (True, "email"),
"name": (False, "name"),
"email": (False, "contact_email"),
"uid": (True, "uid"),
}
'';
seafileSettings = {
quota.default = 30;
history.keep_days = 40;
library_trash.expire_days = 14;
fileserver = {
host = "unix:/run/seafile/server.sock";
web_token_expire_time = 14400; # 4 hours
max_download_dir_size = 100000; # 100gb max download size.
};
};
};
services.caddy.virtualHosts.${url} = {
extraConfig = ''
config = mkIf cfg {
services.caddy.virtualHosts.${url}.extraConfig = ''
handle_path /seafhttp/* {
reverse_proxy * unix//run/seafile/server.sock
}
@ -71,5 +23,88 @@ in {
reverse_proxy * unix//run/seahub/gunicorn.sock
}
'';
services.seafile = {
enable = config.niksos.server;
seahubPackage = inputs.nixpkgs-stable.legacyPackages.${pkgs.system}.seahub;
adminEmail = "jsw@jsw.tf";
initialAdminPassword = "ChangeMeTheFuckNow!";
gc.enable = true;
ccnetSettings.General.SERVICE_URL = httpsUrl;
seahubExtraConf = ''
ALLOWED_HOSTS = ['.${url}']
CSRF_COOKIE_SECURE = True
CSRF_COOKIE_SAMESITE = 'Strict'
CSRF_TRUSTED_ORIGINS = ['${httpsUrl}']
SITE_NAME = "JSW Cloud"
SITE_TITLE = "JSW Cloud"
ENABLE_OAUTH = True
OAUTH_CREATE_UNKNOWN_USER = True
OAUTH_ACTIVATE_USER_AFTER_CREATION = True
OAUTH_ENABLE_INSECURE_TRANSPORT = False
OAUTH_CLIENT_ID = "329743411726844274"
OAUTH_CLIENT_SECRET = "${oidcSubstitute}"
OAUTH_REDIRECT_URL = '${httpsUrl}/oauth/callback/'
OAUTH_PROVIDER_DOMAIN = '${authUrl}'
OAUTH_PROVIDER = 'JSW Auth'
OAUTH_AUTHORIZATION_URL = '${httpsAuthUrl}/oauth/v2/authorize'
OAUTH_TOKEN_URL = '${httpsAuthUrl}/oauth/v2/token'
OAUTH_USER_INFO_URL = '${httpsAuthUrl}/oidc/v1/userinfo'
OAUTH_SCOPE = ["user",]
OAUTH_ATTRIBUTE_MAP = {
"id": (True, "email"),
"name": (False, "name"),
"email": (False, "contact_email"),
"uid": (True, "uid"),
}
'';
seafileSettings = {
quota.default = 30;
history.keep_days = 40;
library_trash.expire_days = 14;
fileserver = {
host = "unix:/run/seafile/server.sock";
web_token_expire_time = 14400; # 4 hours
max_download_dir_size = 100000; # 100gb max download size.
};
};
};
#NOTE: Overwriting parts of services so that it uses a different root. When upgrading. Please check the following two things:
## * If seafile still uses seafile_settings.py to store openid settings.systemd
## * If the service scripts / settings have changed.systemd
## * Better even, rewrite this entire part.
systemd.services = let
config-dir = "/run/seafile";
replaceSecretBin = lib.getExe pkgs.replace-secret;
seafRoot = "/var/lib/seafile";
ccnetDir = "${seafRoot}/ccnet";
sfCfg = config.services.seafile;
in {
seaf-server = {
preStart = ''
umask 077
cp -f '/etc/seafile' '${config-dir}'
chmod u+w -R '${config-dir}'
${replaceSecretBin} '${oidcSubstitute}' '${config.age.secrets.seafile-oidc.path}' '${config-dir}/seahub_settings.py'
'';
serviceConfig.ExecStart = mkForce ''
${lib.getExe sfCfg.seahubPackage.seafile-server} \
--foreground \
-F '${config-dir} \
-c ${ccnetDir} \
-d ${sfCfg.dataDir} \
-l /var/log/seafile/server.log \
-P /run/seafile/server.pid \
-p /run/seafile
'';
};
seahub.environment.SEAFILE_CENTRAL_CONF_DIR = mkForce config-dir;
};
};
}