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 update: modify rule to detect connection to K8S API Server from a container #952

Merged
merged 1 commit into from
Dec 5, 2019
Merged

rule update: modify rule to detect connection to K8S API Server from a container #952

merged 1 commit into from
Dec 5, 2019

Conversation

rung
Copy link
Contributor

@rung rung commented Dec 4, 2019

Signed-off-by: Hiroki Suezawa suezawa@gmail.com

What type of PR is this?
/kind rule-update

Any specific area of the project related to this PR?
/area rules

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

  • Pod can access to K8S API using private ip address, so I stopped using "outbound" macro.
  • K8S API might have global IP address too. but this rule detects connection to "kubernetes.default.svc.cluster.local" only.
    • "kubernetes.default.svc.cluster.local" is a name to Kubernetes API
    Pods can use the kubernetes.default.svc hostname to query the API server
    

Procedure and Trigger

  1. Start a container
  2. Connect K8S API (Trigger)
curl -k https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/

Does this PR introduce a user-facing change?:
NONE

rules(Contact K8S API Server From Container): now it can automatically resolve the cluster IP address 
rule(macro k8s_api_server): new macro to match the default k8s api server

…a container

Signed-off-by: Hiroki Suezawa <suezawa@gmail.com>
@Kaizhe
Copy link
Contributor

Kaizhe commented Dec 4, 2019

@rung can you post the output here as well with your changes?

@rung
Copy link
Contributor Author

rung commented Dec 4, 2019

@Kaizhe
This is output of this rule.
I didn't change output. I changed rule and macro's condition.

Output sample

{"output":"05:35:37.855410748: Notice Unexpected connection to K8s API Server from container (command=curl -k https://10.70.0.1:443/api/ k8s.ns=default k8s.pod=ubuntu-9f765598b-jxwcd container=577c694601c8 image=ubuntu:latest connection=10.4.2.21:59880->10.70.0.1:443) k8s.ns=default k8s.pod=ubuntu-9f765598b-jxwcd container=577c694601c8 k8s.ns=default k8s.pod=ubuntu-9f765598b-jxwcd container=577c694601c8","priority":"Notice","rule":"Contact K8S API Server From Container","time":"2019-12-04T05:35:37.855410748Z", "output_fields": {"container.id":"577c694601c8","container.image.repository":"ubuntu","container.image.tag":"latest","evt.time":1575437737855410748,"fd.name":"10.4.2.21:59880->10.70.0.1:443","k8s.ns.name":"default","k8s.pod.name":"ubuntu-9f765598b-jxwcd","proc.cmdline":"curl -k https://10.70.0.1:443/api/"}}

@Kaizhe
Copy link
Contributor

Kaizhe commented Dec 4, 2019

/lgtm

@poiana
Copy link
Contributor

poiana commented Dec 4, 2019

LGTM label has been added.

Git tree hash: 76c6c5d75e321f2f49c0f64fd9cf5bd6b6578c7f

@poiana poiana added the approved label Dec 4, 2019
@leodido
Copy link
Member

leodido commented Dec 4, 2019

/milestone 0.19.0

@poiana poiana added this to the 0.19.0 milestone Dec 4, 2019
@poiana
Copy link
Contributor

poiana commented Dec 5, 2019

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fntlnz, Kaizhe

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

@fntlnz
Copy link
Contributor

fntlnz commented Dec 5, 2019

Thanks again @rung ! Good job as always!

@fntlnz fntlnz merged commit fc58ac7 into falcosecurity:dev Dec 5, 2019
@rung rung deleted the modify-rule-k8s-api branch December 5, 2019 11:48
@djsly
Copy link

djsly commented Mar 6, 2020

Quick question, can we have a documentation on how we should add a list of pods that are allowed to talk to the API Server ?

we are getting > 50k alerts per 6 hours... where most of the communication are normal.

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.

6 participants