gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/g3doc/user_guide/tutorials/falco.md (about)

     1  # Configuring Falco with gVisor
     2  
     3  [TOC]
     4  
     5  ## Installation
     6  
     7  This section explains the steps required to install Falco+gVisor integration
     8  depending your environment.
     9  
    10  ### Docker
    11  
    12  First, install [gVisor](/docs/user_guide/install/) and
    13  [Falco](https://falco.org/docs/getting-started/installation/) on the machine.
    14  Run `runsc --version` and check that `runsc version release-20220704.0` or newer
    15  is reported. Run `falco --version` and check that `Falco version` reports
    16  `0.33.1` or higher.
    17  
    18  Once both are installed, you can configure gVisor to connect to Falco whenever a
    19  new sandbox is started. The first command below generates a configuration file
    20  containing a list of trace points that Falco is interested in receiving. This
    21  file is passed to gVisor during container startup so that gVisor connects to
    22  Falco *before* the application starts. The second command installs runsc as a
    23  Docker runtime pointing it to the configuration file we just generated:
    24  
    25  ```shell
    26  falco --gvisor-generate-config | sudo tee /etc/falco/pod-init.json
    27  sudo runsc install --runtime=runsc-falco -- --pod-init-config=/etc/falco/pod-init.json
    28  sudo systemctl restart docker
    29  ```
    30  
    31  gVisor is now configured. Next, let's start Falco and tell it to enable gVisor
    32  monitoring. You should use the same command line that you normally use to start
    33  Falco with these additional flags:
    34  
    35  -   `--gvisor-config`: path to the gVisor configuration file, in our case
    36      `/etc/falco/pod-init.json`.
    37  -   `--gvisor-root`: path to the `--root` flag that docker uses with gVisor,
    38      normally: `/var/run/docker/runtime-runc/moby`.
    39  
    40  For our example, let's just start with the default settings and rules:
    41  
    42  ```shell
    43  sudo falco \
    44    -c /etc/falco/falco.yaml \
    45    --gvisor-config /etc/falco/pod-init.json \
    46    --gvisor-root /var/run/docker/runtime-runc/moby
    47  ```
    48  
    49  > **Note:** If you get `Error: Cannot find runsc binary`, make sure `runsc` is
    50  > in the `PATH`.
    51  
    52  From this point on, every time a gVisor sandbox starts, it connects to Falco to
    53  send trace points occurring inside the container. Those are translated into
    54  Falco events that are processed by the rules you have defined. If you used the
    55  command above, the configuration files are defined in
    56  `/etc/falco/faco_rules.yaml` and `/etc/falco/faco_rules.local.yaml` (where you
    57  can add your own rules).
    58  
    59  ### Kubernetes
    60  
    61  If you are using Kubernetes, the steps above must be done on every node that has
    62  gVisor enabled. Luckily, this can be done for you automatically using
    63  [Falco's Helm chart](https://github.com/falcosecurity/charts/blob/master/falco/README.md).
    64  You can find more details, like available options, in the
    65  [*About gVisor*](https://github.com/falcosecurity/charts/blob/master/falco/README.md#about-gvisor)
    66  section.
    67  
    68  Here is a quick example using
    69  [GKE Sandbox](https://cloud.google.com/kubernetes-engine/docs/concepts/sandbox-pods),
    70  which already pre-configures gVisor for you. You can use any version that is
    71  equal or higher than 1.24.4-gke.1800:
    72  
    73  ```shell
    74  gcloud container clusters create my-cluster --release-channel=rapid --cluster-version=1.25
    75  gcloud container node-pools create gvisor --sandbox=type=gvisor --cluster=my-cluster
    76  gcloud container clusters get-credentials my-cluster
    77  helm install falco-gvisor falcosecurity/falco \
    78    -f https://raw.githubusercontent.com/falcosecurity/charts/master/falco/values-gvisor-gke.yaml \
    79    --namespace falco-gvisor --create-namespace
    80  ```
    81  
    82  ## Triggering Falco Events
    83  
    84  Let's run something interesting inside a container to see a few rules trigger in
    85  Falco. Package managers, like `apt`, don't normally run inside containers in
    86  production, and often indicate that an attacker is trying to install tools to
    87  expose the container. To detect such cases, the default set of rules trigger an
    88  `Error` event when the package manager is invoked. Let's see it in action, first
    89  start a container and run a simple `apt` command:
    90  
    91  ```shell
    92  sudo docker run --rm --runtime=runsc-falco -ti ubuntu
    93  $ apt update
    94  ```
    95  
    96  In the terminal where falco is running, you should see in the output many `Error
    97  Package management process launched` events. Here is one of the events informing
    98  that a package manager was invoked inside the container:
    99  
   100  ```json
   101  {
   102    "output": "18:39:27.542112944: Error Package management process launched in container (user=root user_loginuid=0 command=apt apt update container_id=1473cfd51410 container_name=sad_wu image=ubuntu:latest) container=1473cfd51410 pid=4 tid=4",
   103    "priority": "Error",
   104    "rule": "Launch Package Management Process in Container",
   105    "source": "syscall",
   106    "tags": [
   107      "mitre_persistence",
   108      "process"
   109    ],
   110    "time": "2022-08-02T18:39:27.542112944Z",
   111    "output_fields": {
   112      "container.id": "1473cfd51410",
   113      "container.image.repository": "ubuntu",
   114      "container.image.tag": "latest",
   115      "container.name": "sad_wu",
   116      "evt.time": 1659465567542113000,
   117      "proc.cmdline": "apt apt update",
   118      "proc.vpid": 4,
   119      "thread.vtid": 4,
   120      "user.loginuid": 0,
   121      "user.name": "root"
   122    }
   123  }
   124  ```
   125  
   126  As you can see, it's warning that `apt update` command was ran inside container
   127  `sad_wu`, and gives more information about the user, TID, image name, etc. There
   128  are also rules that trigger when there is a write under `/` and other system
   129  directories that are normally part of the image and shouldn't be changed. If we
   130  proceed with installing packages into the container, apart from the event above,
   131  there are a few other events that are triggered. Let's execute `apt-get install
   132  -y netcat` and look at the output:
   133  
   134  ```json
   135  {
   136    "output": "18:40:42.192811725: Warning Sensitive file opened for reading by non-trusted program (user=root user_loginuid=0 program=dpkg-preconfigure command=dpkg-preconfigure /usr/sbin/dpkg-preconfigure --apt file=/etc/shadow parent=sh gparent=<NA> ggparent=<NA> gggparent=<NA> container_id=1473cfd51410 image=ubuntu) container=1473cfd51410 pid=213 tid=213",
   137    "priority": "Warning",
   138    "rule": "Read sensitive file untrusted",
   139    "source": "syscall",
   140    "tags": [
   141      "filesystem",
   142      "mitre_credential_access",
   143      "mitre_discovery"
   144    ],
   145  }
   146  
   147  {
   148    "output": "18:40:42.494933664: Error File below / or /root opened for writing (user=root user_loginuid=0 command=tar tar -x -f - --warning=no-timestamp parent=dpkg-deb file=md5sums program=tar container_id=1473cfd51410 image=ubuntu) container=1473cfd51410 pid=221 tid=221",
   149    "priority": "Error",
   150    "rule": "Write below root",
   151    "source": "syscall",
   152    "tags": [
   153      "filesystem",
   154      "mitre_persistence"
   155    ],
   156  }
   157  ```
   158  
   159  The first event is raised as a `Warning` when `/etc/shadow` is open by the
   160  package manager to inform that a sensitive file has been open for read. The
   161  second one triggers an `Error` when the package manager tries to untar a file
   162  under the root directory. None of these actions are expected from a webserver
   163  that is operating normally and should raise security alerts.
   164  
   165  You can also install
   166  [falcosidekick](https://github.com/falcosecurity/falcosidekick) and
   167  [falcosidekick-ui](https://github.com/falcosecurity/falcosidekick-ui) for better
   168  ways to visualize the events.
   169  
   170  Now you can configure the rules and run your containers using gVisor and Falco.