@@ -22,7 +22,8 @@ import (
22
22
//+kubebuilder:object:root=true
23
23
//+kubebuilder:subresource:status
24
24
25
- // AdminNetworkPolicy is the Schema for the adminnetworkpolicies API.
25
+ // AdminNetworkPolicy is a cluster level resource that is part of the
26
+ // AdminNetworkPolicy API.
26
27
type AdminNetworkPolicy struct {
27
28
metav1.TypeMeta `json:",inline"`
28
29
metav1.ObjectMeta `json:"metadata"`
@@ -42,36 +43,35 @@ type AdminNetworkPolicyStatus struct {
42
43
43
44
// AdminNetworkPolicySpec defines the desired state of AdminNetworkPolicy.
44
45
type AdminNetworkPolicySpec struct {
45
- // Priority is an int32 value bound to 0 - 1000, the lowest priority,
46
- // "0" corresponds to the highest importance, while higher priorities have
47
- // lower importance.
46
+ // Priority is a value from 0 to 1000. Rules with lower priority values have
47
+ // higher precedence, and are checked before rules with higher priority values.
48
+ // All AdminNetworkPolicy rules have higher precedence than NetworkPolicy or
49
+ // BaselineAdminNetworkPolicy rules
48
50
// +kubebuilder:validation:Minimum=0
49
51
// +kubebuilder:validation:Maximum=1000
50
52
Priority int32 `json:"priority"`
51
53
52
54
// Subject defines the pods to which this AdminNetworkPolicy applies.
53
55
Subject AdminNetworkPolicySubject `json:"subject"`
54
56
55
- // List of Ingress rules to be applied to the selected pods BEFORE any
56
- // NetworkPolicy or BaselineAdminNetworkPolicy rules have been applied.
57
- // A total of 100 rules will be allowed in each ANP instance.
58
- // ANPs with no ingress rules do not affect ingress traffic.
57
+ // Ingress is the list of Ingress rules to be applied to the selected pods.
58
+ // A total of 100 rules will be allowed in each ANP instance. ANPs with no
59
+ // ingress rules do not affect ingress traffic.
59
60
// +optional
60
61
// +kubebuilder:validation:MaxItems=100
61
62
Ingress []AdminNetworkPolicyIngressRule `json:"ingress,omitempty"`
62
63
63
- // List of Egress rules to be applied to the selected pods BEFORE any
64
- // NetworkPolicy or BaselineAdminNetworkPolicy rules have been applied.
65
- // A total of 100 rules will be allowed in each ANP instance.
66
- // ANPs with no egress rules do not affect egress traffic.
64
+ // Egress is the list of Egress rules to be applied to the selected pods.
65
+ // A total of 100 rules will be allowed in each ANP instance. ANPs with no
66
+ // egress rules do not affect egress traffic.
67
67
// +optional
68
68
// +kubebuilder:validation:MaxItems=100
69
69
Egress []AdminNetworkPolicyEgressRule `json:"egress,omitempty"`
70
70
}
71
71
72
72
// AdminNetworkPolicyIngressRule describes an action to take on a particular
73
73
// set of traffic destined for pods selected by an AdminNetworkPolicy's
74
- // Subject field. The traffic must match both ports and from.
74
+ // Subject field.
75
75
type AdminNetworkPolicyIngressRule struct {
76
76
// Name is an identifier for this rule, that may be no more than 100 characters
77
77
// in length. This field should be used by the implementation to help
@@ -81,35 +81,34 @@ type AdminNetworkPolicyIngressRule struct {
81
81
// +kubebuilder:validation:MaxLength=100
82
82
Name string `json:"name,omitempty"`
83
83
84
- // Action specifies the affect this rule will have on matching traffic,
85
- // currently the following actions are supported:
86
- // Allow: allows the selected traffic
84
+ // Action specifies the effect this rule will have on matching traffic.
85
+ // Currently the following actions are supported:
86
+ // Allow: allows the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
87
87
// Deny: denies the selected traffic
88
88
// Pass: instructs the selected traffic to skip any remaining ANP rules, and
89
89
// then pass execution to any NetworkPolicies that select the pod.
90
90
// If the pod is not selected by any NetworkPolicies then execution
91
91
// is passed to any BaselineAdminNetworkPolicies that select the pod.
92
- // This field is mandatory.
93
92
Action AdminNetworkPolicyRuleAction `json:"action"`
94
93
95
- // Ports allows for matching traffic based on port and protocols.
96
- // If Ports is not set then traffic is not filtered via port.
97
- // +optional
98
- // +kubebuilder:validation:MaxItems=100
99
- Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
100
-
101
- // List of sources whose traffic this AdminNetworkPolicyRule applies to.
102
- // If any adminNetworkPolicyPeer matches the source of incoming
94
+ // From is the list of sources whose traffic this rule applies to.
95
+ // If any AdminNetworkPolicyPeer matches the source of incoming
103
96
// traffic then the specified action is applied.
104
97
// This field must be defined and contain at least one item.
105
98
// +kubebuilder:validation:MinItems=1
106
99
// +kubebuilder:validation:MaxItems=100
107
100
From []AdminNetworkPolicyPeer `json:"from"`
101
+
102
+ // Ports allows for matching traffic based on port and protocols.
103
+ // If Ports is not set then the rule does not filter traffic via port.
104
+ // +optional
105
+ // +kubebuilder:validation:MaxItems=100
106
+ Ports * []AdminNetworkPolicyPort `json:"ports,omitempty"`
108
107
}
109
108
110
109
// AdminNetworkPolicyEgressRule describes an action to take on a particular
111
110
// set of traffic originating from pods selected by a AdminNetworkPolicy's
112
- // Subject field. The traffic must match both ports and to.
111
+ // Subject field.
113
112
type AdminNetworkPolicyEgressRule struct {
114
113
// Name is an identifier for this rule, that may be no more than 100 characters
115
114
// in length. This field should be used by the implementation to help
@@ -119,45 +118,51 @@ type AdminNetworkPolicyEgressRule struct {
119
118
// +kubebuilder:validation:MaxLength=100
120
119
Name string `json:"name,omitempty"`
121
120
122
- // Action specifies the affect this rule will have on matching traffic,
123
- // currently the following actions are supported:
121
+ // Action specifies the effect this rule will have on matching traffic.
122
+ // Currently the following actions are supported:
124
123
// Allow: allows the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
125
- // Deny: denies the selected traffic (even if it would otherwise have been denied by NetworkPolicy)
124
+ // Deny: denies the selected traffic
126
125
// Pass: instructs the selected traffic to skip any remaining ANP rules, and
127
126
// then pass execution to any NetworkPolicies that select the pod.
128
127
// If the pod is not selected by any NetworkPolicies then execution
129
128
// is passed to any BaselineAdminNetworkPolicies that select the pod.
130
- // This field is mandatory.
131
129
Action AdminNetworkPolicyRuleAction `json:"action"`
132
130
133
- // Ports allows for matching traffic based on port and protocols.
134
- // If Ports is not set then traffic is not filtered via port.
135
- // +optional
136
- // +kubebuilder:validation:MaxItems=100
137
- Ports []AdminNetworkPolicyPort `json:"ports,omitempty"`
138
-
139
- // List of destinations whose traffic this adminNetworkPolicyRule applies to.
140
- // If any adminNetworkPolicyPeer matches the destination of outgoing
131
+ // To is the List of destinations whose traffic this rule applies to.
132
+ // If any AdminNetworkPolicyPeer matches the destination of outgoing
141
133
// traffic then the specified action is applied.
142
134
// This field must be defined and contain at least one item.
143
135
// +kubebuilder:validation:MinItems=1
144
136
// +kubebuilder:validation:MaxItems=100
145
137
To []AdminNetworkPolicyPeer `json:"to"`
138
+
139
+ // Ports allows for matching traffic based on port and protocols.
140
+ // If Ports is not set then the rule does not filter traffic via port.
141
+ // +optional
142
+ // +kubebuilder:validation:MaxItems=100
143
+ Ports * []AdminNetworkPolicyPort `json:"ports,omitempty"`
146
144
}
147
145
148
146
// AdminNetworkPolicyRuleAction string describes the AdminNetworkPolicy action type.
149
147
// +enum
150
148
type AdminNetworkPolicyRuleAction string
151
149
152
150
const (
153
- // AdminNetworkPolicyRuleActionPass enables admins to provide exceptions to
154
- // AdminNetworkPolicies by passing rule execution directly to any matching
155
- // K8s networkPolicies.
156
- AdminNetworkPolicyRuleActionPass AdminNetworkPolicyRuleAction = "Pass"
157
- // AdminNetworkPolicyRuleActionDeny enables admins to deny specific traffic.
158
- AdminNetworkPolicyRuleActionDeny AdminNetworkPolicyRuleAction = "Deny"
159
- // AdminNetworkPolicyRuleActionAllow enables admins to specifically allow certain traffic.
151
+ // AdminNetworkPolicyRuleActionAllow indicates that matching traffic will be
152
+ // allowed regardless of NetworkPolicy and BaselineAdminNetworkPolicy
153
+ // rules. Users cannot block traffic which has been matched by an "Allow"
154
+ // rule in an AdminNetworkPolicy.
160
155
AdminNetworkPolicyRuleActionAllow AdminNetworkPolicyRuleAction = "Allow"
156
+ // AdminNetworkPolicyRuleActionDeny indicates that matching traffic will be
157
+ // denied before being checked against NetworkPolicy or
158
+ // BaselineAdminNetworkPolicy rules. Pods will never receive traffic which
159
+ // has been matched by a "Deny" rule in an AdminNetworkPolicy.
160
+ AdminNetworkPolicyRuleActionDeny AdminNetworkPolicyRuleAction = "Deny"
161
+ // AdminNetworkPolicyRuleActionPass indicates that matching traffic will
162
+ // bypass further AdminNetworkPolicy processing (ignoring rules with lower
163
+ // precedence) and be allowed or denied based on NetworkPolicy and
164
+ // BaselineAdminNetworkPolicy rules.
165
+ AdminNetworkPolicyRuleActionPass AdminNetworkPolicyRuleAction = "Pass"
161
166
)
162
167
163
168
//+kubebuilder:object:root=true
0 commit comments