Skip to content

Commit bd7ffce

Browse files
committed
Address comments
Signed-off-by: Dyanngg <[email protected]>
1 parent ba69653 commit bd7ffce

File tree

1 file changed

+149
-98
lines changed
  • keps/sig-network/2091-admin-network-policy

1 file changed

+149
-98
lines changed

keps/sig-network/2091-admin-network-policy/README.md

Lines changed: 149 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ under `policy.networking.k8s.io` API group:
164164
- AdminNetworkPolicy
165165
- BaselineAdminNetworkPolicy
166166

167+
The AdminNetworkPolicy(ANP) and BaselineAdminNetworkPolicy(BANP) resources will
168+
help the administrators:
169+
1. Set strict security rules for the cluster, i.e. a developer CANNOT override
170+
these rules by creating NetworkPolicies that applies to the same workloads as the
171+
AdminNetworkPolicy does.
172+
2. Set baseline security rules that describes default connectivity for cluster
173+
workloads, which CAN be overridden by developer NetworkPolicies if needed.
174+
167175
### AdminNetworkPolicy resource
168176

169177
An AdminNetworkPolicy (ANP) resource will help the administrators set strict security
@@ -209,11 +217,10 @@ The policy instances will be ordered based on the numeric priority assigned to e
209217
ANP. `Priority` is a 32 bit integer value, where a smaller number corresponds to
210218
a higher precedence. The lowest numeric priority value is "0", which corresponds
211219
to the highest precedence. Larger numbers have lower precedence.
212-
Any ANP will have higher precedence over the namespaced NetworkPolicy instances
213-
in the cluster. If traffic matches both an ANP rule and a NetworkPolicy rule, the
214-
only case where the NetworkPolicy rule will be evaluated instead of ANP rule, is
215-
when there is a third higher-precedence ANP `Pass` rule that allows it to bypass
216-
any lower-precedence ANP rules.
220+
All ANPs will have higher precedence over NetworkPolicies in the cluster. If
221+
traffic matches both an ANP rule and a NetworkPolicy rule, the only case where the
222+
NetworkPolicy rule will be evaluated is when there is a third higher-precedence
223+
ANP `Pass` rule that allows it to bypass any lower-precedence ANP rules.
217224

218225
The relative precedence of the rules within a single ANP object (all of which
219226
share a priority) will be determined by the order in which the rule is written.
@@ -248,18 +255,17 @@ names.
248255

249256
An BaselineAdminNetworkPolicy (BANP) resource will help the administrators set
250257
baseline security rules that describes default connectivity for cluster workloads,
251-
which CAN be overridden by developer NetworkPolicies if needed.
258+
which CAN be overridden by developer owned NetworkPolicies if needed.
252259

253260
The BaselineAdminNetworkPolicy spec will look almost identical to that of an ANP,
254261
except for two important differences:
255262
1. There is no `Priority` field associated with BaselineAdminNetworkPolicy.
256-
Note that in writing a BaselineAdminNetworkPolicy, admins can still stack a narrower
257-
`Allow` on top of a wider `Deny` rule for example, by positioning the `Allow` rule
258-
higher in the ingress/egress rule list, which will result it to be evaluated
259-
first. However, the authors of this KEP did not have a valid usecase for creating
260-
multiple BaselineAdminNetworkPolicies in a cluster with distinct policy-level
261-
priorities. BANPs are intended for setting cluster default security postures, and
262-
in most cases the subject of such policy should be the entire cluster.
263+
Note that in writing a BaselineAdminNetworkPolicy, admins can create different
264+
priorities in rules by placing them before or after one another. However, the
265+
authors of this KEP did not find a valid usecase for creating multiple
266+
BaselineAdminNetworkPolicies in a cluster with distinct policy-level priorities.
267+
BANPs are intended for setting cluster default security postures, and in most
268+
cases the subject of such policy should be the entire cluster.
263269
2. There is no `Pass` action for BaselineAdminNetworkPolicy rules.
264270

265271
### User Stories
@@ -418,116 +424,148 @@ API group:
418424

419425
// AdminNetworkPolicy describes cluster-level network traffic control rules
420426
type AdminNetworkPolicy struct {
421-
metav1.TypeMeta
422-
metav1.ObjectMeta
427+
metav1.TypeMeta `json:",inline"`
428+
metav1.ObjectMeta `json:"metadata"`
423429

424-
// Specification of the desired behavior of AdminNetworkPolicy.
425-
Spec AdminNetworkPolicySpec
430+
// Specification of the desired behavior of AdminNetworkPolicy.
431+
Spec AdminNetworkPolicySpec `json:"spec"`
426432

427433
// Status is the status to be reported by the implementation, this is not
428434
// standardized in alpha and consumers should report what they see fit in
429435
// relation to their AdminNetworkPolicy implementation.
430436
// +optional
431-
Status AdminNetworkPolicyStatus
437+
Status AdminNetworkPolicyStatus `json:"status,omitempty"`
432438
}
433439

434440
type AdminNetworkPolicyStatus struct {
435441
Conditions []metav1.Condition
436442
}
437443

438-
// AdminNetworkPolicySpec provides the specification of AdminNetworkPolicy
444+
// AdminNetworkPolicySpec defines the desired state of AdminNetworkPolicy.
439445
type AdminNetworkPolicySpec struct {
440-
// Priority is a value from 0 to 1000. Rules with lower numeric priority values
441-
// have higher precedence, and are checked before rules with higher numeric
442-
// priority values. All AdminNetworkPolicy rules have higher precedence than
443-
// NetworkPolicy or BaselineAdminNetworkPolicy rules.
444-
Priority *int32
445-
446-
// Subject defines the objects to which this AdminNetworkPolicy applies.
447-
Subject AdminNetworkPolicySubject
448-
449-
// List of Ingress rules to be applied to the selected objects.
450-
// A total of 100 rules will be allowed per each network policy instance,
451-
// this rule count will be calculated as the total summation of the
452-
// Ingress and Egress rules in a single AdminNetworkPolicy Instance.
453-
Ingress []AdminNetworkPolicyIngressRule
454-
455-
// List of Egress rules to be applied to the selected objects.
456-
// A total of 100 rules will be allowed per each network policy instance,
457-
// this rule count will be calculated as the total summation of the
458-
// Ingress and Egress rules in a single AdminNetworkPolicy Instance.
459-
Egress []AdminNetworkPolicyEgressRule
460-
}
446+
// Priority is a value from 0 to 1000. Rules with lower priority values have
447+
// higher precedence, and are checked before rules with higher priority values.
448+
// All AdminNetworkPolicy rules have higher precedence than NetworkPolicy or
449+
// BaselineAdminNetworkPolicy rules
450+
// The relative precedence of the rules within a single ANP object (all of
451+
// which share the priority) will be determined by the order in which the rule
452+
// is written. Thus, a rule that appears at the top of the ingress/egress rules
453+
// would take the highest precedence. If ingress rules are defined before egress
454+
// rules in the same ANP object then ingress would take precedence and vice versa.
455+
// The behavior is undefined if two ANP objects have same priority.
456+
// +kubebuilder:validation:Minimum=0
457+
// +kubebuilder:validation:Maximum=1000
458+
Priority int32 `json:"priority"`
459+
460+
// Subject defines the pods to which this AdminNetworkPolicy applies.
461+
Subject AdminNetworkPolicySubject `json:"subject"`
461462

462-
// AdminNetworkPolicySubject defines what objects the policy selects.
463-
// Exactly one of the `Namespaces` or `Pods` pointers should be set.
464-
type AdminNetworkPolicySubject struct {
465-
Namespaces *metav1.LabelSelector
466-
Pods *NamespacedPodSubject
463+
// Ingress is the list of Ingress rules to be applied to the selected pods.
464+
// A total of 100 rules will be allowed in each ANP instance. ANPs with no
465+
// ingress rules do not affect ingress traffic.
466+
// +optional
467+
// +kubebuilder:validation:MaxItems=100
468+
Ingress []AdminNetworkPolicyIngressRule `json:"ingress,omitempty"`
469+
470+
// Egress is the list of Egress rules to be applied to the selected pods.
471+
// A total of 100 rules will be allowed in each ANP instance. ANPs with no
472+
// egress rules do not affect egress traffic.
473+
// +optional
474+
// +kubebuilder:validation:MaxItems=100
475+
Egress []AdminNetworkPolicyEgressRule `json:"egress,omitempty"`
467476
}
468477

469478
// AdminNetworkPolicyIngressRule describes an action to take on a particular
470479
// set of traffic destined for pods selected by an AdminNetworkPolicy's
471-
// Subject field. The traffic must match both ports and from.
480+
// Subject field.
472481
type AdminNetworkPolicyIngressRule struct {
473-
// Name is an identifier for this rule, that should be no more than 100 characters
474-
// in length.
475-
// +optional
476-
Name string
477-
478-
// Action specifies whether this rule must pass, allow or deny traffic.
479-
// Allow: allows the selected traffic
480-
// Deny: denies the selected traffic
481-
// Pass: allows the selected traffic to skip and remaining positive priority (non-zero)
482-
// ANP rules and be delegated by K8's Network Policy.
483-
Action AdminNetPolRuleAction
484-
485-
// Ports allows for matching on traffic based on port and protocols.
486-
Ports []AdminNetworkPolicyPort
487-
488-
// List of sources from which traffic will be allowed/denied/passed to the entities
489-
// selected by this AdminNetworkPolicyRule. Items in this list are combined using a logical OR
490-
// operation. If this field is empty, this rule matches no sources.
491-
// If this field is present and contains at least one item, this rule
492-
// allows/denies/passes traffic from the defined AdminNetworkPolicyPeer(s)
493-
From []AdminNetworkPolicyPeer
482+
// Name is an identifier for this rule, that may be no more than 100 characters
483+
// in length. This field should be used by the implementation to help
484+
// improve observability, readability and error-reporting for any applied
485+
// AdminNetworkPolicies.
486+
// +optional
487+
// +kubebuilder:validation:MaxLength=100
488+
Name string `json:"name,omitempty"`
489+
490+
// Action specifies the effect this rule will have on matching traffic.
491+
// Currently the following actions are supported:
492+
// Allow: allows the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
493+
// Deny: denies the selected traffic
494+
// Pass: instructs the selected traffic to skip any remaining ANP rules, and
495+
// then pass execution to any NetworkPolicies that select the pod.
496+
// If the pod is not selected by any NetworkPolicies then execution
497+
// is passed to any BaselineAdminNetworkPolicies that select the pod.
498+
Action AdminNetworkPolicyRuleAction `json:"action"`
499+
500+
// From is the list of sources whose traffic this rule applies to.
501+
// If any AdminNetworkPolicyPeer matches the source of incoming
502+
// traffic then the specified action is applied.
503+
// This field must be defined and contain at least one item.
504+
// +kubebuilder:validation:MinItems=1
505+
// +kubebuilder:validation:MaxItems=100
506+
From []AdminNetworkPolicyPeer `json:"from"`
507+
508+
// Ports allows for matching traffic based on port and protocols.
509+
// If Ports is not set then the rule does not filter traffic via port.
510+
// +optional
511+
// +kubebuilder:validation:MaxItems=100
512+
Ports *[]AdminNetworkPolicyPort `json:"ports,omitempty"`
494513
}
495514

496515
// AdminNetworkPolicyEgressRule describes an action to take on a particular
497516
// set of traffic originating from pods selected by a AdminNetworkPolicy's
498-
// Subject field. The traffic must match both ports and to.
517+
// Subject field.
499518
type AdminNetworkPolicyEgressRule struct {
500-
// Name is an identifier for this rule, that should be no more than 100 characters
501-
// in length.
502-
// +optional
503-
Name string
504-
505-
// Action specifies whether this rule must pass, allow or deny traffic.
506-
// Allow: allows the selected traffic
507-
// Deny: denies the selected traffic
508-
// Pass: allows the selected traffic to skip and remaining positive priority (non-zero)
509-
// ANP rules and be delegated by K8's Network Policy.
510-
Action AdminNetPolRuleAction
511-
512-
// Ports allows for matching on traffic based on port and protocols.
513-
Ports []AdminNetworkPolicyPort
514-
515-
// List of destinations to which traffic will be allowed/denied/passed from the entities
516-
// selected by this AdminNetworkPolicyRule. Items in this list are combined using a logical OR
517-
// operation. If this field is empty, this rule matches no destinations.
518-
// If this field is present and contains at least one item, this rule
519-
// allows/denies/passes traffic to the defined AdminNetworkPolicyPeer(s)
520-
To []AdminNetworkPolicyPeer
519+
// Name is an identifier for this rule, that may be no more than 100 characters
520+
// in length. This field should be used by the implementation to help
521+
// improve observability, readability and error-reporting for any applied
522+
// AdminNetworkPolicies.
523+
// +optional
524+
// +kubebuilder:validation:MaxLength=100
525+
Name string `json:"name,omitempty"`
526+
527+
// Action specifies the effect this rule will have on matching traffic.
528+
// Currently the following actions are supported:
529+
// Allow: allows the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
530+
// Deny: denies the selected traffic
531+
// Pass: instructs the selected traffic to skip any remaining ANP rules, and
532+
// then pass execution to any NetworkPolicies that select the pod.
533+
// If the pod is not selected by any NetworkPolicies then execution
534+
// is passed to any BaselineAdminNetworkPolicies that select the pod.
535+
Action AdminNetworkPolicyRuleAction `json:"action"`
536+
537+
// To is the List of destinations whose traffic this rule applies to.
538+
// If any AdminNetworkPolicyPeer matches the destination of outgoing
539+
// traffic then the specified action is applied.
540+
// This field must be defined and contain at least one item.
541+
// +kubebuilder:validation:MinItems=1
542+
// +kubebuilder:validation:MaxItems=100
543+
To []AdminNetworkPolicyPeer `json:"to"`
544+
545+
// Ports allows for matching traffic based on port and protocols.
546+
// If Ports is not set then the rule does not filter traffic via port.
547+
// +optional
548+
// +kubebuilder:validation:MaxItems=100
549+
Ports *[]AdminNetworkPolicyPort `json:"ports,omitempty"`
521550
}
522551

552+
523553
const (
524-
// RuleActionPass enables admins to provide exceptions to ClusterNetworkPolicies and delegate this rule to
525-
// K8s NetworkPolicies.
526-
AdminNetPolRuleActionPass AdminNetPolRuleAction = "Pass"
527-
// RuleActionDeny enables admins to deny specific traffic.
528-
AdminNetPolRuleActionDeny AdminNetPolRuleAction = "Deny"
529-
// RuleActionAllow enables admins to specifically allow certain traffic.
530-
AdminNetPolRuleActionAllow AdminNetPolRuleAction = "Allow"
554+
// AdminNetworkPolicyRuleActionAllow indicates that matching traffic will be
555+
// allowed regardless of NetworkPolicy and BaselineAdminNetworkPolicy
556+
// rules. Users cannot block traffic which has been matched by an "Allow"
557+
// rule in an AdminNetworkPolicy.
558+
AdminNetworkPolicyRuleActionAllow AdminNetworkPolicyRuleAction = "Allow"
559+
// AdminNetworkPolicyRuleActionDeny indicates that matching traffic will be
560+
// denied before being checked against NetworkPolicy or
561+
// BaselineAdminNetworkPolicy rules. Pods will never receive traffic which
562+
// has been matched by a "Deny" rule in an AdminNetworkPolicy.
563+
AdminNetworkPolicyRuleActionDeny AdminNetworkPolicyRuleAction = "Deny"
564+
// AdminNetworkPolicyRuleActionPass indicates that matching traffic will
565+
// bypass further AdminNetworkPolicy processing (ignoring rules with lower
566+
// precedence) and be allowed or denied based on NetworkPolicy and
567+
// BaselineAdminNetworkPolicy rules.
568+
AdminNetworkPolicyRuleActionPass AdminNetworkPolicyRuleAction = "Pass"
531569
)
532570
```
533571

@@ -659,16 +697,29 @@ resources:
659697

660698
```golang
661699

700+
// AdminNetworkPolicySubject defines what resources the policy applies to.
701+
// Exactly one field must be set.
702+
// +kubebuilder:validation:MaxProperties=1
703+
// +kubebuilder:validation:MinProperties=1
704+
type AdminNetworkPolicySubject struct {
705+
// Namespaces is used to select pods via namespace selectors.
706+
// +optional
707+
Namespaces *metav1.LabelSelector `json:"namespaces,omitempty"`
708+
// Pods is used to select pods via namespace AND pod selectors.
709+
// +optional
710+
Pods *NamespacedPodSubject `json:"pods,omitempty"`
711+
}
712+
662713
// NamespacedPodSubject allows the user to select a given set of pod(s) in
663714
// selected namespace(s)
664715
type NamespacedPodSubject struct {
665716
// This field follows standard label selector semantics; if empty,
666717
// it selects all Namespaces.
667-
NamespaceSelector metav1.LabelSelector
718+
NamespaceSelector metav1.LabelSelector `json:"namespaceSelector"`
668719

669720
// Used to explicitly select pods within a namespace; if empty,
670721
// it selects all Pods.
671-
PodSelector metav1.LabelSelector
722+
PodSelector metav1.LabelSelector `json:"podSelector"`
672723
}
673724

674725
// AdminNetworkPolicyPort describes how to select network ports on pod(s).

0 commit comments

Comments
 (0)