@@ -746,16 +746,14 @@ metadata:
746
746
spec:
747
747
priority: 10
748
748
subject:
749
- namespaceSelector :
749
+ namespaces :
750
750
matchLabels:
751
751
kubernetes.io/metadata.name: sensitive-ns
752
752
ingress:
753
- - action: Deny
754
- from:
755
- - namespaces:
756
- namespaceSelector: {}
757
- ports:
758
- allPorts: true
753
+ - action: Deny
754
+ from:
755
+ - namespaces:
756
+ namespaceSelector: {}
759
757
` ` `
760
758
761
759
# ### Sample spec for Story 2: Allow traffic at a cluster level
@@ -768,31 +766,25 @@ metadata:
768
766
spec:
769
767
priority: 30
770
768
subject:
771
- namespaceSelector : {}
769
+ namespaces : {}
772
770
ingress:
773
- - action: Allow
774
- from:
775
- - namespaces:
776
- namespaceSelector:
777
- matchLabels:
778
- kubernetes.io/metadata.name: monitoring-ns
779
- ports:
780
- allPorts: true
771
+ - action: Allow
772
+ from:
773
+ - namespaces:
774
+ namespaceSelector:
775
+ matchLabels:
776
+ kubernetes.io/metadata.name: monitoring-ns
781
777
egress:
782
- - action: Allow
783
- to:
784
- - namespacedPods:
785
- namespaces:
786
- namespaceSelector:
787
- matchlabels:
788
- kubernetes.io/metadata.name: kube-system
789
- pods:
790
- podSelector:
791
- matchlabels:
792
- app: kube-dns
793
- ports:
794
- allPorts: true
795
-
778
+ - action: Allow
779
+ to:
780
+ - pods:
781
+ namespaces:
782
+ namespaceSelector:
783
+ matchlabels:
784
+ kubernetes.io/metadata.name: kube-system
785
+ podSelector:
786
+ matchlabels:
787
+ app: kube-dns
796
788
` ` `
797
789
798
790
# ### Sample spec for Story 3: Explicitly Delegate traffic to existing K8s Network Policy
@@ -805,23 +797,22 @@ metadata:
805
797
spec:
806
798
priority: 20
807
799
subject:
808
- namespaceSelector : {}
800
+ namespaces : {}
809
801
egress:
810
802
- action: Pass
811
803
to:
812
- - namespacedPods :
804
+ - pods :
813
805
namespaces:
814
806
namespaceSelector:
815
807
matchLabels:
816
808
kubernetes.io/metadata.name: bar-ns-1
817
- pods:
818
- podSelector:
819
- matchLabels:
820
- app: svc-pub
809
+ podSelector:
810
+ matchLabels:
811
+ app: svc-pub
821
812
ports:
822
- list :
813
+ port :
823
814
- protocol: TCP
824
- port : 8080
815
+ number : 8080
825
816
` ` `
826
817
827
818
# ### Sample spec for Story 4: Create and Isolate multiple tenants in a cluster
@@ -834,16 +825,14 @@ metadata:
834
825
spec:
835
826
priority: 50
836
827
subject:
837
- namespaceSelector :
828
+ namespaces :
838
829
matchExpressions: {key: "tenant"; operator: Exists}
839
830
ingress:
840
- - action: Deny
841
- from:
842
- - namespaces:
843
- notSameLabels:
831
+ - action: Deny
832
+ from:
833
+ - namespaces:
834
+ notSameLabels:
844
835
- tenant
845
- ports:
846
- allPorts: true
847
836
` ` `
848
837
849
838
Note : the above AdminNetworkPolicy can also be written in the following fashion:
@@ -855,22 +844,18 @@ metadata:
855
844
spec:
856
845
priority: 50
857
846
subject:
858
- namespaceSelector :
847
+ namespaces :
859
848
matchExpressions: {key: "tenant"; operator: Exists}
860
849
ingress:
861
- - action: Pass
862
- from:
863
- - namespaces:
864
- sameLabels:
865
- - tenant
866
- ports:
867
- allPorts: true
868
- - action: Deny # Deny everything else other than same tenant traffic
869
- from:
870
- - namespaces:
871
- namespaceSelector: {}
872
- ports:
873
- allPorts: true
850
+ - action: Pass
851
+ from:
852
+ - namespaces:
853
+ sameLabels:
854
+ - tenant
855
+ - action: Deny # Deny everything else other than same tenant traffic
856
+ from:
857
+ - namespaces:
858
+ namespaceSelector: {}
874
859
` ` `
875
860
The difference is that in the first case, traffic within tenant Namespaces will fall
876
861
through, and be evaluated against lower-priority ClusterNetworkPolicies, and then
@@ -883,20 +868,23 @@ specifies intra-tenant traffic must be delegated to the tenant Namespace owners.
883
868
884
869
` ` ` yaml
885
870
apiVersion: policy.networking.k8s.io/v1alpha1
886
- kind: AdminNetworkPolicy
871
+ kind: BaselineAdminNetworkPolicy
887
872
metadata:
888
873
name: baseline-rule-example
889
874
spec:
890
- priority: 0
891
875
subject:
892
- namespaceSelector : {}
876
+ namespaces : {}
893
877
ingress:
894
- - action: Deny # zero-trust cluster default security posture
895
- from:
896
- - namespaces:
897
- namespaceSelector: {}
898
- ports:
899
- allPorts: true
878
+ - action: Deny # zero-trust cluster default security posture
879
+ from:
880
+ - namespaces:
881
+ namespaceSelector: {}
882
+ egress:
883
+ - action: Deny
884
+ to:
885
+ - namespaces:
886
+ namespaceSeletor: {}
887
+
900
888
` ` `
901
889
902
890
# ## Test Plan
0 commit comments