mirror of
https://github.com/gravitational/teleport.git
synced 2026-09-01 16:03:55 +08:00
7a7f08cb39
* start the refactor away from aquasecurity/libbpfgo to use cilium/ebpf Remove debug statements and unused code in BPF library This commit eliminates unnecessary debug log statements from bpf_test.go and removes unused code in disk.go and network.go files within BPF library. The aim is to make codebase cleaner, enhancing readability and maintainability without losing track of functional aspects. It's part of an ongoing effort to maintain optimal code quality across the project. Revise Dockerfile and Makefile instructions Adjusted Dockerfile and Makefile commands to optimize build process. The changes ensure better readability and maintainability of code, especially with respect to BPF bytecode and test preparations. A clause was also added to check for the presence of clang before building BPF bytecode. Refactor BPF code and tests Refactored BPF source code and its corresponding tests for better readability and efficiency. This includes updating data structures like rawExecEvent, rawOpenEvent, rawConn4Event and rawConn6Event to their more meritorious versions like commandDataT, diskDataT, networkIpv4DataT and networkIpv6DataT respectively. Also, generated concise and clear bindigs for eBPF programs to replace the previous multi-arch setup. Furthermore, correspondingly adapted all related test cases arising in bpf_test.go, command.go and other files. Remove counter_test from BPF and related test code This commit removes the file counter_test.bpf.c from the enhanced recording in BPF. Following this file deletion, corresponding test functions in bpf_test.go, that were originally testing the functionality provided by counter_test.bpf.c, have been removed as well. Refactor BPF test and improve error handling The commit refactors the BPF test suite to run each test as a sub-test by using t.Run, easing debugging and error tracing. It also simplifies the 'executeCommand' function by removing redundant function calls related to finding executable files, and improves error handling. In 'cgroup.go', the code has been adjusted to retry on EBUSY errors when removing a cgroup, instead of ignoring them. Update cgroup deletion process and error handling The changes made introduce a retry mechanism when deleting a cgroup in case the cgroup is busy. This prevents a failed attempt from immediately returning an error. Additionally, error handling has been improved in the 'writePids' function to better handle 'no such process' errors. Enhance cgroup monitoring in disk.bpf.c The code has been updated to check if current cgroup is being monitored in the "enter_open" method of "disk.bpf.c". If the cgroup is not marked for monitoring, it will be ignored, enhancing overall cgroup management. Improve resource handling This commit introduces a deferred close to the sendEvents function to ensure proper resource handling of the eventBuf object. Add rlimit package to remove resource limits Introduced the "github.com/cilium/ebpf/rlimit" package and added a function to remove resource limits for kernels less than 5.11. This operation is necessary for kernels with a lower version because they may face issues when running applications with allocated memory limitations. Fix a test after rebase Refactor BPF testing setup and implement session closing This commit updates the BPF testing structure to remove the context dependency in event generation functions, simplifying the test setup. Additionally, it adds a 'closed' field to the 'open', 'conn', and 'exec' structs alongside mutex protection. This implementation allows checking if a session is closed before any operations, correctly handling already closed sessions. Furthermore, it corrects tracepoints for handling 'openat' and 'openat2' system calls for different platforms. This refactoring effort aims to improve the robustness and readability of the BPF testing suite. Update conditions for BPF bytecode building This update modifies the Makefile to add a conditional check for the presence of /usr/include/bpf/bpf_helpers.h. This new requirement must be met along with the existence of /usr/include/linux/bpf.h and the installation of Clang, in order to facilitate the correct build of BPF bytecode. Consequently, this change enhances the reliability of the build process. Add conditional for bpf_helpers.h in Makefile This commit adds an additional check in the Makefile for the existence of /usr/include/bpf/bpf_helpers.h. This ensures that BPF bytecode only gets built when both bpf.h and bpf_helpers.h exist, and Clang is installed, improving the build process reliability. Refactor and improve BPF bytecode generation This commit refactors and improves the BPF bytecode generation process. It introduces distinct bytecode structures for different architectures, ensuring better compatibility and execution. The BPF test is adjusted due to its tendency to fail unpredictably, hence it's commented out to avoid unnecessary build failures. This commit also eliminates certain redundancies in `common.mk`, improving the clarity of the build process. Comment out test code in bpf_test.go The test code in the file bpf_test.go has been commented out. These changes are circumstantial and do not imply that the test code is obsolete or unnecessary. The use of such tests may be needed in future commits or for local development testing and debugging. Remove libbpf dependency from Vagrantfile and update README The Vagrantfile and README have been updated to remove the no longer needed libbpf dependency. This change simplifies the project set up by eliminating unused build steps in the Vagrantfile and correcting related instructions in the README. This results in a more streamlined, intuitive build process and reduced potential for code complexity and dependency conflicts. Remove obsolete dependencies and related code blocks The 'aquasecurity/libbpfgo' library referencing and the related code blocks have been removed from the test files and core modules. The corresponding setup instructions in the dockerfiles and build scripts have also been eliminated. This update simplifies the build process and overall project structure while reducing unnecessary dependency risks. Remove aquasecurity/libbpfgo dependency Remove restricted.bpf.c Migrate disk events to cilium Migrate network events to cilium Remove restricted session Use cilium/ebpf for BPF * fix build issues caused by stale branch Also updated bpf bytecode, updated github.com/cilium/ebpf to 0.19.0, and updated bpf/README to reflect changes * fix tests and a bit of cleanup Also added a subtest and fixed receiving IPv6 network events and fixed attempting to create tracepoints for syscalls that are not present on arm64. * repurpose buffer size configs to set event channel buffer size * add new GHA job to check that generated eBPF files are up to date * fix lost event promethus counters and address feedback * address feedback * use only unsafe instead of CGO to convert C strings * rename common_data_t comm -> command * convert strings in bpf programs from char arrays to u8 or uint8 arrays so we can convert them to Go strings without the use of the unsafe package --------- Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com> Co-authored-by: Tim Ross <tim.ross@goteleport.com>
74 lines
1.7 KiB
YAML
74 lines
1.7 KiB
YAML
name: Unit Tests (Go)
|
|
run-name: Unit Tests (Go) - ${{ github.run_id }} - @${{ github.actor }}
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
- branch/*
|
|
pull_request:
|
|
paths:
|
|
- '.github/workflows/unit-tests-code.yaml'
|
|
- '**.go'
|
|
- 'go.mod'
|
|
- 'go.sum'
|
|
- 'build.assets/Makefile'
|
|
- 'build.assets/Dockerfile*'
|
|
- 'Makefile'
|
|
merge_group:
|
|
paths:
|
|
- '.github/workflows/unit-tests-code.yaml'
|
|
- '**.go'
|
|
- 'go.mod'
|
|
- 'go.sum'
|
|
- 'build.assets/Makefile'
|
|
- 'build.assets/Dockerfile*'
|
|
- 'Makefile'
|
|
|
|
jobs:
|
|
test:
|
|
name: Unit Tests (Go)
|
|
if: ${{ !startsWith(github.head_ref, 'dependabot/') }}
|
|
runs-on: ubuntu-22.04-32core
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: read
|
|
|
|
container:
|
|
image: ghcr.io/gravitational/teleport-buildbox:teleport19
|
|
env:
|
|
TELEPORT_ETCD_TEST: yes
|
|
TELEPORT_ETCD_TEST_ENDPOINT: https://etcd0:2379
|
|
TELEPORT_XAUTH_TEST: yes
|
|
WEBASSETS_SKIP_BUILD: 1
|
|
options: --cap-add=SYS_ADMIN --privileged
|
|
|
|
services:
|
|
etcd0:
|
|
image: ghcr.io/gravitational/ci-etcd:3.3.9
|
|
options: >-
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
--add-host etcd0:127.0.0.1
|
|
ports:
|
|
- 2379:2379
|
|
- 2380:2380
|
|
- 3379:3379
|
|
|
|
steps:
|
|
- name: Checkout Teleport
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Prepare workspace
|
|
id: prepare
|
|
uses: ./.github/actions/prepare-workspace
|
|
|
|
- name: Mount debugfs
|
|
run: mount -t debugfs none /sys/kernel/debug/
|
|
|
|
- name: Run tests
|
|
timeout-minutes: 20
|
|
run: make -j"$(nproc)" test-go test-sh test-api
|