Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to disable namespace opt-in #268

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/policy-controller/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
description: The Helm chart for Policy Controller
description: The Helm chart for Policy Controller
home: https://github.com/sigstore/policy-controller

sources:
Expand Down
7 changes: 5 additions & 2 deletions charts/policy-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Version: 0.3.1](https://img.shields.io/badge/Version-0.3.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.4.0](https://img.shields.io/badge/AppVersion-0.4.0-informational?style=flat-square)

The Helm chart for Policy Controller
The Helm chart for Policy Controller

**Homepage:** <https://github.com/sigstore/policy-controller>

Expand Down Expand Up @@ -31,6 +31,7 @@ The Helm chart for Policy Controller
| policywebhook.image.pullPolicy | string | `"IfNotPresent"` | |
| policywebhook.image.repository | string | `"ghcr.io/sigstore/policy-controller/policy-webhook"` | |
| policywebhook.image.version | string | `"sha256:03f6b9807103c988439741fdc2ec4410a85c13ba62fbad58448a070ac07bb5bc"` | `"v0.4.0"` |
| policywebhook.namespaceSelectorDisabled | bool | `false` | |
| policywebhook.podSecurityContext.allowPrivilegeEscalation | bool | `false` | |
| policywebhook.podSecurityContext.capabilities.drop[0] | string | `"all"` | |
| policywebhook.podSecurityContext.enabled | bool | `true` | |
Expand Down Expand Up @@ -159,7 +160,9 @@ Creating a deployment referencing images that are not signed will yield the foll
pod/pod1-signed created
```


## More info

You can find more information about the policy-controller in [here](https://docs.sigstore.dev/policy-controller/overview/).

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this change to a separate PR, so we can address the issue itself.

115 changes: 115 additions & 0 deletions charts/policy-controller/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{{ template "chart.header" . }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why do we need this file ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to do helm-docs --dry-run then modify the README.md each time. Instead you run helm-docs and it generates the entire file for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also makes it easy to validate because if helm-docs generates a diff, then you know it wasn't properly updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sgtm, what do you think @cpanato ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned, let's revert this change and keep only the opt-in functionality.


{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}

{{ template "chart.description" . }}

**Homepage:** <https://github.com/sigstore/policy-controller>


## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| dlorenc | | |
| hectorj2f | | |

## Source Code

* <https://github.com/sigstore/policy-controller>


{{ template "chart.requirementsSection" . }}

{{ template "chart.valuesSection" . }}

### Deploy `policy-controller` Helm Chart

Install `policy-controller` using Helm:

```shell
helm repo add sigstore https://sigstore.github.io/helm-charts

helm repo update

kubectl create namespace cosign-system

helm install policy-controller -n cosign-system sigstore/policy-controller --devel
```

The `policy-controller` enforce images matching the defined list of `ClusterImagePolicy` for the labeled namespaces.

Note that, by default, the `policy-controller` offers a configurable behavior defining whether to allow, deny or warn whenever an image does not match a policy in a specific namespace. This behavior can be configured using the `config-policy-controller` ConfigMap created under the release namespace, and by adding an entry with the property `no-match-policy` and its value `warn|allow|deny`.
By default, any image that does not match a policy is rejected whenever `no-match-policy` is not configured in the ConfigMap.

As supported in previous versions, you could create your own key pair:

```shell
export COSIGN_PASSWORD=<my_cosign_password>
cosign generate-key-pair
```

This command generates two key files `cosign.key` and `cosign.pub`. Next, create a secret to validate the signatures:

```shell
kubectl create secret generic mysecret -n \
cosign-system --from-file=cosign.pub=./cosign.pub
```

**IMPORTANT:** The `cosign.secretKeyRef` flag is not supported anymore. Finally, you could reuse your secret `mysecret` by creating a `ClusterImagePolicy` that sets it as listed authorities, as shown below.

```yaml
apiVersion: policy.sigstore.dev/v1alpha1
kind: ClusterImagePolicy
metadata:
name: cip-key-secret
spec:
images:
- glob: "**your-desired-value**"
authorities:
- key:
secretRef:
name: mysecret

```

### Enabling Admission control

To enable the `policy admission webhook` to check for signed images, you will need to add the following label in each namespace that you would want the webhook triggered:

Label: `policy.sigstore.dev/include: "true"`

```yaml
apiVersion: v1
kind: Namespace
metadata:
labels:
policy.sigstore.dev/include: "true"
kubernetes.io/metadata.name: my-namespace
name: my-namespace
spec:
finalizers:
- kubernetes
```

### Testing the webhook

1. Using Unsigned Images:
Creating a deployment referencing images that are not signed will yield the following error and no resources will be created:

```shell
kubectl apply -f my-deployment.yaml
Error from server (BadRequest): error when creating "my-deployment.yaml": admission webhook "policy.sigstore.dev" denied the request: validation failed: invalid image signature: spec.template.spec.containers[0].image
```

2. Using Signed Images: Assuming a signed `nginx` image with a tag `signed` exists on a registry, the resource will be successfully created.

```shell
kubectl run pod1-signed --image=< REGISTRY_USER >/nginx:signed -n testns
pod/pod1-signed created
```

## More info

You can find more information about the policy-controller in [here](https://docs.sigstore.dev/policy-controller/overview/).
{{ template "helm-docs.versionFooter" . }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ metadata:
name: {{ required "A valid cosign.webhookName is required" .Values.cosign.webhookName }}
webhooks:
- name: {{ required "A valid cosign.webhookName is required" .Values.cosign.webhookName }}
{{- if not .Values.policywebhook.namespaceSelectorDisabled }}
namespaceSelector:
# The webhook should only apply to things that opt-in
matchExpressions:
- key: policy.sigstore.dev/include
operator: In
values: ["true"]
{{- end }}
admissionReviewVersions: [v1]
clientConfig:
service:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ metadata:
name: {{ required "A valid cosign.webhookName is required" .Values.cosign.webhookName }}
webhooks:
- name: {{ required "A valid cosign.webhookName is required" .Values.cosign.webhookName }}
{{- if not .Values.policywebhook.namespaceSelectorDisabled }}
namespaceSelector:
# The webhook should only apply to things that opt-in
matchExpressions:
- key: policy.sigstore.dev/include
operator: In
values: ["true"]
{{- end }}
admissionReviewVersions: [v1]
clientConfig:
service:
Expand Down
3 changes: 3 additions & 0 deletions charts/policy-controller/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
}
}
},
"namespaceSelectorDisabled": {
"type": "boolean"
},
"webhookNames": {
"type": "object",
"properties": {
Expand Down
3 changes: 3 additions & 0 deletions charts/policy-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ policywebhook:
image:
repository: ghcr.io/sigstore/policy-controller/policy-webhook
# crane digest ghcr.io/sigstore/policy-controller/policy-webhook:v0.4.0
# -- `"v0.4.0"`
version: sha256:03f6b9807103c988439741fdc2ec4410a85c13ba62fbad58448a070ac07bb5bc
pullPolicy: IfNotPresent
env: {}
Expand Down Expand Up @@ -38,6 +39,7 @@ policywebhook:
annotations: {}
type: ClusterIP
port: 443
namespaceSelectorDisabled: false
webhookNames:
defaulting: "defaulting.clusterimagepolicy.sigstore.dev"
validating: "validating.clusterimagepolicy.sigstore.dev"
Expand All @@ -48,6 +50,7 @@ webhook:
image:
repository: ghcr.io/sigstore/policy-controller/policy-controller
# crane digest ghcr.io/sigstore/policy-controller/policy-controller:v0.4.0
# -- `"v0.4.0"`
version: sha256:2b1c017535f6a0f672ec38279f3792ca1181555342a2deae53605e202afb9764
pullPolicy: IfNotPresent
env: {}
Expand Down