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

tetragon: Allow persistent enforcement during tetragon restart #2600

Merged
merged 11 commits into from
Jul 11, 2024

Conversation

olsajiri
Copy link
Contributor

@olsajiri olsajiri commented Jun 22, 2024

needs cilium/ebpf#1496 (merged, waiting for cilium/ebpf release)

Adding support to configure tetragon to keep existing policy in place - create pins for all maps/programs/links and do not remove them when tetragon exits.

This allows the policy to be in place when tetragon process is gone.

At the moment the configuration is by global flag. I have changes for configuring this through the spec 'options' flag, but first I need first to find a good way how to configure base sensor with same option. I think it's better to have this in place now, the option flag can come later.

Copy link

netlify bot commented Jun 22, 2024

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 3683daf
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/668e604cb39fcd0008dce362
😎 Deploy Preview https://deploy-preview-2600--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.

@olsajiri olsajiri added the release-note/minor This PR introduces a minor user-visible change label Jun 22, 2024
@olsajiri olsajiri force-pushed the pr/olsajiri/pin_link branch 9 times, most recently from 56ff75f to 4b7113c Compare June 27, 2024 12:43
@olsajiri olsajiri changed the title Pr/olsajiri/pin link tetragon: Allow persistent enforcement during tetragon restart Jun 27, 2024
@olsajiri olsajiri force-pushed the pr/olsajiri/pin_link branch 13 times, most recently from 0a3a057 to 055fa35 Compare July 1, 2024 23:23
@olsajiri olsajiri force-pushed the pr/olsajiri/pin_link branch 3 times, most recently from 0a61e66 to 99a61e7 Compare July 5, 2024 13:25
@kkourt kkourt self-requested a review July 5, 2024 14:00
@olsajiri olsajiri force-pushed the pr/olsajiri/pin_link branch from 99a61e7 to 5d76690 Compare July 5, 2024 20:34
@olsajiri olsajiri force-pushed the pr/olsajiri/pin_link branch from 5d76690 to 7cae9a6 Compare July 7, 2024 21:19
@olsajiri olsajiri marked this pull request as ready for review July 7, 2024 22:04
@olsajiri olsajiri requested review from mtardy and a team as code owners July 7, 2024 22:05
Copy link
Member

@tpapagian tpapagian left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Just a quick question: Is link.Pin also supported in the other types of programs that Tetragon supports (i.e. LSM, Tracing, Uprobes, RawTracepoints)? If yes, I believe that it is a good idea to update those as well. In that case, we also need to have a feature detection function using the same type of program instead of kprobes?

return old, nil
}

func deleteOlBpfDir(path string) {
Copy link
Member

Choose a reason for hiding this comment

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

Typo: deleteOlBpfDir -> deleteOldBpfDir

return
}
if err := os.RemoveAll(path); err != nil {
log.Errorf("Failed to remove old bpf isntance '%s': %s\n", path, err)
Copy link
Member

Choose a reason for hiding this comment

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

Typo: isntance

@olsajiri
Copy link
Contributor Author

LGTM, thanks!

Just a quick question: Is link.Pin also supported in the other types of programs that Tetragon supports (i.e. LSM, Tracing, Uprobes, RawTracepoints)? If yes, I believe that it is a good idea to update those as well. In that case, we also need to have a feature detection function using the same type of program instead of kprobes?

yes, those should be supported as wee, I'll do follow up with that support, thanks

olsajiri added 11 commits July 10, 2024 10:18
Update ebpf version to latest upstream to get link Pin/Unpin changes.

Signed-off-by: Jiri Olsa <[email protected]>
.. to detect link pinning functionality.

Signed-off-by: Jiri Olsa <[email protected]>
Adding --bpf-dir option to alter to 'map dir' for tetragon,
the default stays '/sys/fs/bpf/tetragon'.

Signed-off-by: Jiri Olsa <[email protected]>
Adding support to pin link through linkPin function.

At the moment we limit the link pinning with new PinLink bool
in program.Program object, which will be used/set in future
to control link pin for program.

Adding test for pin link path setup.

Signed-off-by: Jiri Olsa <[email protected]>
Adding support to pin tracepoint links.

Signed-off-by: Jiri Olsa <[email protected]>
Adding support to pin kprobe links for both normal
and override programs.

Signed-off-by: Jiri Olsa <[email protected]>
Adding support to pin kprobe multi links.

Signed-off-by: Jiri Olsa <[email protected]>
Adding support to pin fmodret links.

Signed-off-by: Jiri Olsa <[email protected]>
Adding --keep-sensors-on-exit option to global control
the pinning of maps/programs/links.

By default tetragon creates and destroyes pin files for maps
and programs.

With --keep-sensors-on-exit option tetragon :
  - also create pins for links
  - does not unpin any pns on exit

So this option will effectively keep configured policy still
running even when tetragon process is gone.

Signed-off-by: Jiri Olsa <[email protected]>
Adding support to detect and remove previous bpf instance
of /sysfs/bpf/tetragon directory.

On start tetragon now:
  - detect existing '/sysfs/bpf/tetragon' (or any other configured path)
  - rename it to '/sysfs/bpf/tetragon_old'
  - loads configured policy
  - deletes '/sysfs/bpf/tetragon_old' directory

Signed-off-by: Jiri Olsa <[email protected]>
Adding tests for persistent enforcement - kill and override.

Signed-off-by: Jiri Olsa <[email protected]>
@olsajiri olsajiri force-pushed the pr/olsajiri/pin_link branch from 7cae9a6 to 3683daf Compare July 10, 2024 10:19
@olsajiri olsajiri added release-note/major This PR introduces major new functionality and removed release-note/minor This PR introduces a minor user-visible change labels Jul 10, 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.

LGTM, thanks!

@olsajiri olsajiri merged commit 0cf61b5 into main Jul 11, 2024
49 checks passed
@olsajiri olsajiri deleted the pr/olsajiri/pin_link branch July 11, 2024 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/major This PR introduces major new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants