Create the Policy Controller resources
After installing the Red Hat Trusted Artifact Signer (RHTAS) Policy Controller Operator, you need to create three new resources. These resources are: the base Policy Controller resource, the cluster image policy resource, and the Trust Root resource.
Before you begin
- Installation of the RHTAS Policy Controller Operator.
- A workstation with the
oc,curl, andtufclibinaries installed.
About this task
By default the Policy Controller resyncs the cluster image policies every 10 hours.
Procedure
-
Open a terminal on your workstation, and log in to OpenShift:
oc login --token=TOKEN --server=SERVER_URL_AND_PORT$ oc login --token=sha256~ZvFDBvoIYAbVECixS4-WmkN4RfnNd8Neh3y1WuiFPXC --server=https://example.com:6443Note You can find your login token and URL for use on the command line from the OpenShift web console. Log in to the OpenShift web console. Click your user name, and click Copy login command. Offer your user name and password again, if asked, and click Display Token to view the command.
-
Create and switch to the
policy-controller-operatornamespace:$ oc new-project policy-controller-operator ; oc project policy-controller-operator -
Create a basic Policy Controller resource.
-
Configure the Policy Controller to watch your namespaces that match the defined label selector under
spec.policy-controller.webhook.namespaceSelector.matchExpressions:... spec: policy-controller: ... webhook: ... namespaceSelector: matchExpressions: - key: policy.rhtas.com/include operator: In values: ["true"] ...$ cat <<EOF | oc apply -f - apiVersion: rhtas.charts.redhat.com/v1alpha1 kind: PolicyController metadata: name: policycontroller-sample spec: policy-controller: cosign: webhookName: "policy.rhtas.com" webhook: name: webhook extraArgs: webhook-name: policy.rhtas.com mutating-webhook-name: defaulting.clusterimagepolicy.rhtas.com validating-webhook-name: validating.clusterimagepolicy.rhtas.com failurePolicy: Fail namespaceSelector: matchExpressions: - key: policy.rhtas.com/include operator: In values: ["true"] webhookNames: defaulting: "defaulting.clusterimagepolicy.rhtas.com" validating: "validating.clusterimagepolicy.rhtas.com" EOFImportant You must create this resource in thepolicy-controller-operatornamespace. -
Add the
policy.rhtas.com/include: "true"label to the namespace that you want watched by the Policy Controller:apiVersion: v1 kind: Namespace metadata: labels: policy.rhtas.com/include: "true" name: example-namespace -
If you have a custom Certificate Authority (CA) bundle or self-signed certificates, then you can add your
ConfigMapname and key under thespec.policy-controller.webhook.registryCaBundlesection of the Policy Controller resource:... spec: policy-controller: ... webhook: registryCaBundle: name: CONFIGMAP_NAME key: CA_BUNDLE_KEY ...
-
Configure the Policy Controller to watch your namespaces that match the defined label selector under
-
Create a Trust Root resource. You have three options for creating the Trust Root resource: a custom TUF repository, using your own keys, or using a serialized TUF root.
-
Configure these environment variables from the RHTAS services:
$ export TUF_URL="$(oc -n trusted-artifact-signer get tuf -o jsonpath='{.items[0].status.url}')" $ export BASE64_TUF_ROOT="$(curl -fsSL "$TUF_URL/root.json" | base64 -w0)" $ export FULCIO_URL="$(oc -n trusted-artifact-signer get fulcio -o jsonpath='{.items[0].status.url}')" $ export CTLOG_URL="http://ctlog.trusted-artifact-signer.svc.cluster.local" $ export REKOR_URL="$(oc -n trusted-artifact-signer get rekor -o jsonpath='{.items[0].status.url}')" $ export TSA_URL="$(oc -n trusted-artifact-signer get timestampAuthorities -o jsonpath='{.items[0].status.url}')" -
Option 1. Create the
TrustRootresource for a custom TUF repository:$ cat <<EOF | oc apply -f - apiVersion: policy.sigstore.dev/v1alpha1 kind: TrustRoot metadata: name: trust-root spec: remote: mirror: $TUF_URL root: | $BASE64_TUF_ROOT EOF -
Option 2. Create a Trust Root with your own keys.
- Create and apply the
TrustRootresource using this template:apiVersion: policy.sigstore.dev/v1alpha1 kind: TrustRoot metadata: name: trust-root spec: sigstoreKeys: certificateAuthorities: - subject: organization: fulcio-organization commonName: fulcio-common-name uri: $FULCIO_URL certChain: |- FULCIO_CERT_CHAIN ctLogs: - baseURL: $CTLOG_URL hashAlgorithm: sha-256 publicKey: |- CTFE_PUBLIC_KEY tLogs: - baseURL: $REKOR_URL hashAlgorithm: sha-256 publicKey: |- REKOR_PUBLIC_KEY timestampAuthorities: - subject: organization: tsa-organization commonName: tsa-common-name uri: $TSA_URL certChain: |- TSA_CERT_CHAINNote Substitute the public keys and certificate chain values with your specific values for your RHTAS environment.
- Create and apply the
-
Option 3. Create a Trust Root for a serialized TUF root.
- Create a temporary directory to contain a clone of your TUF root:
$ mkdir -p tuf-repo - Download and clone the TUF repository:
$ curl -s $TUF_URL/root.json > root.json $ tufcli clone --metadata-url=$TUF_URL --metadata-dir=tuf-repo --targets-url=$TUF_URL/targets --targets-dir=tuf-repo/targets --root=root.json - Archive and encode the TUF repository:
$ tar -C ./tuf-repo -czf tuf-repo.tgz . $ export MIRROR_FS=$(base64 -w0 tuf-repo.tgz) - Create the
TrustRootresource:$ cat <<EOF | oc apply -f - apiVersion: policy.sigstore.dev/v1alpha1 kind: TrustRoot metadata: name: trust-root spec: repository: root: |- $BASE64_TUF_ROOT mirrorFS: |- $MIRROR_FS EOF
- Create a temporary directory to contain a clone of your TUF root:
-
Configure these environment variables from the RHTAS services:
-
Create a basic Policy Controller cluster image policy resource.
-
Configure these environment variables for Fulcio, Rekor, the Trust Root, and the OpenID Connect (OIDC) issuer and subject:
$ export FULCIO_URL="$(oc -n trusted-artifact-signer get fulcio -o jsonpath='{.items[0].status.url}')" $ export REKOR_URL="$(oc -n trusted-artifact-signer get rekor -o jsonpath='{.items[0].status.url}')" $ export TRUST_ROOT_RESOURCE="trust-root" $ export OIDC_ISSUER_URL="https://ISSUER_URL" $ export OIDC_SUBJECT="SUBJECT" -
Create the
ClusterImagePolicyresource:$ cat <<EOF | oc apply -f - apiVersion: policy.sigstore.dev/v1beta1 kind: ClusterImagePolicy metadata: name: cluster-image-policy spec: images: - glob: "**" authorities: - keyless: url: $FULCIO_URL trustRootRef: $TRUST_ROOT_RESOURCE identities: - issuer: $OIDC_ISSUER_URL subject: $OIDC_SUBJECT ctlog: url: $REKOR_URL trustRootRef: $TRUST_ROOT_RESOURCE rfc3161timestamp: trustRootRef: $TRUST_ROOT_RESOURCE EOFNote Theglobvalue of**evaluates all container images.
-
Configure these environment variables for Fulcio, Rekor, the Trust Root, and the OpenID Connect (OIDC) issuer and subject: