Skip to content

Conversation

@FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Nov 7, 2025

Description

Today, we default at enforce even for policies that do not support any enforcement.
Introduce a monitor_only mode (that is userspace-only) that:

  • stores monitor in ebpf map during startup to avoid falsely reporting enforce
  • denies further update to policy mode since the policy does not support enforcement

Example output:

$ ./tetra tracingpolicy list
ID   NAME              STATE     FILTERID   NAMESPACE   SENSORS          KERNELMEMORY   MODE           NPOST   NENFORCE   NMONITOR
1    read-etc-passwd   enabled   0          (global)    generic_kprobe   1.87 MB        monitor_only   0       0          0

$ ./tetra tracingpolicy set-mode read-etc-passwd enforce
Error: failed set mode to "enforce" tracing policy: rpc error: code = Unknown desc = setMode called in a collection that does not support enforcement mode

Changelog

new: monitor only mode

@netlify
Copy link

netlify bot commented Nov 7, 2025

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 4f01264
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/69134355fe211700084692ae
😎 Deploy Preview https://deploy-preview-4316--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 project configuration.

@FedeDP FedeDP marked this pull request as ready for review November 10, 2025 08:20
@FedeDP FedeDP requested a review from kkourt November 10, 2025 08:21
@kkourt kkourt added the release-note/minor This PR introduces a minor user-visible change label Nov 10, 2025
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!

Left some comments, but LGTM.

@FedeDP FedeDP force-pushed the new/monitor_only_mode branch from f67e586 to 54304d1 Compare November 10, 2025 16:18
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.

1 read-etc-passwd enabled 0 (global) generic_kprobe 1.87 MB monitor 0 0 0

One more comment: can we have monitor_only in the list?

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 11, 2025

One more comment: can we have monitor_only in the list?

Well, right now the mode we see there is the one seen by bpf.
I'd avoid having something like:

func (c *collection) mode() tetragon.TracingPolicyMode {
	if c.tracingpolicy == nil || c.state != EnabledState {
		return tetragon.TracingPolicyMode_TP_MODE_UNKNOWN
	}
	if !c.allowModeUpdate {
		return tetragon.TracingPolicyMode_TP_MODE_MONITOR_ONLY
	}

	mode, err := policyconf.PolicyMode(c.tracingpolicy)

because:

  • we'd need to add TracingPolicyMode_TP_MODE_MONITOR_ONLY to our grpc api
  • we are no more exposing the real bpf value
  • i'd prefer to keep the allowModeUpdate information bit private

Do you think that, from an UX perspective, is it that bad not to expose TracingPolicyMode_TP_MODE_MONITOR_ONLY ?

@kkourt
Copy link
Contributor

kkourt commented Nov 11, 2025

One more comment: can we have monitor_only in the list?

Well, right now the mode we see there is the one seen by bpf. I'd avoid having something like:

func (c *collection) mode() tetragon.TracingPolicyMode {
	if c.tracingpolicy == nil || c.state != EnabledState {
		return tetragon.TracingPolicyMode_TP_MODE_UNKNOWN
	}
	if !c.allowModeUpdate {
		return tetragon.TracingPolicyMode_TP_MODE_MONITOR_ONLY
	}

	mode, err := policyconf.PolicyMode(c.tracingpolicy)

because:

* we'd need to add `TracingPolicyMode_TP_MODE_MONITOR_ONLY` to our grpc api

* we are no more exposing the real bpf value

* i'd prefer to keep the `allowModeUpdate` information bit private

Do you think that, from an UX perspective, is it that bad not to expose TracingPolicyMode_TP_MODE_MONITOR_ONLY ?

I would say exposing MONITOR_ONY is good to have (but not too bad if we don't do it).
If we do it, however, I would also read the bpf value and check that things make sense.
That is, if bpf is in enforcement mode but userspace is in monitor_only, then something is probably wrong.

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 11, 2025

If we do it, however, I would also read the bpf value and check that things make sense.
That is, if bpf is in enforcement mode but userspace is in monitor_only, then something is probably wrong.

Well i like this use of the new flag. I think it makes sense then, to have this check! Let me update the PR :)

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 11, 2025

Pushed the changes @kkourt !

Also, updated PR description with an updated output from tetra tracingpolicy list.

@FedeDP FedeDP force-pushed the new/monitor_only_mode branch 2 times, most recently from 6ef3c44 to 4f01264 Compare November 11, 2025 14:08
@FedeDP FedeDP requested a review from kkourt November 11, 2025 14:27
@FedeDP FedeDP force-pushed the new/monitor_only_mode branch from 4f01264 to 0862044 Compare November 11, 2025 15:39
@FedeDP FedeDP requested a review from a team as a code owner November 11, 2025 15:39
@FedeDP FedeDP force-pushed the new/monitor_only_mode branch from 0862044 to 288f179 Compare November 11, 2025 15:40
@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 11, 2025

Windows static checks CI is having some problems tracked here: #4330
We can skip it i guess.

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.

MonitorMode Mode = 1
EnforceMode Mode = 0
MonitorMode Mode = 1
MonitorOnlyMode Mode = 2 // monitor and cannot be updated to enforce. Not visible to bpf.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add some information in the commit message for new(pkg/policyconf): introduce MonitorOnlyMode. on what is MonitorOnly mode and what is the motivation? I know it seems obvious now, but providing context is helpful both for people without the context we have now and also for our future selves.

Similarly for the other commits. Note that "why" we are doing something is equally (if not more) important that what. Usually, the what can be figured out by looking at the code, but the why is not so easy.

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 force-pushed the reworded commits; feel free to tell me if there's anything else that you feel like should be improved :)

// state indicates the state of the collection
state TracingPolicyState
state TracingPolicyState
allowModeUpdate bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: How about we keep the mode here? That is, monitor, monitor_only, enforce.

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 think that using the ebpf map as source of truth is a good thing; i'd avoid storing that info bit in userspace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we want the mode to be everywhere, we should really push it down to ebpf; lots of ugliness in this PR would go away then.

if mode != policyconf.MonitorMode {
logger.GetLogger().Warn("monitor-only bit is set but bpf map is not in monitor mode", "policy", c.name)
}
return tetragon.TracingPolicyMode_TP_MODE_MONITOR_ONLY
Copy link
Contributor

Choose a reason for hiding this comment

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

comment: I wonder if we could return something else here if the mode is not monitor mode, but I don't have any good ideas. We can leave it as is and revisit as needed.

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 agree, don't really know what else to return :)

FedeDP and others added 8 commits November 12, 2025 10:22
The new policyconf Mode will be used for policies that do not have
any enforcement action. For those, nothing else but `monitor` mode
should be available.
The new mode is not exposed to ebpf (that will see `MonitorMode`),
but is used in userspace to notify that the policy only supports monitoring.
Also, add a small helper method `SupportEnforcement`.

Signed-off-by: Federico Di Pierro <[email protected]>
It will be used by sensors `handler` to deny mode updates
when `HasEnforcement` is false for all sensors in a collection.

Signed-off-by: Federico Di Pierro <[email protected]>
In case all sensors in a collection do not support enforcement,
deny any col.mode update.

Signed-off-by: Federico Di Pierro <[email protected]>
When there are no enforcers, and no enforcement action
nor override action, for all kinds of probes.

Signed-off-by: Federico Di Pierro <[email protected]>
It will be exposed by the new `SensorIface::HasEnforcement()` API.

Signed-off-by: Federico Di Pierro <[email protected]>
It will be returned by `collection.mode()` when `allowModeUpdate` is false.

Signed-off-by: Federico Di Pierro <[email protected]>

Co-authored-by: Kornilios Kourtis <[email protected]>
@FedeDP FedeDP force-pushed the new/monitor_only_mode branch from 288f179 to eaaa104 Compare November 12, 2025 09:29
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

Development

Successfully merging this pull request may close these issues.

2 participants