Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Policy Assistant] Modify Data Structure for (B)ANP #152

Closed
huntergregory opened this issue Oct 10, 2023 · 0 comments · Fixed by #159
Closed

[Policy Assistant] Modify Data Structure for (B)ANP #152

huntergregory opened this issue Oct 10, 2023 · 0 comments · Fixed by #159

Comments

@huntergregory
Copy link
Contributor

huntergregory commented Oct 10, 2023

Requirement for #150.

Cyclonus uses an interim data structure (matcher.Policy) for the NetworkPolicy. We can modify this to support a generic Policy representing a ANP, BANP, or NetworkPolicy.

New features include:

  • SameLabels in Peer
  • Namespace Selector in Target (Subject)
  • Node Selector in Target/Peer
  • Priority + Action

Code to Modify

Will need to make new implementations of PeerMatcher like those seen in TargetsTableLines().

type Policy struct {
        // NOTE: need policyKind here
	Ingress map[string]*Target
	Egress  map[string]*Target
}

func (p *Policy) IsIngressOrEgressAllowed(traffic *Traffic, isIngress bool) *DirectionResult {
       // NOTE: need new logic here
       // Targets can overlap now since ANP uses namespace selector
}

type Traffic struct {
	Source      *TrafficPeer
	Destination *TrafficPeer

	ResolvedPort     int
	ResolvedPortName string
	Protocol         v1.Protocol
}

type Target struct {
       // NOTE: need:
       // 1. Namespace selector
       // 2. Node Selector
	Namespace   string
	PodSelector metav1.LabelSelector
	Peers       []PeerMatcher
	SourceRules []*networkingv1.NetworkPolicy // need ANP/BNP option
	primaryKey  string
}

type PeerMatcher interface {
	Allows(peer *TrafficPeer, portInt int, portName string, protocol v1.Protocol) bool
       // NOTE: need argument for target’s pod/node labels (to help with SameLabels)
       // NOTE: return value must be (policyKind, priority, action)
}

type TrafficPeer struct {
	Internal *InternalPeer
	IP       string
}

type InternalPeer struct {
	PodLabels map[string]string
	NamespaceLabels map[string]string
	Namespace       string
       // NOTE: need:
       // 1. Node
       // 2. Node labels
}
@huntergregory huntergregory changed the title NetPol Assistant: Modify Data Structure for (B)ANP Policy Assistant: Modify Data Structure for (B)ANP Oct 31, 2023
@huntergregory huntergregory changed the title Policy Assistant: Modify Data Structure for (B)ANP [Policy Assistant] Modify Data Structure for (B)ANP Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant