feat(network): enable optional egress network policy #209
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 cluster
kubectl create namespace test
kubectl create namespace apps1
, then used the Operator's Makefile:make sample_app
. Thenkubectl edit svc quarkus-test -n apps1
and renamed the9097
port to simplyjmx
so 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-jmx
port name.helm install --set core.discovery.kubernetes.namespaces="{test,apps1}" --set networkPolicy.egress.enabled=true cryostat ./charts/cryostat
and follow the post-installation steps for port-forwardingquarkus-test
target intest
(installation namespace) should be discovered and usable as usual. Thequarkus-test
s inapps1
andapps2
should not be discovered.localhost:0
custom target can be tested for connectivity. It should succeed.quarkus-test:9097
custom 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:9097
fails. This is the same as the previous step, just explicitly specifying the namespace instead of allowing it to be implicit.quarkus-test.apps1:9097
succeeds. This is the sample app inapps1
with 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:9097
times 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, asfalse
is the default). This should result in the same usual behaviour since the new policy should not be created.Testing on
minikube
should result in nothing really happening differently, as the defaultminikube
network provider does not supportNetworkPolicy
objects. They will still be created andkubectl describe networkpolicy
will explain what they are intended to do, but no actual ingress/egress restrictions will occur.