此内容没有您所选择的语言版本。
Managing compliance with Conforma
Learn how Conforma enables you to better verify and govern compliance of the code you promote. Additionally, customize the sample policies to fit your corporate standards.
Abstract
Preface 复制链接链接已复制到粘贴板!
Conforma enforces software supply chain security by validating that container images are signed and attested. Use this guide to define policies, check artifacts, and block untrusted builds from your environment.
A secure CI/CD workflow should include artifact verification to detect problems early.
Chapter 1. Conforma for RHADS - SSC 复制链接链接已复制到粘贴板!
Conforma is a policy-driven workflow tool for maintaining software supply chain security by defining and enforcing policies for building and testing container images.
The more complex a software supply chain becomes, the more critical it is to employ reliable checks and best practices to guarantee software artifact integrity, as your image containers, and source code dependability. This is where Conforma streamlines Red Hat Advanced Developer Suite - software supply chain (RHADS - SSC) build and deploy experience.
For a build system that creates Supply-chain Levels for Software Artifacts (SLSA) provenance attestations, such as Tekton with Tekton Chains and GitHub Actions with the SLSA GitHub Generator, checking the signatures and confirming that the contents of the attestations actually match what is expected is a critical part of verifying and maintaining the integrity of your software supply chain. A secure CI/CD workflow should include artifact verification to detect problems early. Conforma validates that a known and trusted build system signs and attests the container image.
The general steps for validating a signed and attested container image are as follows:
- Create or copy a container image with RHADS - SSC.
- Generate a signing key with Cosign.
- Sign the container image with Cosign.
- Attest the image with Cosign.
- Verify your signed and attested container image with the Conforma CLI.
Signed software artifacts like container images are at a significantly lower risk of several attack vectors than unsigned artifacts. When a container image is signed, various cryptographic techniques bind the image to a specific entity or organization. The result is a digital signature that verifies the authenticity of the image so that you can trace it back to its creator and also verify that the image was not altered or tampered with after it was signed.
Conforma uses the industry standard Sigstore and Cosign as a resource library to validate your container images. With Red Hat Trusted Artifact Signer, Red Hat’s supported version of the Sigstore framework, you can use your own on-premise instance of Sigstore’s services to sign and attest your container images with the Cosign CLI.
As for software artifact attestation, it cannot happen without provenance. Provenance is the verifiable information about software artifacts like container images that describes where, when, and how that artifact was produced. The attestation itself is an authenticated statement, in the form of metadata, that proves that an artifact is intact and trustworthy. Conforma uses that attestation to cryptographically verify that the build was not tampered with, and to check the build against any set of policies, such as SLSA requirements. .
When you push your code from either the RHADS - SSC development namespace to the stage namespace, or from the stage namespace to the production namespace, Conforma automatically runs its validation checks to make sure your container image was signed and attested by known and trusted build systems. When your image passes the Conforma check, you can merge your code changes to complete your promotion from one environment to the next.
Chapter 2. Installing the Conforma command line 复制链接链接已复制到粘贴板!
Install the Conforma command-line interface (CLI) to validate and inspect container images and their attestations from your local workstation.
Prerequisites
- A working Red Hat Trusted Artifact Signer installation on Red Hat OpenShift Container Platform (OCP) version 4.13 or higher.
-
A workstation with the
cosignandocbinary files installed. - Access to the OCP web console.
Procedure
Download the
ecbinary file from the OCP cluster.- Log in to the OCP web console. From the home page, click the ? icon, select Command line tools, go to the ec download section, then click the link for your platform.
Open a terminal on your workstation, and decompress the binary
.gzfile by running the following command:gunzip ec-amd64.gz
$ gunzip ec-amd64.gzCopy to Clipboard Copied! Toggle word wrap Toggle overflow Make the binary executable by running the following command:
chmod +x ec-amd64
$ chmod +x ec-amd64Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Move and rename the binary to a location within your
$PATHenvironment:sudo mv ec-amd64 /usr/local/bin/ec
$ sudo mv ec-amd64 /usr/local/bin/ecCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
-
Run the
ec versioncommand. The result should be the version of the Conforma CLI that you just installed.
Chapter 3. Creating a policy 复制链接链接已复制到粘贴板!
A Conforma policy is a rule or set of rules and Conforma-specific annotations. Conforma can perform several types of policy checks, including checking all of the policy rules required for Red Hat products. Conforma uses the general purpose policy engine called Open Policy Agent (OPA). OPA defines its policy rules by using Rego. This means that the policy rules from OPA that are in a Conforma policy are also defined in Rego.
Procedure
Create a Rego file to define a new policy rule, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - METADATA
-
The first 10 lines of code comprise the
METADATAcomment block, which is how rego specifies rules annotations so that Conforma can include those annotation details in its successes and violations report. short_name-
This single policy rule verifies that the
builder.idin your new policy rule matches thebuilder.idin your Supply-chain Levels for Software Artifacts (SLSA) provenance. input.attestationsinputis a Rego object that contains all of the information about your container image, its signature, and its attestations. Theinput.attestationsattribute of theinputobject contains a list of attestations associated with the image.TipYou can save the
inputobject to a JSON file to view the available values, which is helpful in writing new policy rules. To save theinputobject as a JSON file namedinput.json, run a command similar to the following example:ec validate image --public-key cosign.pub \ --image "$REPOSITORY:latest" \ --policy policy.yaml \ --output policy-input=input.json
$ ec validate image --public-key cosign.pub \ --image "$REPOSITORY:latest" \ --policy policy.yaml \ --output policy-input=input.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Create a policy configuration to use your new policy rule:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the new policy to validate your container image, and to display additional information in the successes and violations report, as in the following example:
ec validate image --public-key cosign.pub \ --image "$REPOSITORY:latest" \ --policy policy.yaml \ --show-successes --info --output yaml
$ ec validate image --public-key cosign.pub \ --image "$REPOSITORY:latest" \ --policy policy.yaml \ --show-successes --info --output yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
-
Check the successes and violations report to make sure that your new rule is in the
successeslist.
3.1. Configuring a policy 复制链接链接已复制到粘贴板!
You can configure a Conforma policy with an inline JSON or YAML string. This policy, sometimes called a config or a contract, specifies where Conforma should find the rules and data to use to apply the policies you want to enforce. You can also include or exclude a single rule or a particular package of rules.
Procedure
Configure your policy in the command line as a JSON or YAML string, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional) Exclude a particular package of rules from your Conforma policy, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command includes every rule from every package except for the rules in the specified packages.
(Optional) Exclude a single rule, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This commands includes every rule from the
attestation_task_bundlepackage except for theunacceptable_task_bundlerule.(Optional) Include rules from only a particular package, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command includes only the rules from the specified packages.
(Optional) Include only some rules from a particular package. This means that you can specify both
includeandexcludeto select only the rules you want your Conforma policy to include, as in the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow asterisk (*)The asterisk (*) acts as a wildcard to match any package. It does not match partial names. For example, you cannot specify "s*" to match every package that starts with "s".
These commands specify that you want to include only the
unacceptable_task_bundlerule from theattestation_task_bundlepackage, and exclude all the other rules in that package.
(Optional) Exclude certain checks so that Conforma can validate your container image even if those checks fail or don’t complete, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command specifies that, if either of the identified checks fails or does not complete, Conforma can still finish to validate your container image.
(Optional) Modify the defaults for rules in a package by running either the
config.policy.includecommand or theconfig.policy.excludecommand, along with a list of strings.Your list of strings should include one of the following:
- package name
- Choose from the packages in the "Available rule collections" list.
- rule name
-
Specify a rule name by entering the name of the package and the rule code, separated by a dot (.), as in this example:
attestation_type.unknown_att_type. You can find rule codes under "Attestation type" in the upstream Conforma documentation. - package name:term
- Some policy rules process a list of items. When you add "term" to the "package name" string, you can exclude or include a particular item from that list. This works similarly to "package name," except that it applies only to policy rules in the package that match that term. For example, if you run the test package, you can choose to ignore a given test case but include all the others.
- rule name:term
- This is similar to "package name:term" except that, instead of including or excluding an item from a package, you can include or exclude a particular package policy rule.
- @collection name
-
Add this to your string to specify a predefined collection of rules. Prefix the collection name with the
@symbol. Choose from the available rule collections.
Chapter 4. Signing a container image 复制链接链接已复制到粘贴板!
Sign a container image by using the Red Hat Trusted Artifact Signer and Cosign to ensure its authenticity and integrity before validating it with Conforma.
Prerequisites
- Access to the OpenShift Container Platform (OCP) web console.
- A working Red Hat Trusted Artifact Signer (RHTAS) installation running on OpenShift version 4.13 or later.
-
A workstation with the
ec,cosign, andocbinary files installed.
Procedure
Log in to your OCP cluster by running the following command:
oc login --token=<TOKEN> --server=<SERVER_URL_AND_PORT>
$ oc login --token=<TOKEN> --server=<SERVER_URL_AND_PORT>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc login --token=sha256~ZvFDBvoIYAbVECixS4-WmkN4RfnNd8Neh3y1WuiFPXC \ --server=https://example.com:6443
$ oc login --token=sha256~ZvFDBvoIYAbVECixS4-WmkN4RfnNd8Neh3y1WuiFPXC \ --server=https://example.com:6443Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteTo find your command line login token and URL, log in to the OpenShift web console. Click your user name, then click Copy login command. If prompted, enter your user name and password again, then click Display Token.
- Log in to RHTAS.
Configure your RHTAS shell environment to sign and verify container images by running the following commands:
cd sigstore-ocp
$ cd sigstore-ocpCopy to Clipboard Copied! Toggle word wrap Toggle overflow source tas-env-variables.sh
$ source tas-env-variables.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow You also have the option to set the environment variables manually. For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow source ./tas-env-vars.sh
$ source ./tas-env-vars.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow Log out of your OCP cluster by running the following command:
oc logout
$ oc logoutCopy to Clipboard Copied! Toggle word wrap Toggle overflow Identify the container image you want to sign and attest; for example:
IMAGE=quay.io/lucarval/rhtas-test@sha256:6b95efc134c2af3d45472c0a2f88e6085433df058cc210abb2bb061ac4d74359
IMAGE=quay.io/lucarval/rhtas-test@sha256:6b95efc134c2af3d45472c0a2f88e6085433df058cc210abb2bb061ac4d74359Copy to Clipboard Copied! Toggle word wrap Toggle overflow Indicate to RHADS - SSC that you want to sign and attest your container image with Red Hat Trusted Artifact Signer instead of the public Sigstore deployment by running the following command:
cosign initialize --mirror=$TUF_URL --root=$TUF_URL/root.json
$ cosign initialize --mirror=$TUF_URL --root=$TUF_URL/root.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow Sign your container image by running the following command:
cosign sign -y --fulcio-url=$FULCIO_URL \ --rekor-url=$REKOR_URL \ --oidc-issuer=$OIDC_ISSUER_URL $IMAGE
$ cosign sign -y --fulcio-url=$FULCIO_URL \ --rekor-url=$REKOR_URL \ --oidc-issuer=$OIDC_ISSUER_URL $IMAGECopy to Clipboard Copied! Toggle word wrap Toggle overflow - When prompted, log in to the Keycloak instance that RHADS - SSC installed when you installed RHADS - SSC. This is so Keycloak can authenticate you.
Next steps
Your image is now signed. Now you can:
- Create a SLSA provenance attestation and associate it with your container image.
- Validate your container image with the Conforma.
You must have a signing key before you can sign and attest a container image.
Prerequisites
-
A workstation with the
cosignbinary files installed.
Procedure
Generate a key pair by running the following command:
cosign generate-key-pair
$ cosign generate-key-pairCopy to Clipboard Copied! Toggle word wrap Toggle overflow - When prompted, enter a new password for the key-pair. Make sure your password is memorable and strong.
Verification
You should now have two new files in your working directory: a
cosign.pubfile and acosign.keyfile.-
The
cosign.pubfile contains your public signing key. You can share this key with any collaborator who needs to validate the container image. -
The
cosign.keyfile is your private key for signing content. Only the person responsible for signing and attesting images should have access to thecosign.keyfile.
-
The
When you install the Red Hat Trusted Artifact Signer (RHTAS) service, you can use the ec binary file to validate the attestation and signature of the container images that use the RHTAS service’s keyless signing framework.
Prerequisites
- A working RHTAS installation running on OpenShift Container Platform (OCP) version 4.13 or later.
- Access to the OCP web console.
-
A workstation with the
cosignandocbinary files installed.
Procedure
Download the
ecbinary file from the OCP cluster:- Log in to the OpenShift Container Platform web console. From the home page, click the ? icon in the upper right, then select Command Line Tools.
- From the ec download section, click the link for your platform.
- Open a terminal.
Decompress the
.gzfile by running the following command:gunzip ec-amd64.gz
$ gunzip ec-amd64.gzCopy to Clipboard Copied! Toggle word wrap Toggle overflow Make the
ecbinary file executable by running the following command:chmod +x ec-amd64
$ chmod +x ec-amd64Copy to Clipboard Copied! Toggle word wrap Toggle overflow Move the
ecbinary file to a directory within your$PATHenvironment. For example:sudo mv ec-amd64 /usr/local/bin/ec
$ sudo mv ec-amd64 /usr/local/bin/ecCopy to Clipboard Copied! Toggle word wrap Toggle overflow TipRun the
ec validate image --helpcommand to see all the image validation command options.
Configure your shell environment for container image signing and verification.
Navigate to the
sigstore-ocpdirectory by running the following command:cd sigstore-ocp
$ cd sigstore-ocpCopy to Clipboard Copied! Toggle word wrap Toggle overflow Configure the shell by running the
tas-env-variables.shscript:source tas-env-variables.sh
$ source tas-env-variables.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional) Set the environment variables manually:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow source ./tas-env-vars.sh
$ source ./tas-env-vars.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Initialize The Update Framework (TUF) system by running the following command:
cosign initialize --mirror=$TUF_URL --root=$TUF_URL/root.json
$ cosign initialize --mirror=$TUF_URL --root=$TUF_URL/root.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow Sign your container image by running the following command:
cosign sign -y --fulcio-url=$FULCIO_URL --rekor-url=$REKOR_URL --oidc-issuer=$OIDC_ISSUER_URL IMAGE_NAME
$ cosign sign -y --fulcio-url=$FULCIO_URL --rekor-url=$REKOR_URL --oidc-issuer=$OIDC_ISSUER_URL IMAGE_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
cosign sign -y --fulcio-url=$FULCIO_URL \ --rekor-url=$REKOR_URL \ --oidc-issuer=$OIDC_ISSUER_URL example-hello-world@sha256:2788a47fd0ef1ece30898c1e608050ea71036d3329b9772dbb3d1f69313f745c
$ cosign sign -y --fulcio-url=$FULCIO_URL \ --rekor-url=$REKOR_URL \ --oidc-issuer=$OIDC_ISSUER_URL example-hello-world@sha256:2788a47fd0ef1ece30898c1e608050ea71036d3329b9772dbb3d1f69313f745cCopy to Clipboard Copied! Toggle word wrap Toggle overflow In the web browser that opens, sign the container image with an email address.
Create a
predicate.jsonfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Associate the
predicate.jsonfile with your container image by running the following command:cosign attest -y --predicate ./predicate.json \ --type slsaprovenance IMAGE_NAME:TAG
$ cosign attest -y --predicate ./predicate.json \ --type slsaprovenance IMAGE_NAME:TAGCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
cosign attest -y --predicate ./predicate.json \ --type slsaprovenance example.io/hello-world:latest
$ cosign attest -y --predicate ./predicate.json \ --type slsaprovenance example.io/hello-world:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the container image has at least one attestation and signature by running the following command:
cosign tree IMAGE_NAME:TAG
$ cosign tree IMAGE_NAME:TAGCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the container image with Conforma by running the following command:
ec validate image --image IMAGE_NAME:TAG \ --certificate-identity-regexp 'SIGNER_EMAIL_ADDR' \ --certificate-oidc-issuer-regexp 'keycloak-keycloak-system' \ --output yaml --show-successes
$ ec validate image --image IMAGE_NAME:TAG \ --certificate-identity-regexp 'SIGNER_EMAIL_ADDR' \ --certificate-oidc-issuer-regexp 'keycloak-keycloak-system' \ --output yaml --show-successesCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
ec validate image --image example.io/hello-world:latest \ --certificate-identity 'jdoe@example.com' \ --certificate-oidc-issuer 'keycloak-keycloak-system' \ --output yaml --show-successes
$ ec validate image --image example.io/hello-world:latest \ --certificate-identity 'jdoe@example.com' \ --certificate-oidc-issuer 'keycloak-keycloak-system' \ --output yaml --show-successesCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the output to verify the container image:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Conforma generates a pass or fail report with details about any security violations. When you add the
--infoflag, the report includes more details and possible solutions for any violations.
Chapter 5. Attesting and validating a container image 复制链接链接已复制到粘贴板!
Before Conforma can validate your signed container image, you must first create Supply-chain Levels for Software Artifacts (SLSA) provenance and associate it with your container image. Provenance is the verifiable information about software artifacts, including where, when, and how a given software "link" in a supply chain was produced.
Prerequisites
- A signed container image.
- Access to the OpenShift Container Platform web console.
- A working Red Hat Trusted Artifact Signer installation running on OpenShift version 4.13 or later.
-
A workstation with the
cosignandocbinary files installed.
Procedure
Create a SLSA provenance
predicate.jsonfile. For example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Sign and attest the
predicate.jsonfile you just created by running the following command:cosign attest -y --fulcio-url=$FULCIO_URL \ --rekor-url=$REKOR_URL \ --oidc-issuer=$OIDC_ISSUER_URL \ --predicate predicate.json \ --type slsaprovenance $IMAGE
$ cosign attest -y --fulcio-url=$FULCIO_URL \ --rekor-url=$REKOR_URL \ --oidc-issuer=$OIDC_ISSUER_URL \ --predicate predicate.json \ --type slsaprovenance $IMAGECopy to Clipboard Copied! Toggle word wrap Toggle overflow Keycloak opens to automatically authenticate you based on your login when you signed the container image.
Verify the signature and attestation with Conforma by running the following command:
ec validate image --image $IMAGE \ --certificate-identity-regexp '.*' \ --certificate-oidc-issuer-regexp '.*' \ --output yaml --show-successes
$ ec validate image --image $IMAGE \ --certificate-identity-regexp '.*' \ --certificate-oidc-issuer-regexp '.*' \ --output yaml --show-successesCopy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantBe as specific as possible when you run the
ec validate imagecommand so that each signature matches the expectedidentity.
Verification
- When Conforma has validated your container image, a detailed report of all Conforma verifications and signatures opens.