Skip to content

Commit

Permalink
Support Cluster ImagePolicy CRD
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Wang <qiwan@redhat.com>
  • Loading branch information
QiWang19 committed Mar 1, 2024
1 parent 1738652 commit 36d9f66
Show file tree
Hide file tree
Showing 76 changed files with 3,045 additions and 302 deletions.
1 change: 1 addition & 0 deletions cmd/machine-config-controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle
ctx.ConfigInformerFactory.Config().V1().Images(),
ctx.ConfigInformerFactory.Config().V1().ImageDigestMirrorSets(),
ctx.ConfigInformerFactory.Config().V1().ImageTagMirrorSets(),
ctx.ConfigInformerFactory,
ctx.OperatorInformerFactory.Operator().V1alpha1().ImageContentSourcePolicies(),
ctx.ConfigInformerFactory.Config().V1().ClusterVersions(),
ctx.ClientBuilder.KubeClientOrDie("container-runtime-config-controller"),
Expand Down
98 changes: 98 additions & 0 deletions docs/ClusterImagePolicyDesign.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
## Summary
ClusterImagePolicy CRD is managed by ContainerRuntimeConfig controller. This CRD allows setting up configurations for CRI-O to verify the container images signed using [Sigstore](https://www.sigstore.dev/) tools.

## Goals
Generating corresponding CRI-O configuration files for image signature verification. Rollout ClusterImagePolicy to `/etc/containers/policy.json` for cluster wide configuration. Roll out the registries configuration to `/etc/containers/registries.d/sigstore-registries.yaml`.

## Non-Goals
Rolling out configuration for OCP payload repositories. The (super scope of) OCP payload repositories will not be written to the configuration files.

## CRD
[ClusterImagePolicy CRD](https://github.com/openshift/api/blob/master/config/v1alpha1/0000_10_config-operator_01_clusterimagepolicy-TechPreviewNoUpgrade.crd.yaml)

## Example

Below is an example of a ClusterImagePolicy CRD.

```yaml
apiVersion: config.openshift.io/v1alpha1
kind: ClusterImagePolicy
metadata:
name: p0
spec:
scopes:
- registry.ci.openshift.org
- example.com/global
policy:
rootOfTrust:
policyType: PublicKey
publicKey:
keyData: Zm9vIGJhcg==
signedIdentity:
matchPolicy: MatchRepoDigestOrExact
```

Save the above clusterimagepolicy locally, for example as pubKeyPolicy.yaml.
Now apply the clusterimagepolicy that you created:

```shell
oc apply -f pubKeyPolicy.yaml
```

Check that it was created:

```shell
oc get clusterimagepolicy
NAME AGE
p0 9s

```

## Validation and Troubleshooting
The status.conditions.message field shows if the CR has conflicting scope(s). The below ClusterImagePolicy is in pending status because the scope for OCP release payload is skipped.

```shell
# the clusterimagepolicy has scope registry.build05.ci.openshift.org that is the OCP release payload repository
$ oc describe clusterimagepolicy.config.openshift.io/p0
...
...
Status:
Conditions:
Last Transition Time: 2024-02-04T03:24:36Z
Message: has conflict scope(s) ["registry.build05.ci.openshift.org"] of Openshift payload repository registry.build05.ci.openshift.org/ci-ln-gfmf0yb/release, skip the scope(s)
Observed Generation: 1
Reason: ConflictScopes
Status: True
Type: Pending
```

The machine-config-controller logs will show the error message if the ClusterImagePolicy and Image CR has conflicting configurations. Controller will fail to roll out the CR.
- if blocked registries configured by Image CR exist, the clusterimagepolicy scopes must not equal to or nested under blockedRegistries
- if allowed registries configured by Image CR exist, the clusterimagepolicy scopes nested under the allowedRegistries
For example, the below error message is shown when the ClusterImagePolicy and blockedRegistries of Image CR has conflicting configurations.

```shell
I0204 03:51:18.253145 1 container_runtime_config_controller.go:497] Error syncing image config openshift-config: could not Create/Update MachineConfig: could not update policy json with new changes: clusterimagePolicy configured for the scope example.com/global is nested inside blockedRegistries ```
```
## Implementation Details
The ContainerRuntimeConfigController would perform the following steps:
1. Validate the ClusterImagePolicy objects are not for OCP release payload repositories.
2. Render the current MachineConfigs (storage.files.contents[policy.json]) into the originalPolicyIgn
3. Serialize the cluster level policies to `policy.json`.
4. Add registries configuration to `sigstore-registries.yaml`. This configuration is used to specify the sigstore is being used as the image signature verification backend.
5. Update the ignition file `/etc/containers/policy.json` within the `99-<pool>-generated-registries` MachineConfig.
6. Create or Update the ignition file `/etc/containers/registries.d/sigstore-registries.yaml` within the `99-<pool>-generated-imagepolicies` MachineConfig.
After deletion all of the ClusterImagePolicy instance the config will be reverted to the original policy.json.
## See Also
see **[containers-policy.json(5)](https://github.com/containers/image/blob/main/docs/containers-policy.json.5.md)**, **[containers-registries.d(5)](https://github.com/containers/image/blob/main/docs/containers-registries.d.5.md)** for more information.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ require (
github.com/google/renameio v0.1.0
github.com/imdario/mergo v0.3.13
github.com/opencontainers/go-digest v1.0.0
github.com/openshift/api v0.0.0-20240205144533-7162acc29bb6
github.com/openshift/client-go v0.0.0-20240104132419-223261fd8630
github.com/openshift/api v0.0.0-20240215110531-750a3e21ebaf
github.com/openshift/client-go v0.0.0-20240215090359-b71f6f2731f5
github.com/openshift/cluster-config-operator v0.0.0-alpha.0.0.20231213185242-e4dc676febfe
github.com/openshift/library-go v0.0.0-20231020125034-5a2d9fe760b3
github.com/openshift/runtime-utils v0.0.0-20230921210328-7bdb5b9c177b
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,10 @@ github.com/opencontainers/runc v1.1.10 h1:EaL5WeO9lv9wmS6SASjszOeQdSctvpbu0DdBQB
github.com/opencontainers/runc v1.1.10/go.mod h1:+/R6+KmDlh+hOO8NkjmgkG9Qzvypzk0yXxAPYYR65+M=
github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg=
github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/openshift/api v0.0.0-20240205144533-7162acc29bb6 h1:OrjG0Lt0pXNYd6LUfGD3BYoBWXhfRMAMK0LYu8pdyqQ=
github.com/openshift/api v0.0.0-20240205144533-7162acc29bb6/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
github.com/openshift/client-go v0.0.0-20240104132419-223261fd8630 h1:JQ/TO3bSDowReecFDvz+Nr0Fx8aoJI0zdo01y2W5NKk=
github.com/openshift/client-go v0.0.0-20240104132419-223261fd8630/go.mod h1:8W4atsD8vBtEK0qplKpFWo+7XsQwzHTlqL7o/XpagRM=
github.com/openshift/api v0.0.0-20240215110531-750a3e21ebaf h1:ZA6VKfclZuTjOhhLEmKyulM7Ily+9cXxq9IqrREBIjA=
github.com/openshift/api v0.0.0-20240215110531-750a3e21ebaf/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
github.com/openshift/client-go v0.0.0-20240215090359-b71f6f2731f5 h1:iQ2Y1LUX7FbBm6ddaSVz/KeWXUMkqrBP/C5yt0DvBgI=
github.com/openshift/client-go v0.0.0-20240215090359-b71f6f2731f5/go.mod h1:Y5Hp789dTrF6Fq8cA5YQlpwffmlLy8mc2un/CY0cg7Q=
github.com/openshift/cluster-config-operator v0.0.0-alpha.0.0.20231213185242-e4dc676febfe h1:wDQtyIbJJIoif2Ux0S+9MJWIWEGV0oG+iLm8WtqwdSw=
github.com/openshift/cluster-config-operator v0.0.0-alpha.0.0.20231213185242-e4dc676febfe/go.mod h1:SGUtv1pKZSzSVr2YCxXFvhE+LbGfI+vcetEhNicKayw=
github.com/openshift/kube-openapi v0.0.0-20230816122517-ffc8f001abb0 h1:GPlAy197Jkr+D0T2FNWanamraTdzS/r9ZkT29lxvHaA=
Expand Down

0 comments on commit 36d9f66

Please sign in to comment.