-
Notifications
You must be signed in to change notification settings - Fork 14
feat(network): enable optional egress network policy #209
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
base: main
Are you sure you want to change the base?
Conversation
|
Since #208 got merged, let's review this too? |
8ca4149 to
4528e3d
Compare
4528e3d to
da720d4
Compare
|
This will have a conflict with #247, depending on which one gets merged first - the egress policy will need to be automatically adjusted to allow Cryostat to open outgoing connections to the external S3 provider, if any. |
|
https://kubernetes.io/docs/concepts/services-networking/network-policies/ I'm actually not sure if there is a way to create an egress policy which allows for outbound connections to an external service. Users may simply need to leave egress policies disabled if they are using an external S3 provider. |
a2465f8 to
c5d7469
Compare
ebaron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a bit of trouble on a Kind cluster following the instructions. The sample app in the "test" namespace appears, and I can receive MBean metrics from it, but when trying to create a recording, I get a 504 Gateway Timeout when hitting the "Create" button.
127.0.0.1:58666 - 6287c32c-501f-4b02-a1b1-11a78abc69ca - - [2025/10/15 19:37:20] localhost:8080 POST cryostat "/api/v4/targets/1/recordings" HTTP/1.1 "Mozilla/5.0 (X11; Linux x86_64; rv:143.0) Gecko/20100101 Firefox/143.0" 504 0 30.585
Here's the Egress policy created:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
annotations:
meta.helm.sh/release-name: cryostat
meta.helm.sh/release-namespace: test
creationTimestamp: "2025-10-15T19:32:37Z"
generation: 1
labels:
app.kubernetes.io/managed-by: Helm
name: cryostat-internal-egress
namespace: test
resourceVersion: "1133"
uid: 90c679cb-4325-42e0-b4da-9add847bcc01
spec:
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
- to:
- namespaceSelector:
matchExpressions:
- key: kubernetes.io/metadata.name
operator: In
values:
- test
- test
- apps1
podSelector:
matchLabels:
app.kubernetes.io/component: cryostat
app.kubernetes.io/instance: cryostat
app.kubernetes.io/name: cryostat
app.kubernetes.io/part-of: cryostat
policyTypes:
- Egress|
Hmm, it's working as expected for me still after following the same steps I outlined. I'm also not sure how it could be that Cryostat is able to connect to the target to pull MBean metrics, but unable to connect in order to start a recording since it should be the same kind of connection either way. Could the 504 be coming from something else, like ex. an external storage provider configuration that is failing? |
Yeah maybe an issue with my Kind. I deleted the egress network policy and it's still giving me timeouts. |
ad54f85 to
b1d01b6
Compare
b1d01b6 to
f787604
Compare
Fixes #205
Depends on #208
Based on #208
Extends the previous Ingress policy with an Egress policy. This prevents Cryostat's Pods from opening network connections to unexpected destinations. This primarily prevents things like:
or
or
As mentioned in #208, this is an additional layer and stronger enforcement of the ideas in cryostatio/cryostat-agent#242 and cryostatio/cryostat#323 . If enabled, it also would solve the problem underlying cryostatio/cryostat#685 , though it would be even better to also solve that directly in Cryostat.
Currently, the egress policy seems to cause connections between Cryostat and its database to fail when deploying to OpenShift (crc or otherwise). I was able to test it successfully in
kind v0.25.0.kind create clusterkubectl create namespace testkubectl create namespace apps1, then used the Operator's Makefile:make sample_app. Thenkubectl edit svc quarkus-test -n apps1and renamed the9097port to simplyjmxso that it would not be auto-discovered.kubectl create namespace apps2, then spun up another sample app instance the same as above.kubectl ns test, then spun up yet another sample app instance but left this one with thejfr-jmxport name.helm install --set core.discovery.kubernetes.namespaces="{test,apps1}" --set networkPolicy.egress.enabled=true cryostat ./charts/cryostatand follow the post-installation steps for port-forwardingquarkus-testtarget intest(installation namespace) should be discovered and usable as usual. Thequarkus-tests inapps1andapps2should not be discovered.localhost:0custom target can be tested for connectivity. It should succeed.quarkus-test:9097custom target connectivity test fails quickly. The UI does not properly reflect it at the moment, but the Cryostat Pod logs should show that it is refusing to define this target because it has already been discovered.quarkus-test.test:9097fails. This is the same as the previous step, just explicitly specifying the namespace instead of allowing it to be implicit.quarkus-test.apps1:9097succeeds. This is the sample app inapps1with the renamed port, so it is in a target namespace but not auto-discovered. Therefore, it should be possible to define this custom target.quarkus-test.apps2:9097times out and fails. This is a sample app inapps2, which is not a target namespace, therefore the cluster should deny Cryostat's connection attempt to this application's service.To test in OpenShift, simply install with
--set networkPolicy.egress.enabled=false(or leave it unset, asfalseis the default). This should result in the same usual behaviour since the new policy should not be created.Testing on
minikubeshould result in nothing really happening differently, as the defaultminikubenetwork provider does not supportNetworkPolicyobjects. They will still be created andkubectl describe networkpolicywill explain what they are intended to do, but no actual ingress/egress restrictions will occur.