Skip to content

Commit 93020fc

Browse files
astoycosDyanngg
authored andcommitted
Update ANP Sample Yamls
Signed-off-by: astoycos <[email protected]>
1 parent 475b18a commit 93020fc

File tree

1 file changed

+56
-68
lines changed
  • keps/sig-network/2091-admin-network-policy

1 file changed

+56
-68
lines changed

keps/sig-network/2091-admin-network-policy/README.md

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -746,16 +746,14 @@ metadata:
746746
spec:
747747
priority: 10
748748
subject:
749-
namespaceSelector:
749+
namespaces:
750750
matchLabels:
751751
kubernetes.io/metadata.name: sensitive-ns
752752
ingress:
753-
- action: Deny
754-
from:
755-
- namespaces:
756-
namespaceSelector: {}
757-
ports:
758-
allPorts: true
753+
- action: Deny
754+
from:
755+
- namespaces:
756+
namespaceSelector: {}
759757
```
760758

761759
#### Sample spec for Story 2: Allow traffic at a cluster level
@@ -768,31 +766,25 @@ metadata:
768766
spec:
769767
priority: 30
770768
subject:
771-
namespaceSelector: {}
769+
namespaces: {}
772770
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
781777
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
796788
```
797789

798790
#### Sample spec for Story 3: Explicitly Delegate traffic to existing K8s Network Policy
@@ -805,23 +797,22 @@ metadata:
805797
spec:
806798
priority: 20
807799
subject:
808-
namespaceSelector: {}
800+
namespaces: {}
809801
egress:
810802
- action: Pass
811803
to:
812-
- namespacedPods:
804+
- pods:
813805
namespaces:
814806
namespaceSelector:
815807
matchLabels:
816808
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
821812
ports:
822-
list:
813+
port:
823814
- protocol: TCP
824-
port: 8080
815+
number: 8080
825816
```
826817

827818
#### Sample spec for Story 4: Create and Isolate multiple tenants in a cluster
@@ -834,16 +825,14 @@ metadata:
834825
spec:
835826
priority: 50
836827
subject:
837-
namespaceSelector:
828+
namespaces:
838829
matchExpressions: {key: "tenant"; operator: Exists}
839830
ingress:
840-
- action: Deny
841-
from:
842-
- namespaces:
843-
notSameLabels:
831+
- action: Deny
832+
from:
833+
- namespaces:
834+
notSameLabels:
844835
- tenant
845-
ports:
846-
allPorts: true
847836
```
848837

849838
Note: the above AdminNetworkPolicy can also be written in the following fashion:
@@ -855,22 +844,18 @@ metadata:
855844
spec:
856845
priority: 50
857846
subject:
858-
namespaceSelector:
847+
namespaces:
859848
matchExpressions: {key: "tenant"; operator: Exists}
860849
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: {}
874859
```
875860
The difference is that in the first case, traffic within tenant Namespaces will fall
876861
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.
883868

884869
```yaml
885870
apiVersion: policy.networking.k8s.io/v1alpha1
886-
kind: AdminNetworkPolicy
871+
kind: BaselineAdminNetworkPolicy
887872
metadata:
888873
name: baseline-rule-example
889874
spec:
890-
priority: 0
891875
subject:
892-
namespaceSelector: {}
876+
namespaces: {}
893877
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+
900888
```
901889

902890
### Test Plan

0 commit comments

Comments
 (0)