Skip to content

Working on raw-logs with OAuth support #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 59 additions & 16 deletions systems/edge-nodes/modules/caddy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,35 @@
variables_order = EGPCS
'';
pools = {
php-caddy = {
user = "php-caddy";
group = "caddy";
phpPackage = pkgs.php83;
settings = {
"pm" = "dynamic";
"pm.max_children" = 75;
"pm.start_servers" = 10;
"pm.min_spare_servers" = 5;
"pm.max_spare_servers" = 20;
"pm.max_requests" = 500;
"listen.owner" = config.services.caddy.user;
"listen.group" = config.services.caddy.group;
php-caddy = {
user = "php-caddy";
group = "caddy";
phpPackage = pkgs.php83;
settings = {
"pm" = "dynamic";
"pm.max_children" = 75;
"pm.start_servers" = 10;
"pm.min_spare_servers" = 5;
"pm.max_spare_servers" = 20;
"pm.max_requests" = 500;
"listen.owner" = config.services.caddy.user;
"listen.group" = config.services.caddy.group;
};
};
};
};
};
age.secrets.phpbb_db.file = ../secrets/phpbb_db.age;
age.secrets.caddy-edge.file = ../secrets/caddy.age;
systemd.services.caddy = {
serviceConfig = {
EnvironmentFile = config.age.secrets.phpbb_db.path;
EnvironmentFile = config.age.secrets.caddy-edge.path;
};
};
services.caddy = {
enable = true;
package = pkgs-unstable.caddy.withPlugins {
plugins = [
"github.com/WeidiDeng/[email protected]" # Module to retrieve trusted proxy IPs from cloudflare
"github.com/greenpau/caddy-security" # Security module that provides OAuth
];
hash = "sha256-o/A1YSVSfUvwaepb7IusiwCt2dAGmzZrtM3cb8i8Too=";
};
Expand All @@ -146,6 +147,43 @@
useACMEHost = "tgstation13.org";
extraConfig = ''
encode gzip zstd
order authenticate before respond
order authorize before basicauth
security {
oauth identity provider tgstation {
realm tg
driver generic
client_id {env.TG_OAUTH_RAWLOGS_CLIENT_ID}
client_secret {env.TG_OAUTH_RAWLOGS_CLIENT_SECRET}
scopes user user.groups
base_auth_url https://forums.tgstation13.org/app.php/tgapi/oauth/auth
}

authentication portal tgstation {
enable identity provider tgstation
cookie domain raw-logs.tgstation13.org
ui {
links {
"My Identity" "/whoami" icon "las la-user"
}
}

transform user {
match realm tg
action add role authp/user
}

transform user {
match realm tg
}
}
authorization policy raw-logs {
set auth url https://forums.tgstation13.org/app.php/tgapi/oauth/auth
allow roles authp/admin authp/user
validate bearer header
inject headers with claims
}
}
root ${
toString inputs.tgstation-website.packages.x86_64-linux.default
}
Expand All @@ -159,6 +197,11 @@
root /run/tgstation-website-v2/serverinfo.json
file_server
}
handle_path /raw-logs {
authorize with raw-logs
root /run/tgstation-website-v2/serverinfo.json
file_server
}
redir /phpBB/ https://forums.tgstation13.org/
redir /phpBB/*.php* https://forums.tgstation13.org/{http.request.orig_uri.path.file}?{http.request.orig_uri.query}{http.request.orig_uri.path.*/}
'';
Expand Down
Binary file added systems/edge-nodes/secrets/caddy.age
Binary file not shown.
23 changes: 0 additions & 23 deletions systems/edge-nodes/secrets/phpbb_db.age

This file was deleted.

2 changes: 1 addition & 1 deletion systems/edge-nodes/secrets/secrets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ in {
# TODO: Move to a shared secret (somehow)
"tgstation-pr-announcer.age".publicKeys = users ++ frontend_systems;
"tailscaleAuthKey.age".publicKeys = users ++ systems;
"phpbb_db.age".publicKeys = users ++ frontend_systems;
"caddy.age".publicKeys = users ++ frontend_systems;
}
Loading