Skip to content
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

oci-hook: allow users to set a list of namespace exceptions and define default #2404

Merged
merged 1 commit into from May 14, 2024

Conversation

f1ko
Copy link
Contributor

@f1ko f1ko commented May 3, 2024

Prior to this commit kube-system was always added as an exception in order for Pods in that namespace to be created in the event that the OCI hook was not able to reach the Tetragon agent. This leads to a deadlock scenario when Tetragon itself is not installed in kube-system.

Instead of always adding kube-syste this change will always add the namespace Tetragon is deployed in. In addition to that a user can now define additional namespaces as further exception. For example to ensure Pods in business-critical namespaces can still be created even if the OCI hook fails to reach the Tetragon agent.


Install Tetragon in a namespace other than kube-system:

helm install --namespace tetragon \
        --set tetragonOperator.image.override=localhost/cilium/tetragon-operator:latest \
        --set tetragon.image.override=localhost/cilium/tetragon:latest  \
        --set tetragon.grpc.address="unix:///var/run/cilium/tetragon/tetragon.sock" \
        --set tetragon.ociHookSetup.enabled=true \
        tetragon ./install/kubernetes/tetragon
$ kubectl get pods
NAME                                 READY   STATUS    RESTARTS   AGE
tetragon-46lr7                       2/2     Running   0          13s
tetragon-operator-7c8cc5964f-jzxdx   1/1     Running   0          13s

Fixes #2402


Install helm with the new failAllowNamespaces values:

helm install --wait --namespace tetragon \
        --set tetragonOperator.image.override=localhost/cilium/tetragon-operator:latest \
        --set tetragon.image.override=localhost/cilium/tetragon:latest  \
        --set tetragon.grpc.address='unix:///var/run/cilium/tetragon/tetragon.sock' \
        --set tetragon.ociHookSetup.enabled=true \
        --set tetragon.ociHookSetup.failAllowNamespaces='business-critical-a\,business-critical-b' \
        tetragon ./install/kubernetes/tetragon

Uninstall Tetragon to trigger OCI hook error:

helm uninstall --namespace tetragon tetragon

Create various namespaces:

kubectl create ns business-critical-a
kubectl create ns business-critical-b
kubectl create ns business-critical-c

Create deployments in namespaces:

kubectl create deploy -n business-critical-a nginx --image docker.io/nginx
kubectl create deploy -n business-critical-b nginx --image docker.io/nginx
kubectl create deploy -n business-critical-c nginx --image docker.io/nginx

As can be seen Pods in business-critical-a and business-critical-b were created and are Running whereas business-critical-c wasn't part of the list and therefore continues to fail:

$ kubectl get pods -A -l app=nginx
NAMESPACE             NAME                     READY   STATUS                 RESTARTS   AGE
business-critical-a   nginx-68fd89949f-8h4xg   1/1     Running                0          12s
business-critical-b   nginx-68fd89949f-q7l2j   1/1     Running                0          12s
business-critical-c   nginx-68fd89949f-kjflf   0/1     CreateContainerError   0          12s

Fixes #2403

@f1ko f1ko requested a review from a team as a code owner May 3, 2024 08:58
@f1ko f1ko requested a review from tpapagian May 3, 2024 08:58
@f1ko
Copy link
Contributor Author

f1ko commented May 3, 2024

I think it makes sense to add @kkourt as a reviewer as he knows the most about the OCI hook implementation at this point.

@f1ko f1ko force-pushed the oci-hook branch 2 times, most recently from fc9726f to e523052 Compare May 9, 2024 10:13
Copy link

netlify bot commented May 9, 2024

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 2424f81
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/664217a05d4e87000864db24
😎 Deploy Preview https://deploy-preview-2404--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kkourt kkourt self-requested a review May 13, 2024 08:59
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM.
I do have a small suggestion, but I'm pre-approving since it's a trivial change.

Comment on lines 203 to 205
# -- Comma-separated list of namespaces to allow Pod creation for, in case tetragon-oci-hook fails to reach Tetragon agent.
failAllowNamespaces: ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we document that if this is left empty, the namespace where tetragon is installed will be used by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved via 2424f81

@kkourt kkourt added the release-note/minor This PR introduces a minor user-visible change label May 13, 2024
@kkourt kkourt changed the title oci-hook: allow users to set a list of namespace exceptions and definee default oci-hook: allow users to set a list of namespace exceptions and define default May 13, 2024
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

I'm changing my review to "Request changes", because of my later comment. It would be nice to have a way to always include the tetragon namespace in the failed namespaces list because otherwise Tetragon will not be able to start.

@f1ko
Copy link
Contributor Author

f1ko commented May 13, 2024

Thanks for the review!
Added a small hint to clarify that Tetragon's namespace is always added (even if the user leaves failAllowNamespaces empty).

As per your last comment this is already accounted for, see this comment.

Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

Thanks!

@kkourt
Copy link
Contributor

kkourt commented May 13, 2024

One final request: Can you squash the changes from my feedback into a single commit? (git rebase --interactive using the squash and fixup actions should help).

Prior to this commit `kube-system` was always added as an exception in order for Pods in that namespace to be created in the event that the OCI hook was not able to reach the Tetragon agent.
This leads to a deadlock scenario when Tetragon itself is not installed in `kube-system` as the agent won't start and leave the cluster in an unhealthy state.

Instead of always adding `kube-syste` this change will always add the namespace Tetragon is deployed in, to guarantee that the agent can always start.
In addition to that a user can now define additional namespaces as further exceptions.
For example to ensure Pods in business-critical namespaces can still be created even if the OCI hook fails to reach the Tetragon agent.

Signed-off-by: Filip Nikolic <oss.filipn@gmail.com>
@f1ko
Copy link
Contributor Author

f1ko commented May 13, 2024

Done 👍

@kkourt kkourt merged commit 58d92f0 into cilium:main May 14, 2024
41 of 42 checks passed
@f1ko f1ko deleted the oci-hook branch May 14, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor This PR introduces a minor user-visible change
Projects
None yet
2 participants