k8s: the gateway's group reads the store credential files nginx includes
This commit is contained in:
parent
0d6065cf8f
commit
f65aed2147
1 changed files with 119 additions and 64 deletions
|
|
@ -298,6 +298,13 @@ pkgs.testers.runNixOSTest {
|
|||
# which needs certificates this host does not mint, so a second nginx
|
||||
# carries the passthrough alone, as `k8s-bao-login` does.
|
||||
services.nginx.enable = lib.mkForce false;
|
||||
# The user the module would create: the stub gateway below runs as it, so a
|
||||
# file it includes has to be the gateway's to read, as under the real unit
|
||||
# (`User = cfg.user`).
|
||||
users.users.nginx = {
|
||||
isSystemUser = true;
|
||||
group = "nginx";
|
||||
};
|
||||
networking.hosts."${bridgeIp}" = [
|
||||
baoName
|
||||
natsName
|
||||
|
|
@ -510,16 +517,20 @@ pkgs.testers.runNixOSTest {
|
|||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
serviceConfig = {
|
||||
User = "nginx";
|
||||
Group = "nginx";
|
||||
RuntimeDirectory = "logs-gateway-test";
|
||||
ExecStart = "${pkgs.nginx}/bin/nginx -c ${gatewayConf config} -g 'daemon off;'";
|
||||
ExecStart = "${pkgs.nginx}/bin/nginx -e stderr -c ${gatewayConf config} -g 'daemon off;'";
|
||||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 2;
|
||||
};
|
||||
};
|
||||
|
||||
environment.etc."logs-gateway.conf".source = gatewayConf config;
|
||||
environment.systemPackages = [
|
||||
pkgs.kubectl
|
||||
pkgs.nginx
|
||||
pkgs.curl
|
||||
pkgs.jq
|
||||
pkgs.openssl
|
||||
|
|
@ -1095,7 +1106,7 @@ pkgs.testers.runNixOSTest {
|
|||
assert machine.succeed(f"cat {STORE_PASSWORD}").strip() == stored
|
||||
secret = machine.succeed(f"kubectl -n {NS} get secret swarm-victorialogs-credentials -o jsonpath='{{.data.store-auth}}' | base64 -d").strip()
|
||||
assert secret == stored
|
||||
assert machine.succeed(f"stat -c '%a %U %G' {STORE_PASSWORD} {STORE_CONF} {STORE_AUTH_DIR}").split("\n")[:3] == ["600 root root", "600 root root", "700 root root"]
|
||||
assert machine.succeed(f"stat -c '%a %U %G' {STORE_PASSWORD} {STORE_CONF} {STORE_AUTH_DIR}").split("\n")[:3] == ["600 root root", "640 root nginx", "750 root nginx"]
|
||||
assert stored not in machine.succeed(f"cat {MANIFESTS}/{VL}.yaml"), "the manifest holds no credential"
|
||||
# Insert, select, a delete route, the admin routes, the store's own
|
||||
# metrics and the UI answer 401 with no credential and with a caller's
|
||||
|
|
@ -1159,6 +1170,26 @@ pkgs.testers.runNixOSTest {
|
|||
assert machine.succeed(f"cat {STORE_CONF}") == saved
|
||||
wait_for_record(AGENT_TOKEN, "switch", "written before the switch")
|
||||
|
||||
with subtest("the gateway's user reads the credential file and not the password, and a file only root reads keeps nginx from loading its configuration"):
|
||||
# The stub gateway runs as the user the module's nginx unit runs as
|
||||
# (`User = cfg.user`), so what it includes has to be that user's to read.
|
||||
nginx_check = "runuser -u nginx -- ${pkgs.nginx}/bin/nginx -e stderr -t -c /etc/logs-gateway.conf 2>&1"
|
||||
assert machine.succeed("systemctl show --property=User --value logs-gateway").strip() == "nginx"
|
||||
machine.succeed(f"runuser -u nginx -- cat {STORE_CONF}")
|
||||
machine.fail(f"runuser -u nginx -- cat {STORE_PASSWORD}")
|
||||
machine.succeed(nginx_check)
|
||||
# Control: the same file owned and moded as it was, root's alone.
|
||||
machine.succeed(f"chown root:root {STORE_CONF} && chmod 0600 {STORE_CONF}")
|
||||
status, out = machine.execute(nginx_check)
|
||||
assert status != 0 and f'open() "{STORE_CONF}" failed (13: Permission denied)' in out, (status, out)
|
||||
# The unit finds the value right and the owner wrong, and puts it back.
|
||||
machine.succeed("systemctl restart swarm-bao-store-auth.service")
|
||||
store_credential_published()
|
||||
assert machine.succeed(f"stat -c '%a %U %G' {STORE_CONF}").strip() == "640 root nginx"
|
||||
machine.succeed(nginx_check)
|
||||
machine.succeed("systemctl reload logs-gateway")
|
||||
machine.wait_until_succeeds("systemctl is-active logs-gateway", timeout=30)
|
||||
|
||||
with subtest("a record posted to the ingest route and the store's own metrics come through the gateway, and a restarted pod still holds both records"):
|
||||
import base64
|
||||
|
||||
|
|
@ -1485,7 +1516,7 @@ pkgs.testers.runNixOSTest {
|
|||
assert machine.succeed(f"cat {VM_PASSWORD}").strip() == stored
|
||||
secret = machine.succeed(f"kubectl -n {NS} get secret swarm-victoriametrics-credentials -o jsonpath='{{.data.store-auth}}' | base64 -d").strip()
|
||||
assert secret == stored
|
||||
assert machine.succeed(f"stat -c '%a %U %G' {VM_PASSWORD} {VM_CONF}").split("\n")[:2] == ["600 root root", "600 root root"]
|
||||
assert machine.succeed(f"stat -c '%a %U %G' {VM_PASSWORD} {VM_CONF}").split("\n")[:2] == ["600 root root", "640 root nginx"]
|
||||
assert stored not in machine.succeed(f"cat {MANIFESTS}/{VM}.yaml"), "the manifest holds no credential"
|
||||
# Writes, imports, queries, exports, the routes that delete and
|
||||
# snapshot, the config and reload routes, the store's own metrics and
|
||||
|
|
|
|||
Loading…
Reference in a new issue