|
| 1 | +# Skyhook Kyverno Policies |
| 2 | + |
| 3 | +This directory contains example [Kyverno](https://kyverno.io/) policies for Skyhook. These policies can be used to enforce security and best practices for Skyhook packages. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before applying any policies, you need to have Kyverno installed in your cluster. You can install it using one of the following methods: |
| 8 | + |
| 9 | +### Helm Installation (Recommended) |
| 10 | + |
| 11 | +```bash |
| 12 | +helm repo add kyverno https://kyverno.github.io/kyverno/ |
| 13 | +helm install kyverno kyverno/kyverno -n kyverno --create-namespace |
| 14 | +``` |
| 15 | + |
| 16 | +### Manual Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +kubectl apply -f https://raw.githubusercontent.com/kyverno/kyverno/main/definitions/install.yaml |
| 20 | +``` |
| 21 | + |
| 22 | +## Available Policies |
| 23 | + |
| 24 | +### Restrict Package Images |
| 25 | +The `disable_packages.yaml` policy demonstrates how to restrict which container images can be used in Skyhook packages. This is particularly useful for: |
| 26 | +- Preventing the use of potentially dangerous images (e.g., those containing shell scripts) |
| 27 | +- Enforcing the use of approved container registries |
| 28 | +- Maintaining security standards across your cluster |
| 29 | + |
| 30 | +To apply the policy: |
| 31 | + |
| 32 | +```bash |
| 33 | +kubectl apply -f disable_packages.yaml |
| 34 | +``` |
| 35 | + |
| 36 | +The policy will prevent the creation of Skyhook resources that contain packages with restricted image patterns. Currently, it blocks: |
| 37 | +- Images containing 'shellscript' anywhere in the image name |
| 38 | +- Images from Docker Hub (matching 'docker.io/*') |
| 39 | + |
| 40 | +## Testing the Policy |
| 41 | + |
| 42 | +You can test the policy by trying to create a Skyhook resource with a restricted image. For example: |
| 43 | + |
| 44 | +```yaml |
| 45 | +apiVersion: skyhook.nvidia.com/v1alpha1 |
| 46 | +kind: Skyhook |
| 47 | +metadata: |
| 48 | + labels: |
| 49 | + app.kubernetes.io/part-of: skyhook-operator |
| 50 | + app.kubernetes.io/created-by: skyhook-operator |
| 51 | + name: test-scr |
| 52 | +spec: |
| 53 | + packages: |
| 54 | + shellscript: |
| 55 | + configMap: |
| 56 | + config.sh: |- |
| 57 | + #!/bin/bash |
| 58 | + echo "hello" |
| 59 | + image: shellscript |
| 60 | + version: 1.3.2 |
| 61 | + |
| 62 | + # This will be blocked by the policy |
| 63 | +``` |
| 64 | + |
| 65 | +The creation will be denied with an appropriate error message. |
| 66 | + |
| 67 | +## Customizing Policies |
| 68 | + |
| 69 | +The example policies are templates that you can modify to fit your security needs. Common customizations include: |
| 70 | +- Adding additional restricted image patterns |
| 71 | +- Modifying the validation rules |
| 72 | +- Adjusting the failure action (warn vs enforce) |
| 73 | + |
| 74 | +See the [Kyverno documentation](https://kyverno.io/docs/) for more details on policy customization. |
| 75 | + |
0 commit comments