Skip to content

Commit 5020065

Browse files
Add the kyverno polices as a reference (#624)
* Add the kyverno polices verbatim Just as a reference, the links are still ded * Add messages bits * Add 011, the kafkarator policy * Add a preamble * fix some links * Add tags for kyverno * use links from the issue * Remember to say please * chore: move to correct folder * Add Redis reference section * Make an explicit how-to for manual redis instances * Harmonize redis and opensearch * Redis and postgres are similar enough for one section * Chore: do a format * s/openSe/opense * Add an example for environment keys * Unbreak tables * Capitalize * Aiven is an implementation detail I * Use OpenSearch & Redis instead of Aiven * remove opensearch bits from the aivenesque docs since we do not create opensearch automatically * un-harmonize redis and opensearch unfortunately * re-add opensearch create
1 parent 7fd5457 commit 5020065

File tree

13 files changed

+239
-65
lines changed

13 files changed

+239
-65
lines changed

docs/explanation/naisdevice.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# naisdevice
1+
# Naisdevice
22

3-
naisdevice is a mechanism provided by NAIS, that lets you connect to services not available on the public internet from your machine.
3+
Naisdevice is a mechanism provided by NAIS, that lets you connect to services not available on the public internet from your machine.
44

55
Examples of such services are:
66

docs/how-to-guides/persistence/.pages

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
nav:
22
- buckets
33
- kafka
4-
- ...
4+
- opensearch
5+
- redis

docs/how-to-guides/persistence/opensearch/.pages

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# OpenSearch
2-
31
OpenSearch is a fork of Elasticsearch that is maintained by Amazon. It is a drop-in replacement for Elasticsearch, and is fully compatible with the Elasticsearch API. It is a community-driven project that is open source and free to use.
42

53
OpenSearch is a distributed, RESTful search and analytics engine capable of solving a growing number of use cases. It is a good choice for storing data that is not relational in nature.
64

7-
NAIS offers OpenSearch via [Aiven](https://aiven.io/). Aiven OpenSearch can be used by applications in all environments, but must be *defined* in a GCP cluster.
5+
NAIS offers OpenSearch via Aiven. Aiven OpenSearch can be used by applications in all environments, but must be defined in a GCP cluste

docs/how-to-guides/persistence/opensearch/create.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
---
33
description: >-
44
NAIS provides managed search index services through OpenSearch as a drop-in
5-
replacement for Elasticsearch. This page describes how to get started with
6-
OpenSearch for your applications.
5+
replacement for Elasticsearch.
76
---
87

9-
Creating a OpenSearch instance is done by adding a OpenSearch resource to your namespace with detailed configuration in a GCP cluster. In your `Application` or `Naisjob` specifications, you specify an instance and access.
8+
Explicitly creating a OpenSearch instance is done by adding a OpenSearch resource to your namespace with detailed configuration in a GCP cluster. In your `Application` or `Naisjob` specifications, you specify an instance and access.
109

1110
The minimal OpenSearch resource looks like this:
1211

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: Redis
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Redis
2+
3+
Nais provides Redis through Aiven via their Aiven
4+
Operator.
5+
6+
You can create many Redis instances for your `Application`.
7+
8+
## 0. Prerequisites
9+
- [Member of a NAIS team](../../explanation/team.md)
10+
11+
!!! warning It is not possible to share Redis instances between teams.
12+
13+
## 1. Enable Redis in your [manifest](../../reference/application-spec.md)
14+
15+
???+ note ".nais/app.yaml"
16+
```yaml
17+
spec:
18+
redis:
19+
- instance: sessions
20+
access: readwrite
21+
- instance: lookup
22+
access: read
23+
```
24+
25+
26+
The above snippet will allow your application to use the `sessions`
27+
Redis instance, and provide the application with credentials for a
28+
read/write user. In addition, the application will get credentials for
29+
a read-only user for the `lookup` instance. See the [manifest
30+
reference](../../reference/application-spec.md#redis) for other
31+
options for `access`.
32+
33+
If all you need is a Redis instance for one application using just the
34+
default settings, this is all you need. If you want to share a Redis
35+
instance across applications, or want to change configuration away
36+
from the defaults, please read the [section on explicitly creating
37+
redis instances](./create-redis-instance-explicitly.md).
38+
39+
For each edis instance, your application will receive
40+
three environment variables. The environment variables use a fixed
41+
prefix, and the instance name uppercased as a suffix.
42+
| Key | Value | |
43+
|----------------------------------|--------------------------------------|---|
44+
| `REDIS_URI_<InstanceName>` | The URI for the instance | |
45+
| `REDIS_USERNAME_<InstanceName>` | The username to use when connecting. | |
46+
| `REDIS_PASSWORD_<InstanceName>` | The password to use when connecting. | |

docs/how-to-guides/persistence/redis.md docs/how-to-guides/persistence/redis/create-redis-instance-explicitly.md

+6-51
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,11 @@
1-
# Redis
2-
This guide will show you how to install and use redis in your application
3-
4-
## 0. Prerequisites
5-
- [Member of a NAIS team](../../explanation/team.md)
6-
7-
!!! warning
8-
It is not possible to share Redis instances between teams.
9-
10-
## 1. Enable redis in your [manifest](../../reference/application-spec.md#redis)
11-
12-
???+ note ".nais/app.yaml"
13-
```yaml
14-
spec:
15-
redis:
16-
- instance: sessions
17-
access: readwrite
18-
- instance: lookup
19-
access: read
20-
```
21-
22-
23-
The above snippet will allow your application to use the `sessions` Redis instance, and provide the application with credentials for a read/write user.
24-
In addition, the application will get credentials for a read-only user for the `lookup` instance.
25-
See the reference for other options for `access`.
26-
27-
If all you need is a Redis instance for one application using just the default settings, this is all you need.
28-
If you want to share a Redis instance across applications, or want to change configuration away from the defaults, read the next section.
29-
30-
For each instance added to this list, your application will receive three environment variables.
31-
The environment variables use a fixed prefix, and the instance name uppercased as a suffix.
32-
33-
Example for the sessions instance used above:
34-
(TODO: how do we fix this for non-nav=)
35-
36-
| Key | Value |
37-
|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
38-
| REDIS_URI_SESSIONS | The URI for the Redis instance, typically with a `rediss` scheme. <br/>Example: `rediss://redis-team-sessions-nav-dev.aivencloud.com:26483` |
39-
| REDIS_USERNAME_SESSIONS | The username to use when connecting. |
40-
| REDIS_PASSWORD_SESSIONS | The password to use when connecting. |
41-
42-
So far we have used `sessions` as the instance name, but you can name your redis instance what you want with some restrictions.
43-
44-
When you refer to redis in your `Application`, nais will look for a redis instance with the given name, or attempt to create one with default settings if it doesn't exist.
45-
46-
## Creating a Redis instance explicitly
1+
# Creating a Redis instance explicitly
472

483
We recommend creating your Redis instances in their own workflow for more control over configuration, especially if you intend for multiple applications using the same Redis instance, or if you need to change configuration.
494

505
Creating a Redis instance is done by adding a Redis resource to your namespace with detailed configuration.
516
Some configuration is enforced by the nais platform, while the rest is up to the users.
527

53-
Earlier we talked about the "instance name".
8+
Earlier we talked about the "instance name".
549
In reality, the actual name of the redis instance will be `redis-<team name>-<instance name>` (where `team name` is the same as the namespace your application resides in).
5510
The resource needs to have this full name in order to be accepted.
5611

@@ -73,8 +28,8 @@ spec:
7328
A minimal Redis resource only requires `plan` and `project`.
7429

7530
* `project` should match your nais tenant (`<<tenant()>>`) and the environment you are running in (ex. `dev`, `prod`), with a dash (`-`) in between.
76-
* `plan` is the Aiven plan for your Redis instance.
77-
See Aivens list of [possible plan values](https://aiven.io/pricing?product=redis).
31+
* `plan` is the Aiven plan for your Redis instance.
32+
See Aivens list of [possible plan values](https://aiven.io/pricing?product=redis).
7833
The values are lowercased.
7934
Make sure you understand the differences between the plans before selecting the one you need.
8035
Examples: `startup-4`, `startup-56`, `business-4`, `premium-14`.
@@ -94,11 +49,11 @@ Business plans are backed up every 12 hours, keeping 3 days of backups available
9449

9550
Once the resource is added to the cluster, some additional fields are filled in by the platform and should be left alone unless you have a good reason:
9651

97-
| field | |
52+
| field | |
9853
|-------------------------|-------------------------------------------------------------------------------------------------------|
9954
| `projectVpcId` | Ensures the instance is connected to the correct project VPC and is not available on public internet. |
10055
| `tags` | Adds tags to the instance used for tracking billing in Aiven. |
101-
| `cloudName` | Where the Redis instance should run. |
56+
| `cloudName` | Where the Redis instance should run. |
10257
| `terminationProtection` | Protects the instance against unintended termination. Must be set to `false` before deletion. |
10358

10459
There are some fields available that should not be used:

docs/reference/kyverno-policies.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
tags:
3+
- Kyverno
4+
---
5+
6+
# Kyverno policies
7+
8+
Nais enforces certain cluster policies using kyverno, in addition to different baseline security
9+
policies you will also find some custom policies for the nais platform.
10+
11+
## 001 - Add spot toleration
12+
13+
This policy adds a toleration for pods to be deployed to nodes on spot
14+
instances, for cost reasons.
15+
16+
## 002 - Default allow egress
17+
18+
This policy generates a default allow egress NetworkPolicy for all
19+
Namespaces. It allows all egress traffic except for RFC 1918 private
20+
address space. This policy is based on the following Kubernetes
21+
NetworkPolicy:
22+
https://kubernetes.io/docs/concepts/services-networking/network-policies/#default-allow-all-egress
23+
24+
## 003 - Deny image registries
25+
26+
This policy denies images from registries not on the list of allowed
27+
registries.
28+
29+
### Message
30+
31+
Image not from an approved registry. Upload the image to an approved registry and try again.
32+
33+
## 004 - Deny creation of Kafka Topics
34+
35+
This policy Denies the creation of Kafka Topics. Documentation:
36+
https://docs.nais.io/how-to-guides/persistence/kafka/create/
37+
38+
### Message
39+
40+
Kafka Topic resource is not supported in this cluster\nDocumentation: https://docs.nais.io/how-to-guides/persistence/kafka/create/
41+
42+
## 005 - Deny deletion of Kafka topics
43+
44+
This policy Denies the deletion of Kafka topics without the
45+
kafka.nais.io/removeDataWhenResourceIsDeleted annotation.
46+
Documentation:
47+
https://docs.nais.io/how-to-guides/persistence/kafka/delete/
48+
49+
### Message
50+
51+
Deleting Topic is not allowed without the kafka.nais.io/removeDataWhenResourceIsDeleted annotation.\nDocumentation: https://docs.nais.io/how-to-guides/persistence/kafka/delete/
52+
53+
54+
## 006 - Deny specific service types
55+
56+
This policy denies the creation of services with types other than ClusterIP and ExternalName.
57+
This policy is based on the example policy from the Kyverno documentation.
58+
https://kyverno.io/docs/writing-policies/deny-service-types/
59+
60+
### Message
61+
62+
Service type must be one of ClusterIP or ExternalName in this namespace.
63+
64+
## 007 - Replace legacy GitHub registry
65+
66+
This policy rewrites references to the old GitHub registry (docker.pkg.github.com) with the new one (ghcr.io).
67+
68+
## 008 - Verify SLSA Provenance (Keyless)
69+
70+
This policy uses artifact provenance to identify how an artifact was produced
71+
and from where it originated. SLSA provenance is an industry-standard
72+
method of representing that provenance. This policy verifies that an
73+
image has SLSA provenance and was signed by the expected subject and issuer
74+
when produced through GitHub Actions. It requires configuration based upon
75+
your own values.
76+
77+
## 009 - Ephemeral containers with allowed images and limited capabilities
78+
79+
This policies ensures that ephemeral containers use allowed images and have limited capabilities.
80+
When using 'kubectl debug' please set flag `--profile=restricted`.
81+
For-example: `kubectl debug -it --image=cgr.dev/chainguard/busybox:latest --profile=restricted`
82+
83+
### Message
84+
85+
The fields spec.ephemeralContainers[*].image requires to be set for allowed image
86+
see `https://docs.nais.io/basics/debug`.
87+
Running as root is not allowed. The fields spec.ephemeralContainers[*].securityContext.runAsNonRoot
88+
must be `true`, and spec.ephemeralContainers[*].securityContext.capabilities.drop
89+
must be set to `- ALL` to reduce capabilities.
90+
The use of `kubectl debug` requires to set `--profile=restricted`.
91+
92+
## 010 - Aiven operator
93+
94+
This policy denies invalid names and projects, and missing project vpcs. Please see the documentation at https://docs.nais.io/how-to-guides/persistence/redis#creating-a-redis-instance-explicitly or https://docs.nais.io/how-to-guides/persistence/opensearch/create depending on your usecase.
95+
96+
### message
97+
98+
Invalid name. Please see https://docs.nais.io/how-to-guides/persistence/redis#creating-a-redis-instance-explicitly or https://docs.nais.io/how-to-guides/persistence/opensearch/create"
99+
100+
101+
## 011 - Validate fields for Kafka resources.
102+
103+
This policy validates that the fields for the given resources has allowed values.
104+
Currently only validates the pool field.
105+
106+
### Message
107+
Kafka pool {{ "{{ request.object.spec.pool }}" | quote }} is not supported in this cluster.
108+
Allowed values: [{{ $valid | join ", " }}]
109+
110+
Please see the documentation at https://docs.nais.io/how-to-guides/persistence/kafka/create/
111+
112+
113+
## 012 - Validate fields for Azure AD resources
114+
115+
This policy validates that Azure AD fields for the given resource has allowed values. Currently only validates the tenant field.
116+
117+
### Message
118+
119+
Azure AD tenant "{{ request.object.spec.tenant }}" is not supported in this cluster. Allowed values: [nav.no]
120+
Please see the documentation at https://doc.nais.io/security/auth/azure-ad/

docs/reference/opensearch.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
tags:
3+
- opensearch
4+
---
5+
6+
# Opensearch
7+
8+
Nais provides OpenSearch by way of Aiven via their Aiven Operator.
9+
10+
11+
## Configuration options
12+
13+
The `spec.opensearch` configuration has two fields as you get exactly one OpenSearch instance per Application.
14+
15+
```yaml
16+
spec:
17+
opensearch:
18+
instance: <OpenSearchInstanceName>
19+
access: readwrite | read | write | admin
20+
```
21+
22+
Specifying an OpenSearch instance will yield three environment variables in the Application
23+
24+
| Key | Value |
25+
|-------------------------------------------------|--------------------------------------|
26+
| `OPEN_SEARCH_URI_<Open_SearchInstanceName>` | The URI for the OpenSearch instance. |
27+
| `OPEN_SEARCH_USERNAME_<OpenSearchInstanceName>` | The username to use when connecting. |
28+
| `OPEN_SEARCH_PASSWORD_<OpenSearchInstanceName>` | The password to use when connecting. |

docs/reference/redis.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
tags:
3+
- redis
4+
---
5+
6+
# Redis
7+
8+
Nais provides Redis by way of Aiven via their Aiven Operator.
9+
10+
## Configuration options
11+
12+
The `spec.redis` field takes a list of records of two fields, instance and access. Instance is the instance name and access is the access mode.
13+
14+
```yaml
15+
spec:
16+
redis:
17+
- instance: <RedisInstanceName>
18+
access: readwrite | read | write | admin
19+
```
20+
21+
every `<RedisInstanceName> will give three environment variables for the applications to use,
22+
23+
| Key | Value |
24+
|------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
25+
| `REDIS_URI_<RedisInstanceName>` | The URI for the Redis instance, typically with a `redis` scheme. <br/>Example: `rediss://redis-team-sessions-nav-dev.aivencloud.com:26483` |
26+
| `REDIS_USERNAME_<RedisInstanceName>` | The username to use when connecting. |
27+
| `REDIS_PASSWORD_<RedisInstanceName>` | The password to use when connecting. |

flake.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
default =
2929
let
3030
# Use Python 3.10
31-
python = pkgs.python310;
31+
python = pkgs.python311;
3232
in
3333
pkgs.mkShell {
3434
# The Nix packages provided in the environment

0 commit comments

Comments
 (0)