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

feat: Add collection key to differentiate namespaced policies #2337

Conversation

joshuajorel
Copy link
Contributor

@joshuajorel joshuajorel commented Apr 16, 2024

Currently, TracingPolicy and TracingPolicyNamespaced encounter conflicts whenever a policy is applied with the same name. A policy with the same name, even if it is in a different namespace does not get applied. This behavior should be allowed given the k8s context e.g. a policy in one namespace is a different policy from one in a different namespace even with the same name.

tetragon: allow namespaced and non-namespaced policies to have the same name

Fixes: #2299

Copy link
Contributor

@lambdanis lambdanis left a comment

Choose a reason for hiding this comment

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

Thank you for tackling this @joshuajorel! I see it's still WIP, but I left a few comments.

pkg/sensors/collection.go Outdated Show resolved Hide resolved
pkg/sensors/handler.go Outdated Show resolved Hide resolved
pkg/sensors/handler.go Outdated Show resolved Hide resolved
@lambdanis lambdanis added the release-note/bug This PR fixes an issue in a previous release of Tetragon. label Apr 16, 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.

Thanks!

Please find some comments below.

pkg/sensors/manager.go Outdated Show resolved Hide resolved
pkg/sensors/manager.go Outdated Show resolved Hide resolved
pkg/sensors/manager.go Outdated Show resolved Hide resolved
pkg/sensors/manager.go Outdated Show resolved Hide resolved
pkg/sensors/manager.go Outdated Show resolved Hide resolved
pkg/sensors/manager.go Outdated Show resolved Hide resolved
pkg/sensors/manager.go Outdated Show resolved Hide resolved
Copy link

netlify bot commented Apr 19, 2024

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 340e184
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/662f842cfaa54900083b5a56
😎 Deploy Preview https://deploy-preview-2337--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.

@joshuajorel
Copy link
Contributor Author

@kkourt @lambdanis - what is the usecase for enabling and disabling a Sensor? Since every interaction with Tetragon (as far I can see) goes through a TracingPolicy, where is this functionality used?

@kkourt
Copy link
Contributor

kkourt commented Apr 29, 2024

@kkourt @lambdanis - what is the usecase for enabling and disabling a Sensor? Since every interaction with Tetragon (as far I can see) goes through a TracingPolicy, where is this functionality used?

Hi,

The sensor interface (and infrastructure) is indeed deprecated. There is an issue to remove it #1272, but we first need to provide means to disable a tracing policy as we do with sensors.

@joshuajorel joshuajorel force-pushed the pr/joshuajorel/add-k8s-namespace-segregation-for-policies branch from acd9375 to 340e184 Compare April 29, 2024 11:27
@joshuajorel joshuajorel changed the title [WIP] feat: Add collection key to differentiate namespaced policies feat: Add collection key to differentiate namespaced policies Apr 29, 2024
@joshuajorel joshuajorel marked this pull request as ready for review April 29, 2024 11:28
@joshuajorel joshuajorel requested a review from kkourt April 29, 2024 11:28
@joshuajorel joshuajorel requested a review from a team as a code owner April 29, 2024 11:28
@lambdanis lambdanis self-requested a review April 29, 2024 19:31
@lambdanis
Copy link
Contributor

Hey @joshuajorel thank you for the updates.

Could you rewrite the commits so that changes are clearly grouped and documented? I think one commit introducing collectionKey, one introducing API changes, and one bringing everything together would be good. Or a single commit with all changes would be okay too. Please also keep the commit message titles no longer that 75 characters - otherwise the CI job fails.

@joshuajorel joshuajorel force-pushed the pr/joshuajorel/add-k8s-namespace-segregation-for-policies branch from 340e184 to 7d9918e Compare May 3, 2024 03:15
Copy link
Contributor

@lambdanis lambdanis left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you @joshuajorel. Let's wait for @kkourt to confirm nothing is missing.

if col, exists := h.collections[op.name]; exists && col.state != LoadErrorState {
return fmt.Errorf("failed to add tracing policy %s, a sensor collection with the name already exists", op.name)
if col, exists := h.collections[op.ck]; exists && col.state != LoadErrorState {
return fmt.Errorf("failed to add tracing policy %s, a sensor collection with the name already exists", op.ck)
Copy link
Contributor

@lambdanis lambdanis May 7, 2024

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("failed to add tracing policy %s, a sensor collection with the name already exists", op.ck)
return fmt.Errorf("failed to add tracing policy %s, a sensor collection with this key already exists", op.ck)

or something similar (non-blocking)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change wording to reference key instead of name

@joshuajorel
Copy link
Contributor Author

Looks good to me, thank you @joshuajorel. Let's wait for @kkourt to confirm nothing is missing.

Thank you for taking the time to review @lambdanis ! Will wait for @kkourt 's review

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, changes LGTM. I left one comment about removing the unneeded name field.

One of the things we also need to do is update the CLI: https://github.com/cilium/tetragon/blob/main/cmd/tetra/tracingpolicy/tracingpolicy.go. Could you also do that?

pkg/sensors/manager.go Show resolved Hide resolved
pkg/sensors/manager.go Show resolved Hide resolved
pkg/sensors/manager.go Show resolved Hide resolved
@joshuajorel
Copy link
Contributor Author

Thanks, changes LGTM. I left one comment about removing the unneeded name field.

One of the things we also need to do is update the CLI: https://github.com/cilium/tetragon/blob/main/cmd/tetra/tracingpolicy/tracingpolicy.go. Could you also do that?

Sure. Let me do the changes and get back to you. Thank you very much!

@kkourt
Copy link
Contributor

kkourt commented May 14, 2024

Thanks, changes LGTM. I left one comment about removing the unneeded name field.
One of the things we also need to do is update the CLI: https://github.com/cilium/tetragon/blob/main/cmd/tetra/tracingpolicy/tracingpolicy.go. Could you also do that?

Sure. Let me do the changes and get back to you. Thank you very much!

Thanks! I would suggest doing the CLI updates in a different patch to ease reviewing.

TracingPolicy and TracingPolicyNamespaced encounter conflicts whenever a policy is applied with the same name. A policy with the same name, even if it is in a different namespace does not get applied. This commit adds a collectionKey to differentiate policies with the same, but in different namespaces.

Fixes: cilium#2299

Signed-off-by: Joshua Jorel Lee <joshua.jorel.lee@gmail.com>
@joshuajorel joshuajorel force-pushed the pr/joshuajorel/add-k8s-namespace-segregation-for-policies branch from 7d9918e to d5641fd Compare May 15, 2024 10:11
By adding a collectionKey to differentiate namespaces, the CLI needs to be updated to support this update. This change adds a namespace flag to the CLI for the delete, enable, and disable commands. If the namespace flag is unset, it will reference the global TracingPolicy.

Fixes: cilium#2299

Signed-off-by: Joshua Jorel Lee <joshua.jorel.lee@gmail.com>
@joshuajorel joshuajorel force-pushed the pr/joshuajorel/add-k8s-namespace-segregation-for-policies branch from 0c7d2b1 to 6ec273f Compare May 20, 2024 09:59
@joshuajorel joshuajorel requested a review from kkourt May 21, 2024 05:23
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!

@kkourt
Copy link
Contributor

kkourt commented May 22, 2024

Everything's ✅ , so merging this. Many thanks @joshuajorel this is an awesome contribution.

@kkourt kkourt merged commit d7619f9 into cilium:main May 22, 2024
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/bug This PR fixes an issue in a previous release of Tetragon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a TracingPolicyNamespaced with the same name for a different namespace does not get applied.
4 participants