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

Adding first iteration on AppArmor profile generation to the recorder #1917

Merged
merged 31 commits into from
Jan 22, 2024

Conversation

0xmilkmix
Copy link
Contributor

@0xmilkmix 0xmilkmix commented Oct 12, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

This is a PR adding features for AppArmor profiles generation to the recorder:

  • Modifications to the eBPF recorder to trace executions, file operations, sockets operations and capabilities
  • Modifications to the AppArmor CRD to add an abstract representation, allowing to generate simpler profiles (like Bane
  • Modifications to the spoc CLI to generate AppArmor profiles (CRD and raw) from the command line

This PR does not include the integration with the recorder controller for now. I wanted to first discussed the idea and first iteration with you. Would it be possible to have collaborations so that the code from this PR could then be integrated by you in the controller for in-cluster recording?

Also, note that using open/openat tracing has some limitations. Namely, symlinks will not be resolved and this could lead to misconfigured AppArmor profiles. A LSM hook such as security_open would be beneficial here.

Other known limitations in the submitted version:

  • No support for recording sub-processes
  • Sometime the recorded process could end and events would still be in the ring buffer, generating an incomplete profile
    • fixed

Does this PR have test?

N/A

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Yes

The `spoc` cli tool now features `apparmor` and `raw-apparmor` types to generate CRDs and raw apparmor profiles.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. labels Oct 12, 2023
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 12, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Oct 12, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @0xmilkmix!

It looks like this is your first PR to kubernetes-sigs/security-profiles-operator 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/security-profiles-operator has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 12, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @0xmilkmix. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Oct 12, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 12, 2023

Codecov Report

Merging #1917 (5744f83) into main (3f0a531) will decrease coverage by 2.11%.
Report is 1 commits behind head on main.
The diff coverage is 4.07%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1917      +/-   ##
==========================================
- Coverage   47.32%   45.21%   -2.11%     
==========================================
  Files          77       79       +2     
  Lines        7352     7714     +362     
==========================================
+ Hits         3479     3488       +9     
- Misses       3742     4090     +348     
- Partials      131      136       +5     

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 12, 2023
@0xmilkmix 0xmilkmix marked this pull request as ready for review October 12, 2023 07:12
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 12, 2023
Copy link
Contributor

@ccojocar ccojocar left a comment

Choose a reason for hiding this comment

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

@0xmilkmix Great work! I left a few comments.

I think we can improve a bit the code by reducing the duplication in the recorder.bpf.c. Also in the bpfrecorder.go, I would use an interface to extract the parts for each recorder type instead of using an if recordingMode everywhere. This would make the code a bit more clearer.


struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 10240);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why this max number?

internal/pkg/daemon/bpfrecorder/bpf/recorder.bpf.c Outdated Show resolved Hide resolved
internal/pkg/daemon/bpfrecorder/bpf/recorder.bpf.c Outdated Show resolved Hide resolved
internal/pkg/daemon/bpfrecorder/bpf/recorder.bpf.c Outdated Show resolved Hide resolved
internal/pkg/daemon/bpfrecorder/bpf/recorder.bpf.c Outdated Show resolved Hide resolved
internal/pkg/daemon/bpfrecorder/bpf/recorder.bpf.c Outdated Show resolved Hide resolved
internal/pkg/daemon/bpfrecorder/bpfrecorder.go Outdated Show resolved Hide resolved
internal/pkg/cli/recorder/recorder.go Outdated Show resolved Hide resolved
internal/pkg/cli/recorder/recorder.go Show resolved Hide resolved
@ccojocar
Copy link
Contributor

It would be helpful to add some integration tests similar with this one https://github.com/kubernetes-sigs/security-profiles-operator/blob/main/test/tc_bpf_recorder_test.go. In this way, we can have some validation.

@ccojocar
Copy link
Contributor

I think you need to run make update-bpf to update the bytecode. Also you can verify that everything is fine afterwards with make verify-bpf.

@saschagrunert
Copy link
Member

@0xmilkmix may I ask you to rebase please?

@0xmilkmix
Copy link
Contributor Author

Thanks for the feedback. I'll try to work on them this week or next one.

Best regards

Copy link
Contributor

@ccojocar ccojocar left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the review comments.

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 7, 2023
@ccojocar
Copy link
Contributor

ccojocar commented Dec 7, 2023

@0xmilkmix I think there are some lint warnings which need to be fixed.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 7, 2023
@0xmilkmix
Copy link
Contributor Author

I think you need to run make update-bpf to update the bytecode. Also you can verify that everything is fine afterwards with make verify-bpf.

Should be ok now, thanks.

0xmilkmix and others added 21 commits January 22, 2024 09:53
…ic recorders

Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
… not setting it

Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 22, 2024
@ccojocar
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 22, 2024
@k8s-ci-robot k8s-ci-robot merged commit b420b76 into kubernetes-sigs:main Jan 22, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants