Skip to content

OCPCLOUD-2980: add ingress/egress network policy #1387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Allow egress from apps in openshift-machine-api to kube api
# Allow egress from apps in openshift-machine-api to DNS
# Allow egress from apps in openshift-machine-api to external cloud platforms
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-egress
namespace: openshift-machine-api
annotations:
capability.openshift.io/name: MachineAPI
exclude.release.openshift.io/internal-openshift-hosted: "true"
include.release.openshift.io/self-managed-high-availability: "true"
include.release.openshift.io/single-node-developer: "true"
spec:
egress:
- ports:
- protocol: TCP
port: 1
endPort: 65535
- ports:
- protocol: UDP
port: 5353
Comment on lines +16 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to just allow all traffic to egress? What does the recommendations document suggest?

podSelector:
matchExpressions:
- key: k8s-app
operator: In
values:
- cluster-autoscaler
- cluster-autoscaler-operator
- cluster-baremetal-operator
- control-plane-machine-set-operator
- controller
- machine-api-operator
policyTypes:
- Egress
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Allow ingress to the openshift-machine-api namespace pods for internal cluster request
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-ingress-cluster
namespace: openshift-machine-api
annotations:
capability.openshift.io/name: MachineAPI
exclude.release.openshift.io/internal-openshift-hosted: "true"
include.release.openshift.io/self-managed-high-availability: "true"
include.release.openshift.io/single-node-developer: "true"
spec:
ingress:
- ports:
- protocol: TCP
port: 9440
endPort: 9442
- protocol: TCP
port: 8443
podSelector:
matchExpressions:
- key: k8s-app
operator: In
values:
- cluster-autoscaler
- cluster-autoscaler-operator
- cluster-baremetal-operator
- control-plane-machine-set-operator
- controller
- machine-api-operator
policyTypes:
- Ingress
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Allow ingress to the openshift-machine-api namespace pods for kubeapi requests
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-ingress-kubeapi
namespace: openshift-machine-api
annotations:
capability.openshift.io/name: MachineAPI
exclude.release.openshift.io/internal-openshift-hosted: "true"
include.release.openshift.io/self-managed-high-availability: "true"
include.release.openshift.io/single-node-developer: "true"
spec:
ingress:
- ports:
- protocol: TCP
port: 8443
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is present in multiple policies, what's it for?

- protocol: TCP
port: 9443
podSelector:
matchExpressions:
- key: k8s-app
operator: In
values:
- cluster-autoscaler
- cluster-autoscaler-operator
- cluster-baremetal-operator
- control-plane-machine-set-operator
- controller
- machine-api-operator
policyTypes:
- Ingress
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Allow ingress to the openshift-machine-api namespace pods for metrics request
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-ingress-metrics
namespace: openshift-machine-api
annotations:
capability.openshift.io/name: MachineAPI
exclude.release.openshift.io/internal-openshift-hosted: "true"
include.release.openshift.io/self-managed-high-availability: "true"
include.release.openshift.io/single-node-developer: "true"
spec:
ingress:
- ports:
- protocol: TCP
port: 8085
- protocol: TCP
port: 8440
endPort: 8444
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also includes 8443, third time now, I assume it's not an issue including a port multiple times, just curious why it's showing up so much

- protocol: TCP
port: 9191
endPort: 9192
podSelector:
matchExpressions:
- key: k8s-app
operator: In
values:
- cluster-autoscaler
- cluster-autoscaler-operator
- cluster-baremetal-operator
- control-plane-machine-set-operator
- controller
- machine-api-operator
policyTypes:
- Ingress
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Default deny all ingress and egress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks different to @miyadav's one for CAPI, can we co-ordinate what is and isn't needed between the two PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked @miyadav's pr openshift/cluster-capi-operator#325, this file install/0000_90_machine-api-operator_05_networkpolicy-default-deny.yaml looks similar with his manifests/0000_30_cluster-api_17_deny-all.yaml, but he added many comments, do you mean it's different here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you're right, they are the same apart from naming and comments.

Can we call these both default-deny? @miyadav would you be happy to update yours so the name is consistent with Huali's one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sure , thanks

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: openshift-machine-api
annotations:
capability.openshift.io/name: MachineAPI
exclude.release.openshift.io/internal-openshift-hosted: "true"
include.release.openshift.io/self-managed-high-availability: "true"
include.release.openshift.io/single-node-developer: "true"
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress