8.3. Identifying the differences in allowed connections between project versions
The roxctl netpol connectivity diff command identifies differences in allowed connections between two project versions. It analyzes network policy, Admin Network Policy (ANP), and Baseline Admin Network Policy (BANP) manifests in each version’s directory. This analysis provides a text-based report of the differences. It also includes the impact of ANP and BANP resources, giving you a complete view of policy changes across cluster scopes.
You can view connectivity difference reports in a variety of output formats, including text, md, dot, and csv.
Generate a report on connectivity differences between two sets of Kubernetes manifests, including network policies by using the roxctl netpol connectivity diff command .
Prerequisites
-
You have two folders,
dir1anddir2, each containing Kubernetes manifests, including network policies.
Procedure
To find the connectivity differences between the Kubernetes manifests in the specified directories, run the following command:
$ roxctl netpol connectivity diff --dir1=<folder_path_1> --dir2=<folder_path_2> [flags]1 - 1
- Specify the path to the folders, which can include sub-folders that contain YAML resources and network policies for analysis. The command scans the entire sub-folder trees for both the directories.
For example,
<folder_path_1>isnetpol-analysis-example-minimal/and<folder_path_2>isnetpol-diff-example-minimal/. Optionally, you can also specify parameters to change the behavior of the command.
The command considers all YAML files that you can accept by using kubectl apply -f, and the YAML files then become valid inputs for your roxctl netpol connectivity diff command.
| diff-type | source | destination | dir 1 | dir 2 | workloads-diff-info |
|---|---|---|---|---|---|
| changed | default/frontend[Deployment] | default/backend[Deployment] | TCP 9090 | TCP 9090,UDP 53 | |
| added | 0.0.0.0-255.255.255.255 | default/backend[Deployment] | No Connections | TCP 9090 |
The semantic difference report gives you an overview of the connections that were changed, added, or removed in dir2 compared to the connections allowed in dir1. When you review the output, each line represents one allowed connection that was added, removed, or changed in dir2 compared to dir1.
If applicable, the workloads-diff-info provides additional details about added or removed workloads related to the added or removed connection.
For example, if a connection from workload A to workload B is removed because workload B was deleted, the workloads-diff-info indicates that workload B was removed. However, if such a connection was removed only because of network policy changes and neither workload A nor B was deleted, the workloads-diff-info is empty.
8.3.2. Distinguishing between syntactic and semantic difference outputs 링크 복사링크가 클립보드에 복사되었습니다!
In the following example, dir1 is netpol-analysis-example-minimal/, and dir2 is netpol-diff-example-minimal/. The difference between the directories is a small change in the network policy backend-netpol.
Example policy from dir1:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
creationTimestamp: null
name: backend-netpol
spec:
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
ports:
- port: 9090
protocol: TCP
podSelector:
matchLabels:
app: backendservice
policyTypes:
- Ingress
- Egress
status: {}
The change in dir2 is an added - before the ports attribute, which produces a difference output.
8.3.2.1. Syntactic difference output 링크 복사링크가 클립보드에 복사되었습니다!
Procedure
Run the following command to compare the contents of the
netpols.yamlfiles in the two specified directories:$ diff netpol-diff-example-minimal/netpols.yaml netpol-analysis-example-minimal/netpols.yamlExample output
12c12 < - ports: --- > ports:
8.3.2.2. Semantic difference output 링크 복사링크가 클립보드에 복사되었습니다!
Procedure
Run the following command to analyze the connectivity differences between the Kubernetes manifests and network policies in the two specified directories:
$ roxctl netpol connectivity diff --dir1=roxctl/netpol/connectivity/diff/testdata/netpol-analysis-example-minimal/ --dir2=roxctl/netpol/connectivity/diff/testdata/netpol-diff-example-minimalExample output
Connectivity diff: diff-type: changed, source: default/frontend[Deployment], destination: default/backend[Deployment], dir1: TCP 9090, dir2: TCP 9090,UDP 53 diff-type: added, source: 0.0.0.0-255.255.255.255, destination: default/backend[Deployment], dir1: No Connections, dir2: TCP 9090