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

rule(k8s): secret get detection for both successful and unsuccessful attempts #1949

Merged
merged 1 commit into from
Apr 28, 2022

Conversation

Dentrax
Copy link
Contributor

@Dentrax Dentrax commented Mar 19, 2022

Signed-off-by: Furkan [email protected]

Success case: (ERROR)

{"priority":"Error","rule":"K8s Secret Get Successfully","source":"k8s_audit","tags":["k8s"],"time":"2022-03-19T20:00:07.793262080Z", "output_fields": {"jevt.time":"20:00:07.793262080","ka.auth.decision":"allow","ka.auth.reason":"","ka.response.code":"200","ka.target.name":"falco-token-xdkwt","ka.target.namespace":"security","ka.user.name":"kubernetes-admin"}}

Fail case: (WARNING):

  1. Get developer token from kube-system
DEVELOPER_TOKEN=$(kubectl get secrets -n kube-system $(kubectl get serviceaccounts developer -n kube-system -o json \
  | jq -r '.secrets[0].name') -o json \
  | jq -r '.data.token' \
  | base64 -D)
  1. Edit your kubeconfig:
users:
- name: developer
  user:
    token: $DEVELOPER_TOKEN
  1. Test:
$ KUBECONFIG=1poc.yaml k get secrets falco-token-xdkwt

Error from server (Forbidden): secrets "falco-token-xdkwt" is forbidden: User "system:serviceaccount:kube-system:developer" cannot get resource "secrets" in API group "" in the namespace "security"
{"priority":"Warning","rule":"K8s Secret Get Unsuccessfully Tried","source":"k8s_audit","tags":["k8s"],"time":"2022-03-19T20:41:16.571718912Z", "output_fields": {"jevt.time":"20:41:16.571718912","ka.auth.decision":"forbid","ka.auth.reason":"","ka.response.code":"403","ka.target.name":"falco-token-xdkwt","ka.target.namespace":"security","ka.user.name":"system:serviceaccount:kube-system:developer"}}

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

If contributing rules or changes to rules, please make sure to also uncomment one of the following line:

/kind rule-update

/kind rule-create

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area build

/area engine

/area rules

/area tests

/area proposals

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

I don't add non_system_user condition because in general practice, cluster admins deploys cluster role (i.e., with restricted role) into kube-system namespace. Which would ended up false-negative. I think we should remove this condition in both secret create and delete rules.

Does this PR introduce a user-facing change?:

NONE

rule(k8s: secret): detect `get` attempts for both successful and unsuccessful attempts

@poiana
Copy link
Contributor

poiana commented Mar 19, 2022

Welcome @Dentrax! It looks like this is your first PR to falcosecurity/falco 🎉

@poiana poiana added the size/S label Mar 19, 2022
@Dentrax Dentrax changed the title update(rules): k8s: secret get detection rule(k8s): secret get detection for both successful and unsuccessful attempts Mar 19, 2022
@jasondellaluce
Copy link
Contributor

/milestone 0.32.0

@poiana poiana added this to the 0.32.0 milestone Mar 24, 2022
@Kaizhe
Copy link
Contributor

Kaizhe commented Mar 25, 2022

@Dentrax , thank you for your contribution. There are already audit like k8s Falco rules. We need to be careful not to turn Falco into a k8s auditing tool.

@poiana
Copy link
Contributor

poiana commented Mar 25, 2022

LGTM label has been added.

Git tree hash: 79a51c94156764c8a7fd7998e3604427deec575b

Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Apr 28, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Dentrax, leogr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit 990a8fd into falcosecurity:master Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants