Skip to content

feat(enforce): Slice 4.0+4.1 — kernel-op taxonomy and BPF policy lowering - #83

Merged
gnanirahulnutakki merged 1 commit into
devfrom
feat/epicA-slice4-lower
Jul 1, 2026
Merged

feat(enforce): Slice 4.0+4.1 — kernel-op taxonomy and BPF policy lowering#83
gnanirahulnutakki merged 1 commit into
devfrom
feat/epicA-slice4-lower

Conversation

@gnanirahulnutakki

Copy link
Copy Markdown
Member

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.py

  • OP_EXEC / OP_FILE_READ / OP_FILE_WRITE / OP_NET_CONNECT / OP_EXTERNAL_SEND constants
  • ACT_ALLOW / ACT_DENY / ACT_ALLOWLIST and ENFORCE_MODE_PERMISSIVE / ENFORCE_MODE_ENFORCE
  • SEC_TO_OPS mapping from mission_compile._VALID_SIDE_EFFECT_CLASSES → BPF ops
  • Schema dataclasses: CgroupOpKey/Value, PathAllowKey, NetAllowKey, EnforceEvent

go/pkg/kernelcapture/bpf_enforce_types.go

  • Go mirror of the six BPF map schemas: CgroupOpMapKey/Value, PathAllowPrefix, NetAllowPrefix, BpfEnforceEvent
  • BpfOp / BpfAction / BpfEnforceMode typed constants with String() methods

4.1 — python/vibap/bpf_lower.py

lower_to_bpf_policy_plan()BpfPolicyPlan(op_policies, path_allow, net_allow, tier2_ops)

Input BPF output
allowed_side_effect_classes ACT_DENY for ops whose class is absent
forbidden_tools ACT_DENY for mappable ops; unmappable → tier2_ops
allowed_tools ACT_ALLOW for mappable ops; unmappable → tier2_ops
resource_scope / SubpathPolicy path_allow + ACT_ALLOWLIST for file ops
UrlAllowlistPolicy (hostname) tier2_ops — BPF works on IP/CIDR
UrlAllowlistPolicy (IP/CIDR) net_allow + ACT_ALLOWLIST for net ops
effect_policies / flow_policies / lineage_budgets tier2_ops; MissionPolicyNotImplementedError in ENFORCE_STRICT

ENFORCE_STRICT loud-guard: raises MissionPolicyNotImplementedError (same class as mission_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

  • BPF-LSM C program (process_enforce.bpf.c) — Slice 4.2
  • Daemon BPF-map write path — Slice 4.2
  • Kernel enforcement events / ringbuf consumer — Slice 4.3+
  • URL hostname resolution to IP — future; caller can pre-resolve and pass via net_prefixes

Tests

uv run pytest tests/test_bpf_lower.py tests/test_mission_compile.py  # 74 + 53 = 127 passed
go test ./pkg/kernelcapture/...  # all passing

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,
)
Comment thread python/vibap/bpf_lower.py
import ipaddress
import re
from collections import defaultdict
from dataclasses import dataclass, field
Comment thread python/vibap/bpf_lower.py
"cargo"}
)

_EXTERNAL_SEND_KEYWORDS: frozenset[str] = frozenset(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants