2021-04-02 18:53:00 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
{
|
2021-01-08 03:03:00 +00:00
|
|
|
name = "pomerium";
|
2021-04-02 18:53:00 +00:00
|
|
|
meta = with lib.maintainers; {
|
2024-01-26 04:04:56 +00:00
|
|
|
maintainers = [
|
|
|
|
lukegb
|
2021-01-08 03:03:00 +00:00
|
|
|
devusb
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-12-10 19:26:33 +00:00
|
|
|
nodes =
|
|
|
|
let
|
|
|
|
base =
|
|
|
|
myIP:
|
2021-01-08 03:03:00 +00:00
|
|
|
{ pkgs, lib, ... }:
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2021-01-08 03:03:00 +00:00
|
|
|
virtualisation.vlans = [ 1 ];
|
|
|
|
networking = {
|
|
|
|
dhcpcd.enable = false;
|
|
|
|
firewall.allowedTCPPorts = [
|
2024-12-10 19:26:33 +00:00
|
|
|
80
|
|
|
|
443
|
|
|
|
];
|
2021-01-08 03:03:00 +00:00
|
|
|
hosts = {
|
|
|
|
"192.168.1.1" = [
|
|
|
|
"pomerium"
|
|
|
|
"pom-auth"
|
2024-12-10 19:26:33 +00:00
|
|
|
];
|
2021-01-08 03:03:00 +00:00
|
|
|
"192.168.1.2" = [
|
|
|
|
"backend"
|
|
|
|
"dummy-oidc"
|
2024-12-10 19:26:33 +00:00
|
|
|
];
|
|
|
|
};
|
2021-01-08 03:03:00 +00:00
|
|
|
interfaces.eth1.ipv4.addresses = pkgs.lib.mkOverride 0 [
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2021-01-08 03:03:00 +00:00
|
|
|
address = myIP;
|
|
|
|
prefixLength = 24;
|
2024-12-10 19:26:33 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2021-01-08 03:03:00 +00:00
|
|
|
pomerium =
|
|
|
|
{ pkgs, lib, ... }:
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2021-01-08 03:03:00 +00:00
|
|
|
imports = [ (base "192.168.1.1") ];
|
|
|
|
environment.systemPackages = with pkgs; [ chromium ];
|
|
|
|
services.pomerium = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
address = ":80";
|
|
|
|
insecure_server = true;
|
|
|
|
authenticate_service_url = "http://pom-auth";
|
|
|
|
|
|
|
|
idp_provider = "oidc";
|
|
|
|
idp_scopes = [ "oidc" ];
|
|
|
|
idp_client_id = "dummy";
|
|
|
|
idp_provider_url = "http://dummy-oidc";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2021-01-08 03:03:00 +00:00
|
|
|
policy = [
|
|
|
|
{
|
|
|
|
from = "https://my.website";
|
|
|
|
to = "http://192.168.1.2";
|
|
|
|
allow_public_unauthenticated_access = true;
|
|
|
|
preserve_host_header = true;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
from = "https://login.required";
|
|
|
|
to = "http://192.168.1.2";
|
|
|
|
allowed_domains = [ "my.domain" ];
|
|
|
|
preserve_host_header = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
secretsFile = pkgs.writeText "pomerium-secrets" ''
|
|
|
|
# 12345678901234567890123456789012 in base64
|
|
|
|
COOKIE_SECRET=MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=
|
|
|
|
IDP_CLIENT_SECRET=dummy
|
|
|
|
'';
|
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2021-01-08 03:03:00 +00:00
|
|
|
backend =
|
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
{
|
|
|
|
imports = [ (base "192.168.1.2") ];
|
|
|
|
services.nginx.enable = true;
|
|
|
|
services.nginx.virtualHosts."my.website" = {
|
|
|
|
root = pkgs.runCommand "testdir" { } ''
|
|
|
|
mkdir "$out"
|
|
|
|
echo hello world > "$out/index.html"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
services.nginx.virtualHosts."dummy-oidc" = {
|
|
|
|
root = pkgs.runCommand "testdir" { } ''
|
|
|
|
mkdir -p "$out/.well-known"
|
|
|
|
cat <<EOF >"$out/.well-known/openid-configuration"
|
|
|
|
{
|
|
|
|
"issuer": "http://dummy-oidc",
|
|
|
|
"authorization_endpoint": "http://dummy-oidc/auth.txt",
|
|
|
|
"token_endpoint": "http://dummy-oidc/token",
|
|
|
|
"jwks_uri": "http://dummy-oidc/jwks.json",
|
|
|
|
"userinfo_endpoint": "http://dummy-oidc/userinfo",
|
|
|
|
"id_token_signing_alg_values_supported": ["RS256"]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
echo hello I am login page >"$out/auth.txt"
|
|
|
|
'';
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
|
|
|
};
|
2021-01-08 03:03:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
{ ... }:
|
|
|
|
''
|
|
|
|
backend.wait_for_unit("nginx")
|
|
|
|
backend.wait_for_open_port(80)
|
|
|
|
|
|
|
|
pomerium.wait_for_unit("pomerium")
|
|
|
|
pomerium.wait_for_open_port(80)
|
|
|
|
|
|
|
|
with subtest("no authentication required"):
|
|
|
|
pomerium.succeed(
|
2021-06-05 13:50:58 +00:00
|
|
|
"curl --resolve my.website:80:127.0.0.1 http://my.website | grep 'hello world'"
|
2021-01-08 03:03:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with subtest("login required"):
|
|
|
|
pomerium.succeed(
|
2021-06-05 13:50:58 +00:00
|
|
|
"curl -I --resolve login.required:80:127.0.0.1 http://login.required | grep pom-auth"
|
2021-01-08 03:03:00 +00:00
|
|
|
)
|
|
|
|
pomerium.succeed(
|
2021-06-05 13:50:58 +00:00
|
|
|
"curl -L --resolve login.required:80:127.0.0.1 http://login.required | grep 'hello I am login page'"
|
2021-01-08 03:03:00 +00:00
|
|
|
)
|
2023-03-18 11:49:22 +00:00
|
|
|
|
|
|
|
with subtest("ui"):
|
|
|
|
pomerium.succeed(
|
|
|
|
# check for a string that only appears if the UI is displayed correctly
|
2024-01-26 04:04:59 +00:00
|
|
|
"chromium --no-sandbox --headless --disable-gpu --dump-dom --host-resolver-rules='MAP login.required 127.0.0.1:80' http://login.required/.pomerium | grep 'User Details Not Available'"
|
2023-03-18 11:49:22 +00:00
|
|
|
)
|
2021-01-08 03:03:00 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|