summaryrefslogtreecommitdiffstats
path: root/test/run.sh
diff options
context:
space:
mode:
authordev <dev@example>2026-11-15 11:28:47 +0000
committerdev <dev@example>2026-11-15 11:28:47 +0000
commitc2b95afc6aefbab69133a202cab95a50a2df82fc (patch)
tree4788b1b9302ef77b244c4107de2f3da15982f303 /test/run.sh
parent5a9afae082f36812a2e7c9e61d8662628b798f41 (diff)
downloadaccess-control-c2b95afc6aefbab69133a202cab95a50a2df82fc.tar.gz
access-control-c2b95afc6aefbab69133a202cab95a50a2df82fc.zip
Drop grant/revoke and validate's host-wiring checks
Two features out, to answer a size target: src/ and cmd/ go from 2,306 non-blank lines to 1,495. `grant` and `revoke` were a convenience wrapper over a file that is a read-only mount in production by design, so they sat outside the enforcement path. src/edit.c is gone; both names now report an unknown command with exit 64. `validate` keeps the policy checks - parse errors with their line numbers, an unreadable policy, the @all-whole-repo and not-readable-by- the-git-account warnings - and stops cross-checking the machine around it. The repository cross-check, hook/hooksPath, sshd, the git account's shell and the key/htpasswd identity checks are deleted, along with --root, --hook-dir, --gitconfig, --sshd-config, --passwd, --keys, --htpasswd and --no-host; plain `validate` is what `validate --no-host` used to be. The container's build gate and the test suite are updated to match, since both called the removed flag. Orphaned by the removals and deleted with them: authz_repo_reachable, and authz_rule_validate's ref_ok parameter, which existed only so grant could interleave its own ref-pattern test. Surviving behaviour is unchanged. A 1,370-invocation differential run against the pre-removal binary - the check matrix, every authorize path, the hook reached through its own name, fake-git ancestry and HEAD, policy-only validate, the failure modes - differs only in the usage text that documented the removed surface. make strict, make test and make sanitizer are all clean, with ASan and UBSan silent. Also folded in from the same effort, since it touched the same files: authz_rule_validate as the single grammar, rule_covers() as the single answer for rule/ref coverage, vmsgv() behind the validate message tags, one kv reader for gitconfig and sshd_config while both were still there, and `sanitizer:` in the Makefile appending to CFLAGS rather than replacing it.
Diffstat (limited to 'test/run.sh')
-rwxr-xr-xtest/run.sh311
1 files changed, 7 insertions, 304 deletions
diff --git a/test/run.sh b/test/run.sh
index a608468..d3268b0 100755
--- a/test/run.sh
+++ b/test/run.sh
@@ -154,7 +154,7 @@ alice * admin
bob team write refs/heads/feature/*
EOF
-out=$("$AUTHZ" --policy "$P" validate --no-host 2>&1)
+out=$("$AUTHZ" --policy "$P" validate 2>&1)
rc=$?
expect "the fixture policy is sound" 0 "is in force" "$rc" "$out"
@@ -546,323 +546,26 @@ chmod 644 "$TMP/secret.conf"
section "validate: the policy alone"
POLICY=$P
-out=$("$AUTHZ" --policy "$P" validate --no-host 2>&1); rc=$?
+out=$("$AUTHZ" --policy "$P" validate 2>&1); rc=$?
expect "the fixture passes" 0 "is in force" "$rc" "$out"
expect_not "with nothing to complain about" 0 "warn " "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/broken.conf" validate --no-host 2>&1); rc=$?
+out=$("$AUTHZ" --policy "$TMP/broken.conf" validate 2>&1); rc=$?
expect "a broken policy is reported with its line number" 3 ":2: error" "$rc" "$out"
cat >"$TMP/noise.conf" <<'EOF'
@all web write
bob missing write refs/heads/*
EOF
-out=$("$AUTHZ" --policy "$TMP/noise.conf" validate --no-host 2>&1); rc=$?
+out=$("$AUTHZ" --policy "$TMP/noise.conf" validate 2>&1); rc=$?
expect "warnings do not fail a validate" 0 "warning(s)" "$rc" "$out"
contains "$out" "@all the whole of web" || bad "an unscoped @all should be warned about"
-out=$("$AUTHZ" --policy "$TMP/noise.conf" validate --no-host --strict 2>&1); rc=$?
+out=$("$AUTHZ" --policy "$TMP/noise.conf" validate --strict 2>&1); rc=$?
expect "--strict makes warnings fatal" 1 "warning" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/nope.conf" validate --no-host 2>&1); rc=$?
+out=$("$AUTHZ" --policy "$TMP/nope.conf" validate 2>&1); rc=$?
expect "a missing policy is not a valid policy" 3 "cannot be read" "$rc" "$out"
-section "validate: the host around it"
-
-mkhost() {
- H=$TMP/host
- rm -rf "$H"
- mkdir -p "$H/hooks" "$H/repos/team.git" "$H/repos/secrets.git" "$H/secrets"
- ln -sf "$AUTHZ_ABS" "$H/hooks/pre-receive" 2>/dev/null || cp "$AUTHZ" "$H/hooks/pre-receive"
- printf '[core]\n\thooksPath = %s/hooks\n' "$H" >"$H/gitconfig"
- printf 'PermitUserEnvironment yes\nForceCommand /usr/bin/git-shell\nAuthorizedKeysFile %s/secrets/authorized_keys\n' "$H" >"$H/sshd_config"
- printf 'git:x:1000:1000::/var/lib/git:/usr/bin/git-shell\n' >"$H/passwd"
- printf 'ssh-ed25519 AAAA bob\n' >"$H/secrets/authorized_keys"
- printf 'environment="GIT_HOST_USER=bob" ssh-ed25519 BBBB\n' >>"$H/secrets/authorized_keys"
- printf 'bob:$2y$05$hash\n' >"$H/secrets/htpasswd"
- cat >"$H/authz.conf" <<'POL'
-alice * admin
-bob team write refs/heads/feature/*
-POL
-}
-
-host_validate() {
- "$AUTHZ" --policy "$H/authz.conf" validate \
- --root "$H/repos" --hook-dir "$H/hooks" --gitconfig "$H/gitconfig" \
- --sshd-config "$H/sshd_config" --passwd "$H/passwd" \
- --keys "$H/secrets/authorized_keys" --htpasswd "$H/secrets/htpasswd" "$@" 2>&1
-}
-
-mkhost
-out=$(host_validate); rc=$?
-expect "a wired-up host passes" 0 "is in force" "$rc" "$out"
-expect "and says what it checked" 0 "ForceCommand" "$rc" "$out"
-
-sed "s|hooksPath = .*|hooksPath = /somewhere/else|" "$H/gitconfig" >"$H/gitconfig2"
-mv "$H/gitconfig2" "$H/gitconfig"
-out=$(host_validate); rc=$?
-expect "the wrong core.hooksPath is an error" 1 "checked by something else" "$rc" "$out"
-
-sed "s|hooksPath|hooks-path|" "$H/gitconfig" >"$H/gitconfig2"
-mv "$H/gitconfig2" "$H/gitconfig"
-out=$(host_validate); rc=$?
-expect "no core.hooksPath at all is an error" 1 "does not set core.hooksPath" "$rc" "$out"
-
-mkhost
-mv "$H/hooks/pre-receive" "$H/hooks/away"
-out=$(host_validate); rc=$?
-expect "a missing hook is an error" 1 "every push would be accepted unchecked" "$rc" "$out"
-mv "$H/hooks/away" "$H/hooks/pre-receive"
-
-mkhost
-sed "s/PermitUserEnvironment yes/PermitUserEnvironment no/" "$H/sshd_config" >"$H/s2"
-mv "$H/s2" "$H/sshd_config"
-out=$(host_validate); rc=$?
-expect "PermitUserEnvironment no means anonymous pushes" 1 "anonymous" "$rc" "$out"
-
-mkhost
-sed "s|^ForceCommand.*|# no force command|" "$H/sshd_config" >"$H/s2"
-mv "$H/s2" "$H/sshd_config"
-out=$(host_validate); rc=$?
-expect "no ForceCommand is an error" 1 "interactive shell" "$rc" "$out"
-
-mkhost
-sed "s|git-shell|/bin/sh|" "$H/passwd" >"$H/p2"
-mv "$H/p2" "$H/passwd"
-out=$(host_validate); rc=$?
-expect "a git account with a real shell is an error" 1 "not git-shell" "$rc" "$out"
-
-mkhost
-printf 'environment="GIT_HOST_USER=ghost" ssh-ed25519 CCCC\n' >"$H/secrets/authorized_keys"
-out=$(host_validate); rc=$?
-expect "a key identity with no rule is a warning" 0 "ghost" "$rc" "$out"
-out=$(host_validate --strict); rc=$?
-expect "and fatal under --strict" 1 "ghost" "$rc" "$out"
-
-mkhost
-printf 'ssh-ed25519 AAAAanonymouskey\n' >>"$H/secrets/authorized_keys"
-out=$(host_validate); rc=$?
-expect "an identity-less key is a warning" 0 "no GIT_HOST_USER" "$rc" "$out"
-
-mkhost
-printf 'mallory:$2y$05$hash\n' >>"$H/secrets/htpasswd"
-out=$(host_validate); rc=$?
-expect "an htpasswd user with no rule is a warning" 0 "change nothing" "$rc" "$out"
-
-mkhost
-printf 'bob team write\n' >"$H/authz.conf"
-mkdir -p "$H/repos/orphan.git"
-out=$(host_validate); rc=$?
-expect "a repository nobody can push to is a warning" 0 "orphan" "$rc" "$out"
-
-mkhost
-printf 'bob nowhere write\n' >>"$H/authz.conf"
-out=$(host_validate); rc=$?
-expect "a rule on a repository that is not there is a warning" 0 "nowhere" "$rc" "$out"
-
-mkhost
-printf 'alice web admin\nbob nowhere write refs/heads/*\n' >"$H/authz.conf"
-printf 'mallory:$2y$05$x\n' >"$H/secrets/htpasswd"
-mkdir -p "$H/repos/orphan.git"
-out=$(host_validate); rc=$?
-if contains "$out" "orphan" && contains "$out" "mallory" &&
- contains "$out" "nowhere" && contains "$out" "web"; then
- ok
-else
- bad "several warnings at once: said $out"
-fi
-expect "warnings alone still let the host serve" 0 "is in force" "$rc" "$out"
-
-# sshd reads a directive once and keeps the first answer it got, and "none" is
-# how a Match block turns a ForceCommand back off - both of those are the same
-# wide-open state as having no ForceCommand at all, so validate has to see them
-# that way too.
-
-mkhost
-printf 'PermitUserEnvironment yes\nForceCommand none\n' >"$H/sshd_config"
-out=$(host_validate); rc=$?
-expect "ForceCommand none is as open as no ForceCommand" 1 "interactive shell" "$rc" "$out"
-
-mkhost
-printf 'PermitUserEnvironment no\nPermitUserEnvironment yes\n' >"$H/sshd_config"
-out=$(host_validate); rc=$?
-expect "sshd keeps the first PermitUserEnvironment, not the last" 1 "anonymous" "$rc" "$out"
-
-mkhost
-printf 'PermitUserEnvironment yes\nForceCommand /usr/bin/git-shell\nForceCommand none\n' >"$H/sshd_config"
-out=$(host_validate); rc=$?
-expect "and the first ForceCommand is the one that counts" 0 "ForceCommand /usr/bin/git-shell" "$rc" "$out"
-
-# git spells section names case-insensitively, so [CORE] sets core.hooksPath just
-# as [core] does; refusing to see it reports a broken host that is not broken.
-mkhost
-printf '[CORE]\n\thooksPath = %s/hooks\n' "$H" >"$H/gitconfig"
-out=$(host_validate); rc=$?
-expect "a gitconfig section name is case-insensitive, like git's own" 0 "core.hooksPath" "$rc" "$out"
-
-# -------------------------------------------------------------- edit (grant)
-
-section "grant and revoke"
-
-cat >"$TMP/edit.conf" <<'EOF'
-# policy, kept in git and rolled out as a ConfigMap
-alice * admin # break glass
-bob team write refs/heads/feature/*
-EOF
-
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant carol team force refs/heads/feature/* 2>&1); rc=$?
-expect "grant appends" 0 "appended" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" check carol team force refs/heads/feature/x 2>&1); rc=$?
-expect "and the grant is in force immediately" 0 "allow" "$rc" "$out"
-if grep -q '^# policy, kept in git' "$TMP/edit.conf" &&
- grep -q 'break glass' "$TMP/edit.conf"; then
- ok
-else
- bad "the comments survived neither"
-fi
-
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team admin 2>&1); rc=$?
-expect "grant replaces the pair's rule" 0 "replaced line 3" "$rc" "$out"
-n=$(grep -c '^bob' "$TMP/edit.conf")
-[ "$n" = 1 ] && ok || bad "bob's rule is not collapsed into one line ($n lines)"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" check bob team admin refs/heads/main 2>&1); rc=$?
-expect "and the new level applies" 0 "allow" "$rc" "$out"
-
-out=$("$AUTHZ" --policy "$TMP/edit.conf" revoke bob team 2>&1); rc=$?
-expect "revoke removes the rule" 0 "revoked bob" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" check bob team admin refs/heads/dev 2>&1); rc=$?
-expect "and the access is gone" 1 "no rule" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" revoke bob team 2>&1); rc=$?
-expect "revoking nothing reports nothing" 1 "no rule for bob" "$rc" "$out"
-
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant frank team write refs/heads/main refs/tags/release/* 2>&1); rc=$?
-expect "grant can name several refs" 0 "granted frank" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" check frank team write refs/heads/main 2>&1); rc=$?
-expect "and the list is in force" 0 "allow" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" check frank team write refs/heads/dev 2>&1); rc=$?
-expect "and covers nothing else of his own" 1 "but not on refs/heads/dev" "$rc" "$out"
-if grep -q '^frank team write refs/heads/main refs/tags/release/\*$' "$TMP/edit.conf"; then
- ok
-else
- bad "the refs did not land on one line as written"
-fi
-
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team nope 2>&1); rc=$?
-expect "grant rejects a level that is not one" 64 "unknown access level" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob group/team write 2>&1); rc=$?
-expect "grant rejects a repository name with a slash in it" 64 "invalid repo pattern" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team write '!refs/heads/main' 2>&1); rc=$?
-expect "grant has no deny" 64 "no deny" "$rc" "$out"
-
-# A ref argument has to be one field. The line it lands on is split on whitespace
-# again when the file is read, and '#' starts a comment, so writing an argument
-# verbatim would either grant more than was asked for or leave a file that no
-# longer parses - and a policy that does not parse denies every push there is.
-cp "$TMP/edit.conf" "$TMP/edit.conf.before"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team write 'refs/heads/a b' 2>&1); rc=$?
-expect "a ref argument with a space in it is refused" 64 "not a ref pattern" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team write 'refs/heads/a#b' 2>&1); rc=$?
-expect "a ref argument with a comment marker is refused" 64 "not a ref pattern" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team write "$(printf 'refs/heads/a\nb')" 2>&1); rc=$?
-expect "a ref argument with a newline in it is refused" 64 "not a ref pattern" "$rc" "$out"
-cmp -s "$TMP/edit.conf" "$TMP/edit.conf.before" ||
- bad "a refused grant still changed the file"
-
-# The pair's rule being the last line of the file is still a replacement: nothing
-# was appended, and the message says which line was taken over.
-cat >"$TMP/lastline.conf" <<'EOF'
-alice * admin
-bob team write refs/heads/feature/*
-EOF
-out=$("$AUTHZ" --policy "$TMP/lastline.conf" grant bob team admin 2>&1); rc=$?
-expect "replacing the last line says replaced, not appended" 0 "replaced line 2" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/lastline.conf" grant zed team admin 2>&1); rc=$?
-expect "and a rule with no pair yet is still an append" 0 "appended as line 3" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" protect refs/heads/main 2>&1); rc=$?
-expect "protect is gone, and says it is unknown" 64 "unknown command" "$rc" "$out"
-printf 'set protected-refs refs/heads/main\n' >>"$TMP/edit.conf"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" check alice team admin refs/heads/main 2>&1); rc=$?
-expect "a policy that still carries protected-refs is refused, not ignored" 3 "no longer exists" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" validate --no-host 2>&1); rc=$?
-expect "and validate says every push is denied" 3 "not used" "$rc" "$out"
-grep -v 'protected-refs' "$TMP/edit.conf" > "$TMP/edit.conf.clean" &&
- cp "$TMP/edit.conf.clean" "$TMP/edit.conf"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" validate --no-host 2>&1); rc=$?
-expect "cleaned, it validates again" 0 "is in force" "$rc" "$out"
-
-cp "$TMP/edit.conf" "$TMP/edit.conf.orig"
-out=$("$AUTHZ" --policy "$TMP/broken.conf" grant bob team write 2>&1); rc=$?
-expect "editing a policy that does not parse is refused" 3 "does not parse" "$rc" "$out"
-cmp -s "$TMP/edit.conf" "$TMP/edit.conf.orig" || bad "a refused edit still changed the file"
-
-section "edit: where the result goes"
-
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant erin secrets admin --out "$TMP/other.conf" 2>&1); rc=$?
-expect "--out writes elsewhere" 0 "$TMP/other.conf" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/other.conf" check erin secrets admin refs/heads/main 2>&1); rc=$?
-expect "and the new file works" 0 "allow" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" check erin secrets admin refs/heads/main 2>&1); rc=$?
-expect "and the original does not have it" 1 "no rule" "$rc" "$out"
-
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant erin secrets admin --stdout 2>&1 >/dev/null); rc=$?
-expect "--stdout reports on stderr" 0 "untouched" "$rc" "$out"
-cp "$TMP/edit.conf" "$TMP/edit.conf.bak"
-out=$("$AUTHZ" --policy "$TMP/edit.conf" revoke carol team --stdout 2>/dev/null); rc=$?
-expect "--stdout prints the new file" 0 "alice * admin" "$rc" "$out"
-cmp -s "$TMP/edit.conf" "$TMP/edit.conf.bak" && ok || bad "--stdout modified the policy"
-if contains "$out" "alice * admin" && contains "$out" "break glass"; then
- ok
-else
- bad "--stdout lost the comments or the settings"
-fi
-
-# It is the directory that decides: a read-only mount is a read-only directory,
-# while a 0444 file in a writable directory is still replaceable.
-
-cp "$TMP/edit.conf" "$TMP/ro.conf"
-chmod 444 "$TMP/ro.conf"
-out=$("$AUTHZ" --policy "$TMP/ro.conf" grant bob team admin 2>&1); rc=$?
-if [ "$(id -u)" = 0 ]; then
- skip_it "an unwritable directory is refused" "running as root, who defeats chmod"
- expect "the mode of a 0444 policy survives a write" 0 "granted" "$rc" "$out"
- mode=$(ls -l "$TMP/ro.conf" | cut -c2-10)
- [ "$mode" = "r--r--r--" ] && ok || bad "a 0444 policy came back as $mode"
-else
- mkdir -p "$TMP/rodir"
- cp "$TMP/edit.conf" "$TMP/rodir/policy.conf"
- chmod 555 "$TMP/rodir"
- out=$("$AUTHZ" --policy "$TMP/rodir/policy.conf" grant bob team admin 2>&1); rc=$?
- expect "a policy in a read-only directory cannot be replaced" 1 "cannot write beside" "$rc" "$out"
- chmod 755 "$TMP/rodir"
-fi
-out=$("$AUTHZ" --policy "$TMP/ro.conf" grant bob team admin --out - 2>/dev/null); rc=$?
-expect "--out works whatever the input's mode is" 0 "bob team admin" "$rc" "$out"
-
-section "edit: leaving the file alone"
-
-cat >"$TMP/mode.conf" <<'EOF'
-alice * admin
-EOF
-chmod 640 "$TMP/mode.conf"
-out=$("$AUTHZ" --policy "$TMP/mode.conf" grant bob team write 2>&1); rc=$?
-expect "a grant succeeds" 0 "granted" "$rc" "$out"
-mode=$(ls -l "$TMP/mode.conf" | cut -c2-10)
-[ "$mode" = "rw-r-----" ] && ok || bad "the mode changed to $mode"
-left=$(ls -a "$TMP" | grep -c '^\.authz')
-[ "$left" = 0 ] && ok || bad "$left temporary file(s) left behind"
-
-printf 'alice * admin' >"$TMP/nonl.conf" # no final newline
-out=$("$AUTHZ" --policy "$TMP/nonl.conf" grant bob team write 2>&1); rc=$?
-expect "a file without a trailing newline is editable" 0 "granted" "$rc" "$out"
-[ "$(tail -c 1 "$TMP/nonl.conf" | wc -l)" = 1 ] && ok || bad "the last line still has no newline"
-
-out=$("$AUTHZ" --policy "$TMP/fresh.conf" grant alice '*' admin 2>&1); rc=$?
-expect "grant can create the first rule of a new policy" 0 "granted" "$rc" "$out"
-out=$("$AUTHZ" --policy "$TMP/fresh.conf" check alice anything admin refs/heads/main 2>&1); rc=$?
-expect "and the new policy works" 0 "allow" "$rc" "$out"
-
-out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team write --out "$TMP/nodir/x.conf" 2>&1); rc=$?
-expect "writing where the directory is not there fails" 1 "cannot write beside" "$rc" "$out"
-
# ------------------------------------------------------------------ install
section "install"
@@ -918,7 +621,7 @@ fi
if [ -f authz.conf ]; then
section "the example policy that ships with it"
- out=$("$AUTHZ" --policy authz.conf validate --no-host 2>&1); rc=$?
+ out=$("$AUTHZ" --policy authz.conf validate 2>&1); rc=$?
expect "it validates" 0 "is in force" "$rc" "$out"
out=$("$AUTHZ" --policy authz.conf check alice anything admin refs/heads/main 2>&1); rc=$?
expect "alice can do anything" 0 "allow" "$rc" "$out"