-
Notifications
You must be signed in to change notification settings - Fork 111
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
Share bpf maps internally and remove pinning / bpffs requirement #1251
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1251 +/- ##
==========================================
+ Coverage 81.78% 81.82% +0.03%
==========================================
Files 135 135
Lines 11416 11384 -32
==========================================
- Hits 9337 9315 -22
+ Misses 1544 1543 -1
+ Partials 535 526 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
745afd8
to
4cf890f
Compare
bpf/headers/bpf_helpers.h
Outdated
@@ -137,6 +137,9 @@ enum libbpf_pin_type { | |||
LIBBPF_PIN_NONE, | |||
/* PIN_BY_NAME: pin maps by name (in /sys/fs/bpf by default) */ | |||
LIBBPF_PIN_BY_NAME, | |||
|
|||
// XXX custom | |||
LIBBPF_PIN_INTERNAL = 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have decided to do this mainly so that we don't introduce a header that will need to be included everywhere, containing a single constant define.
I reckon this should be refactored if or when we decide to resplit the tracers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if i understand what are you saying here. What do you mean resplit the tracers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add this explanation to a comment on LIBBPF_PIN_INTERNAL so we don't forget the context it in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to move this into a header of our own, since we might copy - paste a new version of libbpf headers here and cause an compile error. To the person that does this it may not be obvious what caused the build break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marctc I was under the impression everything was grouped together so that we could share the maps, but perhaps I am missing a part of the history. I intend to split the tc
programs off generic_tracer
to allow them to be loaded separately - it will be possible to do the same now for other programs if we conclude it's desirable.
@grcevski @mariomac I will move this constant elsewhere to avoid confusion.
internalMaps[k] = internalMap | ||
} | ||
|
||
collOpts.MapReplacements[k] = internalMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cilium/ebpf
will clone internalMap
when processing MapReplacements
, meaning both clones can be safely closed irrespective of each other (clones still share the underlying map object though, it's just the underlying file descriptor that is dup'd)
3ae5f82
to
979b73f
Compare
@@ -45,31 +42,6 @@ spec: | |||
{{- if .Values.priorityClassName }} | |||
priorityClassName: {{ .Values.priorityClassName }} | |||
{{- end }} | |||
{{- if not (.Values.privileged) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be prudent to get a second pair of eyes on these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably could do it in a separate PR IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marctc ok, I will revert this part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM amazing find @rafaelroquetto. Did you notice if this impacted the peformance? Personally i'd had removed the unprivileged stuff in a different PR (also to document how to run Beyla without privileges), but overall looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing! I love removing code :)
As Marc says, I would let the changes in the helm chart for another PR, so we can focus on merging this feature and later test the unconfinement requirements.
bpf/headers/bpf_helpers.h
Outdated
@@ -137,6 +137,9 @@ enum libbpf_pin_type { | |||
LIBBPF_PIN_NONE, | |||
/* PIN_BY_NAME: pin maps by name (in /sys/fs/bpf by default) */ | |||
LIBBPF_PIN_BY_NAME, | |||
|
|||
// XXX custom | |||
LIBBPF_PIN_INTERNAL = 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add this explanation to a comment on LIBBPF_PIN_INTERNAL so we don't forget the context it in the future
@@ -25,9 +25,6 @@ spec: | |||
{{- with .Values.podAnnotations }} | |||
{{- toYaml . | nindent 8 }} | |||
{{- end }} | |||
{{- if not (.Values.privileged) }} | |||
container.apparmor.security.beta.kubernetes.io/beyla: "unconfined" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we set this when the container is NOT privileged, so we can add the required capabilities. I don't remember if this was required only for SYS_ADMIN capability, or setting the rest of capabilities require it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I remember we had to use this "unconfined" because App Armour prevents us from mounting file systems or writing to /sys/fs. So if we don't have to mount anymore we don't need to remove this restriction.
However we shouldn't remove this in this PR. It should be a follow-up and we should probably confirm this is works now with real k8s install, since we have no tests for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great work, minor comments :).
bpf/headers/bpf_helpers.h
Outdated
@@ -137,6 +137,9 @@ enum libbpf_pin_type { | |||
LIBBPF_PIN_NONE, | |||
/* PIN_BY_NAME: pin maps by name (in /sys/fs/bpf by default) */ | |||
LIBBPF_PIN_BY_NAME, | |||
|
|||
// XXX custom | |||
LIBBPF_PIN_INTERNAL = 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to move this into a header of our own, since we might copy - paste a new version of libbpf headers here and cause an compile error. To the person that does this it may not be obvious what caused the build break.
@@ -25,9 +25,6 @@ spec: | |||
{{- with .Values.podAnnotations }} | |||
{{- toYaml . | nindent 8 }} | |||
{{- end }} | |||
{{- if not (.Values.privileged) }} | |||
container.apparmor.security.beta.kubernetes.io/beyla: "unconfined" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I remember we had to use this "unconfined" because App Armour prevents us from mounting file systems or writing to /sys/fs. So if we don't have to mount anymore we don't need to remove this restriction.
However we shouldn't remove this in this PR. It should be a follow-up and we should probably confirm this is works now with real k8s install, since we have no tests for this.
@marctc Thanks. I will remove the changes to the helm chart, but I intend to keep the documentation changes (i.e. removing the mentions to the ebpf filesystem since they are no longer relevant). I will take care of a "how to run beyla unprivileged" in a separate PR, as this will mostly boil down to capabilities and these changes are "backwards compatible". |
This reverts commit e4cdd4d.
979b73f
to
df95555
Compare
Leverage the fact that
pinning/PinType
is anuint
and introduce a newPinType
calledPinInternal
, which shares the corresponding maps inside the same userspace process (i.e. all of the maps sharing the same name refer to the same ebpf map object, but no actual bpffs pinning is given).All bpf filesystem mounting code has been removed.
Resolves #1249