2023-09-12 08:44:05 -06:00
|
|
|
{ config
|
|
|
|
, pkgs
|
|
|
|
, lib
|
|
|
|
, inputs
|
|
|
|
, xinlib
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
tailnetACLs =
|
|
|
|
let
|
|
|
|
acls = {
|
|
|
|
hosts = {
|
2024-04-25 15:21:47 -06:00
|
|
|
console = "100.83.166.33";
|
|
|
|
nbc = "100.74.8.55";
|
|
|
|
startpage = "127.0.0.1";
|
|
|
|
gitle = "100.111.162.87";
|
|
|
|
faf = "100.80.94.131";
|
|
|
|
h = "100.83.77.133";
|
|
|
|
box = "100.115.16.150";
|
|
|
|
pwntie = "100.84.170.57";
|
|
|
|
sputnik = "100.78.154.31";
|
|
|
|
europa = "100.64.26.122";
|
2024-05-05 10:06:58 -06:00
|
|
|
il = "100.86.182.99";
|
2024-05-28 11:44:27 -06:00
|
|
|
tv = "100.118.196.38";
|
2024-07-12 07:58:01 -06:00
|
|
|
ollama = "100.121.227.121";
|
2024-07-25 09:50:35 -06:00
|
|
|
display = "100.77.35.34";
|
2024-08-09 14:23:32 -06:00
|
|
|
rimgo = "100.121.77.91";
|
|
|
|
invidious = "100.71.57.99";
|
2023-09-12 08:44:05 -06:00
|
|
|
};
|
2023-07-27 09:51:55 -06:00
|
|
|
|
2023-09-12 08:44:05 -06:00
|
|
|
tagOwners = {
|
2024-04-25 15:21:47 -06:00
|
|
|
"tag:admin" = [ "autogroup:admin" ];
|
|
|
|
"tag:untrusted" = [ "qbit@tapenet.org" ];
|
|
|
|
"tag:ro-service" = [ "qbit@tapenet.org" ];
|
|
|
|
"tag:mobile" = [ "qbit@tapenet.org" ];
|
|
|
|
"tag:laptop" = [ "qbit@tapenet.org" ];
|
|
|
|
"tag:internal-server" = [ "qbit@tapenet.org" ];
|
|
|
|
"tag:external-server" = [ "qbit@tapenet.org" ];
|
|
|
|
"tag:work" = [ "qbit@tapenet.org" ];
|
|
|
|
"tag:dns-server" = [ "qbit@tapenet.org" ];
|
|
|
|
"tag:openbsd" = [ "qbit@tapenet.org" ];
|
2023-09-12 08:44:05 -06:00
|
|
|
};
|
2023-07-27 09:51:55 -06:00
|
|
|
|
2023-09-12 08:44:05 -06:00
|
|
|
acls = [
|
|
|
|
{
|
2024-04-25 15:21:47 -06:00
|
|
|
# Allow laptops and mobile devices to ssh to everything
|
2023-09-12 08:44:05 -06:00
|
|
|
action = "accept";
|
2024-04-25 15:21:47 -06:00
|
|
|
src = [ "tag:mobile" "tag:laptop" ];
|
|
|
|
dst = [ "*:*" ];
|
2023-09-12 08:44:05 -06:00
|
|
|
}
|
|
|
|
{
|
2024-04-25 15:21:47 -06:00
|
|
|
"action" = "accept";
|
|
|
|
"src" = [ "tag:internal-server" "tag:external-server" "tag:work" "tag:laptop" ];
|
|
|
|
"dst" = [ "nbc:443" ];
|
2023-09-12 08:44:05 -06:00
|
|
|
}
|
|
|
|
{
|
2024-04-25 15:21:47 -06:00
|
|
|
"action" = "accept";
|
|
|
|
"src" = [ "tag:untrusted" "tag:internal-server" ];
|
|
|
|
"dst" = [ "tag:ro-service:443" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"action" = "accept";
|
|
|
|
"src" = [ "tag:work" ];
|
2024-08-09 14:23:32 -06:00
|
|
|
"dst" = [ "console:2222" "startpage:443" "rimgo:443" "invidious:443" ];
|
2024-04-25 15:21:47 -06:00
|
|
|
}
|
|
|
|
{
|
|
|
|
"action" = "accept";
|
|
|
|
"src" = [ "tag:openbsd" ];
|
|
|
|
"dst" = [ "box:443" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
# prometheus
|
|
|
|
"action" = "accept";
|
|
|
|
"src" = [ "box" ];
|
|
|
|
"dst" = [ "h:9002" "pwntie:9002" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
# DNS
|
|
|
|
"action" = "accept";
|
|
|
|
"src" = [ "*" ];
|
|
|
|
"dst" = [ "faf:53" ];
|
|
|
|
"proto" = "udp";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
# ollama
|
|
|
|
"action" = "accept";
|
2024-05-24 20:45:11 -06:00
|
|
|
"src" = [ "europa" "h" ];
|
2024-07-12 07:58:01 -06:00
|
|
|
"dst" = [ "ollama:443" ];
|
2024-04-25 15:21:47 -06:00
|
|
|
"proto" = "tcp";
|
|
|
|
}
|
2024-05-28 11:44:27 -06:00
|
|
|
{
|
|
|
|
# jellyfin for tv
|
|
|
|
"action" = "accept";
|
2024-07-25 09:50:35 -06:00
|
|
|
"src" = [ "tv" "display" ];
|
2024-05-28 11:44:27 -06:00
|
|
|
"dst" = [ "box:443" ];
|
|
|
|
"proto" = "tcp";
|
|
|
|
}
|
2024-06-13 21:08:52 -06:00
|
|
|
{
|
|
|
|
"action" = "accept";
|
|
|
|
"src" = [ "box" ];
|
|
|
|
"dst" = [ "tv:8080" "tv:9090" ];
|
|
|
|
"proto" = "tcp";
|
|
|
|
}
|
2024-07-12 07:58:01 -06:00
|
|
|
{
|
|
|
|
action = "accept";
|
|
|
|
src = [ "h" ];
|
|
|
|
dst = [ "ollama:443" ];
|
|
|
|
proto = "tcp";
|
|
|
|
}
|
2024-04-25 15:21:47 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
tests = [
|
|
|
|
{
|
|
|
|
# RO service can't access things
|
|
|
|
"src" = "tag:ro-service";
|
|
|
|
"deny" = [ "tag:laptop:443" "tag:mobile:80" "tag:laptop:22" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:external-server";
|
|
|
|
"deny" = [ "tag:laptop:22" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:laptop";
|
|
|
|
"allow" = [ "tag:ro-service:443" "tag:ro-service:80" "tag:external-server:22" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:laptop";
|
|
|
|
"allow" = [ "qbit@tapenet.org:22" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:untrusted";
|
|
|
|
"deny" = [ "tag:laptop:22" ];
|
|
|
|
"allow" = [ "tag:ro-service:443" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:laptop";
|
|
|
|
"allow" = [ "tag:untrusted:22" "tag:untrusted:2222" "tag:work:22" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:work";
|
|
|
|
"deny" = [ "tag:laptop:22" ];
|
|
|
|
}
|
|
|
|
|
|
|
|
# Gitle shouldn't be able to access things, but things should access it
|
|
|
|
{
|
|
|
|
"src" = "gitle";
|
|
|
|
"deny" = [ "tag:laptop:22" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:laptop";
|
|
|
|
"allow" = [ "gitle:22" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:laptop";
|
|
|
|
"allow" = [ "faf:53" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:internal-server";
|
|
|
|
"allow" = [ "nbc:443" "tag:ro-service:443" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:laptop";
|
|
|
|
"allow" = [ "h:8967" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "h";
|
|
|
|
"proto" = "udp";
|
|
|
|
"allow" = [ "faf:53" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "tag:openbsd";
|
|
|
|
"proto" = "tcp";
|
|
|
|
"allow" = [ "box:443" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "sputnik";
|
|
|
|
"proto" = "tcp";
|
|
|
|
"allow" = [ "europa:1714" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "sputnik";
|
|
|
|
"proto" = "udp";
|
|
|
|
"allow" = [ "europa:1714" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
"src" = "europa";
|
|
|
|
"proto" = "tcp";
|
2024-07-12 07:58:01 -06:00
|
|
|
"allow" = [ "ollama:443" ];
|
2023-09-12 08:44:05 -06:00
|
|
|
}
|
2024-05-28 11:44:27 -06:00
|
|
|
{
|
|
|
|
"src" = "tv";
|
|
|
|
"proto" = "tcp";
|
|
|
|
"allow" = [ "box:443" ];
|
|
|
|
}
|
2024-07-25 09:50:35 -06:00
|
|
|
{
|
|
|
|
src = "display";
|
|
|
|
proto = "tcp";
|
|
|
|
allow = [ "box:443" ];
|
|
|
|
}
|
2023-09-12 08:44:05 -06:00
|
|
|
];
|
|
|
|
};
|
|
|
|
in
|
2023-07-27 09:51:55 -06:00
|
|
|
pkgs.writeTextFile {
|
|
|
|
name = "tailnet-acls.json";
|
|
|
|
text = builtins.toJSON acls;
|
|
|
|
};
|
2024-04-25 15:21:47 -06:00
|
|
|
aclUpdateScript = pkgs.writeShellScriptBin
|
|
|
|
"tailnet-acl-updater"
|
|
|
|
''
|
|
|
|
set -eu
|
2023-07-27 09:51:55 -06:00
|
|
|
|
2024-04-25 15:21:47 -06:00
|
|
|
. ${config.sops.secrets.po_env.path}
|
2023-07-27 09:51:55 -06:00
|
|
|
|
2024-04-25 15:21:47 -06:00
|
|
|
JQ=${pkgs.jq}/bin/jq
|
|
|
|
PO=${inputs.po.packages.${pkgs.system}.po}/bin/po
|
2023-07-27 09:51:55 -06:00
|
|
|
|
2024-04-25 15:21:47 -06:00
|
|
|
APIURL="https://api.tailscale.com/api/v2/tailnet/-/acl"
|
|
|
|
TOKEN="$(cat ${config.sops.secrets.tailnet_acl_manager.path}):"
|
2023-07-27 09:51:55 -06:00
|
|
|
|
2024-04-25 15:21:47 -06:00
|
|
|
ERROR="$(${pkgs.curl}/bin/curl "$APIURL/validate" -u "$TOKEN" -d @${tailnetACLs} | $JQ -r .message)"
|
2023-07-27 09:51:55 -06:00
|
|
|
|
2024-04-25 15:21:47 -06:00
|
|
|
if [ "$ERROR" = "null" ]; then
|
|
|
|
RESP="$(${pkgs.curl}/bin/curl "$APIURL" -u "$TOKEN" -d @${tailnetACLs} | $JQ -r .message)"
|
|
|
|
if [ "$RESP" != "null" ]; then
|
|
|
|
$PO -title "Failed to update TailNet!" -body "$RESP"
|
|
|
|
fi
|
2024-07-12 07:58:01 -06:00
|
|
|
else
|
2024-07-25 09:52:27 -06:00
|
|
|
$PO -title "Failed to update TailNet!" -body "$ERROR"
|
2023-07-27 09:51:55 -06:00
|
|
|
fi
|
2024-04-25 15:21:47 -06:00
|
|
|
'';
|
2023-07-27 09:51:55 -06:00
|
|
|
jobs = [
|
|
|
|
{
|
|
|
|
name = "update-talenet-acls";
|
|
|
|
script = "${aclUpdateScript}/bin/tailnet-acl-updater";
|
|
|
|
startAt = "*:30:00";
|
2023-09-12 08:44:05 -06:00
|
|
|
path = [ ];
|
2023-07-27 09:51:55 -06:00
|
|
|
inherit (config.nixManager) user;
|
|
|
|
}
|
|
|
|
];
|
2023-07-27 14:41:13 -06:00
|
|
|
enabled = config.nixManager.enable;
|
2023-07-27 09:51:55 -06:00
|
|
|
in
|
2023-09-12 08:44:05 -06:00
|
|
|
with lib; {
|
|
|
|
sops.secrets = mkIf enabled {
|
|
|
|
tailnet_acl_manager = {
|
|
|
|
owner = config.nixManager.user;
|
|
|
|
sopsFile = config.xin-secrets.manager;
|
|
|
|
};
|
|
|
|
};
|
2023-10-11 07:37:34 -06:00
|
|
|
systemd.services = mkIf enabled (listToAttrs (builtins.map xinlib.jobToService jobs));
|
2024-07-24 14:37:50 -06:00
|
|
|
environment.systemPackages = mkIf enabled [ aclUpdateScript ];
|
2023-09-12 08:44:05 -06:00
|
|
|
}
|