Skip to content

Commit 1fb6096

Browse files
saschagrunertk8s-ci-robot
authored andcommitted
Drop btfhub support
Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
1 parent 64b3da2 commit 1fb6096

File tree

2,017 files changed

+11
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,017 files changed

+11
-721
lines changed

Makefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,6 @@ $(BUILD_DIR)/enricher.bpf.o: $(BUILD_DIR) ## Build the BPF module
373373
update-vmlinux: ## Generate the vmlinux.h required for building the BPF modules.
374374
./hack/update-vmlinux
375375

376-
.PHONY: update-btf
377-
update-btf: $(BUILD_DIR) ## Build and update all generated BTF code for supported kernels
378-
$(GO) run ./internal/pkg/daemon/bpfrecorder/generate
379-
380376
.PHONY: update-bpf
381377
update-bpf: clean \
382378
internal/pkg/daemon/bpfrecorder/bpf/recorder.bpf.o.amd64 \
@@ -486,10 +482,6 @@ verify-mocks: update-mocks ## Verify the content of the generated mocks
486482
verify-bpf: update-bpf ## Verify the generated bpf code
487483
hack/tree-status
488484

489-
.PHONY: verify-btf
490-
verify-btf: update-btf ## Verify the generated btf code
491-
git diff
492-
493485
.PHONY: verify-format
494486
verify-format: ## Verify the code format
495487
clang-format -i $(shell find . -type f -name '*.c' -or -name '*.proto' | grep -v ./vendor)

bpf-support.md

Lines changed: 0 additions & 113 deletions
This file was deleted.

dependencies.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ dependencies:
183183
- path: hack/pull-security-profiles-operator-verify
184184
match: CLANG_VERSION
185185

186-
- name: btfhub
187-
version: 12d2b6bb4664b6b1d15076f8090dcb0e55696d34
188-
refPaths:
189-
- path: hack/update-btf
190-
match: BTFHUB_COMMIT
191-
192186
- name: flatcar
193187
version: 3510.2.3
194188
refPaths:

hack/update-btf

Lines changed: 0 additions & 34 deletions
This file was deleted.

installation-usage.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,10 @@ to record the syscalls or SELinux events.
653653

654654
The operator also supports an [eBPF](https://ebpf.io) based recorder. This
655655
recorder only supports seccomp and apparmor profiles for now. Recording via ebpf works for
656-
kernels which expose the `/sys/kernel/btf/vmlinux` file per default as well as a
657-
[custom list of selected Linux kernels](bpf-support.md). In addition, this
658-
feature requires new library versions and thus might not be enabled. You
659-
can find out if your SPO build has the eBPF feature disabled by looking at
660-
the build tags:
656+
kernels which expose the `/sys/kernel/btf/vmlinux` file per default. In
657+
addition, this feature requires new library versions and thus might not be
658+
enabled. You can find out if your SPO build has the eBPF feature disabled by
659+
looking at the build tags:
661660

662661
```
663662
> kubectl logs --selector name=security-profiles-operator | grep buildTags

internal/pkg/daemon/bpfrecorder/bpfrecorder.go

Lines changed: 7 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"time"
3838

3939
bpf "github.com/aquasecurity/libbpfgo"
40-
"github.com/blang/semver/v4"
4140
"github.com/go-logr/logr"
4241
"github.com/jellydator/ttlcache/v3"
4342
"google.golang.org/grpc"
@@ -49,7 +48,6 @@ import (
4948
apimetrics "sigs.k8s.io/security-profiles-operator/api/grpc/metrics"
5049
"sigs.k8s.io/security-profiles-operator/internal/pkg/bimap"
5150
"sigs.k8s.io/security-profiles-operator/internal/pkg/config"
52-
"sigs.k8s.io/security-profiles-operator/internal/pkg/daemon/bpfrecorder/types"
5351
"sigs.k8s.io/security-profiles-operator/internal/pkg/util"
5452
)
5553

@@ -481,8 +479,7 @@ func (b *BpfRecorder) Load() (err error) {
481479

482480
b.logger.Info("Loading bpf module...")
483481

484-
b.btfPath, err = b.findBtfPath()
485-
if err != nil {
482+
if err := b.findBtfPath(); err != nil {
486483
return fmt.Errorf("find btf: %w", err)
487484
}
488485

@@ -678,100 +675,17 @@ func (b *BpfRecorder) StopRecording() error {
678675
return nil
679676
}
680677

681-
func (b *BpfRecorder) findBtfPath() (string, error) {
678+
func (b *BpfRecorder) findBtfPath() error {
679+
const btf = "/sys/kernel/btf/vmlinux"
680+
682681
// Use the system btf if possible
683-
if _, err := b.Stat("/sys/kernel/btf/vmlinux"); err == nil {
682+
if _, err := b.Stat(btf); err == nil {
684683
b.logger.Info("Using system btf file")
685684

686-
return "", nil
687-
}
688-
689-
b.logger.Info("Trying to find matching in-memory btf")
690-
691-
btf := types.Btf{}
692-
if err := b.Unmarshal([]byte(btfJSON), &btf); err != nil {
693-
return "", fmt.Errorf("unmarshal btf JSON: %w", err)
694-
}
695-
696-
res, err := b.ReadOSRelease()
697-
if err != nil {
698-
return "", fmt.Errorf("read os-release file: %w", err)
699-
}
700-
701-
osID := types.Os(res["ID"])
702-
btfOs, ok := btf[osID]
703-
704-
if !ok {
705-
b.logger.Info(fmt.Sprintf("OS not found in btf map: %s", osID))
706-
707-
return "", nil
708-
}
709-
710-
b.logger.Info(fmt.Sprintf("OS found in btf map: %s", osID))
711-
712-
osVersion := types.OsVersion(res["VERSION_ID"])
713-
btfOsVersion, ok := btfOs[osVersion]
714-
715-
if !ok {
716-
b.logger.Info(fmt.Sprintf("OS version not found in btf map: %s", osVersion))
717-
718-
return "", nil
719-
}
720-
721-
b.logger.Info(fmt.Sprintf("OS version found in btf map: %s", osVersion))
722-
723-
arch, version, err := b.Uname()
724-
if err != nil {
725-
b.logger.Error(err, "failed to get kernel version, continuing without BTF...")
726-
727-
return "", nil
728-
}
729-
730-
btfArch, ok := btfOsVersion[arch]
731-
if !ok {
732-
b.logger.Info(fmt.Sprintf("Architecture not found in btf map: %s", arch))
733-
734-
return "", nil
735-
}
736-
737-
b.logger.Info(fmt.Sprintf("Architecture found in btf map: %s", arch))
738-
739-
const (
740-
lowestMajor = 5
741-
lowestMinor = 8
742-
)
743-
744-
if version.LT(semver.Version{Major: lowestMajor, Minor: lowestMinor}) {
745-
return "", fmt.Errorf("unsupported kernel version %s: at least Linux 5.8 is required", version)
746-
}
747-
748-
kernel := types.Kernel(version.String())
749-
btfBytes, ok := btfArch[kernel]
750-
751-
if !ok {
752-
b.logger.Info(fmt.Sprintf("Kernel not found in btf map: %s", kernel))
753-
754-
return "", nil
755-
}
756-
757-
b.logger.Info(fmt.Sprintf("Kernel found in btf map: %s", kernel))
758-
759-
file, err := b.TempFile(
760-
"",
761-
fmt.Sprintf("spo-btf-%s-%s-%s-%s", osID, osVersion, arch, kernel),
762-
)
763-
if err != nil {
764-
return "", fmt.Errorf("create temp file: %w", err)
765-
}
766-
defer file.Close()
767-
768-
if _, err := b.Write(file, btfBytes); err != nil {
769-
return "", fmt.Errorf("write BTF: %w", err)
685+
return nil
770686
}
771687

772-
b.logger.Info("Wrote BTF to file: " + file.Name())
773-
774-
return file.Name(), nil
688+
return fmt.Errorf("we dropped support for in-memory btf, please use a kernel which supports %s", btf)
775689
}
776690

777691
func (b *BpfRecorder) processEvents(events chan []byte) {

0 commit comments

Comments
 (0)