Skip to main content

Juniper Policy

@hmcrum/juniper-policyv2026.09.17.1· 4d agoMODELS
01README

Deterministic queries over a Junos SRX security policy tree expressed as YAML.

Asking a language model "is this flow already permitted?" produces an impression: sometimes right, never citable, different on the next run. The same question is really set membership over five dimensions — from-zone, to-zone, source, destination, application — plus CIDR and port containment. This model answers it as a lookup that cites the file and line it came from.

Normalization is the real work, and it is what a parser buys you over an impression: a /32 host route inside a /21 the address book names, a member reached through two levels of address_set, a port inside a declared range, a rule whose zone list is a superset of yours.

Methods

  • load_policies — parse every policy YAML into one typed snapshot: rules, address objects, address sets, applications and application sets, each carrying its file and line. Also reports files no terraform role loads, references that resolve to nothing, and names defined twice — none of which are visible in the YAML itself.

  • find_duplicates — given a proposed flow, return exact, subsumed, overlapping or none. Deliberately not a boolean: "already covered by a broader rule" and "partly allowed, and the remainder is the real request" lead to different decisions.

  • zone_traversal — resolve a flow's zone pairs and report which trust boundaries it crosses, plus the rules that already exist for those pairs. Emits a mermaid graph built from parsed data.

  • evaluate_checklist — answer the mechanically-answerable review items with verdicts and file:line evidence. Items needing judgment return requires_human rather than a guess.

Design notes

No zone taxonomy or trust ordering is shipped as a default. Zone names are an estate's own vocabulary, and a built-in ranking would be one site's topology published as though it were a standard. Unranked zone pairs are reported as unranked rather than as a reassuring zero, because a silent "no trust drop detected" from a table containing neither zone is the failure this model exists to prevent.

Likewise, names that resolve outside the YAML tree — Junos built-ins, dynamic address feeds, anything a rendering layer injects per device — are reported separately from genuinely broken references. A check that cries wolf dozens of times is a check nobody reads.

Read-only throughout: it parses files and never writes to a device or a repo.

Quick Start

swamp extension pull @hmcrum/juniper-policy
swamp model create @hmcrum/juniper-policy srx \
  --global-arg policyDir=/path/to/terraform/security-policies \
  --global-arg terraformMain=/path/to/terraform/main.tf
swamp model @hmcrum/juniper-policy method run load_policies srx
swamp model @hmcrum/juniper-policy method run find_duplicates srx \
  --input 'fromZone=["trust"]' \
  --input 'toZone=["dmz"]' \
  --input 'sourceAddress=["192.0.2.0/24"]' \
  --input 'destinationAddress=["any"]' \
  --input 'application=["junos-https"]'
02Models1
@hmcrum/juniper-policyv2026.09.17.1juniper_policy.ts

Global Arguments

ArgumentTypeDescription
policyDirstringDirectory holding the security policy YAML files, e.g. /path/to/terraform/security-policies
terraformMainstringOptional path to terraform main.tf, to learn which role loads which policy file. Empty skips the unreferenced-file check
untrustedZonesarrayZones treated as outside the trust boundary. Defaults to the single Junos-conventional name; add your own
trustRankrecordZone name to trust rank, higher being more trusted. No defaults are shipped — an assumed trust model that does not match the real one is worse than none, so unranked zones are reported as unranked rather than assumed equal
externalAddressPatternsarrayExtra regexes for address names defined outside the YAML tree, such as names a rendering layer injects per device or objects fed in from an inventory system. Matches are reported as external rather than broken
fn load_policies()
Parse every policy YAML in policyDir into one typed snapshot: rules, address objects, address sets, applications and application sets, each carrying its file and line. Also reports files no terraform role loads, references that resolve to nothing, and names defined twice — all invisible in the YAML itself. Read-only.
fn find_duplicates(fromZone: array, toZone: array, sourceAddress: array, destinationAddress: array, application: array)
Given a proposed flow, return whether an existing permit rule already allows it: exact, subsumed, overlapping or none — never a boolean, because 'already covered by a broader rule' and 'partly allowed' lead to different decisions. Normalizes CIDR containment, address set membership, application sets and port ranges, and cites the matching rule's file and line. Read-only.
ArgumentTypeDescription
fromZonearraySource security zone(s) of the proposed flow
toZonearrayDestination security zone(s) of the proposed flow
sourceAddressarraySource address book names, literal CIDRs, or `any`
destinationAddressarrayDestination address book names, literal CIDRs, or `any`
applicationarrayApplication or application-set names, or `any`
fn zone_traversal(fromZone: array, toZone: array)
Resolve a flow's zone pairs and report which trust boundaries it crosses, using the configured trust ranking rather than an inference. Emits the mermaid graph and the rules that already exist for those zone pairs, so the diagram in a review comes from parsed data. Read-only.
ArgumentTypeDescription
fromZonearraySource security zone(s)
toZonearrayDestination security zone(s)
fn evaluate_checklist(fromZone: array, toZone: array, sourceAddress: array, destinationAddress: array, application: array)
Answer the mechanically-answerable security review items for a proposed rule — duplicate status, zone traversal, address and application resolution, scope, naming, name collision — each with a verdict and file:line evidence. Items needing judgment return requires_human rather than a guess. Read-only.
ArgumentTypeDescription
fromZonearraySource security zone(s) of the proposed flow
toZonearrayDestination security zone(s) of the proposed flow
sourceAddressarraySource address book names, literal CIDRs, or `any`
destinationAddressarrayDestination address book names, literal CIDRs, or `any`
applicationarrayApplication or application-set names, or `any`

Resources

policy_snapshot(1h)— Every security policy, address object and application parsed from the policy tree, with the file and line each came from
duplicate_check(infinite)— Whether an existing permit rule already covers a proposed flow, exactly or by subsumption, with citations
zone_traversal(infinite)— Trust boundaries a proposed flow crosses, and the rules that already exist for those zone pairs
checklist(infinite)— Per-item security review verdicts, separating mechanical answers from the ones needing a human
03Stats
A
100 / 100
Downloads
0
Archive size
52.7 KB
  • Has README or module doc2/2earned
  • README has a code example1/1earned
  • README is substantive1/1earned
  • Most symbols documented1/1earned
  • No slow types (deprecated)1/1earned
  • Dependencies pass trust audit2/2earned
  • Has description1/1earned
  • Platform support declared (or universal)2/2earned
  • License declared1/1earned
  • Verified public repository2/2earned
04Platforms
05Labels