pinwheel: Use the Cloudflare One client for the work VPN
This commit is contained in:
9 files changed
+63
-91
No files matched your search
@@ -27,7 +27,7 @@ in
|
|||||||
zsh.enable = true;
|
zsh.enable = true;
|
||||||
atuin.enable = true;
|
atuin.enable = true;
|
||||||
|
|
||||||
openvpn.enable = true;
|
vpn.enable = true;
|
||||||
|
|
||||||
c.enable = true;
|
c.enable = true;
|
||||||
go.enable = true;
|
go.enable = true;
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
pkgs,
|
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
enabled = config.mod.openvpn.enable;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
mod.openvpn = {
|
|
||||||
enable = lib.mkEnableOption "enable openpn module";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = lib.mkIf enabled {
|
|
||||||
home-manager.users.alex = {
|
|
||||||
home.packages = [
|
|
||||||
pkgs.openvpn
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
services.resolved = {
|
|
||||||
enable = true;
|
|
||||||
settings = {
|
|
||||||
Resolve = {
|
|
||||||
Domains = [ "~." ];
|
|
||||||
DNSSEC = false;
|
|
||||||
DNSOverTLS = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
enabled = config.mod.vpn.enable;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
mod.vpn = {
|
||||||
|
enable = lib.mkEnableOption "enable vpn module";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf enabled {
|
||||||
|
services.cloudflare-warp.enable = true;
|
||||||
|
services.resolved.enable = true;
|
||||||
|
|
||||||
|
systemd.services.cloudflare-warp-dns = {
|
||||||
|
bindsTo = [ "sys-subsystem-net-devices-CloudflareWARP.device" ];
|
||||||
|
after = [ "sys-subsystem-net-devices-CloudflareWARP.device" ];
|
||||||
|
wantedBy = [ "sys-subsystem-net-devices-CloudflareWARP.device" ];
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
script = ''
|
||||||
|
resolvectl dns CloudflareWARP 127.0.2.2 127.0.2.3
|
||||||
|
resolvectl domain CloudflareWARP '~.'
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -94,7 +94,7 @@ let
|
|||||||
|
|
||||||
work-vpn = pkgs.writeShellScript "work-vpn" ''
|
work-vpn = pkgs.writeShellScript "work-vpn" ''
|
||||||
connected() {
|
connected() {
|
||||||
systemctl is-active --quiet openvpn-work-staging.service openvpn-work-production.service
|
warp-cli --accept-tos status | ${pkgs.gnugrep}/bin/grep -q "Status update: Connected"
|
||||||
}
|
}
|
||||||
|
|
||||||
output() {
|
output() {
|
||||||
@@ -107,9 +107,9 @@ let
|
|||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
if connected; then
|
if connected; then
|
||||||
systemctl stop work-vpn.target && ${pkgs.libnotify}/bin/notify-send "Disconnected from work VPN"
|
work-vpn down && ${pkgs.libnotify}/bin/notify-send "Disconnected from work VPN"
|
||||||
else
|
else
|
||||||
systemctl start work-vpn.target && ${pkgs.libnotify}/bin/notify-send "Connected to work VPN"
|
work-vpn up && ${pkgs.libnotify}/bin/notify-send "Connected to work VPN"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
let
|
let
|
||||||
gitEnabled = config.mod.git.enable;
|
gitEnabled = config.mod.git.enable;
|
||||||
goEnabled = config.mod.go.enable;
|
goEnabled = config.mod.go.enable;
|
||||||
openvpnEnabled = config.mod.openvpn.enable;
|
vpnEnabled = config.mod.vpn.enable;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
home-manager.users.alex = {
|
home-manager.users.alex = {
|
||||||
@@ -90,12 +90,32 @@ EOF
|
|||||||
pkgs.golangci-lint
|
pkgs.golangci-lint
|
||||||
|
|
||||||
(pkgs.writeShellScriptBin "work-vpn" ''
|
(pkgs.writeShellScriptBin "work-vpn" ''
|
||||||
|
registered() {
|
||||||
|
! warp-cli --accept-tos status | ${pkgs.gnugrep}/bin/grep -q "Registration Missing"
|
||||||
|
}
|
||||||
|
|
||||||
|
connected() {
|
||||||
|
warp-cli --accept-tos status | ${pkgs.gnugrep}/bin/grep -q "Status update: Connected"
|
||||||
|
}
|
||||||
|
|
||||||
|
wait-for() {
|
||||||
|
for _ in $(${pkgs.coreutils}/bin/seq $1); do
|
||||||
|
$2 && return 0
|
||||||
|
${pkgs.coreutils}/bin/sleep 1
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
up)
|
up)
|
||||||
systemctl start work-vpn.target
|
if ! registered; then
|
||||||
|
warp-cli --accept-tos registration new
|
||||||
|
wait-for 300 registered
|
||||||
|
fi
|
||||||
|
warp-cli --accept-tos connect && wait-for 30 connected
|
||||||
;;
|
;;
|
||||||
down)
|
down)
|
||||||
systemctl stop work-vpn.target
|
warp-cli --accept-tos disconnect
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
'')
|
'')
|
||||||
@@ -145,46 +165,6 @@ EOF
|
|||||||
pkgs.zlib
|
pkgs.zlib
|
||||||
];
|
];
|
||||||
|
|
||||||
services.openvpn.servers = lib.mkIf openvpnEnabled {
|
|
||||||
work-staging = {
|
|
||||||
config = "config ${config.age.secrets.work-staging-ovpn.path}";
|
|
||||||
autoStart = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
work-production = {
|
|
||||||
config = "config ${config.age.secrets.work-production-ovpn.path}";
|
|
||||||
autoStart = false;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.targets.work-vpn = lib.mkIf openvpnEnabled {
|
|
||||||
description = "Work VPN";
|
|
||||||
requires = [
|
|
||||||
"openvpn-work-staging.service"
|
|
||||||
"openvpn-work-production.service"
|
|
||||||
];
|
|
||||||
after = [
|
|
||||||
"openvpn-work-staging.service"
|
|
||||||
"openvpn-work-production.service"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.services = lib.mkIf openvpnEnabled {
|
|
||||||
openvpn-work-staging.partOf = [ "work-vpn.target" ];
|
|
||||||
openvpn-work-production.partOf = [ "work-vpn.target" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
security.polkit.extraConfig = lib.mkIf openvpnEnabled ''
|
|
||||||
polkit.addRule(function(action, subject) {
|
|
||||||
if (action.id == "org.freedesktop.systemd1.manage-units" &&
|
|
||||||
subject.user == "alex" &&
|
|
||||||
action.lookup("unit") == "work-vpn.target" &&
|
|
||||||
["start", "stop", "restart"].indexOf(action.lookup("verb")) >= 0) {
|
|
||||||
return polkit.Result.YES;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
'';
|
|
||||||
|
|
||||||
age.secrets = {
|
age.secrets = {
|
||||||
"work-gitconfig" = lib.mkIf gitEnabled {
|
"work-gitconfig" = lib.mkIf gitEnabled {
|
||||||
file = ../../../../secrets/pinwheel/work-gitconfig.age;
|
file = ../../../../secrets/pinwheel/work-gitconfig.age;
|
||||||
@@ -210,12 +190,10 @@ EOF
|
|||||||
group = "users";
|
group = "users";
|
||||||
};
|
};
|
||||||
|
|
||||||
"work-staging-ovpn" = lib.mkIf openvpnEnabled {
|
"work-cloudflare-mdm" = lib.mkIf vpnEnabled {
|
||||||
file = ../../../../secrets/pinwheel/work-staging-ovpn.age;
|
file = ../../../../secrets/pinwheel/work-cloudflare-mdm.age;
|
||||||
};
|
path = "/var/lib/cloudflare-warp/mdm.xml";
|
||||||
|
symlink = false;
|
||||||
"work-production-ovpn" = lib.mkIf openvpnEnabled {
|
|
||||||
file = ../../../../secrets/pinwheel/work-production-ovpn.age;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-2
@@ -24,9 +24,8 @@ in {
|
|||||||
"pinwheel/work-gitconfig.age".publicKeys = [ pinwheel alex ];
|
"pinwheel/work-gitconfig.age".publicKeys = [ pinwheel alex ];
|
||||||
"pinwheel/work-github-token.age".publicKeys = [ pinwheel alex ];
|
"pinwheel/work-github-token.age".publicKeys = [ pinwheel alex ];
|
||||||
"pinwheel/work-rv-teams.age".publicKeys = [ pinwheel alex ];
|
"pinwheel/work-rv-teams.age".publicKeys = [ pinwheel alex ];
|
||||||
|
"pinwheel/work-cloudflare-mdm.age".publicKeys = [ pinwheel alex ];
|
||||||
"pinwheel/work-go-private.age".publicKeys = [ pinwheel alex ];
|
"pinwheel/work-go-private.age".publicKeys = [ pinwheel alex ];
|
||||||
"pinwheel/work-staging-ovpn.age".publicKeys = [ pinwheel alex ];
|
|
||||||
"pinwheel/work-production-ovpn.age".publicKeys = [ pinwheel alex ];
|
|
||||||
"pinwheel/naviterm-config.age".publicKeys = [ pinwheel alex ];
|
"pinwheel/naviterm-config.age".publicKeys = [ pinwheel alex ];
|
||||||
"pinwheel/navidrome-password.age".publicKeys = [ pinwheel alex ];
|
"pinwheel/navidrome-password.age".publicKeys = [ pinwheel alex ];
|
||||||
"pinwheel/ndp-llm-api-key.age".publicKeys = [ pinwheel alex ];
|
"pinwheel/ndp-llm-api-key.age".publicKeys = [ pinwheel alex ];
|
||||||
|
|||||||
Reference in new issue
Block a user