Skip to content

Commit 433f53c

Browse files
wwwiljetstack-bot
authored andcommitted
Update docs and README, add additional info (#57)
Signed-off-by: wwwil <[email protected]>
1 parent a6e1df3 commit 433f53c

File tree

4 files changed

+285
-48
lines changed

4 files changed

+285
-48
lines changed

README.md

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
# Jetstack Preflight
1111

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/).
1314

1415
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
1516
**Table of Contents**
@@ -23,11 +24,9 @@ Preflight is a tool to automatically perform Kubernetes cluster configuration ch
2324

2425
<!-- markdown-toc end -->
2526

26-
2727
## Background
2828

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.
3130
These are consulting sessions in which a Jetstack engineer inspects a customer's
3231
cluster to suggest improvements and identify configuration issues.
3332
The product of this assessment is a report
@@ -39,53 +38,100 @@ Automating the checks allows them to be more comprehensive and much faster.
3938

4039
The automation also allows the checks to be run repeatedly,
4140
meaning they can be deployed in-cluster to provide continuous configuration checking.
42-
4341
This enables new interesting use cases as policy compliance audits.
4442

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+
4553
## Preflight Packages
4654

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).
4857

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.
5063

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
65+
[Rego](https://www.openpolicyagent.org/docs/latest/#rego) package.
5266

53-
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.
5470

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.
5673

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).
5876

59-
```
60-
preflight package lint <path to package>
61-
```
77+
![Preflight package structure diagram](./docs/images/preflight_package.png)
78+
79+
## Get Preflight
80+
81+
### Download
6282

63-
## Install Preflight
83+
Preflight binaries and *bundles*,
84+
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).
6486

65-
### Use Preflight locally
87+
### Build
6688

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`.
6891

69-
Create your `preflight.yaml` configuration file (you can take inspiration from the ones in `./examples`).
92+
## Use Preflight
7093

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:
72102

73103
```
74104
preflight check
75105
```
76106

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.
107+
You can try the Pods example
108+
[`./examples/pods.preflight.yaml`](./examples/pods.preflight.yaml)
109+
without having to change a line,
110+
if you have your *kubeconfig* is located at `~/.kube/config` and
111+
is pointing to a working cluster.
78112

79113
```
80114
preflight check --config-file=./examples/pods.preflight.yaml
81115
```
82116

83-
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
84121

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.**
86128

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/).
88133

89-
### Preflight In-Cluster with periodic checks
134+
### Use Preflight In-Cluster
90135

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).

docs/configuration.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Preflight Configuration
2+
3+
Configuration is provided to the Preflight application using a YAML file.
4+
This specifies what packages to use, how data gatherers are configured,
5+
and what outputs to produce.
6+
7+
Several example configuration files can be found in [`examples`](./examples).
8+
9+
## Cluster Name
10+
11+
The `cluster-name` field is used as the 'directory' prefix for output.
12+
The value shouldn't contain spaces or `/`.
13+
For example:
14+
15+
```
16+
cluster-name: my-cluster
17+
```
18+
19+
## Data Gatherers
20+
21+
Data gatherers are specified under the `data-gatherers` field.
22+
For example:
23+
24+
```
25+
data-gatherers:
26+
gke:
27+
project: my-gcp-project
28+
location: us-central1-a
29+
cluster: my-cluster
30+
credentials: /tmp/credentials.json
31+
k8s/pods:
32+
kubeconfig: ~/.kube/config
33+
```
34+
35+
Each data gatherer has it's own configuration requirements,
36+
which are documented separately.
37+
38+
The following data gatherers are available:
39+
40+
- [Kubernetes Pods](docs/datagatherers/k8s_pods.md)
41+
- [Google Kubernetes Engine](docs/datagatherers/gke.md)
42+
- [Amazon Elastic Kubernetes Service](docs/datagatherers/eks.md)
43+
- [Microsoft Azure Kubernetes Service](docs/datagatherers/aks.md)
44+
45+
# Package Sources
46+
47+
The `package-sources` field is a list of locations
48+
which Preflight should load packages from.
49+
For example:
50+
51+
```
52+
package-sources:
53+
- type: local
54+
dir: ./preflight-packages/
55+
- type: local
56+
dir: /home/user/other-preflight-packages
57+
```
58+
59+
Each source must a `type`, though currently the only valid type is `local`.
60+
Local sources must then specify a directory
61+
for Preflight to look for packages in using the `dir` field.
62+
Preflight will search for packages in this directory recursively.
63+
64+
In future other source types may be added,
65+
for example to load packages in GCS buckets.
66+
67+
# Enabled Packages
68+
69+
The `enabled-packages` field is a list of packages that Preflight should use.
70+
For example:
71+
72+
```
73+
enabled-packages:
74+
- "examples.jetstack.io/gke_basic"
75+
- "jetstack.io/pods"
76+
```
77+
78+
This allows `package-sources` to be large collections of packages,
79+
only some of which will be run depending on user configuration.
80+
81+
## Outputs
82+
83+
The `outputs` field is a list of output formats and locations that Preflight
84+
will write data to. Multiple outputs can be specified,
85+
each with their own settings.
86+
87+
```
88+
outputs:
89+
- type: local
90+
path: ./output
91+
format: json
92+
- type: local
93+
path: ./output
94+
format: intermediate
95+
- type: cli
96+
```
97+
98+
Possible types of output include:
99+
- `local` for a local file.
100+
- `gcs` for a Google Cloud Storage bucket.
101+
- `cli` for command line output.
102+
103+
Most types also require a `format` to be specified.
104+
Possible formats are:
105+
- `json` for raw JSON output.
106+
- `markdown` for a markdown formatted report.
107+
- `html` for a HTML formatted report.
108+
- `intermediate` to output the raw JSON fetched by the *data gatherers*.
109+
110+
With the `cli` type output the format is optional
111+
and defaults to the `cli` format, for a coloured CLI formatted report.
112+
113+
The reports in `markdown`, `html` and `cli` format make use of the
114+
*policy manifest* to produce a human readable report describing
115+
which checks passed and which failed.
116+
The `json` format is raw output from OPA evaluation.
117+
118+
If no `outputs` are specified Preflight will output a report
119+
of the results to the CLI.

docs/datagatherers/gke.md

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,72 @@
1-
# GKE data gatherer
1+
# GKE Data Gatherer
22

3-
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.
155

166
## Data
177

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:
1914

2015
```json
2116
{
2217
"Cluster": {...}
2318
}
2419
```
2520

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.
45+
46+
An example configuration can be found at
47+
[`./examples/gke.preflight.yaml`](./examples/gke.preflight.yaml).
48+
49+
## Permissions
50+
51+
If a `credentials` file is not specified,
52+
Preflight will attempt to use Workload Identity or Application Default Credentials.
53+
54+
If Preflight is running locally
55+
and the `gcloud` command is installed and configured,
56+
just run `gcloud auth application-default login` to set up
57+
Application Default Credentials.
58+
59+
The `credentials` file is useful if you want to configure
60+
a separate service account for Preflight to use to fetch GKE data.
61+
62+
Whatever user or service account is used must have the correct
63+
[IAM Roles](https://cloud.google.com/kubernetes-engine/docs/how-to/iam).
64+
Specifically it must have the `container.clusters.get` permission.
65+
This can be given with the _Kubernetes Engine Cluster Viewer_ role
66+
(`roles/container.clusterViewer`).
2767

28-
> Tip: Use the 'intermediate' output format to get the raw output from the data gatherer. You can use that try your rego rules.
68+
A sample Terraform project can be found at
69+
[`./deployment/terraform/gke-datagatherer/`](deployment/terraform/gke-datagatherer).
70+
This can be used to create a GCP service account called `preflight` which
71+
is then bound to a custom role of the same name
72+
with the minimum required permissions.

0 commit comments

Comments
 (0)