You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-25Lines changed: 71 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,8 @@
9
9
10
10
# Jetstack Preflight
11
11
12
-
Preflight is a tool to automatically perform Kubernetes cluster configuration checks using [Open Policy Agent (OPA)](https://www.openpolicyagent.org/).
12
+
Preflight is a tool to automatically perform Kubernetes cluster
13
+
configuration checks using [Open Policy Agent (OPA)](https://www.openpolicyagent.org/).
13
14
14
15
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
15
16
**Table of Contents**
@@ -23,11 +24,9 @@ Preflight is a tool to automatically perform Kubernetes cluster configuration ch
23
24
24
25
<!-- markdown-toc end -->
25
26
26
-
27
27
## Background
28
28
29
-
Preflight was originally designed to automate Jetstack's
30
-
production readiness assessments.
29
+
Preflight was originally designed to automate Jetstack's production readiness assessments.
31
30
These are consulting sessions in which a Jetstack engineer inspects a customer's
32
31
cluster to suggest improvements and identify configuration issues.
33
32
The product of this assessment is a report
@@ -39,53 +38,100 @@ Automating the checks allows them to be more comprehensive and much faster.
39
38
40
39
The automation also allows the checks to be run repeatedly,
41
40
meaning they can be deployed in-cluster to provide continuous configuration checking.
42
-
43
41
This enables new interesting use cases as policy compliance audits.
44
42
43
+
## Preflight Application
44
+
45
+
The Preflight application uses *data gatherers*
46
+
to collect required data in JSON format.
47
+
Preflight then checks the gathered data against rules specified in
48
+
*Preflight packages* and outputs rule violations with relevant information.
49
+
50
+
Preflight is designed to run both locally for one-off checking,
51
+
and in-cluster to for continuous checking.
52
+
45
53
## Preflight Packages
46
54
47
-
Policies for cluster configuration are encoded into "Preflight Packages".
55
+
Policies for cluster configuration are encoded into *Preflight packages*.
56
+
You can find some examples in [./preflight-packages](./preflight-packages).
48
57
49
-
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).
58
+
Each package focuses on a different aspect of the cluster.
59
+
For example, the [`gke_basic`](preflight-packages/examples.jetstack.io/gke_basic)
60
+
package provides rules for the configuration of a GKE cluster,
61
+
and the [`pods`](preflight-packages/jetstack.io/pods) package
62
+
provides rules for the configuration of Kubernetes Pods.
50
63
51
-
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*.
64
+
A Preflight package consists of a *Policy Manifest* and a
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.
67
+
The *Policy Manifest* is a YAML file that specifies a package's rules.
68
+
It gives descriptions of the rules and remeditation advice,
69
+
so the tool can display useful information when a rule doesn't pass.
54
70
55
-
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/)).
71
+
Rego is OPA's high-level declarative language for specifying rules.
72
+
Rego rules can be defined in multiples files grouped into logical Rego packages.
56
73
57
-
Additionally, Preflight has a built-in linter for packages:
74
+
Anyone can create new Preflight packages to perform their own checks.
75
+
The Preflight docs include a guide on [how to write packages](./docs/how_to_write_packages.md).
which include a binary and all the *packages* in this repo,
85
+
can be downloaded from the [releases page](https://github.com/jetstack/preflight/releases).
64
86
65
-
### Use Preflight locally
87
+
### Build
66
88
67
-
You can compile Preflight by running `make build`. It will create the binary in `builds/preflight`.
89
+
You can compile Preflight by running `make build`.
90
+
It will create the binary in `builds/preflight`.
68
91
69
-
Create your `preflight.yaml` configuration file (you can take inspiration from the ones in `./examples`).
92
+
## Use Preflight
70
93
71
-
Run Preflight (by default it looks for `./preflight.yaml`)
94
+
Create your `preflight.yaml` configuration file.
95
+
There is full [configuration documentation](./docs/configuration.md) available,
96
+
as well as several example files in [`./examples`](./examples).
97
+
98
+
### Use Preflight Locally
99
+
100
+
By default Preflight looks for a configuration at `./preflight.yaml`.
101
+
Once this is set up, run a Preflight check like so:
72
102
73
103
```
74
104
preflight check
75
105
```
76
106
77
-
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.
You will see a CLI formatted report if everything goes well. Also, you will get a JSON report in `./output`.
117
+
You will see a CLI formatted report if everything goes well.
118
+
Also, you will get a JSON report in `./output`.
119
+
120
+
## Use Preflight Web UI
84
121
85
-
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.**
122
+
If you want to visualise the report in your browser,
123
+
you can access the [*Preflight Web UI*](https://preflight.jetstack.io/)
124
+
and load the JSON report.
125
+
**This is a static website.**
126
+
**Your report is not being uploaded to any server.**
127
+
**Everything happens in your browser.**
86
128
87
-
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/).
129
+
You can give it a try without even running the tool,
130
+
since we provide some report examples, [gke.json](./examples/reports/gke.json),
131
+
and [pods.json](./examples/reports/pods.json),
132
+
ready to be loaded into the [*Preflight Web UI*](https://preflight.jetstack.io/).
88
133
89
-
### Preflight In-Cluster with periodic checks
134
+
### Use Preflight In-Cluster
90
135
91
-
See [Installation Manual: Preflight In-Cluster](./docs/installation_manual_in_cluster.md).
136
+
Preflight can be installed in-cluster to run continuous checks.
137
+
See the [Installation Manual: Preflight In-Cluster](./docs/installation_manual_in_cluster.md).
It pulls information about one cluster from the GKE API.
4
-
5
-
## Configuration
6
-
7
-
[Here](../../examples/gke.preflight.yaml) you have a sample configuration file setting up the GKE data gatherer.
8
-
9
-
You have to set these parameters in the configuration:
10
-
11
-
-**project:** the ID of your Google Cloud Platform project.
12
-
-**location:** the compute zone or region where your cluster is running.
13
-
-**cluster:** the name of your GKE cluster.
14
-
-**credentials***optional***:** path to a file containing valid credentials for your cluster. Useful if you want to configure a separate service account. If not specified, it will attept to use Workload Identity. If you run Preflight locally on your machine, you can just run `gcloud auth application-default login`
3
+
The GKE *data gatherer* fetches information about a cluster
4
+
from the Google Kubernetes Engine API.
15
5
16
6
## Data
17
7
18
-
The output of the GKE data gatherer follows this format:
8
+
The output of the GKE data gatherer follows the format described in the
9
+
[GKE API reference](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#Cluster)
10
+
and the [Go Docs](https://godoc.org/google.golang.org/api/container/v1#Cluster).
11
+
These are useful to check when writing new rules.
12
+
13
+
The gathered data looks like this:
19
14
20
15
```json
21
16
{
22
17
"Cluster": {...}
23
18
}
24
19
```
25
20
26
-
The `Cluster` property is a JSON representation of [google.golang.org/api/container/v1#Cluster](https://godoc.org/google.golang.org/api/container/v1#Cluster).
21
+
## Configuration
22
+
23
+
To use the GKE *data gatherer* add a `gke` section to the
24
+
`data-gatherers` configuration.
25
+
For example:
26
+
27
+
```
28
+
...
29
+
data-gatherers:
30
+
gke:
31
+
project: my-gcp-project
32
+
location: us-central1-a
33
+
cluster: my-gke-cluster
34
+
# Path to a file containing the credentials. If empty, it will try to use Workload Identity (run `gcloud auth application-default login`).
35
+
# credentials: /tmp/credentials.json
36
+
...
37
+
```
38
+
39
+
The `gke` configuration contains the following fields:
40
+
41
+
-`project`: The ID of your Google Cloud Platform project.
42
+
-`location`: The compute zone or region where your cluster is running.
43
+
-`cluster`: The name of your GKE cluster.
44
+
-`credentials`: *optional* The path to a file containing credentials for your cluster.
0 commit comments