require a proxy credential at squid and prove it in the self-check
This commit is contained in:
parent
52d532ff5a
commit
b7adb90f53
1 changed files with 207 additions and 43 deletions
|
|
@ -485,39 +485,60 @@ let
|
|||
&& !(lib.hasInfix "localnet" conf);
|
||||
}
|
||||
{
|
||||
# First match wins, so a destination deny after the allow is dead.
|
||||
name = "squid refuses unlisted names, then loopback, link-local and bridge destinations, before any allow";
|
||||
# First match wins, so a destination deny after the allow is dead, and
|
||||
# a credential check after it never challenges anyone. The two IP-literal
|
||||
# denies stay ahead of the unlisted-name deny: `dstdomain` on an IP
|
||||
# literal does a reverse lookup.
|
||||
name = "squid refuses unlisted names, then loopback, link-local and bridge destinations, then a missing credential, before any allow";
|
||||
ok =
|
||||
let
|
||||
lines = lib.splitString "\n" hiveOtel.services.squid.configText;
|
||||
at = l: lib.lists.findFirstIndex (x: x == l) null lines;
|
||||
allow = at "http_access allow allowed_dst";
|
||||
authed = at "http_access deny !authed";
|
||||
in
|
||||
allow != null
|
||||
&& authed != null
|
||||
&& at "http_access deny to_localhost" != null
|
||||
&& at "http_access deny to_localhost" < allow
|
||||
&& at "http_access deny to_linklocal" != null
|
||||
&& at "http_access deny to_linklocal" < allow
|
||||
&& at "http_access deny to_bridge" != null
|
||||
&& at "http_access deny to_bridge" < allow
|
||||
&& at "http_access deny to_localhost" < authed
|
||||
&& at "http_access deny to_linklocal" < authed
|
||||
&& at "http_access deny to_bridge" < authed
|
||||
&& authed < allow
|
||||
&& at "http_access deny ip_v4_host" != null
|
||||
&& at "http_access deny ip_v4_host" < at "http_access deny !allowed_dst"
|
||||
&& at "http_access deny ip_v6_host" < at "http_access deny !allowed_dst"
|
||||
&& at "http_access deny !allowed_dst" != null
|
||||
&& at "http_access deny !allowed_dst" < at "http_access deny to_localhost"
|
||||
&& builtins.elem "cache deny all" lines
|
||||
&& lib.last (lib.filter (l: l != "") lines) == "http_access deny all";
|
||||
}
|
||||
{
|
||||
# The file hive-c0re renders exists, owned by it and readable by squid's
|
||||
# group, from boot; hive-c0re gets its path only on a host with a store
|
||||
# identity.
|
||||
name = "squid's users file exists for hive-c0re to write, and hive-c0re is told where it is";
|
||||
# The helper is the NCSA one, on the file hive-c0re renders. The file
|
||||
# exists, empty, before squid starts (the helper exits on a missing one),
|
||||
# and the self-check imports its credential without failing when there is
|
||||
# none.
|
||||
name = "squid authenticates with the NCSA helper on a users file that exists before it starts";
|
||||
ok =
|
||||
let
|
||||
conf = hiveOtel.services.squid.configText;
|
||||
lines = lib.splitString "\n" conf;
|
||||
users = hiveOtel.services.hyperhive.squid.usersFile;
|
||||
rules = hiveOtel.systemd.tmpfiles.rules;
|
||||
sc = hiveOtel.systemd.services.squid-selfcheck.serviceConfig;
|
||||
in
|
||||
users == "/var/lib/hive-squid/users"
|
||||
lib.any (
|
||||
l: lib.hasInfix "/libexec/basic_ncsa_auth ${users}" l && lib.hasPrefix "auth_param basic program " l
|
||||
) lines
|
||||
&& builtins.elem "acl authed proxy_auth REQUIRED" lines
|
||||
&& users == "/var/lib/hive-squid/users"
|
||||
&& builtins.elem "d /var/lib/hive-squid 2750 hive-core squid - -" rules
|
||||
&& builtins.elem "f ${users} 0640 hive-core squid - -" rules
|
||||
&& sc.ImportCredential == hiveOtel.services.hyperhive.squid.selfcheck.credentialName
|
||||
&& hiveOtelAllLocal.systemd.services.hive-c0re.environment.HIVE_SQUID_USERS_FILE == users;
|
||||
}
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue