Repository navigation
Check package installs that a macOS session process starts - #85
Merged
Merged
Conversation
Only the command that `agentmon exec` started was package-checked. An install that an agent ran under `agentmon wrap`, or that a command started, was not. On build 1678, `pip install django==2.2` (CVE-2022-34265, CVSS 9.8) installed under wrap, although agent-default blocks a critical vulnerability. PolicyAdapter.CheckExec now runs the package check on an exec that the command rules allow. A block or a failed check denies the exec. An approve verdict denies it and asks for a dialog, as an approve exec rule does. ES reports a script's interpreter as the executable, so `pip3 install x` arrives as python3.15. The kernel puts the script path in argv[1], and the extension now sends the script, so the daemon classifies argv[1]. pkgcheck also reads `python -m pip` as pip, and a versioned name such as pip3.15 as pip3. A check resolves the install and asks the providers, which takes seconds. An exec whose arguments hold an install word now waits until 1 s before the ES deadline, at most 30 s, on a socket connection of its own. Every other exec keeps the 2 s limit on the shared connection. The exec API and the extension share one Checker, which reuses a verdict for the same install for 30 s, so one `agentmon exec pip install` does not resolve twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Testing the macOS package check on hardware found four defects that
stopped any package check from working as agent-default intends. They
affect the exec API path as well.
- The OSV provider called /v1/querybatch, which returns only the ID of
each vulnerability. Every finding defaulted to medium, so a rule for
critical vulnerabilities never matched. The provider now fetches each
record from /v1/vulns/{id}, 16 at a time, and caches it. Django 2.2
now gives 6 critical findings.
- The pip resolver ran without --quiet. pip 26 writes "Collecting ..."
lines to stdout before the JSON report, so the report never parsed.
- The checker used the package rules of the daemon's default policy for
every session. CheckForPolicy now takes the session's own rules, on
the exec API path and on the extension path.
- agent-default had no rule for findings other than critical
vulnerabilities and malware. A finding that no rule matches blocks, and
the local provider reports "license unknown" for every package, so every
install was blocked. agent-default now ends with an allow for every
other finding. ComposeRules applies a policy's final catch-all after the
block_on rules, so a stricter block_on still blocks.
On build 1682, scripts/test-macos-package-checks.sh passes 4 of 4: an
agent's `pip install django==2.2` and `python -m pip install django==2.2`
under wrap are refused for the critical vulnerability, and
`pip install six==1.16.0` installs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #84. Retarget to
mainafter #84 merges.The problem
Only the command that
agentmon execstarted was package-checked. An install that an agent ran underagentmon wrap, or that a command started, was not. On build 1678, an agent'spip install django==2.2(CVE-2022-34265, CVSS 9.8) installed underwrap.Hardware testing then found four defects that stopped the package check from working as
agent-defaultintends, on the exec API path as well:/v1/querybatch, which returns onlyidandmodifiedfor each vulnerability. Every finding defaulted to medium, so a rule for critical vulnerabilities never matched.--quiet. pip 26 writesCollecting ...lines to stdout before the JSON report, so the report never parsed.agent-defaulthad no rule for other findings. An unmatched finding blocks, and thelocalprovider reports "license unknown" for every package, so every install was blocked.The fix
macOS exec path:
PolicyAdapter.CheckExecruns the package check on an exec that the command rules allow. A block or a failed check denies the exec, with rulepackage-check. An approve verdict denies the exec and opens a dialog, as an approve exec rule does.argv[1], sopip3 install xarrives as pip3.PolicySocketClient.requestOnce). Every other exec keeps the 2 s limit on the shared connection. If the extension misses an install, the daemon has 1.5 s, and an unfinished check denies.pkgcheck:python -m pipcounts as pip, andpip3.15as pip3.Checkerreuses a verdict for the same install, directory and rules for 30 s. So oneagentmon exec pip installdoes not resolve twice.CheckForPolicytakes the session's package rules, on both paths.ComposeRulesapplies a policy's final catch-all after theblock_onrules, so a stricterblock_onstill blocks./v1/vulns/{id}, 16 at a time, and caches it.--quiet.Policy:
agent-defaultends itspackage_ruleswith an allow for every other finding.Verification
scripts/test-macos-package-checks.shon build 1682 passes 4 of 4. Underwrap, an agent'spip install django==2.2andpython -m pip install django==2.2are refused with[pip] Django@2.2 -> block (83 finding(s)), andpip install six==1.16.0installs. On build 1678, both django installs succeeded.test-macos-wrap-python.sh3 of 3,test-macos-wrap-session-reuse.sh4 of 4,test-macos-socket-signal-rules.sh13 ok,test-macos-network-proxy.sh6 of 6.go test -tags nofuse ./...passes, andgolangci-lintreports 0 issues.Known limits
pipis not found. Every check then fails, and the install is denied. The test setspackage_checks.resolvers.pip.dry_run_command.Part of SECENG-308.
🤖 Generated with Claude Code