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

policylibrary: consolidate privileges raising operations into privileges-raise.yaml single policy #1957

Merged
merged 8 commits into from
Feb 5, 2024

Conversation

tixxdz
Copy link
Member

@tixxdz tixxdz commented Jan 10, 2024

This adds kernel capability types (uint64) and consolidates some operations into single privileges-raise.yaml Tracing Policy.

Produced kprobe event:

        ...
        "function_name": "security_capset",
        "args": [
          {
            "process_credentials_arg": {
          {
            "cap_effective_arg": "000001ffffffffff"
          },
          {
            "cap_inheritable_arg": "0000000000000000"
          },
          {
            "cap_permitted_arg": "000001ffffffffff"
          }
        ],
        "return": {
          "int_arg": 0
        },
        "action": "KPROBE_ACTION_POST",
        "policy_name": "privileges-raise",
        "return_action": "KPROBE_ACTION_POST",
        "message": "Process changed its capabilities using capset system call",

For further details, please see patches. Doc use case will follow later.

@tixxdz tixxdz requested review from mtardy and a team as code owners January 10, 2024 13:54
@tixxdz tixxdz marked this pull request as draft January 10, 2024 13:55
@tixxdz tixxdz added the release-note/minor This PR introduces a minor user-visible change label Jan 10, 2024
Copy link

netlify bot commented Jan 10, 2024

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 6b6b309
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/65c01d5592e78400072a6707
😎 Deploy Preview https://deploy-preview-1957--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.

@tixxdz tixxdz force-pushed the pr/tixxdz/privileges-raise-by-userns branch from 2769e72 to 819c515 Compare January 20, 2024 00:02
@tixxdz tixxdz marked this pull request as ready for review January 20, 2024 00:02
@tixxdz tixxdz force-pushed the pr/tixxdz/privileges-raise-by-userns branch 2 times, most recently from 3b77982 to 3fff5d2 Compare January 22, 2024 12:57
pkg/reader/caps/caps.go Fixed Show fixed Hide fixed
@tixxdz
Copy link
Member Author

tixxdz commented Jan 23, 2024

as requested by @jrfastab tags are in their own PR #2008

@@ -1561,6 +1561,62 @@ func handleMsgGenericKprobe(m *api.MsgGenericKprobe, gk *genericKprobe, r *bytes
}
arg.Label = a.label
unix.Args = append(unix.Args, arg)
case gt.GenericKernelCap:
var output uint64
var arg api.MsgGenericKprobeArgKernelCapType
Copy link
Contributor

Choose a reason for hiding this comment

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

the push 64-bit arg is a bit redundant it would be nice if we could extract that somehow to a helper. But I think the typing is a bit awkward in golang/here for that to work.

@jrfastab
Copy link
Contributor

needs a rebase but otherwise lgtm.

case kernel_cap_ty:
case cap_inh_ty:
case cap_prm_ty:
case cap_eff_ty:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a different type from the bpf side, can we just treat it as u64?

Copy link
Member Author

Choose a reason for hiding this comment

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

But how we will be able to remap it into userspace to one of these?

  "kernel_cap_arg": "00ff..."
  "cap_effective_arg:" "00ff..."

so you pretty print which caps we are talking about effective, permitted etc

If there is a better solution I will convert to it

This adds 'privileges-raise' tracing policy that will include most
operations that will raise privileges.

We could rename privileges-setuid-root.yaml and add on top of it,
but it seems there are users that started to reference and use that
one, so let's be nice add new one to not break their links, also
things are still in example directory.

We definitly need a better plan in the future like how to organize
tracing policies into directories and how to name the files.

Signed-off-by: Djalal Harouni <[email protected]>
kernel_cap_t: default type in kernel for uint64 caps
cap_inheritable: for inheritable capabilities
cap_permitted: for permitted set
cap_effective: for the current effective set.

Signed-off-by: Djalal Harouni <[email protected]>
Internally kernel handles capabilities as uint64 in kernel_cap_t,
so let's add the corresponding capabilities types in order to
use them in calls like security_capset.

The aim is to print the arguments in hex.

Signed-off-by: Djalal Harouni <[email protected]>
Support kernel_cap_t uint64 capabilities. Usually these are the
ones passed to capset() to security_capset().

Signed-off-by: Djalal Harouni <[email protected]>
Produced event:
    ...
    "function_name": "security_capset",
    "args": [
      {
        "process_credentials_arg": {
      {
        "cap_effective_arg": "000001ffffffffff"
      },
      {
        "cap_inheritable_arg": "0000000000000000"
      },
      {
        "cap_permitted_arg": "000001ffffffffff"
      }
    ],
    "return": {
      "int_arg": 0
    },
    "action": "KPROBE_ACTION_POST",
    "policy_name": "privileges-raise",
    "return_action": "KPROBE_ACTION_POST",
    "message": "Process changed its capabilities using capset system call"

Signed-off-by: Djalal Harouni <[email protected]>
Signed-off-by: Djalal Harouni <[email protected]>
@tixxdz tixxdz force-pushed the pr/tixxdz/privileges-raise-by-userns branch from 0f74264 to 6b6b309 Compare February 4, 2024 23:27
@tixxdz
Copy link
Member Author

tixxdz commented Feb 5, 2024

ci failure about validate crd is tracked here: #2063. The version is updated so merging.

@tixxdz tixxdz merged commit 9bfc12c into main Feb 5, 2024
43 of 44 checks passed
@tixxdz tixxdz deleted the pr/tixxdz/privileges-raise-by-userns branch February 5, 2024 08:34
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