Skip to content

Commit

Permalink
[ExternalNode] Handle ExternalNode from Antrea agent side (antrea-io#…
Browse files Browse the repository at this point in the history
…3799)

1. Provide an example RBAC yaml file for Antrea agent running
on VM with definitions of ClusterRole, ServiceAccount and
ClusterRoleBinding.

2. Add ExternalNodeController to monitor ExternalNode CRUD,
invoke interfaces to operate OVS and update interface store
with ExternalEntityInterface.

3. Implement OVS interactions related to ExternalNode CRUD.

4. Add a channel for receiving ExternalEntity updates from
ExternalNodeController and notifying NetworkPolicyController
to reconcile rules related to the updated ExternalEntities.
This is to handle the case when NetworkPolicyController reconciles
rules before ExternalEntityInterface is realized in the
interface store.

5. Support configuring policy bypass rules to skip ANP check.

Signed-off-by: Mengdie Song <[email protected]>
Co-authored-by: wenyingd <[email protected]>
  • Loading branch information
mengdie-song and wenyingd committed Aug 11, 2022
1 parent b28d732 commit 0a99f09
Show file tree
Hide file tree
Showing 36 changed files with 1,287 additions and 88 deletions.
3 changes: 0 additions & 3 deletions build/charts/antrea/conf/antrea-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ featureGates:
# Enable certificated-based authentication for IPsec.
{{- include "featureGate" (dict "featureGates" .Values.featureGates "name" "IPsecCertAuth" "default" false) }}

# Enable running agent on an unmanaged VM/BM.
{{- include "featureGate" (dict "featureGates" .Values.featureGates "name" "ExternalNode" "default" false) }}

# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: {{ .Values.ovs.bridgeName | quote }}
Expand Down
7 changes: 2 additions & 5 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2758,9 +2758,6 @@ data:
# Enable certificated-based authentication for IPsec.
# IPsecCertAuth: false
# Enable running agent on an unmanaged VM/BM.
# ExternalNode: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -3997,7 +3994,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 814300ca95f9d7451131665ebed709cb7639deec890e2ff5ae4c357ae9b00c41
checksum/config: 10aaed69b06e12d9e08fec773f3164817261a1ee026566721b4013f7e614bcbd
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -4238,7 +4235,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 814300ca95f9d7451131665ebed709cb7639deec890e2ff5ae4c357ae9b00c41
checksum/config: 10aaed69b06e12d9e08fec773f3164817261a1ee026566721b4013f7e614bcbd
labels:
app: antrea
component: antrea-controller
Expand Down
7 changes: 2 additions & 5 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2758,9 +2758,6 @@ data:
# Enable certificated-based authentication for IPsec.
# IPsecCertAuth: false
# Enable running agent on an unmanaged VM/BM.
# ExternalNode: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -3997,7 +3994,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 814300ca95f9d7451131665ebed709cb7639deec890e2ff5ae4c357ae9b00c41
checksum/config: 10aaed69b06e12d9e08fec773f3164817261a1ee026566721b4013f7e614bcbd
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -4240,7 +4237,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 814300ca95f9d7451131665ebed709cb7639deec890e2ff5ae4c357ae9b00c41
checksum/config: 10aaed69b06e12d9e08fec773f3164817261a1ee026566721b4013f7e614bcbd
labels:
app: antrea
component: antrea-controller
Expand Down
7 changes: 2 additions & 5 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2758,9 +2758,6 @@ data:
# Enable certificated-based authentication for IPsec.
# IPsecCertAuth: false
# Enable running agent on an unmanaged VM/BM.
# ExternalNode: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -3997,7 +3994,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 3f9907e9f0f4db91b926904114567c4e2c496f6fe03abb4ef80df5af937c0f19
checksum/config: c2dafa5a0433d50e04844c7cc8cebbc912f0d0dd27101aff55945d4e6b5d0ebf
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -4237,7 +4234,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 3f9907e9f0f4db91b926904114567c4e2c496f6fe03abb4ef80df5af937c0f19
checksum/config: c2dafa5a0433d50e04844c7cc8cebbc912f0d0dd27101aff55945d4e6b5d0ebf
labels:
app: antrea
component: antrea-controller
Expand Down
7 changes: 2 additions & 5 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2771,9 +2771,6 @@ data:
# Enable certificated-based authentication for IPsec.
# IPsecCertAuth: false
# Enable running agent on an unmanaged VM/BM.
# ExternalNode: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -4010,7 +4007,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 7b6ba1830aabcf74b5b0a71c74edf49254c4237d604f9d984428252903901f98
checksum/config: 6fceb3665d21444d3e3555239e3aefad12ebf3dd175211e5db10d8b5117293d4
checksum/ipsec-secret: d0eb9c52d0cd4311b6d252a951126bf9bea27ec05590bed8a394f0f792dcb2a4
labels:
app: antrea
Expand Down Expand Up @@ -4296,7 +4293,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 7b6ba1830aabcf74b5b0a71c74edf49254c4237d604f9d984428252903901f98
checksum/config: 6fceb3665d21444d3e3555239e3aefad12ebf3dd175211e5db10d8b5117293d4
labels:
app: antrea
component: antrea-controller
Expand Down
7 changes: 2 additions & 5 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2758,9 +2758,6 @@ data:
# Enable certificated-based authentication for IPsec.
# IPsecCertAuth: false
# Enable running agent on an unmanaged VM/BM.
# ExternalNode: false
# Name of the OpenVSwitch bridge antrea-agent will create and use.
# Make sure it doesn't conflict with your existing OpenVSwitch bridges.
ovsBridge: "br-int"
Expand Down Expand Up @@ -3997,7 +3994,7 @@ spec:
kubectl.kubernetes.io/default-container: antrea-agent
# Automatically restart Pods with a RollingUpdate if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 05340bff4942128434fb2b7ab2c0288d9586d3324d58da987c1a58db78aab6d3
checksum/config: b7ddaa189bfec76b90f129f3fd8d1482edcfaf8c42772956d6e4aa5134e3c3cb
labels:
app: antrea
component: antrea-agent
Expand Down Expand Up @@ -4237,7 +4234,7 @@ spec:
annotations:
# Automatically restart Pod if the ConfigMap changes
# See https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments
checksum/config: 05340bff4942128434fb2b7ab2c0288d9586d3324d58da987c1a58db78aab6d3
checksum/config: b7ddaa189bfec76b90f129f3fd8d1482edcfaf8c42772956d6e4aa5134e3c3cb
labels:
app: antrea
component: antrea-controller
Expand Down
16 changes: 16 additions & 0 deletions build/yamls/externalnode/conf/antrea-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ featureGates:
# Defaults to "k8sNode". Valid values include "k8sNode", and "externalNode".
nodeType: externalNode

externalNode:
# The expected Namespace in which the ExternalNode is created.
# Defaults to "default".
#externalNodeNamespace: default

# The policyBypassRules describes the traffic that is expected to bypass NetworkPolicy rules.
# Each rule contains the following four attributes:
# direction (ingress|egress), protocol(tcp/udp/icmp/ip), remote CIDR, dst port (ICMP doesn't require).
# Here is an example:
# - direction: ingress
# protocol: tcp
# cidr: 1.1.1.1/32
# port: 22
# It is used only when NodeType is externalNode.
#policyBypassRules: []

# The path to access the kubeconfig file used in the connection to K8s APIServer. The file contains the K8s
# APIServer endpoint and the token of ServiceAccount required in the connection.
clientConnection:
Expand Down
112 changes: 112 additions & 0 deletions build/yamls/externalnode/vm-agent-rbac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: vm-agent
namespace: vm-ns # Change the Namespace to where vm-agent is expected to run.
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: vm-agent
rules:
# antrea-controller distributes the CA certificate as a ConfigMap named `antrea-ca` in the Antrea deployment Namespace.
# vm-agent needs to access `antrea-ca` to connect with antrea-controller.
- apiGroups:
- ""
resources:
- configmaps
resourceNames:
- antrea-ca
verbs:
- get
- watch
- list
# This is the content of built-in role kube-system/extension-apiserver-authentication-reader.
# But it doesn't have list/watch permission before K8s v1.17.0 so the extension apiserver (vm-agent) will
# have permission issue after bumping up apiserver library to a version that supports dynamic authentication.
# See https://github.com/kubernetes/kubernetes/pull/85375
# To support K8s clusters older than v1.17.0, we grant the required permissions directly instead of relying on
# the extension-apiserver-authentication role.
- apiGroups:
- ""
resourceNames:
- extension-apiserver-authentication
resources:
- configmaps
verbs:
- get
- list
- watch
- apiGroups:
- crd.antrea.io
resources:
- antreaagentinfos
verbs:
- get
- update
- apiGroups:
- controlplane.antrea.io
resources:
- networkpolicies
- appliedtogroups
- addressgroups
verbs:
- get
- watch
- list
- apiGroups:
- controlplane.antrea.io
resources:
- nodestatssummaries
verbs:
- create
- apiGroups:
- controlplane.antrea.io
resources:
- networkpolicies/status
verbs:
- create
- get
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: vm-agent
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: vm-agent
subjects:
- kind: ServiceAccount
name: vm-agent
namespace: vm-ns # Change the Namespace to where vm-agent is expected to run.
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: vm-agent
namespace: vm-ns # Change the Namespace to where vm-agent is expected to run.
rules:
- apiGroups:
- crd.antrea.io
resources:
- externalnodes
verbs:
- get
- watch
- list
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: vm-agent
namespace: vm-ns # Change the Namespace to where vm-agent is expected to run.
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: vm-agent
subjects:
- kind: ServiceAccount
name: vm-agent
namespace: vm-ns # Change the Namespace to where vm-agent is expected to run.
Loading

0 comments on commit 0a99f09

Please sign in to comment.