feat(enforce): Slice 4.0+4.1 — kernel-op taxonomy and BPF policy lowering - #83
Merged
Conversation
4.0 — kernel-op taxonomy and BPF map schemas (frozen vocabulary): - python/vibap/bpf_types.py: OP_EXEC/OP_FILE_READ/OP_FILE_WRITE/ OP_NET_CONNECT/OP_EXTERNAL_SEND constants; ACT_ALLOW/DENY/ALLOWLIST; ENFORCE_MODE_PERMISSIVE/ENFORCE; SEC_TO_OPS mapping aligned to mission_compile._VALID_SIDE_EFFECT_CLASSES; schema dataclasses for cgroup_op_policy, cgroup_path_allow, cgroup_net_allow, enforce_events. - go/pkg/kernelcapture/bpf_enforce_types.go: Go-side types matching the six BPF map schemas (CgroupOpMapKey/Value, PathAllowPrefix, NetAllowPrefix, BpfEnforceEvent); BpfOp/BpfAction/BpfEnforceMode types with String() methods. 4.1 — bpf_lower.py, mirroring mission_compile.py: - lower_to_bpf_policy_plan(): lowers MissionDeclaration inputs to BpfPolicyPlan(op_policies, path_allow, net_allow, tier2_ops). - allowed_side_effect_classes → ACT_DENY for absent class ops. - forbidden_tools/allowed_tools projected via _tool_to_bpf_op() (keyword-component matching); unmappable → tier2_ops. - resource_scope + SubpathPolicy → path_allow + ACT_ALLOWLIST. - UrlAllowlistPolicy: hostname-only → tier2_ops; IP/CIDR → net_allow. - effect_policies/flow_policies/lineage_budgets → tier2_ops. - ENFORCE_STRICT loud-guard: raises MissionPolicyNotImplementedError on any unimplemented dimension (same philosophy as mission_compile). - 74 golden tests (test_bpf_lower.py) covering all lowering rules. Out of scope for this slice: BPF-LSM C program (4.2), daemon map-write path (4.2), kernel enforcement events (4.3+). Refs: Epic A (#63)
| {"type": "url_allowlist", "allow_domains": ["api.example.com"]} | ||
| ] | ||
| ) | ||
| assert any("api.example.com" in t for t in plan.tier2_ops) |
| ] | ||
| ) | ||
| assert "10.0.0.1" in plan.net_allow | ||
| assert any("api.example.com" in t for t in plan.tier2_ops) |
Comment on lines
+11
to
+16
| from vibap.bpf_lower import ( | ||
| BpfLowerError, | ||
| BpfPolicyPlan, | ||
| OpPolicyEntry, | ||
| lower_to_bpf_policy_plan, | ||
| ) |
| import ipaddress | ||
| import re | ||
| from collections import defaultdict | ||
| from dataclasses import dataclass, field |
| "cargo"} | ||
| ) | ||
|
|
||
| _EXTERNAL_SEND_KEYWORDS: frozenset[str] = frozenset( |
gnanirahulnutakki
marked this pull request as ready for review
July 1, 2026 14:13
This was referenced Jul 2, 2026
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.
Summary
Epic A Slice 4.0+4.1 — the pure-Python/Go foundation for the enforcement bridge.
No kernel code, no BPF program, no daemon writes yet — just the frozen schema and the lowering compiler.
Refs: #63 (Epic A), depends on / precedes PR #82 (Slice 1 daemon).
What this ships
4.0 — Kernel-op taxonomy + BPF map schemas
python/vibap/bpf_types.pyOP_EXEC / OP_FILE_READ / OP_FILE_WRITE / OP_NET_CONNECT / OP_EXTERNAL_SENDconstantsACT_ALLOW / ACT_DENY / ACT_ALLOWLISTandENFORCE_MODE_PERMISSIVE / ENFORCE_MODE_ENFORCESEC_TO_OPSmapping frommission_compile._VALID_SIDE_EFFECT_CLASSES→ BPF opsCgroupOpKey/Value,PathAllowKey,NetAllowKey,EnforceEventgo/pkg/kernelcapture/bpf_enforce_types.goCgroupOpMapKey/Value,PathAllowPrefix,NetAllowPrefix,BpfEnforceEventBpfOp / BpfAction / BpfEnforceModetyped constants withString()methods4.1 —
python/vibap/bpf_lower.pylower_to_bpf_policy_plan()→BpfPolicyPlan(op_policies, path_allow, net_allow, tier2_ops)allowed_side_effect_classesACT_DENYfor ops whose class is absentforbidden_toolsACT_DENYfor mappable ops; unmappable →tier2_opsallowed_toolsACT_ALLOWfor mappable ops; unmappable →tier2_opsresource_scope/SubpathPolicypath_allow+ACT_ALLOWLISTfor file opsUrlAllowlistPolicy(hostname)tier2_ops— BPF works on IP/CIDRUrlAllowlistPolicy(IP/CIDR)net_allow+ACT_ALLOWLISTfor net opseffect_policies / flow_policies / lineage_budgetstier2_ops;MissionPolicyNotImplementedErrorin ENFORCE_STRICTENFORCE_STRICT loud-guard: raises
MissionPolicyNotImplementedError(same class asmission_compile) on any dimension that can't be lowered to BPF. Never silently under-enforces.python/tests/test_bpf_lower.py— 74 golden tests covering every lowering rule.Explicitly NOT in this slice
process_enforce.bpf.c) — Slice 4.2net_prefixesTests