depot/cluster/services/sso/host.nix

62 lines
1.8 KiB
Nix
Raw Normal View History

2023-08-31 01:55:45 +03:00
{ cluster, config, depot, lib, ... }:
with depot.lib.nginx;
2021-10-16 21:24:30 +03:00
let
2023-08-31 01:55:45 +03:00
login = "login.${depot.lib.meta.domain}";
2022-06-18 03:44:51 +03:00
kc = config.links.keycloak;
2022-08-07 23:54:59 +03:00
patroni = cluster.config.links.patroni-pg-access;
2021-10-16 21:24:30 +03:00
in
{
2022-06-18 03:44:51 +03:00
links.keycloak.protocol = "http";
2021-11-29 02:38:59 +02:00
2021-10-16 21:24:30 +03:00
age.secrets.keycloak-dbpass = {
file = ../../../secrets/keycloak-dbpass.age;
2021-10-16 21:24:30 +03:00
owner = "root";
group = "root";
mode = "0400";
};
services.nginx.virtualHosts = {
2022-06-18 03:44:51 +03:00
"${login}" = lib.recursiveUpdate (vhosts.proxy kc.url) {
locations = {
"= /".return = "302 /auth/realms/master/account/";
"/".extraConfig = ''
proxy_busy_buffers_size 512k;
proxy_buffers 4 512k;
proxy_buffer_size 256k;
'';
};
2021-10-16 21:24:30 +03:00
};
"account.${domain}" = vhosts.redirect "https://${login}/auth/realms/master/account/";
};
services.keycloak = {
enable = true;
2023-02-24 16:16:15 +02:00
package = depot.packages.keycloak;
2021-10-16 21:24:30 +03:00
database = {
2022-08-07 23:54:59 +03:00
createLocally = false;
2021-10-16 21:24:30 +03:00
type = "postgresql";
2022-08-07 23:54:59 +03:00
host = patroni.ipv4;
inherit (patroni) port;
useSSL = false;
2021-10-16 21:24:30 +03:00
passwordFile = config.age.secrets.keycloak-dbpass.path;
};
2022-05-30 23:00:21 +03:00
settings = {
2022-06-18 03:44:51 +03:00
http-host = kc.ipv4;
http-port = kc.port;
2022-05-30 23:00:21 +03:00
hostname = login;
proxy = "edge";
# for backcompat, TODO: remove
http-relative-path = "/auth";
2021-10-16 21:24:30 +03:00
};
};
2022-06-19 01:16:25 +03:00
systemd.services.keycloak.environment = {
JAVA_OPTS = builtins.concatStringsSep " " [
2023-02-24 16:16:15 +02:00
"-javaagent:${depot.packages.opentelemetry-java-agent-bin}"
2022-06-19 01:16:25 +03:00
"-Dotel.resource.attributes=service.name=keycloak"
"-Dotel.traces.exporter=otlp"
];
OTEL_EXPORTER_OTLP_PROTOCOL = "grpc";
OTEL_EXPORTER_OTLP_ENDPOINT = cluster.config.links.tempo-otlp-grpc.url;
2022-06-19 01:16:25 +03:00
OTEL_TRACES_SAMPLER = "parentbased_traceidratio";
2023-05-14 00:29:10 +03:00
OTEL_TRACES_SAMPLER_ARG = "0.50";
2022-06-19 01:16:25 +03:00
};
2021-10-16 21:24:30 +03:00
}