|
| 1 | +package v1beta1 |
| 2 | + |
| 3 | +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 4 | + |
| 5 | +// +genclient |
| 6 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 7 | + |
| 8 | +// PolycubeNetworkPolicy is a network policy handled by polycube |
| 9 | +type PolycubeNetworkPolicy struct { |
| 10 | + metav1.TypeMeta `json:",inline"` |
| 11 | + // +optional |
| 12 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 13 | + // ApplyTo defines who this policy is intended for |
| 14 | + ApplyTo PolycubeNetworkPolicyTarget `json:"applyTo,omitempty"` |
| 15 | + // Spec of this policy |
| 16 | + Spec PolycubeNetworkPolicySpec `json:"spec,omitempty"` |
| 17 | +} |
| 18 | + |
| 19 | +// PolycubeNetworkPolicyTarget is the target of this policy |
| 20 | +type PolycubeNetworkPolicyTarget struct { |
| 21 | + // Target is the object that should enforce this policy |
| 22 | + Target PolycubeNetworkPolicyTargetObject `json:"target,omitempty"` |
| 23 | + // +optional |
| 24 | + // If name and labels are irrelevant |
| 25 | + Any *bool `json:"any,omitempty"` |
| 26 | + // +optional |
| 27 | + // WithName specifies the name of the object. Valid only for Service |
| 28 | + WithName string `json:"withName,omitempty"` |
| 29 | + // +optional |
| 30 | + // WithLabels specifies the labels of the target. Valid only for Pod |
| 31 | + WithLabels map[string]string `json:"withLabels,omitempty"` |
| 32 | +} |
| 33 | + |
| 34 | +// PolycubeNetworkPolicyTargetObject is the target object |
| 35 | +type PolycubeNetworkPolicyTargetObject string |
| 36 | + |
| 37 | +const ( |
| 38 | + // PodTarget represents a Pod |
| 39 | + PodTarget PolycubeNetworkPolicyTargetObject = "pod" |
| 40 | + // ServiceTarget represents a Service |
| 41 | + ServiceTarget PolycubeNetworkPolicyTargetObject = "service" |
| 42 | +) |
| 43 | + |
| 44 | +// PolycubeNetworkPolicySpec contains the specifications of this Network Policy |
| 45 | +type PolycubeNetworkPolicySpec struct { |
| 46 | + // +optional |
| 47 | + // Description is the description of the policy |
| 48 | + Description string `json:"description,omitempty"` |
| 49 | + // +optional |
| 50 | + // IngressRules contains the ingress rules |
| 51 | + IngressRules PolycubeNetworkPolicyIngressRuleContainer `json:"ingressRules,omitempty"` |
| 52 | + // +optional |
| 53 | + // EgressRules contains the egress rules |
| 54 | + EngressRules PolycubeNetworkPolicyEgressRuleContainer `json:"egressRules,omitempty"` |
| 55 | +} |
| 56 | + |
| 57 | +// PolycubeNetworkPolicyIngressRuleContainer is a container of ingress rules |
| 58 | +type PolycubeNetworkPolicyIngressRuleContainer struct { |
| 59 | + // +optional |
| 60 | + // DropAll specifies to drop everything in ingress |
| 61 | + DropAll *bool `json:"dropAll,omitempty"` |
| 62 | + // +optional |
| 63 | + // AllowAll specifies to allow anyone in ingress |
| 64 | + AllowAll *bool `json:"allowAll,omitempty"` |
| 65 | + // +optional |
| 66 | + // Rules is a list of ingress rules |
| 67 | + Rules []PolycubeNetworkPolicyIngressRule `json:"rules,omitempty"` |
| 68 | +} |
| 69 | + |
| 70 | +// PolycubeNetworkPolicyEgressRuleContainer is a container of egress rules |
| 71 | +type PolycubeNetworkPolicyEgressRuleContainer struct { |
| 72 | + // +optional |
| 73 | + // DropAll specifies to drop everything in egress |
| 74 | + DropAll *bool `json:"dropAll,omitempty"` |
| 75 | + // +optional |
| 76 | + // AllowAll specifies to allow anyone in egress |
| 77 | + AllowAll *bool `json:"allowAll,omitempty"` |
| 78 | + // +optional |
| 79 | + // Rules is a list of egress rules |
| 80 | + Rules []PolycubeNetworkPolicyEgressRule `json:"rules,omitempty"` |
| 81 | +} |
| 82 | + |
| 83 | +// PolycubeNetworkPolicyIngressRule is an ingress rule |
| 84 | +type PolycubeNetworkPolicyIngressRule struct { |
| 85 | + // From is the peer |
| 86 | + From PolycubeNetworkPolicyPeer `json:"from,omitempty"` |
| 87 | + // Protocols is the level 4 protocol list |
| 88 | + Protocols []PolycubeNetworkPolicyProtocolContainer `json:"protocols,omitempty"` |
| 89 | + // TCPFlags is a list of TCP flags |
| 90 | + TCPFlags []PolycubeNetworkPolicyTCPFlag `json:"tcpflags,omitempty"` |
| 91 | + // Action is the action to be taken |
| 92 | + Action PolycubeNetworkPolicyRuleAction `json:"action,omitempty"` |
| 93 | + // Description is the description of the rule |
| 94 | + Description string `json:"description,omitempty"` |
| 95 | +} |
| 96 | + |
| 97 | +// PolycubeNetworkPolicyProtocolContainer contains the protocol details |
| 98 | +type PolycubeNetworkPolicyProtocolContainer struct { |
| 99 | + // Ports is the container of the ports |
| 100 | + Ports PolycubeNetworkPolicyPorts `json:"ports,omitempty"` |
| 101 | + // Protocol is the l4 protocol |
| 102 | + Protocol PolycubeNetworkPolicyProtocol |
| 103 | +} |
| 104 | + |
| 105 | +// PolycubeNetworkPolicyEgressRule the rule for egress |
| 106 | +type PolycubeNetworkPolicyEgressRule struct { |
| 107 | + // To is the peer |
| 108 | + To PolycubeNetworkPolicyPeer `json:"to,omitempty"` |
| 109 | + // Protocols is the protocols list |
| 110 | + Protocols []PolycubeNetworkPolicyProtocolContainer `json:"protocols,omitempty"` |
| 111 | + // TCPFlags is a list of TCP flags |
| 112 | + TCPFlags []PolycubeNetworkPolicyTCPFlag `json:"tcpflags,omitempty"` |
| 113 | + // Action is the action to be taken |
| 114 | + Action PolycubeNetworkPolicyRuleAction `json:"action,omitempty"` |
| 115 | + // Description is the description of the rule |
| 116 | + Description string `json:"description,omitempty"` |
| 117 | +} |
| 118 | + |
| 119 | +// PolycubeNetworkPolicyPeer contains data of the peer |
| 120 | +type PolycubeNetworkPolicyPeer struct { |
| 121 | + // Peer is the peer type |
| 122 | + Peer PolycubeNetworkPolicyPeerObject `json:"peer,omitempty"` |
| 123 | + // +optional |
| 124 | + // Any tells if name and labels don't matter |
| 125 | + Any *bool `json:"any,omitempty"` |
| 126 | + // +optional |
| 127 | + // WithName specifies the name of the object. Only for Service |
| 128 | + //WithName string `json:"withName,omitempty"` |
| 129 | + // +optional |
| 130 | + // WithLabels specifies the labels of the object. Only for Pod |
| 131 | + WithLabels map[string]string `json:"withLabels,omitempty"` |
| 132 | + // +optional |
| 133 | + // WithIP specifies the ip. Only for World |
| 134 | + WithIP PolycubeNetworkPolicyWithIP `json:"withIP,omitempty"` |
| 135 | + // +optional |
| 136 | + // OnNamespace specifies the namespaces of the peer. Only for Pod |
| 137 | + OnNamespace *PolycubeNetworkPolicyNamespaceSelector `json:"onNamespace,omitempty"` |
| 138 | +} |
| 139 | + |
| 140 | +// PolycubeNetworkPolicyWithIP is the IP container |
| 141 | +type PolycubeNetworkPolicyWithIP struct { |
| 142 | + // List is a list of IPs in CIDR notation |
| 143 | + List []string `json:"list,omitempty"` |
| 144 | +} |
| 145 | + |
| 146 | +// PolycubeNetworkPolicyPeerObject is the object peer |
| 147 | +type PolycubeNetworkPolicyPeerObject string |
| 148 | + |
| 149 | +const ( |
| 150 | + // ServicePeer is the Service |
| 151 | + ServicePeer PolycubeNetworkPolicyPeerObject = "service" |
| 152 | + // PodPeer is the Pod |
| 153 | + PodPeer PolycubeNetworkPolicyPeerObject = "pod" |
| 154 | + // WorldPeer is the World |
| 155 | + WorldPeer PolycubeNetworkPolicyPeerObject = "world" |
| 156 | +) |
| 157 | + |
| 158 | +// PolycubeNetworkPolicyNamespaceSelector is a selector for namespaces |
| 159 | +type PolycubeNetworkPolicyNamespaceSelector struct { |
| 160 | + // +optional |
| 161 | + // WithName is a list of the names of the namespace |
| 162 | + WithNames []string `json:"withNames,omitempty"` |
| 163 | + // +optional |
| 164 | + // WithLabels is the namespace's labels |
| 165 | + WithLabels map[string]string `json:"withLabels,omitempty"` |
| 166 | + // +optional |
| 167 | + // Any specifies any namespace |
| 168 | + Any *bool `json:"any,omitempty"` |
| 169 | +} |
| 170 | + |
| 171 | +// PolycubeNetworkPolicyProtocol is the level 4 protocol |
| 172 | +type PolycubeNetworkPolicyProtocol string |
| 173 | + |
| 174 | +const ( |
| 175 | + // TCP is TCP |
| 176 | + TCP PolycubeNetworkPolicyProtocol = "tcp" |
| 177 | + // UDP is UDP |
| 178 | + UDP PolycubeNetworkPolicyProtocol = "udp" |
| 179 | + // ICMP is ICMPv4 |
| 180 | + ICMP PolycubeNetworkPolicyProtocol = "icmp" |
| 181 | +) |
| 182 | + |
| 183 | +// PolycubeNetworkPolicyPorts contains the ports |
| 184 | +type PolycubeNetworkPolicyPorts struct { |
| 185 | + // +optional |
| 186 | + // Source is the source port |
| 187 | + Source int32 `json:"source,omitempty"` |
| 188 | + // Destination is the destination port |
| 189 | + Destination int32 `json:"destination,omitempty"` |
| 190 | +} |
| 191 | + |
| 192 | +// PolycubeNetworkPolicyTCPFlag is the TCP flag |
| 193 | +type PolycubeNetworkPolicyTCPFlag string |
| 194 | + |
| 195 | +const ( |
| 196 | + // SYNFlag is SYN |
| 197 | + SYNFlag PolycubeNetworkPolicyTCPFlag = "SYN" |
| 198 | + // FINFlag is FIN |
| 199 | + FINFlag PolycubeNetworkPolicyTCPFlag = "FIN" |
| 200 | + // ACKFlag is ACK |
| 201 | + ACKFlag PolycubeNetworkPolicyTCPFlag = "ACK" |
| 202 | + // RSTFlag is RST |
| 203 | + RSTFlag PolycubeNetworkPolicyTCPFlag = "RST" |
| 204 | + // PSHFlag is PSH |
| 205 | + PSHFlag PolycubeNetworkPolicyTCPFlag = "PSH" |
| 206 | + // URGFlag is URG |
| 207 | + URGFlag PolycubeNetworkPolicyTCPFlag = "URG" |
| 208 | + // CWRFlag is CWR |
| 209 | + CWRFlag PolycubeNetworkPolicyTCPFlag = "CWR" |
| 210 | + // ECEFlag is ECE |
| 211 | + ECEFlag PolycubeNetworkPolicyTCPFlag = "ECE" |
| 212 | +) |
| 213 | + |
| 214 | +// PolycubeNetworkPolicyRuleAction is the action |
| 215 | +type PolycubeNetworkPolicyRuleAction string |
| 216 | + |
| 217 | +const ( |
| 218 | + // DropAction is DROP |
| 219 | + DropAction PolycubeNetworkPolicyRuleAction = "drop" |
| 220 | + // AllowAction is Forward |
| 221 | + AllowAction PolycubeNetworkPolicyRuleAction = "forward" |
| 222 | +) |
| 223 | + |
| 224 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 225 | + |
| 226 | +// PolycubeNetworkPolicyList contains a list of Network Policies. |
| 227 | +type PolycubeNetworkPolicyList struct { |
| 228 | + metav1.TypeMeta `json:",inline"` |
| 229 | + // +optional |
| 230 | + metav1.ListMeta `son:"metadata,omitempty"` |
| 231 | + // Items contains the network policies |
| 232 | + Items []PolycubeNetworkPolicy `json:"items"` |
| 233 | +} |
0 commit comments