|
1 | | -# preflight |
2 | | -Automatically perform Kubernetes cluster configuration checks using Open Policy Agent (OPA) |
| 1 | +# Jetstack Preflight |
| 2 | + |
| 3 | +Preflight is a tool to automatically perform Kubernetes cluster configuration checks using [Open Policy Agent (OPA)](https://www.openpolicyagent.org/). |
| 4 | + |
| 5 | +<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --> |
| 6 | +**Table of Contents** |
| 7 | + |
| 8 | +- [Jetstack Preflight](#jetstack-preflight) |
| 9 | + - [Background](#background) |
| 10 | + - [Preflight Packages](#preflight-packages) |
| 11 | + - [Install Preflight](#install-preflight) |
| 12 | + - [Use Preflight locally](#use-preflight-locally) |
| 13 | + - [Get periodic reports by running Preflight as a CronJob](#get-periodic-reports-by-running-preflight-as-a-cronjob) |
| 14 | + |
| 15 | +<!-- markdown-toc end --> |
| 16 | + |
| 17 | + |
| 18 | +## Background |
| 19 | + |
| 20 | +Preflight was originally designed to automate Jetstack's |
| 21 | +production readiness assessments. |
| 22 | +These are consulting sessions in which a Jetstack engineer inspects a customer's |
| 23 | +cluster to suggest improvements and identify configuration issues. |
| 24 | +The product of this assessment is a report |
| 25 | +which describes any problems and offers remediation advice. |
| 26 | + |
| 27 | +While these assessments have provided a lot of value to many customers, |
| 28 | +with a complex system like Kubernetes it's hard to thoroughly check everything. |
| 29 | +Automating the checks allows them to be more comprehensive and much faster. |
| 30 | + |
| 31 | +The automation also allows the checks to be run repeatedly, |
| 32 | +meaning they can be deployed in-cluster to provide continuous configuration checking. |
| 33 | + |
| 34 | +This enables new interesting use cases as policy compliance audits. |
| 35 | + |
| 36 | +## Preflight Packages |
| 37 | + |
| 38 | +Policies for cluster configuration are encoded into "Preflight Packages". |
| 39 | + |
| 40 | +You can find some examples in [./preflight-packages](./preflight-packages) and you can also [write your own Preflight Packages](./docs/how_to_write_packages.md). |
| 41 | + |
| 42 | +Preflight Packages are a very thin wrapper around OPA's policies. A package is made of [Rego](https://www.openpolicyagent.org/docs/latest/#rego) files (OPA's high-level declarative language) and a *Policy Manifest*. |
| 43 | + |
| 44 | +The *Policy Manifest* is a YAML file intended to add metadata to the rules, so the tool can display useful information when a rule doesn't pass. |
| 45 | + |
| 46 | +Since the logic in these packages is just Rego, you can add tests to your policies and use OPA's command line to run them (see [OPA Policy Testing tutorial](https://www.openpolicyagent.org/docs/latest/policy-testing/)). |
| 47 | + |
| 48 | +Additionally, Preflight has a built-in linter for packages: |
| 49 | + |
| 50 | +``` |
| 51 | +preflight package lint <path to package> |
| 52 | +``` |
| 53 | + |
| 54 | +## Install Preflight |
| 55 | + |
| 56 | +You can compile Preflight by running `make build`. It will create the binary in `builds/preflight`. |
| 57 | + |
| 58 | + |
| 59 | +## Use Preflight locally |
| 60 | + |
| 61 | +Create your `preflight.yaml` configuration file (you can take inspiration from the ones in `./examples`). |
| 62 | + |
| 63 | +Run Preflight (by default it looks for `./preflight.yaml`) |
| 64 | + |
| 65 | +``` |
| 66 | +preflight check |
| 67 | +``` |
| 68 | + |
| 69 | +You can try `./examples/pods.preflight.yaml` without having to change a line, if you have your *kubeconfig* (~/.kube/config) pointing to a working cluster. |
| 70 | + |
| 71 | +``` |
| 72 | +preflight check --config-file=./examples/pods.preflight.yaml |
| 73 | +``` |
| 74 | + |
| 75 | +You will see a CLI formatted report if everything goes well. Also, you will get a JSON report in `./output`. |
| 76 | + |
| 77 | +If you want to visualice the report in your browser, you can access [preflight.jetstack.io](https://preflight.jetstack.io/) and load the JSON report. **This is a static website. Your report is not being uploaded to any server. Everything happens in your browser.** |
| 78 | + |
| 79 | +You can give it a try without even running the tool, since we provide some report examples ([gke.json](./examples/reports/gke.json), [pods.json](./examples/reports/pods.json)) ready to be loaded in [preflight.jetstack.io](https://preflight.jetstack.io/). |
| 80 | + |
| 81 | +## Get periodic reports by running Preflight as a CronJob |
| 82 | + |
| 83 | +See [Run Preflight In-Cluster](./docs/preflight-in-cluster.md). |
0 commit comments