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

Tracing: add support for file permissions #2222

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

Jianlin-lv
Copy link

For the observed file/directory, add the associated permission and output the complete file/directory permission information, consistent with the format of 'ls -l'. Can be used in user space to further filter/identify events based on specific file attributes.

@Jianlin-lv Jianlin-lv requested a review from a team as a code owner March 14, 2024 15:20
Copy link

netlify bot commented Mar 14, 2024

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 36c1bf1
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/65f9b5762ab570000880b2a7
😎 Deploy Preview https://deploy-preview-2222--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.

@mtardy mtardy requested a review from tpapagian March 14, 2024 15:22
@tpapagian tpapagian added the release-note/minor This PR introduces a minor user-visible change label Mar 15, 2024
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.

Thanks for contributing to Tetragon! I have tried to run that and I got an event like the following:

{
  "process_kprobe": {
    "process": {
      "exec_id": "YXBhcGFnLXVidW50dS1kZXY6MjYwMzI3ODcyMDgwNzU0OjMzMDk3MA==",
      "pid": 330970,
      "uid": 1010,
      "cwd": "/home/test",
      "binary": "/usr/bin/chmod",
      "arguments": "0777 a.txt"",
      "flags": "execve clone",
      "start_time": "2024-03-15T08:35:25.447770357Z",
      "auid": 1010,
      "parent_exec_id": "YXBhcGFnLXVidW50dS1kZXY6MjU4NTYzOTcwMDAwMDAwOjI4Njc0MQ==",
      "refcnt": 1,
      "tid": 330970
    },
    "parent": {
      "exec_id": "YXBhcGFnLXVidW50dS1kZXY6MjU4NTYzOTcwMDAwMDAwOjI4Njc0MQ==",
      "pid": 286741,
      "uid": 1010,
      "cwd": "/home/test/tetragon",
      "binary": "/usr/bin/bash",
      "flags": "procFS auid",
      "start_time": "2024-03-15T08:06:01.545689544Z",
      "auid": 1010,
      "parent_exec_id": "YXBhcGFnLXVidW50dS1kZXY6MjU4NTYzODEwMDAwMDAwOjI4Njc0MA==",
      "tid": 286741
    },
    "function_name": "security_path_chmod",
    "args": [
      {
        "path_arg": {
          "path": "/home/test/a.txt",
          "permission": "-rw-rw-r--"
        }
      }
    ],
    "action": "KPROBE_ACTION_POST",
    "policy_name": "permission-test",
    "return_action": "KPROBE_ACTION_POST"
  },
  "node_name": "ubuntu-dev",
  "time": "2024-03-15T08:35:25.448337205Z"
}

and this is great!

On the other hand, it seems that some tests are failing. Maybe you can try to run make tests locally to check what exactly fails and try to fix that. Thanks!

@Jianlin-lv
Copy link
Author

Thanks for contributing to Tetragon! I have tried to run that and I got an event like the following:

{
  "process_kprobe": {
    "process": {
      "exec_id": "YXBhcGFnLXVidW50dS1kZXY6MjYwMzI3ODcyMDgwNzU0OjMzMDk3MA==",
      "pid": 330970,
      "uid": 1010,
      "cwd": "/home/test",
      "binary": "/usr/bin/chmod",
      "arguments": "0777 a.txt"",
      "flags": "execve clone",
      "start_time": "2024-03-15T08:35:25.447770357Z",
      "auid": 1010,
      "parent_exec_id": "YXBhcGFnLXVidW50dS1kZXY6MjU4NTYzOTcwMDAwMDAwOjI4Njc0MQ==",
      "refcnt": 1,
      "tid": 330970
    },
    "parent": {
      "exec_id": "YXBhcGFnLXVidW50dS1kZXY6MjU4NTYzOTcwMDAwMDAwOjI4Njc0MQ==",
      "pid": 286741,
      "uid": 1010,
      "cwd": "/home/test/tetragon",
      "binary": "/usr/bin/bash",
      "flags": "procFS auid",
      "start_time": "2024-03-15T08:06:01.545689544Z",
      "auid": 1010,
      "parent_exec_id": "YXBhcGFnLXVidW50dS1kZXY6MjU4NTYzODEwMDAwMDAwOjI4Njc0MA==",
      "tid": 286741
    },
    "function_name": "security_path_chmod",
    "args": [
      {
        "path_arg": {
          "path": "/home/test/a.txt",
          "permission": "-rw-rw-r--"
        }
      }
    ],
    "action": "KPROBE_ACTION_POST",
    "policy_name": "permission-test",
    "return_action": "KPROBE_ACTION_POST"
  },
  "node_name": "ubuntu-dev",
  "time": "2024-03-15T08:35:25.448337205Z"
}

and this is great!

On the other hand, it seems that some tests are failing. Maybe you can try to run make tests locally to check what exactly fails and try to fix that. Thanks!

hi , fixed test failed issue locally. How can I trigger checks on this PR?

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.

Thanks for taking the time to fix the tests. All seems fine now.

So at a high level you modify copy_path kernel function which is called when we have the following types:

In the users-space (in args.go) you handle the first three types but you miss the last one which is handled here. I believe that you have also to read mode there as well.

Furthermore, I have one more comment regarding the tracing policy types.

Let me know if any of these does not make sense. Thanks!

pkg/k8s/apis/cilium.io/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/k8s/apis/cilium.io/v1alpha1/version.go Outdated Show resolved Hide resolved
For the observed file/directory, add the associated permission and
output the complete file/directory permission information, consistent
with the format of 'ls -l'. Can be used in user space to further
filter/identify events based on specific file attributes.

Signed-off-by: Jianlin Lv <[email protected]>
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.

Thanks for taking the time to make the requested changes. This LGTM now!

@tpapagian tpapagian merged commit e1a758a into cilium:main Mar 20, 2024
42 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor This PR introduces a minor user-visible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants