Watch
0
0
Fork
You've already forked hyperhive
0

Compare commits

...
3 changed files with 18 additions and 1 deletions

View file

@ -23,6 +23,15 @@ in
{
formatting = treefmt-eval.config.build.check self;
# The module-eval suite below only evaluates, so nothing else builds
# nginx's config file, whose derivation runs gixy over it. Naming the
# `ExecStart` that points at it makes this derivation depend on it, so a
# directive gixy refuses fails here instead of in a host build. The
# single-host swarm fixture serves the swarm UI vhost.
nginx-conf-all-local = pkgs.runCommand "nginx-conf-all-local" { } ''
echo ${pkgs.lib.escapeShellArg moduleEvalShared.allLocal.systemd.services.nginx.serviceConfig.ExecStart} > $out
'';
# The only checks here that cover **nix**. Every other one is a Rust
# derivation, so a `.nix`-only diff moves no hash and the whole set is
# cache hits — green without evaluating what changed. See

View file

@ -323,8 +323,12 @@ in
# 401 with a `WWW-Authenticate` header, which the UI reads as "log in
# again" and answers with a reload. The header is also how the UI tells
# this 401 from one the controller sends for its own reasons.
# The security headers are repeated inside the `if` block that sets its
# own `add_header`, which would otherwise drop them.
"@swarm_api_unauthorized".extraConfig = ''
${gatewayCfg.lib.securityHeaders}
if ($http_authorization) {
${gatewayCfg.lib.securityHeaders}
add_header WWW-Authenticate 'Bearer realm="swarm"' always;
return 401;
}

View file

@ -499,18 +499,22 @@ let
# with an error that says nothing about the session; only a request that
# asks for `text/html` gets the login. The `/` clause is the control: the
# page route still redirects, so a pass means the two routes differ.
# Each answer carries the gateway's security headers, which a location
# (or `if`) with an `add_header` of its own would otherwise drop.
name = "the controller API answers a refused bearer caller or fetch 401 and a page request the login";
ok =
let
l = allLocal.services.nginx.virtualHosts."t.local".locations;
api = l."/api/".extraConfig;
refused = l."@swarm_api_unauthorized".extraConfig;
sec = allLocal.services.hyperhive.gateway.lib.securityHeaders;
in
lib.hasInfix "error_page 401 = @swarm_api_unauthorized;" api
&& !(lib.hasInfix "=302" api)
&& lib.hasInfix ''proxy_set_header Authorization "";'' api
&& lib.hasInfix "if ($http_authorization) {\n add_header WWW-Authenticate 'Bearer realm=\"swarm\"' always;\n return 401;\n}" refused
&& lib.hasInfix "if ($http_authorization) {\n ${sec}\n add_header WWW-Authenticate 'Bearer realm=\"swarm\"' always;\n return 401;\n}" refused
&& lib.hasInfix "if ($http_accept ~* \"text/html\") {\n return 302 https://auth.t.local/?rd=$target_url;\n}" refused
&& lib.hasPrefix sec refused
&& lib.hasInfix "}\nadd_header WWW-Authenticate 'Bearer realm=\"swarm\"' always;\nreturn 401;" refused
&& lib.hasInfix "error_page 401 =302 https://auth.t.local/" l."/".extraConfig;
}