Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
gcp-binary-authorization: circleci/gcp-binary-authorization@1.0.0
Use gcp-binary-authorization
elements in your existing workflows and jobs.
Get set up to use Binary Authorization on CircleCI. The `run-setup` job will enable all required GCP APIs; enable Binary Authorization for a given GKE cluster (and first create that cluster, if necessary); create a container analysis note; create an attestor; and, optionally, create a Binary Authorization policy. This example also creates a new PGP keypair and stores it in CircleCI as environment variables for future attestation signing, and otherwise uses the minimum required parameters that do not have default values.
1
2
3
4
5
6
7
8
9
10
11
12
version: '2.1'
orbs:
bin-authz: circleci/gcp-binary-authorization@x.y.z
workflows:
setup_binary_authorization:
jobs:
- bin-authz/run-setup:
gke-cluster-name: your-cluster
keypair-email: email-for-your-keypair
keypair-name: name-for-your-keypair
use-existing-keypair: false
workflows: null
Get set up to use Binary Authorization on CircleCI, and complete an attestation signing for a particular container image, all at once. The `create-attestation` job will run all required setup commands, then create and sign an attestation allowing the container image to be successfully deployed. This example uses the minimum required parameters and thus assumes the following: there is an existing GKE cluster to use with Binary Authorization, and there is an existing PGP keypair stored in CircleCI. A container analysis note, attestor, Binary Authorization policy, and attestation are created on-the-fly. Although not shown in this example, a Docker image would likely be built and deployed to a staging/test environment in a previous job, and then deployed to a production cluster in a subsequent job.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
version: '2.1'
orbs:
bin-authz: circleci/gcp-binary-authorization@x.y.z
workflows:
setup_and_run_binary_authorization:
jobs:
- bin-authz/create-attestation:
configure-policy: true
deployment-steps:
- run: >
echo "your deployment logic can live here"
echo "or in a subsequent workflow job"
echo "see `simple-deploy-attested-image` example for sample
kubectl deployment syntax"
gke-cluster-name: your-gke-cluster
image-path: e.g., gcr.io/your-project/your-image
image-tag: tag-that-will-be-deployed
keypair-email: email-address@used-to-generate-keypair.com
note-description-long: |
Longform description of container analysis note
run-setup: true
Get set up to use Binary Authorization on CircleCI. The `run-setup` job will enable all required GCP APIs; enable Binary Authorization for a given GKE cluster (and first create that cluster, if necessary); create a container analysis note; create an attestor; and, optionally, create a Binary Authorization policy. This simple example uses the minimum required parameters that do not have default values.
1
2
3
4
5
6
7
8
9
version: '2.1'
orbs:
bin-authz: circleci/gcp-binary-authorization@x.y.z
workflows:
setup_binary_authorization:
jobs:
- bin-authz/run-setup:
gke-cluster-name: your-cluster
workflows: null
In the first job, use the GCP GCR Orb to push an image to a Google Container Registry. In the second job, use the Binary Authorization Orb to sign the image for release, then deploy the image to Google Kubernetes Engine.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
version: '2.1'
orbs:
bin-authz: circleci/gcp-binary-authorization@x.y.z
gcp-gcr: circleci/gcp-gcr@x.y.z
workflows:
push_sign_deploy:
jobs:
- gcp-gcr/build_and_push_image:
context: your-context
image: your-image
registry-url: gcr.io
tag: your-tag
- bin-authz/create-attestation:
attestor: $CIRCLE_USERNAME
context: your-context
deployment-steps:
- run: |
kubectl run your-server \
--image gcr.io/$GOOGLE_PROJECT_ID/your-image@$YOUR_IMAGE_DIGEST \
--port 8080
gke-cluster-name: your-GKE-cluster-name
image-path: gcr.io/$GOOGLE_PROJECT_ID/your-image
image-tag: your-tag
keypair-email: email.address@used.to.generate.keypair.com
note-filepath: your-container-analysis-note.json
policy-filepath: your-binauthz-policy-file.yaml
requires:
- gcp-gcr/build_and_push_image
use-note-file: true
use-policy-file: true
Sign/authorize a specific tag of a container image stored in a Google container registry for deployment to Google Kubernetes Engine. For details, see Google's Binary Authorization documentation: https://cloud.google.com/binary-authorization/docs
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
admission-whitelist-patterns | Whitelist of container images that are exempt from the attestation requirements in the policy. Supply a comma-separated string list (e.g., see default value) of paths to images in Google's, or any other, container registry. For details, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admissionwhitelistpatterns
| No | gcr.io/google_containers/*,k8s.gcr.io/*,gcr.io/stackdriver-agents/* | string |
attach-workspace | Attach to an existing workspace? Default is `false`
| No | false | boolean |
attestation-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTATION_PROJECT_ID | env_var_name |
attestor | Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
| No | $CIRCLE_USERNAME | string |
attestor-hint | A human-readable name for this attestation authority (e.g., QA)
| No | CircleCI username | string |
attestor-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTOR_PROJECT_ID | env_var_name |
attestor-service-account | Name of environment variable storing the service account address for the attestor Google project. Only required if using a multi-project setup.
| No | ATTESTOR_SERVICE_ACCOUNT | env_var_name |
checkout | Checkout as a first step? Default is `false`
| No | false | boolean |
circle-token | Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables
| No | CIRCLE_TOKEN | env_var_name |
cluster-specific-eval-mode | For the specified cluster, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
| No | REQUIRE_ATTESTATION | enum |
cluster-specific-required-attestors | What attestors will be required to sign releases, for cluster- specific rulesets? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`, as described here: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
| No | projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME | string |
cluster-specific-rules | Specify distinict sets of deployment rules for individual GKE clusters? If so, pass the requisite values to any additional cluster-specific parameters. Currently, only a single set of cluster- specific rules can be specified. For details, see the following: https://cloud.google.com/binary-authorization/docs/key-concepts#cluster-specific_rules
| No | false | boolean |
cluster-specific-specifier | If specifying a set of cluster-specific rules, what is the name of the GKE cluster to which these rules will apply? Supply an environment variable storing a GKE cluster name in the `location.name` format (e.g., `us-east1-a.prod-cluster`)
| No | CLUSTER_SPECIFIER_LOCATION_NAME | env_var_name |
configure-policy | Configure a new Binary Authorization policy for this attestation? Choose `false` to use the existing policy stored in Binary Authorization
| No | false | boolean |
create-new-gke-cluster | Create a new GKE cluster to use with Binary Authorization? Default is `false`
| No | false | boolean |
default-evaluation-mode | By default, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
| No | REQUIRE_ATTESTATION | enum |
default-required-attestors | What attestors will be required to sign releases, by default? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
| No | projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME | string |
deployer-project-id | Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
| No | DEPLOYER_PROJECT_ID | env_var_name |
deployer-service-account | Name of environment variable storing the service account address for the deployer Google project. Only required if using a multi-project setup.
| No | DEPLOYER_SERVICE_ACCOUNT | env_var_name |
deployer-service-key | Name of environment variable storing the full service key JSON file for the deployer Google project. Only required if using a multi- project setup.
| No | DEPLOYER_SERVICE_KEY | env_var_name |
deployment-steps | Optional deployment steps to run after signing an image for release. See the `deploy-attested-image` usage example for one possible implementation.
| No | [] | steps |
enable-apis | Do required APIs (container.googleapis.com, containeranalysis.googleapis.com, binaryauthorization.googleapis.com) need to be enabled?
| No | true | boolean |
executor | Executor to use for this job, defaults to Google's official Docker image with the gcloud CLI preinstalled
| No | default | executor |
gke-cluster-name | Name of the GKE cluster for which to enable Binary Authorization
| No | '' | string |
google-compute-zone | Name of environment variable storing the Google compute zone to use by default when running commands with the gcloud CLI
| No | GOOGLE_COMPUTE_ZONE | env_var_name |
google-project-id | Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
| No | GOOGLE_PROJECT_ID | env_var_name |
google-service-account | Name of environment variable storing the service account address for the Google project. Not required if using a multi-project setup.
| No | GOOGLE_SERVICE_ACCOUNT | env_var_name |
google-service-key | Name of environment variable storing the full service key JSON file for the Google project. Not required if using a multi-project setup.
| No | GOOGLE_SERVICE_KEY | env_var_name |
image-path | Path in Google's, or any other, container registry to the image being deployed (e.g., `gcr.io/example-project/quickstart-image`)
| Yes | - | string |
image-tag | Specific tag of image that will be deployed, used to generate a full SHA-256 for attestation.
| No | latest | string |
keypair-email | Email address attached to existing PGP keypair, or to attach to newly created keypair.
| Yes | - | string |
keypair-name | Name to attach to PGP keypair. Only required if `use-existing-keypair` is set to `false`.
| No | '' | string |
keypair-passphrase | Name of environment variable storing the passphrase used to generate PGP keypair
| No | BIN_AUTHZ_KEYPAIR_PASSPHRASE | env_var_name |
multi-project-setup | Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
| No | false | boolean |
note-description-long | Longer, more detailed description of container analysis note
| No | '' | string |
note-description-short | One-sentence description of this note | No | >- Container analysis note from CircleCI job $CIRCLE_JOB, number $CIRCLE_BUILD_NUM, triggered by $CIRCLE_USERNAME | string |
note-expiration-time | Timestamp-formatted expiration time for this note (empty if the note does not expire). For details, see the following: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp
| No | '' | string |
note-filepath | Path to your container analysis note file. Should be an existing file if `use-note-file` is `true`; otherwise, note will be created at this path.
| No | /tmp/note_payload.json | string |
note-id | Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
| No | $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM | string |
note-related-url | Any URL related to the container analysis note | No | $CIRCLE_BUILD_URL | string |
payload-filepath | Path at which to generate an attestation payload | No | /tmp/generated_payload.json | string |
policy-filepath | Path to a Binary Authorization policy YAML file. Should be an existing file if `use-policy-file` is `true`; otherwise, a policy file will be created (`configure-policy`) or imported (`import-existing- policy`) at this path.
| No | /tmp/policy.yaml | string |
private-key | Name of environment variable storing (or under which to store, if `use-existing-keypair` is false and `store-generated-keypair` is true) the private portion of the keypair with which to sign the attestation. If `use-existing-keypair` is true, store the private key in Contexts or as a project-level environment variable, as a single- line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. For details, see the following documentation: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
| No | BIN_AUTHZ_PRIVATE_KEY | env_var_name |
public-key | Name of environment variable storing (or under which to store, if `use-existing-keypair` is false and `store-generated-keypair` is true) the public portion of the keypair with which to sign the attestation. If `use-existing-keypair` is true, store the public key in Contexts or as a project-level environment variable, as a single- line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. For details, see the following documentation: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
| No | BIN_AUTHZ_PUBLIC_KEY | env_var_name |
related-note-names | Names of any notes relevant or related to this note | No | '' | string |
run-setup | Run Binary Authorization setup steps? Setup steps are designed to be run once to initialize Binary Authorization for a particular CircleCI project.
| No | false | boolean |
store-generated-keypair | Store public and private portions of generated keypair as CircleCI environment variables?
| No | true | boolean |
use-existing-keypair | Use an existing PGP keypair? If `false`, a keypair will be created on-the-fly
| No | true | boolean |
use-note-file | Upload an existing container analysis note file instead of creating one via this command's paramaters?
| No | false | boolean |
use-passphrase | If `use-existing-keypair` is set to `false`: does the existing PGP keypair have a passphrase? If `use-existing-keypair` is set to `true`: generate a PGP keypair with a passphrase?
| No | false | boolean |
use-policy-file | Use a locally stored Binary Authorization policy YAML file instead of creating one via this command's paramaters (`configure-policy`) or using an existing policy already stored in Binary Authorization?
| No | false | boolean |
workspace-root | Workspace root path that is either an absolute path or a path relative to the working directory.
| No | workspace | string |
Get set up to use Google's Binary Authorization on CircleCI. This job is designed to be run once to initialize Binary Authorization for a particular CircleCI project. It will enable all required APIs, optionally create a GKE cluster, create an attestor, optionally generate and store a PGP keypair, and optionally create and store a Binary Authorization policy YAML file. After running this job successfully, it can be removed from your config.yml file. To use this job, at least one existing Google project is required; if using a multi-project Binary Authorization setup, three separate Google projects (deployer, attestor, attestation) are required. This job is also available as an orb command, also called `setup`, if more control over its mode of execution is desired. For further information, see Google's Binary Authorization documentation: https://cloud.google.com/binary-authorization/docs/overview
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
admission-whitelist-patterns | Whitelist of container images that are exempt from the attestation requirements in the policy. Supply a comma-separated string list (e.g., see default value) of paths to images in Google's, or any other, container registry. For details, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admissionwhitelistpatterns
| No | gcr.io/google_containers/*,k8s.gcr.io/*,gcr.io/stackdriver-agents/* | string |
attach-workspace | Attach to an existing workspace? Default is `false`
| No | false | boolean |
attestation-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTATION_PROJECT_ID | env_var_name |
attestor | Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
| No | $CIRCLE_USERNAME | string |
attestor-hint | A human-readable name for this attestation authority (e.g., QA)
| No | CircleCI username | string |
attestor-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTOR_PROJECT_ID | env_var_name |
attestor-service-account | Name of environment variable storing the service account address for the attestor Google project. Only required if using a multi-project setup.
| No | ATTESTOR_SERVICE_ACCOUNT | env_var_name |
checkout | Checkout as a first step? Default is `false`
| No | false | boolean |
circle-token | Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables. Only required if generating and storing a new keypair.
| No | CIRCLE_TOKEN | env_var_name |
cluster-specific-eval-mode | For the specified cluster, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
| No | REQUIRE_ATTESTATION | enum |
cluster-specific-required-attestors | What attestors will be required to sign releases, for cluster- specific rulesets? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`, as described here: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
| No | projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME | string |
cluster-specific-rules | Specify distinict sets of deployment rules for individual GKE clusters? If so, pass the requisite values to any additional cluster-specific parameters. Currently, only a single set of cluster- specific rules can be specified. For details, see the following: https://cloud.google.com/binary-authorization/docs/key-concepts#cluster-specific_rules
| No | false | boolean |
cluster-specific-specifier | If specifying a set of cluster-specific rules, what is the name of the GKE cluster to which these rules will apply? Supply an environment variable storing a GKE cluster name in the `location.name` format (e.g., `us-east1-a.prod-cluster`)
| No | CLUSTER_SPECIFIER_LOCATION_NAME | env_var_name |
configure-policy | Configure a Binary Authorization policy as part of setup? Choose `true` if a single policy will most likely persist across future deployments; choose `false` if a new policy will be generated for each deployment.
| No | true | boolean |
create-new-gke-cluster | Create a new GKE cluster to use with Binary Authorization? Defaults to `false`
| No | false | boolean |
default-evaluation-mode | By default, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
| No | REQUIRE_ATTESTATION | enum |
default-required-attestors | What attestors will be required to sign releases, by default? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
| No | projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME | string |
deployer-project-id | Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
| No | DEPLOYER_PROJECT_ID | env_var_name |
deployer-service-account | Name of environment variable storing the service account address for the deployer Google project. Only required if using a multi-project setup.
| No | DEPLOYER_SERVICE_ACCOUNT | env_var_name |
deployer-service-key | Name of environment variable storing the full service key JSON file for the deployer Google project. Only required if using a multi- project setup.
| No | DEPLOYER_SERVICE_KEY | env_var_name |
enable-apis | Do required APIs (container.googleapis.com, containeranalysis.googleapis.com, binaryauthorization.googleapis.com) need to be enabled?
| No | true | boolean |
executor | Executor to use for this job, defaults to Google's official Docker image with the gcloud CLI preinstalled
| No | default | executor |
gke-cluster-name | Name of the GKE cluster for which to enable Binary Authorization
| No | '' | string |
google-compute-zone | Name of environment variable storing the Google compute zone to use by default when running commands with the gcloud CLI
| No | GOOGLE_COMPUTE_ZONE | env_var_name |
google-project-id | Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
| No | GOOGLE_PROJECT_ID | env_var_name |
google-service-account | Name of environment variable storing the service account address for the Google project. Not required if using a multi-project setup.
| No | GOOGLE_SERVICE_ACCOUNT | env_var_name |
google-service-key | Name of environment variable storing the full service key JSON file for the Google project. Not required if using a multi-project setup.
| No | GOOGLE_SERVICE_KEY | env_var_name |
keypair-email | Email address to attach to PGP keypair. Only required here if `use-existing-keypair` is set to `false` (required by subsequent commands either way).
| No | '' | string |
keypair-name | Name to attach to PGP keypair. Only required if `use-existing-keypair` is set to `false`.
| No | '' | string |
keypair-passphrase | Name of environment variable storing a passphrase to use when generating a PGP keypair. Only required if `use-existing-keypair` is set to `false`.
| No | BIN_AUTHZ_KEYPAIR_PASSPHRASE | env_var_name |
multi-project-setup | Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
| No | false | boolean |
note-description-long | Longer, more detailed description of this note | No | '' | string |
note-description-short | One-sentence description of this note | No | >- Container analysis note from CircleCI job $CIRCLE_JOB, number $CIRCLE_BUILD_NUM, triggered by $CIRCLE_USERNAME | string |
note-expiration-time | Timestamp-formatted expiration time for this note (empty if the note does not expire). For details, see the following: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp
| No | '' | string |
note-filepath | Path to your container analysis note file. Should be an existing file if `use-note-file` is `true`; otherwise, note will be created at this path.
| No | /tmp/note_payload.json | string |
note-id | Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
| No | $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM | string |
note-related-url | Any URL related to the note | No | $CIRCLE_BUILD_URL | string |
policy-filepath | Path to a Binary Authorization policy YAML file. Should be an existing file if `use-policy-file` is `true`; otherwise, a policy file will be created at this path.
| No | /tmp/policy.yaml | string |
private-key | Name of environment variable under which to store the private portion of the keypair generated to use with Binary Authorization. Only required here if `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true (required by subsequent commands either way).
| No | BIN_AUTHZ_PRIVATE_KEY | env_var_name |
public-key | Name of environment variable storing or under which to store the public portion of the keypair with which to sign the attestation. Not required if `use-existing-keypair` is set to `false`. Store the public key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. See Google's documentation: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
| No | BIN_AUTHZ_PUBLIC_KEY | env_var_name |
related-note-names | Names of any notes relevant or related to this note | No | '' | string |
store-generated-keypair | Store public and private portions of generated keypair as CircleCI environment variables?
| No | true | boolean |
use-existing-keypair | Use an existing PGP keypair? If `false`, a keypair will be created on-the-fly
| No | true | boolean |
use-note-file | Upload an existing container analysis note file instead of creating one via this command's paramaters?
| No | false | boolean |
use-passphrase | Generate a PGP keypair with a passphrase? Only required if `use-existing-keypair` is set to `false`
| No | false | boolean |
use-policy-file | Use an existing Binary Authorization policy YAML file instead of creating one via this command's paramaters?
| No | false | boolean |
workspace-root | Workspace root path that is either an absolute path or a path relative to the working directory.
| No | workspace | string |
Configure a Binary Authorization deployment policy. See the following: https://cloud.google.com/binary-authorization/docs/key-concepts#policies https://cloud.google.com/binary-authorization/docs/configuring-policy-cli https://cloud.google.com/binary-authorization/docs/policy-yaml-reference
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
admission-whitelist-patterns | Whitelist of container images that are exempt from the attestation requirements in the policy. Supply a comma-separated string list (e.g., see default value) of paths to images in Google's, or any other, container registry. For details, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admissionwhitelistpatterns
| No | gcr.io/google_containers/*,k8s.gcr.io/*,gcr.io/stackdriver-agents/* | string |
attestor-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTOR_PROJECT_ID | env_var_name |
cluster-specific-eval-mode | For the specified cluster, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
| No | REQUIRE_ATTESTATION | enum |
cluster-specific-required-attestors | What attestors will be required to sign releases, for cluster- specific rulesets? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`, as described here: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
| No | projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME | string |
cluster-specific-rules | Specify distinct sets of deployment rules for individual GKE clusters? If so, pass the requisite values to any additional cluster-specific parameters. Currently, only a single set of cluster- specific rules can be specified. For details, see the following: https://cloud.google.com/binary-authorization/docs/key-concepts#cluster-specific_rules
| No | false | boolean |
cluster-specific-specifier | If specifying a set of cluster-specific rules, what is the name of the GKE cluster to which these rules will apply? Supply an environment variable storing a GKE cluster name in the `location.name` format (e.g., `us-east1-a.prod-cluster`)
| No | CLUSTER_SPECIFIER_LOCATION_NAME | env_var_name |
default-evaluation-mode | By default, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
| No | REQUIRE_ATTESTATION | enum |
default-required-attestors | What attestors will be required to sign releases, by default? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
| No | projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME | string |
deployer-project-id | Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
| No | DEPLOYER_PROJECT_ID | env_var_name |
google-project-id | Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
| No | GOOGLE_PROJECT_ID | env_var_name |
multi-project-setup | Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
| No | false | boolean |
policy-filepath | Path to a Binary Authorization policy YAML file. Should be an existing file if `use-policy-file` is `true`; otherwise, a policy file will be created at this path.
| No | /tmp/policy.yaml | string |
use-policy-file | Use an existing Binary Authorization policy YAML file instead of creating one via this command's parameters?
| No | false | boolean |
Create a Binary Authorization attestation authorizing a container image for deployment. See Google's Binary Authorization documentation: https://cloud.google.com/binary-authorization/docs/key-concepts#attestations https://cloud.google.com/binary-authorization/docs/making-attestations
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
attestation-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTATION_PROJECT_ID | env_var_name |
attestor | Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
| No | $CIRCLE_USERNAME | string |
attestor-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTOR_PROJECT_ID | env_var_name |
create-new-gke-cluster | Create a new GKE cluster to use with Binary Authorization? Defaults to `false` Passed to setup command.
| No | false | boolean |
enable-apis | Do required APIs (container.googleapis.com, containeranalysis.googleapis.com, binaryauthorization.googleapis.com) need to be enabled? Passed to setup command.
| No | false | boolean |
gke-cluster-name | Name of the GKE cluster for which to enable Binary Authorization Passed to setup command.
| No | '' | string |
google-project-id | Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
| No | GOOGLE_PROJECT_ID | env_var_name |
image-path | Path in Google's, or any other, container registry to the image being deployed (e.g., `gcr.io/example-project/quickstart-image`)
| Yes | - | string |
image-tag | Specific tag of image that will be deployed, used to generate a full SHA-256 for attestation.
| No | latest | string |
keypair-email | Email address attached to PGP keypair | Yes | - | string |
keypair-passphrase | Name of environment variable storing the passphrase used to generate PGP keypair
| No | BIN_AUTHZ_KEYPAIR_PASSPHRASE | env_var_name |
multi-project-setup | Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
| No | false | boolean |
payload-filepath | Path at which to generate an attestation payload | No | /tmp/generated_payload.json | string |
private-key | Name of environment variable storing the private portion of the keypair with which to sign the attestation. Unless `use-existing-keypair` is set to `false`, store the private key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. See Google's documentation for details: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
| No | BIN_AUTHZ_PRIVATE_KEY | env_var_name |
public-key | Name of environment variable storing the public portion of the keypair with which to sign the attestation. Not required if `use-existing-keypair` is set to `false`. Store the public key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. See Google's documentation for details: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
| No | BIN_AUTHZ_PUBLIC_KEY | env_var_name |
run-setup | Set to `true` to handle setup through this command. Helpful if an attestor has not been created before this step.
| No | false | boolean |
use-existing-keypair | Use an existing PGP keypair? Only select `false` if a keypair was generated on-the-fly in the `create-attestor` command
| No | true | boolean |
use-passphrase | If `use-existing-keypair` is set to `false`: does the existing PGP keypair have a passphrase? If `use-existing-keypair` is set to `true`: was the newly generated PGP keypair created with a passphrase?
| No | false | boolean |
Create an attestor in Binary Authorization. For details, see: https://cloud.google.com/binary-authorization/docs/key-concepts#attestors
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
attestor | Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
| No | $CIRCLE_USERNAME | string |
attestor-project-id | Name of environment variable storing the Google project ID for the`` attestor project. Only required if using a multi-project setup.
| No | ATTESTOR_PROJECT_ID | env_var_name |
circle-token | Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables. Only required if `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true.
| No | CIRCLE_TOKEN | env_var_name |
deployer-service-account | Name of environment variable storing the service account address for the deployer Google project. Only required if using a multi-project setup.
| No | DEPLOYER_SERVICE_ACCOUNT | env_var_name |
google-project-id | Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
| No | GOOGLE_PROJECT_ID | env_var_name |
keypair-email | Email address to attach to PGP keypair. Only required here if `use-existing-keypair` is set to `false` (required by subsequent commands either way).
| No | '' | string |
keypair-name | Name to attach to PGP keypair. Only required if `use-existing-keypair` is set to `false`.
| No | '' | string |
keypair-passphrase | Name of environment variable storing a passphrase to use when generating a PGP keypair. Only required if `use-existing-keypair` is set to `false`.
| No | BIN_AUTHZ_KEYPAIR_PASSPHRASE | env_var_name |
multi-project-setup | Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
| No | false | boolean |
note-id | Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
| No | $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM | string |
private-key | Name of environment variable under which to store the private portion of the keypair generated to use with Binary Authorization. Only required here if `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true (required by subsequent commands either way).
| No | BIN_AUTHZ_PRIVATE_KEY | env_var_name |
public-key | Name of environment variable storing the public portion of the keypair with which to sign the attestation. If `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true, the public key will be stored in CircleCI as a project environment variable under this name. Otherwise, please store the public key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA- 2048-type key. See Google's PGP key documentation for details: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
| No | BIN_AUTHZ_PUBLIC_KEY | env_var_name |
store-generated-keypair | Store public and private portions of generated keypair as CircleCI environment variables?
| No | true | boolean |
use-existing-keypair | Use an existing PGP keypair? If `false`, a keypair will be created on-the-fly
| No | true | boolean |
use-passphrase | Generate a PGP keypair with a passphrase? Only required if `use-existing-keypair` is set to `false`
| No | false | boolean |
Create a Container Analysis note. For details, see the following: https://cloud.google.com/container-registry/docs/container-analysis#note
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
attestor | Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
| No | $CIRCLE_USERNAME | string |
attestor-hint | A human-readable name for this attestation authority (e.g., QA)
| No | CircleCI username | string |
attestor-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTOR_PROJECT_ID | env_var_name |
attestor-service-account | Name of environment variable storing the service account address for the attestor Google project. Only required if using a multi-project setup.
| No | ATTESTOR_SERVICE_ACCOUNT | env_var_name |
google-project-id | Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
| No | GOOGLE_PROJECT_ID | env_var_name |
google-service-account | Name of environment variable storing the service account address for the Google project. Not required if using a multi-project setup.
| No | GOOGLE_SERVICE_ACCOUNT | env_var_name |
multi-project-setup | Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
| No | false | boolean |
note-description-long | Longer, more detailed description of this note. This will be evaluated. | No | '' | string |
note-description-short | One-sentence description of this note. This will be evaluated. | No | >- Container analysis note from CircleCI job $CIRCLE_JOB, number $CIRCLE_BUILD_NUM, triggered by $CIRCLE_USERNAME | string |
note-expiration-time | Timestamp-formatted expiration time for this note (empty if the note does not expire). For details, see the following: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp
| No | '' | string |
note-filepath | Path to your container analysis note file. Should be an existing file if `use-note-file` is `true`; otherwise, note will be created at this path.
| No | /tmp/note_payload.json | string |
note-id | Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
| No | $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM | string |
note-related-url | Any URL related to the note. This will be evaluated. | No | $CIRCLE_BUILD_URL | string |
related-note-names | Names of any notes relevant or related to this note | No | '' | string |
use-note-file | Upload an existing container analysis note file instead of creating one via this command's parameters?
| No | false | boolean |
Generate an RSA-2048-type PGP keypair to use with Google's Binary Authorization and optionally store its public and private portions as CircleCI environment variables.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
circle-token | Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables
| No | CIRCLE_TOKEN | env_var_name |
keypair-email | Email address to attach to PGP keypair
| Yes | - | string |
keypair-name | Name to attach to PGP keypair
| No | '' | string |
keypair-passphrase | Name of environment variable storing a passphrase to use when generating a PGP keypair (only required if `use-passphrase` is set to `true`)
| No | BIN_AUTHZ_KEYPAIR_PASSPHRASE | env_var_name |
private-key | Name of environment variable under which to store the private portion of the keypair generated to use with Binary Authorization
| No | BIN_AUTHZ_PRIVATE_KEY | env_var_name |
public-key | Name of environment variable under which to store the public portion of the keypair generated to use with Binary Authorization
| No | BIN_AUTHZ_PUBLIC_KEY | env_var_name |
store-generated-keypair | Store public and private portions of generated keypair as CircleCI environment variables?
| No | true | boolean |
use-passphrase | Generate a PGP keypair with a passphrase?
| No | false | boolean |
Get Google Kubernetes Engine credentials and update a local kubeconfig file to enable further Binary Authorization commands on that cluster. Generally does not need to be run on its own, as it is run as part of both the `run-setup` and `create-attestation` jobs.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
deployer-project-id | Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
| No | DEPLOYER_PROJECT_ID | env_var_name |
gke-cluster-name | Name of the GKE cluster for which to enable Binary Authorization
| No | '' | string |
google-compute-zone | Name of environment variable storing the Google compute zone to use by default when running commands with the gcloud CLI
| No | GOOGLE_COMPUTE_ZONE | env_var_name |
google-project-id | Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
| No | GOOGLE_PROJECT_ID | env_var_name |
multi-project-setup | Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
| No | false | boolean |
Get set up to use Google's Binary Authorization on CircleCI. This command is designed to be run once to initialize Binary Authorization for a particular CircleCI project. It will enable all required APIs, optionally create a GKE cluster, create a Container Analysis note and an attestor, optionally generate and store a PGP keypair, and optionally create and store a Binary Authorization policy YAML file. After running this command successfully, it can be removed from your config.yml file. To use this command, at least one existing Google project is required; if using a multi-project Binary Authorization setup, three separate Google projects (deployer, attestor, attestation) are required. For easier execution, this command is also available as an orb job, also called `setup`. For additional information, see Google's Binary Authorization documentation: https://cloud.google.com/binary-authorization/docs/overview
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
admission-whitelist-patterns | Whitelist of container images that are exempt from the attestation requirements in the policy. Supply a comma-separated string list (e.g., see default value) of paths to images in Google's, or any other, container registry. For details, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admissionwhitelistpatterns
| No | gcr.io/google_containers/*,k8s.gcr.io/*,gcr.io/stackdriver-agents/* | string |
attestation-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTATION_PROJECT_ID | env_var_name |
attestor | Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
| No | $CIRCLE_USERNAME | string |
attestor-hint | A human-readable name for this attestation authority (e.g., QA)
| No | CircleCI username | string |
attestor-project-id | Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
| No | ATTESTOR_PROJECT_ID | env_var_name |
attestor-service-account | Name of environment variable storing the service account address for the attestor Google project. Only required if using a multi-project setup.
| No | ATTESTOR_SERVICE_ACCOUNT | env_var_name |
circle-token | Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables
| No | CIRCLE_TOKEN | env_var_name |
cluster-specific-eval-mode | For the specified cluster, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
| No | REQUIRE_ATTESTATION | enum |
cluster-specific-required-attestors | What attestors will be required to sign releases, for cluster- specific rulesets? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`, as described here: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
| No | projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME | string |
cluster-specific-rules | Specify distinict sets of deployment rules for individual GKE clusters? If so, pass the requisite values to any additional cluster-specific parameters. Currently, only a single set of cluster- specific rules can be specified. For details, see the following: https://cloud.google.com/binary-authorization/docs/key-concepts#cluster-specific_rules
| No | false | boolean |
cluster-specific-specifier | If specifying a set of cluster-specific rules, what is the name of the GKE cluster to which these rules will apply? Supply an environment variable storing a GKE cluster name in the `location.name` format (e.g., `us-east1-a.prod-cluster`)
| No | CLUSTER_SPECIFIER_LOCATION_NAME | env_var_name |
configure-policy | Configure a Binary Authorization policy as part of setup? Choose `true` if a single policy will most likely persist across future deployments; choose `false` if a new policy will be generated for each deployment.
| No | true | boolean |
create-new-gke-cluster | Create a new GKE cluster to use with Binary Authorization? Defaults to `false`
| No | false | boolean |
default-evaluation-mode | By default, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
| No | REQUIRE_ATTESTATION | enum |
default-required-attestors | What attestors will be required to sign releases, by default? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
| No | projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME | string |
deployer-project-id | Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
| No | DEPLOYER_PROJECT_ID | env_var_name |
deployer-service-account | Name of environment variable storing the service account address for the deployer Google project. Only required if using a multi-project setup.
| No | DEPLOYER_SERVICE_ACCOUNT | env_var_name |
enable-apis | Do required APIs (container.googleapis.com, containeranalysis.googleapis.com, binaryauthorization.googleapis.com) need to be enabled?
| No | true | boolean |
gke-cluster-name | Name of the GKE cluster for which to enable Binary Authorization
| No | '' | string |
google-compute-zone | Name of environment variable storing the Google compute zone to use by default when running commands with the gcloud CLI
| No | GOOGLE_COMPUTE_ZONE | env_var_name |
google-project-id | Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
| No | GOOGLE_PROJECT_ID | env_var_name |
google-service-account | Name of environment variable storing the service account address for the Google project. Not required if using a multi-project setup.
| No | GOOGLE_SERVICE_ACCOUNT | env_var_name |
keypair-email | Email address to attach to PGP keypair. Only required here if `use-existing-keypair` is set to `false` (required by subsequent commands either way).
| Yes | - | string |
keypair-name | Name to attach to PGP keypair. Only required if `use-existing-keypair` is set to `false`.
| No | '' | string |
keypair-passphrase | Name of environment variable storing a passphrase to use when generating a PGP keypair. Only required if `use-existing-keypair` is set to `false`.
| No | BIN_AUTHZ_KEYPAIR_PASSPHRASE | env_var_name |
multi-project-setup | Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
| No | false | boolean |
note-description-long | Longer, more detailed description of this note | No | '' | string |
note-description-short | One-sentence description of this note | No | >- Container analysis note from CircleCI job $CIRCLE_JOB, number $CIRCLE_BUILD_NUM, triggered by $CIRCLE_USERNAME | string |
note-expiration-time | Timestamp-formatted expiration time for this note (empty if the note does not expire). For details, see the following: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp
| No | '' | string |
note-filepath | Path to your container analysis note file. Should be an existing file if `use-note-file` is `true`; otherwise, note will be created at this path.
| No | /tmp/note_payload.json | string |
note-id | Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
| No | $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM | string |
note-related-url | Any URL related to the note | No | $CIRCLE_BUILD_URL | string |
policy-filepath | Path to a Binary Authorization policy YAML file. Should be an existing file if `use-policy-file` is `true`; otherwise, a policy file will be created at this path.
| No | /tmp/policy.yaml | string |
private-key | Name of environment variable under which to store the private portion of the keypair generated to use with Binary Authorization. Only required here if `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true (required by subsequent commands either way).
| No | BIN_AUTHZ_PRIVATE_KEY | env_var_name |
public-key | Name of environment variable storing the public portion of the keypair with which to sign the attestation. If `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true, the public key will be stored in CircleCI as a project environment variable under this name. Otherwise, please store the public key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA- 2048-type key. See Google's PGP key documentation for details: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
| No | BIN_AUTHZ_PUBLIC_KEY | env_var_name |
related-note-names | Names of any notes relevant or related to this note | No | '' | string |
store-generated-keypair | Store public and private portions of generated keypair as CircleCI environment variables?
| No | true | boolean |
use-existing-keypair | Use an existing PGP keypair? If `false`, a keypair will be created on-the-fly
| No | true | boolean |
use-note-file | Upload an existing container analysis note file instead of creating one via this command's paramaters?
| No | false | boolean |
use-passphrase | Generate a PGP keypair with a passphrase? Only required if `use-existing-keypair` is set to `false`
| No | false | boolean |
use-policy-file | Use an existing Binary Authorization policy YAML file instead of creating one via this command's paramaters?
| No | false | boolean |
The official Google Docker container with the gcloud SDK pre-installed
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
resource-class | The resource_class with which this job should be run: https://circleci.com/docs/2.0/configuration-reference/#resource_class
| No | medium | enum |
tag | Version of the Google Cloud SDK Docker image to use. For full list, see https://hub.docker.com/r/google/cloud-sdk/tags
| No | latest | string |
CircleCI's VM image, often useful for working with Docker images
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
image-tag | Version of CircleCI's machine executor to use. For full list, see https://circleci.com/docs/2.0/configuration-reference/#machine
| No | ubuntu-2204:2022.04.2 | string |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
Configure Google's Binary Authorization service to sign and certify container images for deployment. For more information, see orb source: https://github.com/CircleCI-Public/gcp-binary-authorization-orb
display:
home_url: https://cloud.google.com/binary-authorization
source_url: https://github.com/CircleCI-Public/gcp-binary-authorization-orb
orbs:
gcp-cli: circleci/gcp-cli@2.4.1
commands:
configure-policy:
description: |
Configure a Binary Authorization deployment policy. See the following: https://cloud.google.com/binary-authorization/docs/key-concepts#policies https://cloud.google.com/binary-authorization/docs/configuring-policy-cli https://cloud.google.com/binary-authorization/docs/policy-yaml-reference
parameters:
admission-whitelist-patterns:
default: gcr.io/google_containers/*,k8s.gcr.io/*,gcr.io/stackdriver-agents/*
description: |
Whitelist of container images that are exempt from the attestation requirements in the policy. Supply a comma-separated string list (e.g., see default value) of paths to images in Google's, or any other, container registry. For details, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admissionwhitelistpatterns
type: string
attestor-project-id:
default: ATTESTOR_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
cluster-specific-eval-mode:
default: REQUIRE_ATTESTATION
description: |
For the specified cluster, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
enum:
- ALWAYS_ALLOW
- ALWAYS_DENY
- REQUIRE_ATTESTATION
type: enum
cluster-specific-required-attestors:
default: projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME
description: |
What attestors will be required to sign releases, for cluster- specific rulesets? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`, as described here: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
type: string
cluster-specific-rules:
default: false
description: |
Specify distinct sets of deployment rules for individual GKE clusters? If so, pass the requisite values to any additional cluster-specific parameters. Currently, only a single set of cluster- specific rules can be specified. For details, see the following: https://cloud.google.com/binary-authorization/docs/key-concepts#cluster-specific_rules
type: boolean
cluster-specific-specifier:
default: CLUSTER_SPECIFIER_LOCATION_NAME
description: |
If specifying a set of cluster-specific rules, what is the name of the GKE cluster to which these rules will apply? Supply an environment variable storing a GKE cluster name in the `location.name` format (e.g., `us-east1-a.prod-cluster`)
type: env_var_name
default-evaluation-mode:
default: REQUIRE_ATTESTATION
description: |
By default, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
enum:
- ALWAYS_ALLOW
- ALWAYS_DENY
- REQUIRE_ATTESTATION
type: enum
default-required-attestors:
default: projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME
description: |
What attestors will be required to sign releases, by default? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
type: string
deployer-project-id:
default: DEPLOYER_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
type: env_var_name
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
type: env_var_name
multi-project-setup:
default: false
description: |
Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
type: boolean
policy-filepath:
default: /tmp/policy.yaml
description: |
Path to a Binary Authorization policy YAML file. Should be an existing file if `use-policy-file` is `true`; otherwise, a policy file will be created at this path.
type: string
use-policy-file:
default: false
description: |
Use an existing Binary Authorization policy YAML file instead of creating one via this command's parameters?
type: boolean
steps:
- unless:
condition: <<parameters.use-policy-file>>
steps:
- run:
command: |-
echo "name: projects/${!INDIRECT_PROJECT_ID}/policy
admissionWhitelistPatterns:
ADMISSION_WHITELIST_PATTERNS
defaultAdmissionRule:
evaluationMode: ${PARAM_EVAL_MODE}
enforcementMode: ENFORCED_BLOCK_AND_AUDIT_LOG
requireAttestationsBy:
DEFAULT_REQUIRED_ATTESTORS" > "${PARAM_POLICY_FILE}"
if [ "${PARAM_CLUSTER_SPECIFIC_RULES}" = true ]; then
echo "clusterAdmissionRules:
${!INDIRECT_CLUSTER_SPECIFIER}:
evaluationMode: ${PARAM_CLUSTER_EVAL_MODE}
enforcementMode: ENFORCED_BLOCK_AND_AUDIT_LOG
requireAttestationsBy:
CLUSTER_SPECIFIC_REQUIRED_ATTESTORS" >> "${PARAM_POLICY_FILE}"
fi
echo "Success! Binary Authorization policy YAML file created at ${PARAM_POLICY_FILE}"
environment:
INDIRECT_CLUSTER_SPECIFIER: <<parameters.cluster-specific-specifier>>
INDIRECT_PROJECT_ID: <<#parameters.multi-project-setup>><<parameters.deployer-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
PARAM_CLUSTER_EVAL_MODE: <<parameters.cluster-specific-eval-mode>>
PARAM_CLUSTER_SPECIFIC_RULES: <<parameters.cluster-specific-rules>>
PARAM_EVAL_MODE: <<parameters.default-evaluation-mode>>
PARAM_POLICY_FILE: <<parameters.policy-filepath>>
name: Create policy YAML file
- run:
command: "set -x\n# insert_whitelist () {\n# WHITELIST_PATTERNS=$1\n \n# # use comma delimiters to create array\n# arrWHITELIST_PATTERNS=(\"${WHITELIST_PATTERNS//,/ }\")\n \n# # need || true in case array is length 1\n# # in which case, assigning END=0 will exit code 1\n# END=$((${#arrWHITELIST_PATTERNS[@]}-1)) || true\n \n# # iterate over array to echo admission whitelist patterns into a file\n# # \\\\ is required for sed\n# for ((i=0;i<END;i++)); do\n# echo \"- namePattern: ${arrWHITELIST_PATTERNS[i]}\\\\\" >> WHITELIST_PATTERNS.txt\n# done\n \n# # need to handle iteration for the last item separately\n# # sed does not require it to have \\ at line end\n# echo \"- namePattern: ${arrWHITELIST_PATTERNS[-1]}\" >> WHITELIST_PATTERNS.txt\n \n# READY_TO_REPLACE=$(cat WHITELIST_PATTERNS.txt)\n \n# sed -i.bak \"s@$2@$READY_TO_REPLACE@g\" \"${PARAM_POLICY_FILE}\"\n \n# rm -rf WHITELIST_PATTERNS.txt\n# }\n\n# insert_whitelist \\\n# \"${PARAM_WHITELIST_PATTERNS}\" \\\n# ADMISSION_WHITELIST_PATTERNS\n\n\nWHITELIST_LIST=$(echo \"${PARAM_WHITELIST_PATTERNS}\" | awk '{n=split($0,a,\",\")}; { for (i in a) { printf \"- namePattern: %s%s\", a[i], (i < n) ? \"\\\\\\n\" : \"\" }}')\nsed -i.bak \"s@ADMISSION_WHITELIST_PATTERNS@${WHITELIST_LIST}@g\" \"${PARAM_POLICY_FILE}\"\n\necho \"Success! Admission whitelist patterns inserted into Binary Authorization policy YAML\""
environment:
PARAM_POLICY_FILE: <<parameters.policy-filepath>>
PARAM_WHITELIST_PATTERNS: <<parameters.admission-whitelist-patterns>>
name: Insert admission whitelist patterns
- run:
command: "PARAM_REQUIRED_ATTESTORS=$(eval \"echo ${EVAL_REQUIRED_ATTESTORS}\")\nPARAM_CLUSTER_SPECIFIC_ATTESTORS=$(eval \"echo ${EVAL_CLUSTER_SPECIFIC_ATTESTORS}\")\n\ninsert_attestors () {\n REQUIRED_ATTESTORS=$1\n \n # use comma delimiters to create array\n arrREQUIRED_ATTESTORS=(\"${REQUIRED_ATTESTORS//,/ }\")\n \n # need || true in case array is length 1\n # in which case, assigning END=0 will exit code 1\n END=$((${#arrREQUIRED_ATTESTORS[@]}-1)) || true\n \n # iterate over array to echo required attestors into a file\n # $3 is offset, to ensure we create valid yaml\n # \\\\ is required for sed\n for ((i=0;i<END;i++)); do\n echo \"$3- ${arrREQUIRED_ATTESTORS[i]}\\\\\" >> REQUIRED_ATTESTORS.txt\n done\n \n # need to handle iteration for the last item separately\n # sed does not require it to have \\ at line end\n echo \"$3- ${arrREQUIRED_ATTESTORS[-1]}\" >> REQUIRED_ATTESTORS.txt\n \n READY_TO_REPLACE=$(cat REQUIRED_ATTESTORS.txt)\n \n sed -i.bak \"s@$2@$READY_TO_REPLACE@g\" \\\n \"${PARAM_POLICY_FILE}\"\n \n rm -rf REQUIRED_ATTESTORS.txt\n}\n\ninsert_attestors \\\n\"${PARAM_REQUIRED_ATTESTORS}\" \\\nDEFAULT_REQUIRED_ATTESTORS \\\n\" \"\n\nif [ \"${PARAM_CLUSTER_SPECIFIC_RULES}\" = true ]; then\n insert_attestors \\\n \"${PARAM_CLUSTER_SPECIFIC_ATTESTORS}\" \\\n CLUSTER_SPECIFIC_REQUIRED_ATTESTORS \\\n \" \"\nfi\n\necho \"Success! Required attestor values inserted into Binary Authorization policy YAML\""
environment:
EVAL_CLUSTER_SPECIFIC_ATTESTORS: <<parameters.cluster-specific-required-attestors>>
EVAL_REQUIRED_ATTESTORS: <<parameters.default-required-attestors>>
PARAM_CLUSTER_SPECIFIC_RULES: <<parameters.cluster-specific-rules>>
PARAM_POLICY_FILE: <<parameters.policy-filepath>>
name: Insert required attestor values
- run:
command: |-
gcloud \
--project="${!INDIRECT_PROJECT_ID}" \
container binauthz policy import \
"${PARAM_POLICY_FILE}"
environment:
INDIRECT_PROJECT_ID: <<#parameters.multi-project-setup>><<parameters.deployer-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
PARAM_POLICY_FILE: <<parameters.policy-filepath>>
name: Import policy YAML into Binary Authorization
- store_artifacts:
path: <<parameters.policy-filepath>>
create-attestation:
description: |
Create a Binary Authorization attestation authorizing a container image for deployment. See Google's Binary Authorization documentation: https://cloud.google.com/binary-authorization/docs/key-concepts#attestations https://cloud.google.com/binary-authorization/docs/making-attestations
parameters:
attestation-project-id:
default: ATTESTATION_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
attestor:
default: $CIRCLE_USERNAME
description: |
Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
type: string
attestor-project-id:
default: ATTESTOR_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
create-new-gke-cluster:
default: false
description: |
Create a new GKE cluster to use with Binary Authorization? Defaults to `false` Passed to setup command.
type: boolean
enable-apis:
default: false
description: |
Do required APIs (container.googleapis.com, containeranalysis.googleapis.com, binaryauthorization.googleapis.com) need to be enabled? Passed to setup command.
type: boolean
gke-cluster-name:
default: ""
description: |
Name of the GKE cluster for which to enable Binary Authorization Passed to setup command.
type: string
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
type: env_var_name
image-path:
description: |
Path in Google's, or any other, container registry to the image being deployed (e.g., `gcr.io/example-project/quickstart-image`)
type: string
image-tag:
default: latest
description: |
Specific tag of image that will be deployed, used to generate a full SHA-256 for attestation.
type: string
keypair-email:
description: Email address attached to PGP keypair
type: string
keypair-passphrase:
default: BIN_AUTHZ_KEYPAIR_PASSPHRASE
description: |
Name of environment variable storing the passphrase used to generate PGP keypair
type: env_var_name
multi-project-setup:
default: false
description: |
Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
type: boolean
payload-filepath:
default: /tmp/generated_payload.json
description: Path at which to generate an attestation payload
type: string
private-key:
default: BIN_AUTHZ_PRIVATE_KEY
description: |
Name of environment variable storing the private portion of the keypair with which to sign the attestation. Unless `use-existing-keypair` is set to `false`, store the private key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. See Google's documentation for details: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
type: env_var_name
public-key:
default: BIN_AUTHZ_PUBLIC_KEY
description: |
Name of environment variable storing the public portion of the keypair with which to sign the attestation. Not required if `use-existing-keypair` is set to `false`. Store the public key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. See Google's documentation for details: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
type: env_var_name
run-setup:
default: false
description: |
Set to `true` to handle setup through this command. Helpful if an attestor has not been created before this step.
type: boolean
use-existing-keypair:
default: true
description: |
Use an existing PGP keypair? Only select `false` if a keypair was generated on-the-fly in the `create-attestor` command
type: boolean
use-passphrase:
default: false
description: |
If `use-existing-keypair` is set to `false`: does the existing PGP keypair have a passphrase? If `use-existing-keypair` is set to `true`: was the newly generated PGP keypair created with a passphrase?
type: boolean
steps:
- run:
command: |
PARAM_IMAGE_PATH=$(eval echo "${EVAL_IMAGE_PATH}")
PARAM_IMAGE_TAG=$(eval echo "${EVAL_IMAGE_TAG}")
DIGEST=$(gcloud container images describe \
"${PARAM_IMAGE_PATH}:${PARAM_IMAGE_TAG}" \
--format='get(image_summary.digest)')
echo "${DIGEST}" > "/tmp/BIN_AUTHZ_DIGEST"
echo "Success! Image digest stored"
environment:
EVAL_IMAGE_PATH: <<parameters.image-path>>
EVAL_IMAGE_TAG: <<parameters.image-tag>>
PARAM_PAYLOAD_FILEPATH: <<parameters.payload-filepath>>
name: Store image digest
- run:
command: |
PARAM_IMAGE_PATH=$(eval echo "${EVAL_IMAGE_PATH}")
DIGEST=$(cat "/tmp/BIN_AUTHZ_DIGEST")
gcloud container binauthz create-signature-payload \
--artifact-url="${PARAM_IMAGE_PATH}@${DIGEST}" \
> "${PARAM_PAYLOAD_FILEPATH}"
echo "Success! Attestion payload created"
environment:
EVAL_IMAGE_PATH: <<parameters.image-path>>
PARAM_PAYLOAD_FILEPATH: <<parameters.payload-filepath>>
name: Create attestation payload
- when:
condition: <<parameters.run-setup>>
steps:
- setup:
attestor: <<parameters.attestor>>
create-new-gke-cluster: <<parameters.create-new-gke-cluster>>
enable-apis: <<parameters.enable-apis>>
gke-cluster-name: <<parameters.gke-cluster-name>>
keypair-email: <<parameters.keypair-email>>
- when:
condition: <<parameters.use-existing-keypair>>
steps:
- run:
command: "echo -e \"${!INDIRECT_PUBLIC_KEY}\" > public.key\necho -e \"${!INDIRECT_PRIVATE_KEY}\" > private.key\n\ngpg --import --no-tty --batch --yes public.key\n\nif [ \"${PARAM_USE_PASSPHRASE}\" = true ]; then\n echo use-agent >> ~/.gnupg/gpg.conf\n echo pinentry-mode loopback >> ~/.gnupg/gpg.conf\n echo allow-loopback-pinentry >> ~/.gnupg/gpg-agent.conf\n echo RELOADAGENT | gpg-connect-agent\n \n echo \"${!INSERT_KEYPAIR_PASSPHRASE}\" | \\\n gpg --import --no-tty --batch --yes private.key\nelse\n gpg --import --no-tty --batch --yes private.key\nfi"
environment:
INDIRECT_PRIVATE_KEY: <<parameters.private-key>>
INDIRECT_PUBLIC_KEY: <<parameters.public-key>>
INSERT_KEYPAIR_PASSPHRASE: <<parameters.keypair-passphrase>>
PARAM_USE_PASSPHRASE: <<parameters.private-key>>
name: Set up public/private keys
- run:
command: |-
# extract fingerprint from key
FINGERPRINT_STRING=$(gpg \
--list-keys --with-fingerprint --with-colons \
"${PARAMS_KEYPAIR_EMAIL}" | \
grep fpr)
# use colon delimiters to separate fingerprint
arrFINGERPRINT=("${FINGERPRINT_STRING//:/ }")
FINGERPRINT=${arrFINGERPRINT[-1]}
echo "$FINGERPRINT" > FINGERPRINT.txt
echo "Success! PGP keypair fingerprint extracted"
environment:
PARAMS_KEYPAIR_EMAIL: <<parameters.keypair-email>>
name: Extract keypair fingerprint
- when:
condition: <<parameters.use-existing-keypair>>
steps:
- run:
command: |-
# set sudo to work whether logged in as root user or non-root user
if [[ ${EUID} == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
${SUDO} apt-get -y install expect > /dev/null 2>&1
FINGERPRINT=$(cat FINGERPRINT.txt)
expect -c "spawn gpg --edit-key \
${FINGERPRINT} \
trust quit; send \"5\ry\r\"; expect eof" \
> /dev/null 2>&1
echo "Success! PGP keypair marked as trusted"
name: Set up attestation signing
- when:
condition: <<parameters.use-passphrase>>
steps:
- run:
command: "# GPG_TTY=$(tty)\n# export GPG_TTY\n\nPARAM_KEYPAIR=\"${!INDIRECT_PASSPHRASE}\"\n\n# have to sign like this on gpg v1.x\nif gpg --version | grep -q \") 1\\.\"; then\n echo \"${PARAM_KEYPAIR}\" | gpg \\\n --batch --yes --passphrase-fd 0 \\\n --local-user \"${PARAM_KEYPAIR_EMAIL}\" \\\n --passphrase \"${PARAM_KEYPAIR}\" \\\n --armor \\\n --output /tmp/generated_signature.pgp \\\n --sign \"${PARAM_PAYLOAD_FILEPATH}\"\n \n # & sign like this on gpg v2.x\n elif gpg --version | grep -q \") 2\\.\"; then\n echo \"${PARAM_KEYPAIR}\" | gpg \\\n --pinentry-mode loopback \\\n --local-user \"${PARAM_KEYPAIR_EMAIL}\" \\\n --passphrase \"${PARAM_KEYPAIR}\" \\\n --armor \\\n --output /tmp/generated_signature.pgp \\\n --sign \"${PARAM_PAYLOAD_FILEPATH}\"\nfi\n\necho \"Success! Attestation payload signed\""
environment:
INDIRECT_PASSPHRASE: <<parameters.keypair-passphrase>>
PARAM_KEYPAIR_EMAIL: <<parameters.keypair-email>>
PARAM_PAYLOAD_FILEPATH: <<parameters.payload-filepath>>
name: Sign attestation payload
- unless:
condition: <<parameters.use-passphrase>>
steps:
- run:
command: |-
gpg \
--local-user "${PARAM_KEYPAIR_EMAIL}" \
--armor \
--output /tmp/generated_signature.pgp \
--sign "${PARAM_PAYLOAD_FILEPATH}"
echo "Success! Attestation payload signed"
environment:
PARAM_KEYPAIR_EMAIL: <<parameters.keypair-email>>
PARAM_PAYLOAD_FILEPATH: <<parameters.payload-filepath>>
name: Sign attestation payload
- run:
command: |
PARAM_ATTESTOR=$(eval echo "${EVAL_ATTESTOR}")
PARAM_IMAGE_PATH=$(eval echo "${EVAL_IMAGE_PATH}")
FINGERPRINT=$(cat FINGERPRINT.txt)
DIGEST=$(cat "/tmp/BIN_AUTHZ_DIGEST")
gcloud \
--project="${!INDIRECT_ATTESTATION}" \
container binauthz attestations create \
--artifact-url="${PARAM_IMAGE_PATH}@${DIGEST}" \
--attestor="projects/${PARAM_ATTESTOR}" \
--signature-file=/tmp/generated_signature.pgp \
--public-key-id="${FINGERPRINT}"
rm -rf FINGERPRINT.txt
echo "Success! Attestation created"
environment:
EVAL_ATTESTOR: <<#parameters.multi-project-setup>>$<<parameters.attestor-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>>$<<parameters.google-project-id>><</parameters.multi-project-setup>>/attestors/<<parameters.attestor>>
EVAL_IMAGE_PATH: <<parameters.image-path>>
INDIRECT_ATTESTATION: <<#parameters.multi-project-setup>><<parameters.attestation-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
name: Create attestation
- run:
command: |
PARAM_IMAGE_PATH=$(eval echo "${EVAL_IMAGE_PATH}")
PARAM_ATTESTOR=$(eval echo "${EVAL_ATTESTOR}")
DIGEST=$(cat "/tmp/BIN_AUTHZ_DIGEST")
sleep 10 && \
gcloud \
--project="${!INDIRECT_ATTESTATION}" \
container binauthz attestations list \
--attestor="${PARAM_ATTESTOR}" \
--attestor-project="${!INDIRECT_ATTESTOR}" \
--artifact-url="${PARAM_IMAGE_PATH}@$DIGEST" | \
grep -v "Listed 0 items"
rm -rf "/tmp/BIN_AUTHZ_DIGEST"
environment:
EVAL_ATTESTOR: <<parameters.attestor>>
EVAL_IMAGE_PATH: <<parameters.image-path>>
INDIRECT_ATTESTATION: <<#parameters.multi-project-setup>><<parameters.attestation-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
INDIRECT_ATTESTOR: <<#parameters.multi-project-setup>><<parameters.attestor-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
name: Verify attestation creation
- store_artifacts:
path: <<parameters.payload-filepath>>
create-attestor:
description: |
Create an attestor in Binary Authorization. For details, see: https://cloud.google.com/binary-authorization/docs/key-concepts#attestors
parameters:
attestor:
default: $CIRCLE_USERNAME
description: |
Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
type: string
attestor-project-id:
default: ATTESTOR_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the`` attestor project. Only required if using a multi-project setup.
type: env_var_name
circle-token:
default: CIRCLE_TOKEN
description: |
Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables. Only required if `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true.
type: env_var_name
deployer-service-account:
default: DEPLOYER_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the deployer Google project. Only required if using a multi-project setup.
type: env_var_name
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
type: env_var_name
keypair-email:
default: ""
description: |
Email address to attach to PGP keypair. Only required here if `use-existing-keypair` is set to `false` (required by subsequent commands either way).
type: string
keypair-name:
default: ""
description: |
Name to attach to PGP keypair. Only required if `use-existing-keypair` is set to `false`.
type: string
keypair-passphrase:
default: BIN_AUTHZ_KEYPAIR_PASSPHRASE
description: |
Name of environment variable storing a passphrase to use when generating a PGP keypair. Only required if `use-existing-keypair` is set to `false`.
type: env_var_name
multi-project-setup:
default: false
description: |
Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
type: boolean
note-id:
default: $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM
description: |
Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
type: string
private-key:
default: BIN_AUTHZ_PRIVATE_KEY
description: |
Name of environment variable under which to store the private portion of the keypair generated to use with Binary Authorization. Only required here if `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true (required by subsequent commands either way).
type: env_var_name
public-key:
default: BIN_AUTHZ_PUBLIC_KEY
description: |
Name of environment variable storing the public portion of the keypair with which to sign the attestation. If `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true, the public key will be stored in CircleCI as a project environment variable under this name. Otherwise, please store the public key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA- 2048-type key. See Google's PGP key documentation for details: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
type: env_var_name
store-generated-keypair:
default: true
description: |
Store public and private portions of generated keypair as CircleCI environment variables?
type: boolean
use-existing-keypair:
default: true
description: |
Use an existing PGP keypair? If `false`, a keypair will be created on-the-fly
type: boolean
use-passphrase:
default: false
description: |
Generate a PGP keypair with a passphrase? Only required if `use-existing-keypair` is set to `false`
type: boolean
steps:
- run:
command: |-
PARAM_ATTESTOR=$(eval echo "${EVAL_ATTESTOR}")
PARAM_NOTE_ID=$(eval echo "${EVAL_NOTE_ID}")
gcloud \
--project="${!INDIRECT_PROJECT}" \
container binauthz attestors create "${PARAM_ATTESTOR}" \
--attestation-authority-note="${PARAM_NOTE_ID}" \
--attestation-authority-note-project="${!INDIRECT_PROJECT}"
echo "Success! Attestor ${PARAM_ATTESTOR} has been created"
environment:
EVAL_ATTESTOR: <<parameters.attestor>>
EVAL_NOTE_ID: <<parameters.note-id>>
INDIRECT_PROJECT: <<#parameters.multi-project-setup>><<parameters.attestor-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
name: Create attestor
- unless:
condition: <<parameters.use-existing-keypair>>
steps:
- generate-keypair:
circle-token: <<parameters.circle-token>>
keypair-email: <<parameters.keypair-email>>
keypair-name: <<parameters.keypair-name>>
keypair-passphrase: <<parameters.keypair-passphrase>>
private-key: <<parameters.private-key>>
public-key: <<parameters.public-key>>
store-generated-keypair: <<parameters.store-generated-keypair>>
use-passphrase: <<parameters.use-passphrase>>
- run:
command: "PARAM_ATTESTOR=$(eval echo \"${EVAL_ATTESTOR}\")\n\nif [ \"${PARAM_USE_KEYPAIR}\" -eq 1 ]; then\n echo -e \"${!INDIRECT_PUBLIC_KEY}\" > /tmp/generated-key.pgp\nelse\n # extract fingerprint from key\n FINGERPRINT_STRING=$(gpg \\\n --list-keys --with-fingerprint --with-colons \\\n \"${PARAM_KEYPAIR_EMAIL}\" | \\\n grep fpr)\n \n # use colon delimiters to separate fingerprint\n arrFINGERPRINT=(\"${FINGERPRINT_STRING//:/ }\")\n FINGERPRINT=${arrFINGERPRINT[-1]}\n \n echo \"${FINGERPRINT}\" | gpg --armor --export > /tmp/generated-key.pgp\nfi\n\nif [ \"${PARAM_MULTI_PROJECT}\" -eq 1 ]; then\n PROJECT_PREFIX=\"projects/${!INDIRECT_ATTESTOR_PROJECT}/attestors/\"\nfi\n\ngcloud container binauthz attestors public-keys add \\\n--attestor=\"${PROJECT_PREFIX}${PARAM_ATTESTOR}\" \\\n--pgp-public-key-file=/tmp/generated-key.pgp"
environment:
EVAL_ATTESTOR: <<parameters.attestor>>
INDIRECT_ATTESTOR_PROJECT: <<parameters.attestor-project-id>>
INDIRECT_PUBLIC_KEY: <<parameters.public-key>>
PARAM_KEYPAIR_EMAIL: <<parameters.keypair-email>>
PARAM_MULTI_PROJECT: <<parameters.multi-project-setup>>
PARAM_USE_KEYPAIR: <<parameters.use-existing-keypair>>
name: Add PGP public key to attestor
- run:
command: |-
PARAM_ATTESTOR=$(eval echo "${EVAL_ATTESTOR}")
gcloud \
--project="${!INDIRECT_PROJECT}" \
beta container binauthz attestors list | \
grep "${PARAM_ATTESTOR}"
environment:
EVAL_ATTESTOR: <<parameters.attestor>>
INDIRECT_PROJECT: <<#parameters.multi-project-setup>><<parameters.attestor-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
name: Verify attestor creation with key
- when:
condition: <<parameters.multi-project-setup>>
steps:
- run:
command: |-
PARAM_ATTESTOR=$(eval echo "${EVAL_ATTESTOR}")
gcloud \
--project "${!INDIRECT_ATTESTOR_PROJECT}" \
container binauthz attestors add-iam-policy-binding \
"projects/${!INDIRECT_ATTESTOR_PROJECT}/attestors/${PARAM_ATTESTOR}" \
--member="serviceAccount:${!INDIRECT_SERVICE_ACCOUNT}" \
--role=roles/binaryauthorization.attestorsVerifier
environment:
EVAL_ATTESTOR: <<parameters.attestor>>
INDIRECT_ATTESTOR_PROJECT: <<parameters.attestor-project-id>>
INDIRECT_SERVICE_ACCOUNT: <<parameters.deployer-service-account>>
name: Add deployer project IAM role binding
create-note:
description: |
Create a Container Analysis note. For details, see the following: https://cloud.google.com/container-registry/docs/container-analysis#note
parameters:
attestor:
default: $CIRCLE_USERNAME
description: |
Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
type: string
attestor-hint:
default: CircleCI username
description: |
A human-readable name for this attestation authority (e.g., QA)
type: string
attestor-project-id:
default: ATTESTOR_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
attestor-service-account:
default: ATTESTOR_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the attestor Google project. Only required if using a multi-project setup.
type: env_var_name
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
type: env_var_name
google-service-account:
default: GOOGLE_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the Google project. Not required if using a multi-project setup.
type: env_var_name
multi-project-setup:
default: false
description: |
Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
type: boolean
note-description-long:
default: ""
description: Longer, more detailed description of this note. This will be evaluated.
type: string
note-description-short:
default: Container analysis note from CircleCI job $CIRCLE_JOB, number $CIRCLE_BUILD_NUM, triggered by $CIRCLE_USERNAME
description: One-sentence description of this note. This will be evaluated.
type: string
note-expiration-time:
default: ""
description: |
Timestamp-formatted expiration time for this note (empty if the note does not expire). For details, see the following: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp
type: string
note-filepath:
default: /tmp/note_payload.json
description: |
Path to your container analysis note file. Should be an existing file if `use-note-file` is `true`; otherwise, note will be created at this path.
type: string
note-id:
default: $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM
description: |
Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
type: string
note-related-url:
default: $CIRCLE_BUILD_URL
description: Any URL related to the note. This will be evaluated.
type: string
related-note-names:
default: ""
description: Names of any notes relevant or related to this note
type: string
use-note-file:
default: false
description: |
Upload an existing container analysis note file instead of creating one via this command's parameters?
type: boolean
steps:
- unless:
condition: <<parameters.use-note-file>>
steps:
- run:
command: |-
PARAM_NOTE_RELATED_URL=$(eval echo "${EVAL_NOTE_RELATED_URL}")
PARAM_NOTE_ID=$(eval echo "${EVAL_NOTE_ID}")
PARAM_SHORT_DESCRIPTION=$(eval echo "${EVAL_SHORT_DESCRIPTION}")
PARAM_LONG_DESCRIPTION=$(eval echo "${EVAL_LONG_DESCRIPTION}")
echo "{
\"name\": \"projects/${!INDIRECT_PROJECT}/notes/${PARAM_NOTE_ID}\",
\"shortDescription\": \"${PARAM_SHORT_DESCRIPTION}\",${PARAM_LONG_DESCRIPTION}
\"attestation\": {
\"hint\": {
\"human_readable_name\": \"${PARAM_ATTESTOR_HINT}\"
}
},
\"relatedUrl\": [
{
\"url\": \"${PARAM_NOTE_RELATED_URL}\",
\"label\": \"related URL\"
}
],${PARAM_EXPIRATION_TIME}${PARAM_RELATED_NOTE_NAMES}
}" > "${PARAM_NOTE_FILEPATH}"
echo "Success! Container analysis note created at ${PARAM_NOTE_FILEPATH}"
environment:
EVAL_LONG_DESCRIPTION: |
<<#parameters.note-description-long>>
"longDescription": "<<parameters.note-description-long>>",<</parameters.note-description-long>>
EVAL_NOTE_ID: <<parameters.note-id>>
EVAL_NOTE_RELATED_URL: <<parameters.note-related-url>>
EVAL_SHORT_DESCRIPTION: <<parameters.note-description-short>>
INDIRECT_PROJECT: <<#parameters.multi-project-setup>><<parameters.attestor-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
PARAM_ATTESTOR_HINT: <<parameters.attestor-hint>>
PARAM_EXPIRATION_TIME: |
<<#parameters.note-expiration-time>>
"expirationTime": "<<parameters.note-expiration-time>>",<</parameters.note-expiration-time>>
PARAM_NOTE_FILEPATH: <<parameters.note-filepath>>
PARAM_RELATED_NOTE_NAMES: |
<<#parameters.related-note-names>>
"relatedNoteNames": "<<parameters.related-note-names>>",<</parameters.related-note-names>>
name: Create Container Analysis note
- run:
command: |
PARAM_NOTE_ID=$(eval echo "${EVAL_NOTE_ID}")
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
--data-binary @"${PARAM_NOTE_PATH}" \
"https://containeranalysis.googleapis.com/v1/projects/${!INDIRECT_PROJECT}/notes/?noteId=${PARAM_NOTE_ID}"
environment:
EVAL_NOTE_ID: <<parameters.note-id>>
INDIRECT_PROJECT: <<#parameters.multi-project-setup>><<parameters.attestor-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
PARAM_NOTE_PATH: <<parameters.note-filepath>>
name: Store Container Analysis note
- run:
command: |
PARAM_NOTE_ID=$(eval echo "${EVAL_NOTE_ID}")
PARAM_NOTE_SHORT=$(eval echo "${EVAL_NOTE_SHORT}")
curl \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://containeranalysis.googleapis.com/v1/projects/${!INDIRECT_PROJECT}/notes/${PARAM_NOTE_ID}" | \
grep "${PARAM_NOTE_SHORT}"
environment:
EVAL_NOTE_ID: <<parameters.note-id>>
EVAL_NOTE_SHORT: <<parameters.note-description-short>>
INDIRECT_PROJECT: <<#parameters.multi-project-setup>><<parameters.attestor-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
name: Verify Container Analysis note upload
- when:
condition: <<parameters.multi-project-setup>>
steps:
- run:
command: |-
echo "{
\"policy\": {
\"bindings\": [
{
\"role\": \"roles/containeranalysis.notes.occurrences.viewer\",
\"members\": [
\"serviceAccount:${!INDIRECT_SERVICE_ACCOUNT}\"
]
}
]
}
}" > "/tmp/iam_request.json"
environment:
INDIRECT_ATTESTOR_ID: <<parameters.attestor-project-id>>
INDIRECT_SERVICE_ACCOUNT: <<parameters.attestor-service-account>>
name: Create Container Analysis note IAM request
- run:
command: |-
PARAM_NOTE_ID=$(eval echo "${EVAL_NOTE_ID}")
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
--data-binary @/tmp/iam_request.json \
"https://containeranalysis.googleapis.com/v1/projects/${!INDIRECT_ATTESTOR_ID}/notes/${PARAM_NOTE_ID}:setIamPolicy"
environment:
EVAL_NOTE_ID: <<parameters.note-id>>
INDIRECT_ATTESTOR_ID: <<parameters.attestor-project-id>>
name: Set permissions on Container Analysis note
- store_artifacts:
path: <<parameters.note-filepath>>
generate-keypair:
description: |
Generate an RSA-2048-type PGP keypair to use with Google's Binary Authorization and optionally store its public and private portions as CircleCI environment variables.
parameters:
circle-token:
default: CIRCLE_TOKEN
description: |
Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables
type: env_var_name
keypair-email:
description: |
Email address to attach to PGP keypair
type: string
keypair-name:
default: ""
description: |
Name to attach to PGP keypair
type: string
keypair-passphrase:
default: BIN_AUTHZ_KEYPAIR_PASSPHRASE
description: |
Name of environment variable storing a passphrase to use when generating a PGP keypair (only required if `use-passphrase` is set to `true`)
type: env_var_name
private-key:
default: BIN_AUTHZ_PRIVATE_KEY
description: |
Name of environment variable under which to store the private portion of the keypair generated to use with Binary Authorization
type: env_var_name
public-key:
default: BIN_AUTHZ_PUBLIC_KEY
description: |
Name of environment variable under which to store the public portion of the keypair generated to use with Binary Authorization
type: env_var_name
store-generated-keypair:
default: true
description: |
Store public and private portions of generated keypair as CircleCI environment variables?
type: boolean
use-passphrase:
default: false
description: |
Generate a PGP keypair with a passphrase?
type: boolean
steps:
- run:
command: |-
# set sudo to work whether logged in as root user or non-root user
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
if uname -a | grep Darwin > /dev/null 2>&1; then
exit 0
elif grep -q Alpine /etc/issue > /dev/null 2>&1; then
apk add haveged > /dev/null 2>&1
elif grep -q Debian /etc/issue > /dev/null 2>&1; then
$SUDO apt-get install -y haveged > /dev/null 2>&1
elif grep -q Ubuntu /etc/issue > /dev/null 2>&1; then
$SUDO apt-get install -y haveged > /dev/null 2>&1
fi
echo "Success! Package containing HAVEGE algorithm installed to boost entropy"
name: Boost entropy for key generation
- unless:
condition: <<parameters.use-passphrase>>
steps:
- run:
command: |-
GPG_VERSION=$(gpg --version)
echo "Key-Type: RSA
Key-Length: 2048
Name-Real: ${PARAM_KEYPAIR_NAME}
Name-Email: ${PARAM_KEYPAIR_EMAIL}
" >> generated-key
# Use no-ask-passphrase for v2.0 or older
if "${GPG_VERSION}" | grep -q ") 1\." || "${GPG_VERSION}" | grep -q ") 2\.0"; then
echo "%no-ask-passphrase" >> generated-key
else
echo "%no-protection" \>> generated-key
fi
echo "%commit" >> generated-key
echo "Success! PGP keypair file generated"
environment:
PARAM_KEYPAIR_EMAIL: <<parameters.keypair-email>>
PARAM_KEYPAIR_NAME: <<parameters.keypair-name>>
name: Generate PGP keypair file
- run:
command: |
gpg --batch --gen-key generated-key
rm -rf generated-key
name: Generate PGP keypair from file
- when:
condition: <<parameters.use-passphrase>>
steps:
- run:
command: |-
echo "Key-Type: RSA
Key-Length: 2048
Name-Real: ${PARAM_KEYPAIR_NAME}
Name-Email: ${PARAM_KEYPAIR_EMAIL}
Passphrase: ${!INDIRECT_KEYPAIR_PASS}
%commit" > /tmp/gcp_binauth_gpg_key
gpg --batch --gen-key /tmp/gcp_binauth_gpg_key > /dev/null 2>&1
echo "Success! GPG kepair generated"
environment:
INDIRECT_KEYPAIR_PASS: <<parameters.keypair-passphrase>>
PARAM_KEYPAIR_EMAIL: <<parameters.keypair-email>>
PARAM_KEYPAIR_NAME: <<parameters.keypair-name>>
name: Generate PGP keypair with passphrase
- run:
command: |-
# extract fingerprint from key
FINGERPRINT_STRING=$(gpg \
--list-keys --with-fingerprint --with-colons \
"${PARAM_KEYPAIR_EMAIL}" | \
grep fpr)
# use colon delimiters to separate fingerprint
arrFINGERPRINT=("${FINGERPRINT_STRING//:/ }")
FINGERPRINT=${arrFINGERPRINT[-1]}
echo "${FINGERPRINT}" | gpg --armor --export > /tmp/public-key.pgp
echo "${FINGERPRINT}" | gpg --armor --export-secret-subkeys > /tmp/private-key.pgp
PUBLIC_KEY_ENV_VAR=$(perl -p -e 's/\n/\\n/' /tmp/public-key.pgp)
PRIVATE_KEY_ENV_VAR=$(perl -p -e 's/\n/\\n/' /tmp/private-key.pgp)
# determine VCS type, so we don't worry about it later
if echo "$CIRCLE_REPOSITORY_URL" | grep -q github.com:"$CIRCLE_PROJECT_USERNAME"; then
VCS_TYPE=github
else
VCS_TYPE=bitbucket
fi
curl -X POST --header "Content-Type: application/json" -d \
"{\"name\":\"${PARAM_PUBLIC_KEY}\", \"value\":\"$PUBLIC_KEY_ENV_VAR\"}" \
https://circleci.com/api/v1.1/project/$VCS_TYPE/"$CIRCLE_PROJECT_USERNAME"/"$CIRCLE_PROJECT_REPONAME"/envvar?circle-token="${!INDIRECT_CIRCLE_TOKEN}" > /dev/null 2>&1
curl -X POST --header "Content-Type: application/json" -d \
"{\"name\":\"${PARAM_PRIVATE_KEY}\", \"value\":\"$PRIVATE_KEY_ENV_VAR\"}" \
https://circleci.com/api/v1.1/project/$VCS_TYPE/"$CIRCLE_PROJECT_USERNAME"/"$CIRCLE_PROJECT_REPONAME"/envvar?circle-token="${!INDIRECT_CIRCLE_TOKEN}" > /dev/null 2>&1
echo "Success! PGP keypair stored as CircleCI project environment variables"
environment:
INDIRECT_CIRCLE_TOKEN: <<parameters.circle-token>>
PARAM_KEYPAIR_EMAIL: <<parameters.keypair-email>>
PARAM_PRIVATE_KEY: <<parameters.private-key>>
PARAM_PUBLIC_KEY: <<parameters.public-key>>
name: Store keypair in CircleCI
get-gke-credentials:
description: |
Get Google Kubernetes Engine credentials and update a local kubeconfig file to enable further Binary Authorization commands on that cluster. Generally does not need to be run on its own, as it is run as part of both the `run-setup` and `create-attestation` jobs.
parameters:
deployer-project-id:
default: DEPLOYER_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
type: env_var_name
gke-cluster-name:
default: ""
description: |
Name of the GKE cluster for which to enable Binary Authorization
type: string
google-compute-zone:
default: GOOGLE_COMPUTE_ZONE
description: |
Name of environment variable storing the Google compute zone to use by default when running commands with the gcloud CLI
type: env_var_name
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
type: env_var_name
multi-project-setup:
default: false
description: |
Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
type: boolean
steps:
- run:
command: |-
gcloud \
--project="${!INDIRECT_PROJECT_ID}" \
container clusters get-credentials \
--zone "${!INDIRECT_ZONE}" \
"${PARAM_GKE_CLUSTER}"
environment:
INDIRECT_PROJECT_ID: <<#parameters.multi-project-setup>><<parameters.deployer-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
INDIRECT_ZONE: <<parameters.google-compute-zone>>
PARAM_GKE_CLUSTER: <<parameters.gke-cluster-name>>
name: Configure kubectl
setup:
description: |
Get set up to use Google's Binary Authorization on CircleCI. This command is designed to be run once to initialize Binary Authorization for a particular CircleCI project. It will enable all required APIs, optionally create a GKE cluster, create a Container Analysis note and an attestor, optionally generate and store a PGP keypair, and optionally create and store a Binary Authorization policy YAML file. After running this command successfully, it can be removed from your config.yml file. To use this command, at least one existing Google project is required; if using a multi-project Binary Authorization setup, three separate Google projects (deployer, attestor, attestation) are required. For easier execution, this command is also available as an orb job, also called `setup`. For additional information, see Google's Binary Authorization documentation: https://cloud.google.com/binary-authorization/docs/overview
parameters:
admission-whitelist-patterns:
default: gcr.io/google_containers/*,k8s.gcr.io/*,gcr.io/stackdriver-agents/*
description: |
Whitelist of container images that are exempt from the attestation requirements in the policy. Supply a comma-separated string list (e.g., see default value) of paths to images in Google's, or any other, container registry. For details, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admissionwhitelistpatterns
type: string
attestation-project-id:
default: ATTESTATION_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
attestor:
default: $CIRCLE_USERNAME
description: |
Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
type: string
attestor-hint:
default: CircleCI username
description: |
A human-readable name for this attestation authority (e.g., QA)
type: string
attestor-project-id:
default: ATTESTOR_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
attestor-service-account:
default: ATTESTOR_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the attestor Google project. Only required if using a multi-project setup.
type: env_var_name
circle-token:
default: CIRCLE_TOKEN
description: |
Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables
type: env_var_name
cluster-specific-eval-mode:
default: REQUIRE_ATTESTATION
description: |
For the specified cluster, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
enum:
- ALWAYS_ALLOW
- ALWAYS_DENY
- REQUIRE_ATTESTATION
type: enum
cluster-specific-required-attestors:
default: projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME
description: |
What attestors will be required to sign releases, for cluster- specific rulesets? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`, as described here: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
type: string
cluster-specific-rules:
default: false
description: |
Specify distinict sets of deployment rules for individual GKE clusters? If so, pass the requisite values to any additional cluster-specific parameters. Currently, only a single set of cluster- specific rules can be specified. For details, see the following: https://cloud.google.com/binary-authorization/docs/key-concepts#cluster-specific_rules
type: boolean
cluster-specific-specifier:
default: CLUSTER_SPECIFIER_LOCATION_NAME
description: |
If specifying a set of cluster-specific rules, what is the name of the GKE cluster to which these rules will apply? Supply an environment variable storing a GKE cluster name in the `location.name` format (e.g., `us-east1-a.prod-cluster`)
type: env_var_name
configure-policy:
default: true
description: |
Configure a Binary Authorization policy as part of setup? Choose `true` if a single policy will most likely persist across future deployments; choose `false` if a new policy will be generated for each deployment.
type: boolean
create-new-gke-cluster:
default: false
description: |
Create a new GKE cluster to use with Binary Authorization? Defaults to `false`
type: boolean
default-evaluation-mode:
default: REQUIRE_ATTESTATION
description: |
By default, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
enum:
- ALWAYS_ALLOW
- ALWAYS_DENY
- REQUIRE_ATTESTATION
type: enum
default-required-attestors:
default: projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME
description: |
What attestors will be required to sign releases, by default? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
type: string
deployer-project-id:
default: DEPLOYER_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
type: env_var_name
deployer-service-account:
default: DEPLOYER_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the deployer Google project. Only required if using a multi-project setup.
type: env_var_name
enable-apis:
default: true
description: |
Do required APIs (container.googleapis.com, containeranalysis.googleapis.com, binaryauthorization.googleapis.com) need to be enabled?
type: boolean
gke-cluster-name:
default: ""
description: |
Name of the GKE cluster for which to enable Binary Authorization
type: string
google-compute-zone:
default: GOOGLE_COMPUTE_ZONE
description: |
Name of environment variable storing the Google compute zone to use by default when running commands with the gcloud CLI
type: env_var_name
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
type: env_var_name
google-service-account:
default: GOOGLE_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the Google project. Not required if using a multi-project setup.
type: env_var_name
keypair-email:
description: |
Email address to attach to PGP keypair. Only required here if `use-existing-keypair` is set to `false` (required by subsequent commands either way).
type: string
keypair-name:
default: ""
description: |
Name to attach to PGP keypair. Only required if `use-existing-keypair` is set to `false`.
type: string
keypair-passphrase:
default: BIN_AUTHZ_KEYPAIR_PASSPHRASE
description: |
Name of environment variable storing a passphrase to use when generating a PGP keypair. Only required if `use-existing-keypair` is set to `false`.
type: env_var_name
multi-project-setup:
default: false
description: |
Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
type: boolean
note-description-long:
default: ""
description: Longer, more detailed description of this note
type: string
note-description-short:
default: Container analysis note from CircleCI job $CIRCLE_JOB, number $CIRCLE_BUILD_NUM, triggered by $CIRCLE_USERNAME
description: One-sentence description of this note
type: string
note-expiration-time:
default: ""
description: |
Timestamp-formatted expiration time for this note (empty if the note does not expire). For details, see the following: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp
type: string
note-filepath:
default: /tmp/note_payload.json
description: |
Path to your container analysis note file. Should be an existing file if `use-note-file` is `true`; otherwise, note will be created at this path.
type: string
note-id:
default: $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM
description: |
Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
type: string
note-related-url:
default: $CIRCLE_BUILD_URL
description: Any URL related to the note
type: string
policy-filepath:
default: /tmp/policy.yaml
description: |
Path to a Binary Authorization policy YAML file. Should be an existing file if `use-policy-file` is `true`; otherwise, a policy file will be created at this path.
type: string
private-key:
default: BIN_AUTHZ_PRIVATE_KEY
description: |
Name of environment variable under which to store the private portion of the keypair generated to use with Binary Authorization. Only required here if `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true (required by subsequent commands either way).
type: env_var_name
public-key:
default: BIN_AUTHZ_PUBLIC_KEY
description: |
Name of environment variable storing the public portion of the keypair with which to sign the attestation. If `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true, the public key will be stored in CircleCI as a project environment variable under this name. Otherwise, please store the public key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA- 2048-type key. See Google's PGP key documentation for details: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
type: env_var_name
related-note-names:
default: ""
description: Names of any notes relevant or related to this note
type: string
store-generated-keypair:
default: true
description: |
Store public and private portions of generated keypair as CircleCI environment variables?
type: boolean
use-existing-keypair:
default: true
description: |
Use an existing PGP keypair? If `false`, a keypair will be created on-the-fly
type: boolean
use-note-file:
default: false
description: |
Upload an existing container analysis note file instead of creating one via this command's paramaters?
type: boolean
use-passphrase:
default: false
description: |
Generate a PGP keypair with a passphrase? Only required if `use-existing-keypair` is set to `false`
type: boolean
use-policy-file:
default: false
description: |
Use an existing Binary Authorization policy YAML file instead of creating one via this command's paramaters?
type: boolean
steps:
- when:
condition: <<parameters.enable-apis>>
steps:
- when:
condition: <<parameters.multi-project-setup>>
steps:
- run:
command: |-
gcloud services \
--project="${!INDIRECT_DEPLOY_ID}" \
enable \
container.googleapis.com \
binaryauthorization.googleapis.com
gcloud services \
--project="${!INDIRECT_ATTESTATION_ID}" \
enable \
containeranalysis.googleapis.com \
binaryauthorization.googleapis.com \
gcloud services \
--project="${!INDIRECT_ATTESTATION_ID}" \
enable \
containeranalysis.googleapis.com \
binaryauthorization.googleapis.com
environment:
INDIRECT_ATTESTATION_ID: <<parameters.attestation-project-id>>
INDIRECT_ATTESTOR_ID: <<parameters.attestor-project-id>>
INDIRECT_DEPLOY_ID: <<parameters.deployer-project-id>>
name: Enable GCP APIs
- unless:
condition: <<parameters.multi-project-setup>>
steps:
- run:
command: |-
gcloud services \
--project="${!INDIRECT_GOOGLE_PROJECT_ID}"\
enable \
container.googleapis.com \
containeranalysis.googleapis.com \
binaryauthorization.googleapis.com
environment:
INDIRECT_GOOGLE_PROJECT_ID: <<parameters.google-project-id>>
name: Enable GCP APIs
- run:
command: |-
gcloud \
--project="${!INDIRECT_PROJECT}" \
container clusters \
"${PARAM_ACTION}" \
--enable-binauthz \
--zone "${!INDIRECT_COMPUTE_ZONE}" \
"${GKE_CLUSTER_NAME}"
environment:
GKE_CLUSTER_NAME: <<parameters.gke-cluster-name>>
INDIRECT_COMPUTE_ZONE: <<parameters.google-compute-zone>>
INDIRECT_PROJECT: <<#parameters.multi-project-setup>><<parameters.deployer-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
PARAM_ACTION: <<#parameters.create-new-gke-cluster>>create<</parameters.create-new-gke-cluster>><<^parameters.create-new-gke-cluster>>update<</parameters.create-new-gke-cluster>>
name: <<#parameters.create-new-gke-cluster>>Create<</parameters.create-new-gke-cluster>><<^parameters.create-new-gke-cluster>>Enable<</parameters.create-new-gke-cluster>> Binary Authorization<<#parameters.create-new-gke-cluster>>-enabled GKE cluster<</parameters.create-new-gke-cluster>>
- create-note:
attestor: <<parameters.attestor>>
attestor-hint: <<parameters.attestor-hint>>
attestor-project-id: <<parameters.attestor-project-id>>
attestor-service-account: <<parameters.attestor-service-account>>
google-project-id: <<parameters.google-project-id>>
google-service-account: <<parameters.google-service-account>>
multi-project-setup: <<parameters.multi-project-setup>>
note-description-long: <<parameters.note-description-long>>
note-description-short: <<parameters.note-description-short>>
note-expiration-time: <<parameters.note-expiration-time>>
note-filepath: <<parameters.note-filepath>>
note-id: <<parameters.note-id>>
note-related-url: <<parameters.note-related-url>>
related-note-names: <<parameters.related-note-names>>
use-note-file: <<parameters.use-note-file>>
- create-attestor:
attestor: <<parameters.attestor>>
attestor-project-id: <<parameters.attestor-project-id>>
circle-token: <<parameters.circle-token>>
deployer-service-account: <<parameters.deployer-service-account>>
google-project-id: <<parameters.google-project-id>>
keypair-email: <<parameters.keypair-email>>
keypair-name: <<parameters.keypair-name>>
keypair-passphrase: <<parameters.keypair-passphrase>>
multi-project-setup: <<parameters.multi-project-setup>>
note-id: <<parameters.note-id>>
private-key: <<parameters.private-key>>
public-key: <<parameters.public-key>>
store-generated-keypair: <<parameters.store-generated-keypair>>
use-existing-keypair: <<parameters.use-existing-keypair>>
use-passphrase: <<parameters.use-passphrase>>
- when:
condition: <<parameters.configure-policy>>
steps:
- configure-policy:
admission-whitelist-patterns: <<parameters.admission-whitelist-patterns>>
attestor-project-id: <<parameters.attestor-project-id>>
cluster-specific-eval-mode: <<parameters.cluster-specific-eval-mode>>
cluster-specific-required-attestors: <<parameters.cluster-specific-required-attestors>>
cluster-specific-rules: <<parameters.cluster-specific-rules>>
cluster-specific-specifier: <<parameters.cluster-specific-specifier>>
default-evaluation-mode: <<parameters.default-evaluation-mode>>
default-required-attestors: <<parameters.default-required-attestors>>
deployer-project-id: <<parameters.deployer-project-id>>
google-project-id: <<parameters.google-project-id>>
multi-project-setup: <<parameters.multi-project-setup>>
policy-filepath: <<parameters.policy-filepath>>
use-policy-file: <<parameters.use-policy-file>>
executors:
default:
description: |
The official Google Docker container with the gcloud SDK pre-installed
docker:
- image: google/cloud-sdk:<<parameters.tag>>
parameters:
resource-class:
default: medium
description: |
The resource_class with which this job should be run: https://circleci.com/docs/2.0/configuration-reference/#resource_class
enum:
- small
- medium
- medium+
- large
- xlarge
type: enum
tag:
default: latest
description: |
Version of the Google Cloud SDK Docker image to use. For full list, see https://hub.docker.com/r/google/cloud-sdk/tags
type: string
resource_class: <<parameters.resource-class>>
machine:
description: |
CircleCI's VM image, often useful for working with Docker images
machine:
image: <<parameters.image-tag>>
parameters:
image-tag:
default: ubuntu-2204:2022.04.2
description: |
Version of CircleCI's machine executor to use. For full list, see https://circleci.com/docs/2.0/configuration-reference/#machine
type: string
jobs:
create-attestation:
description: |
Sign/authorize a specific tag of a container image stored in a Google container registry for deployment to Google Kubernetes Engine. For details, see Google's Binary Authorization documentation: https://cloud.google.com/binary-authorization/docs
executor: <<parameters.executor>>
parameters:
admission-whitelist-patterns:
default: gcr.io/google_containers/*,k8s.gcr.io/*,gcr.io/stackdriver-agents/*
description: |
Whitelist of container images that are exempt from the attestation requirements in the policy. Supply a comma-separated string list (e.g., see default value) of paths to images in Google's, or any other, container registry. For details, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admissionwhitelistpatterns
type: string
attach-workspace:
default: false
description: |
Attach to an existing workspace? Default is `false`
type: boolean
attestation-project-id:
default: ATTESTATION_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
attestor:
default: $CIRCLE_USERNAME
description: |
Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
type: string
attestor-hint:
default: CircleCI username
description: |
A human-readable name for this attestation authority (e.g., QA)
type: string
attestor-project-id:
default: ATTESTOR_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
attestor-service-account:
default: ATTESTOR_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the attestor Google project. Only required if using a multi-project setup.
type: env_var_name
checkout:
default: false
description: |
Checkout as a first step? Default is `false`
type: boolean
circle-token:
default: CIRCLE_TOKEN
description: |
Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables
type: env_var_name
cluster-specific-eval-mode:
default: REQUIRE_ATTESTATION
description: |
For the specified cluster, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
enum:
- ALWAYS_ALLOW
- ALWAYS_DENY
- REQUIRE_ATTESTATION
type: enum
cluster-specific-required-attestors:
default: projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME
description: |
What attestors will be required to sign releases, for cluster- specific rulesets? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`, as described here: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
type: string
cluster-specific-rules:
default: false
description: |
Specify distinict sets of deployment rules for individual GKE clusters? If so, pass the requisite values to any additional cluster-specific parameters. Currently, only a single set of cluster- specific rules can be specified. For details, see the following: https://cloud.google.com/binary-authorization/docs/key-concepts#cluster-specific_rules
type: boolean
cluster-specific-specifier:
default: CLUSTER_SPECIFIER_LOCATION_NAME
description: |
If specifying a set of cluster-specific rules, what is the name of the GKE cluster to which these rules will apply? Supply an environment variable storing a GKE cluster name in the `location.name` format (e.g., `us-east1-a.prod-cluster`)
type: env_var_name
configure-policy:
default: false
description: |
Configure a new Binary Authorization policy for this attestation? Choose `false` to use the existing policy stored in Binary Authorization
type: boolean
create-new-gke-cluster:
default: false
description: |
Create a new GKE cluster to use with Binary Authorization? Default is `false`
type: boolean
default-evaluation-mode:
default: REQUIRE_ATTESTATION
description: |
By default, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
enum:
- ALWAYS_ALLOW
- ALWAYS_DENY
- REQUIRE_ATTESTATION
type: enum
default-required-attestors:
default: projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME
description: |
What attestors will be required to sign releases, by default? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
type: string
deployer-project-id:
default: DEPLOYER_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
type: env_var_name
deployer-service-account:
default: DEPLOYER_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the deployer Google project. Only required if using a multi-project setup.
type: env_var_name
deployer-service-key:
default: DEPLOYER_SERVICE_KEY
description: |
Name of environment variable storing the full service key JSON file for the deployer Google project. Only required if using a multi- project setup.
type: env_var_name
deployment-steps:
default: []
description: |
Optional deployment steps to run after signing an image for release. See the `deploy-attested-image` usage example for one possible implementation.
type: steps
enable-apis:
default: true
description: |
Do required APIs (container.googleapis.com, containeranalysis.googleapis.com, binaryauthorization.googleapis.com) need to be enabled?
type: boolean
executor:
default: default
description: |
Executor to use for this job, defaults to Google's official Docker image with the gcloud CLI preinstalled
type: executor
gke-cluster-name:
default: ""
description: |
Name of the GKE cluster for which to enable Binary Authorization
type: string
google-compute-zone:
default: GOOGLE_COMPUTE_ZONE
description: |
Name of environment variable storing the Google compute zone to use by default when running commands with the gcloud CLI
type: env_var_name
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
type: env_var_name
google-service-account:
default: GOOGLE_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the Google project. Not required if using a multi-project setup.
type: env_var_name
google-service-key:
default: GOOGLE_SERVICE_KEY
description: |
Name of environment variable storing the full service key JSON file for the Google project. Not required if using a multi-project setup.
type: env_var_name
image-path:
description: |
Path in Google's, or any other, container registry to the image being deployed (e.g., `gcr.io/example-project/quickstart-image`)
type: string
image-tag:
default: latest
description: |
Specific tag of image that will be deployed, used to generate a full SHA-256 for attestation.
type: string
keypair-email:
description: |
Email address attached to existing PGP keypair, or to attach to newly created keypair.
type: string
keypair-name:
default: ""
description: |
Name to attach to PGP keypair. Only required if `use-existing-keypair` is set to `false`.
type: string
keypair-passphrase:
default: BIN_AUTHZ_KEYPAIR_PASSPHRASE
description: |
Name of environment variable storing the passphrase used to generate PGP keypair
type: env_var_name
multi-project-setup:
default: false
description: |
Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
type: boolean
note-description-long:
default: ""
description: |
Longer, more detailed description of container analysis note
type: string
note-description-short:
default: Container analysis note from CircleCI job $CIRCLE_JOB, number $CIRCLE_BUILD_NUM, triggered by $CIRCLE_USERNAME
description: One-sentence description of this note
type: string
note-expiration-time:
default: ""
description: |
Timestamp-formatted expiration time for this note (empty if the note does not expire). For details, see the following: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp
type: string
note-filepath:
default: /tmp/note_payload.json
description: |
Path to your container analysis note file. Should be an existing file if `use-note-file` is `true`; otherwise, note will be created at this path.
type: string
note-id:
default: $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM
description: |
Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
type: string
note-related-url:
default: $CIRCLE_BUILD_URL
description: Any URL related to the container analysis note
type: string
payload-filepath:
default: /tmp/generated_payload.json
description: Path at which to generate an attestation payload
type: string
policy-filepath:
default: /tmp/policy.yaml
description: |
Path to a Binary Authorization policy YAML file. Should be an existing file if `use-policy-file` is `true`; otherwise, a policy file will be created (`configure-policy`) or imported (`import-existing- policy`) at this path.
type: string
private-key:
default: BIN_AUTHZ_PRIVATE_KEY
description: |
Name of environment variable storing (or under which to store, if `use-existing-keypair` is false and `store-generated-keypair` is true) the private portion of the keypair with which to sign the attestation. If `use-existing-keypair` is true, store the private key in Contexts or as a project-level environment variable, as a single- line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. For details, see the following documentation: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
type: env_var_name
public-key:
default: BIN_AUTHZ_PUBLIC_KEY
description: |
Name of environment variable storing (or under which to store, if `use-existing-keypair` is false and `store-generated-keypair` is true) the public portion of the keypair with which to sign the attestation. If `use-existing-keypair` is true, store the public key in Contexts or as a project-level environment variable, as a single- line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. For details, see the following documentation: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
type: env_var_name
related-note-names:
default: ""
description: Names of any notes relevant or related to this note
type: string
run-setup:
default: false
description: |
Run Binary Authorization setup steps? Setup steps are designed to be run once to initialize Binary Authorization for a particular CircleCI project.
type: boolean
store-generated-keypair:
default: true
description: |
Store public and private portions of generated keypair as CircleCI environment variables?
type: boolean
use-existing-keypair:
default: true
description: |
Use an existing PGP keypair? If `false`, a keypair will be created on-the-fly
type: boolean
use-note-file:
default: false
description: |
Upload an existing container analysis note file instead of creating one via this command's paramaters?
type: boolean
use-passphrase:
default: false
description: |
If `use-existing-keypair` is set to `false`: does the existing PGP keypair have a passphrase? If `use-existing-keypair` is set to `true`: generate a PGP keypair with a passphrase?
type: boolean
use-policy-file:
default: false
description: |
Use a locally stored Binary Authorization policy YAML file instead of creating one via this command's paramaters (`configure-policy`) or using an existing policy already stored in Binary Authorization?
type: boolean
workspace-root:
default: workspace
description: |
Workspace root path that is either an absolute path or a path relative to the working directory.
type: string
steps:
- when:
condition: <<parameters.checkout>>
steps:
- checkout
- when:
condition: <<parameters.attach-workspace>>
steps:
- attach_workspace:
at: <<parameters.workspace-root>>
- run:
command: "if [[ $(command -v pyenv) ]]; then\n PYTHON_VERSION=$(pyenv global | grep 2.7)\n \n if [[ -z \"${PYTHON_VERSION}\" ]]; then\n PYTHON_VERSION='2.7.18'\n pyenv install 2.7.18\n fi\n\n pyenv global \"$PYTHON_VERSION\"\nfi\n\nif [[ $(command -v python2) ]]; then\n PYTHON_DIR=$(command -v python2)\n echo export CLOUDSDK_PYTHON=\"${PYTHON_DIR}\" >> \"${BASH_ENV}\"\nfi"
name: Use python2
- gcp-cli/install
- gcp-cli/initialize:
gcloud-service-key: <<#parameters.multi-project-setup>><<parameters.deployer-service-key>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-service-key>><</parameters.multi-project-setup>>
google-compute-zone: <<parameters.google-compute-zone>>
google-project-id: <<#parameters.multi-project-setup>><<parameters.deployer-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
- when:
condition: <<parameters.run-setup>>
steps:
- setup:
admission-whitelist-patterns: <<parameters.admission-whitelist-patterns>>
attestation-project-id: <<parameters.attestation-project-id>>
attestor: <<parameters.attestor>>
attestor-hint: <<parameters.attestor-hint>>
attestor-project-id: <<parameters.attestor-project-id>>
attestor-service-account: <<parameters.attestor-service-account>>
circle-token: <<parameters.circle-token>>
cluster-specific-eval-mode: <<parameters.cluster-specific-eval-mode>>
cluster-specific-required-attestors: <<parameters.cluster-specific-required-attestors>>
cluster-specific-rules: <<parameters.cluster-specific-rules>>
cluster-specific-specifier: <<parameters.cluster-specific-specifier>>
configure-policy: <<parameters.configure-policy>>
create-new-gke-cluster: <<parameters.create-new-gke-cluster>>
default-evaluation-mode: <<parameters.default-evaluation-mode>>
default-required-attestors: <<parameters.default-required-attestors>>
deployer-project-id: <<parameters.deployer-project-id>>
deployer-service-account: <<parameters.deployer-service-account>>
enable-apis: <<parameters.enable-apis>>
gke-cluster-name: <<parameters.gke-cluster-name>>
google-compute-zone: <<parameters.google-compute-zone>>
google-project-id: <<parameters.google-project-id>>
google-service-account: <<parameters.google-service-account>>
keypair-email: <<parameters.keypair-email>>
keypair-name: <<parameters.keypair-name>>
keypair-passphrase: <<parameters.keypair-passphrase>>
multi-project-setup: <<parameters.multi-project-setup>>
note-description-long: <<parameters.note-description-long>>
note-description-short: <<parameters.note-description-short>>
note-expiration-time: <<parameters.note-expiration-time>>
note-filepath: <<parameters.note-filepath>>
note-id: <<parameters.note-id>>
note-related-url: <<parameters.note-related-url>>
policy-filepath: <<parameters.policy-filepath>>
private-key: <<parameters.private-key>>
public-key: <<parameters.public-key>>
related-note-names: <<parameters.related-note-names>>
store-generated-keypair: <<parameters.store-generated-keypair>>
use-existing-keypair: <<parameters.use-existing-keypair>>
use-note-file: <<parameters.use-note-file>>
use-passphrase: <<parameters.use-passphrase>>
use-policy-file: <<parameters.use-policy-file>>
- get-gke-credentials:
deployer-project-id: <<parameters.deployer-project-id>>
gke-cluster-name: <<parameters.gke-cluster-name>>
google-compute-zone: <<parameters.google-compute-zone>>
google-project-id: <<parameters.google-project-id>>
multi-project-setup: <<parameters.multi-project-setup>>
- when:
condition: <<parameters.configure-policy>>
steps:
- unless:
condition: <<parameters.run-setup>>
steps:
- configure-policy:
admission-whitelist-patterns: <<parameters.admission-whitelist-patterns>>
attestor-project-id: <<parameters.attestor-project-id>>
cluster-specific-eval-mode: <<parameters.cluster-specific-eval-mode>>
cluster-specific-required-attestors: <<parameters.cluster-specific-required-attestors>>
cluster-specific-rules: <<parameters.cluster-specific-rules>>
cluster-specific-specifier: <<parameters.cluster-specific-specifier>>
default-evaluation-mode: <<parameters.default-evaluation-mode>>
default-required-attestors: <<parameters.default-required-attestors>>
deployer-project-id: <<parameters.deployer-project-id>>
google-project-id: <<parameters.google-project-id>>
multi-project-setup: <<parameters.multi-project-setup>>
policy-filepath: <<parameters.policy-filepath>>
use-policy-file: <<parameters.use-policy-file>>
- create-attestation:
attestation-project-id: <<parameters.attestation-project-id>>
attestor: <<parameters.attestor>>
attestor-project-id: <<parameters.attestor-project-id>>
google-project-id: <<parameters.google-project-id>>
image-path: <<parameters.image-path>>
image-tag: <<parameters.image-tag>>
keypair-email: <<parameters.keypair-email>>
keypair-passphrase: <<parameters.keypair-passphrase>>
multi-project-setup: <<parameters.multi-project-setup>>
payload-filepath: <<parameters.payload-filepath>>
private-key: <<parameters.private-key>>
public-key: <<parameters.public-key>>
use-existing-keypair: <<parameters.use-existing-keypair>>
use-passphrase: <<parameters.use-passphrase>>
- <<parameters.deployment-steps>>
run-setup:
description: |
Get set up to use Google's Binary Authorization on CircleCI. This job is designed to be run once to initialize Binary Authorization for a particular CircleCI project. It will enable all required APIs, optionally create a GKE cluster, create an attestor, optionally generate and store a PGP keypair, and optionally create and store a Binary Authorization policy YAML file. After running this job successfully, it can be removed from your config.yml file. To use this job, at least one existing Google project is required; if using a multi-project Binary Authorization setup, three separate Google projects (deployer, attestor, attestation) are required. This job is also available as an orb command, also called `setup`, if more control over its mode of execution is desired. For further information, see Google's Binary Authorization documentation: https://cloud.google.com/binary-authorization/docs/overview
executor: <<parameters.executor>>
parameters:
admission-whitelist-patterns:
default: gcr.io/google_containers/*,k8s.gcr.io/*,gcr.io/stackdriver-agents/*
description: |
Whitelist of container images that are exempt from the attestation requirements in the policy. Supply a comma-separated string list (e.g., see default value) of paths to images in Google's, or any other, container registry. For details, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admissionwhitelistpatterns
type: string
attach-workspace:
default: false
description: |
Attach to an existing workspace? Default is `false`
type: boolean
attestation-project-id:
default: ATTESTATION_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
attestor:
default: $CIRCLE_USERNAME
description: |
Name of the attestation authority for the container analysis note. If the attestor does not yet exist, it will be created. Defaults to the value of the `$CIRCLE_USERNAME` environment variable (VCS user who triggered the CircleCI job).
type: string
attestor-hint:
default: CircleCI username
description: |
A human-readable name for this attestation authority (e.g., QA)
type: string
attestor-project-id:
default: ATTESTOR_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the attestor project. Only required if using a multi-project setup.
type: env_var_name
attestor-service-account:
default: ATTESTOR_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the attestor Google project. Only required if using a multi-project setup.
type: env_var_name
checkout:
default: false
description: |
Checkout as a first step? Default is `false`
type: boolean
circle-token:
default: CIRCLE_TOKEN
description: |
Name of environment variable storing a CircleCI API token, for authenticating calls to store project environment variables. Only required if generating and storing a new keypair.
type: env_var_name
cluster-specific-eval-mode:
default: REQUIRE_ATTESTATION
description: |
For the specified cluster, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
enum:
- ALWAYS_ALLOW
- ALWAYS_DENY
- REQUIRE_ATTESTATION
type: enum
cluster-specific-required-attestors:
default: projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME
description: |
What attestors will be required to sign releases, for cluster- specific rulesets? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`, as described here: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
type: string
cluster-specific-rules:
default: false
description: |
Specify distinict sets of deployment rules for individual GKE clusters? If so, pass the requisite values to any additional cluster-specific parameters. Currently, only a single set of cluster- specific rules can be specified. For details, see the following: https://cloud.google.com/binary-authorization/docs/key-concepts#cluster-specific_rules
type: boolean
cluster-specific-specifier:
default: CLUSTER_SPECIFIER_LOCATION_NAME
description: |
If specifying a set of cluster-specific rules, what is the name of the GKE cluster to which these rules will apply? Supply an environment variable storing a GKE cluster name in the `location.name` format (e.g., `us-east1-a.prod-cluster`)
type: env_var_name
configure-policy:
default: true
description: |
Configure a Binary Authorization policy as part of setup? Choose `true` if a single policy will most likely persist across future deployments; choose `false` if a new policy will be generated for each deployment.
type: boolean
create-new-gke-cluster:
default: false
description: |
Create a new GKE cluster to use with Binary Authorization? Defaults to `false`
type: boolean
default-evaluation-mode:
default: REQUIRE_ATTESTATION
description: |
By default, how should Binary Authorization evaluate deployment requests? For details on these options, see the following: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#evaluationmode
enum:
- ALWAYS_ALLOW
- ALWAYS_DENY
- REQUIRE_ATTESTATION
type: enum
default-required-attestors:
default: projects/$GOOGLE_PROJECT_ID/attestors/$CIRCLE_USERNAME
description: |
What attestors will be required to sign releases, by default? Specify attestors in the form `project/PROJECT_ID/attestors/ATTESTOR_NAME`: https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admission_rule To specify multiple attestors, use a comma-separated string.
type: string
deployer-project-id:
default: DEPLOYER_PROJECT_ID
description: |
Name of environment variable storing the Google project ID for the deployer project. Only required if using a multi-project setup.
type: env_var_name
deployer-service-account:
default: DEPLOYER_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the deployer Google project. Only required if using a multi-project setup.
type: env_var_name
deployer-service-key:
default: DEPLOYER_SERVICE_KEY
description: |
Name of environment variable storing the full service key JSON file for the deployer Google project. Only required if using a multi- project setup.
type: env_var_name
enable-apis:
default: true
description: |
Do required APIs (container.googleapis.com, containeranalysis.googleapis.com, binaryauthorization.googleapis.com) need to be enabled?
type: boolean
executor:
default: default
description: |
Executor to use for this job, defaults to Google's official Docker image with the gcloud CLI preinstalled
type: executor
gke-cluster-name:
default: ""
description: |
Name of the GKE cluster for which to enable Binary Authorization
type: string
google-compute-zone:
default: GOOGLE_COMPUTE_ZONE
description: |
Name of environment variable storing the Google compute zone to use by default when running commands with the gcloud CLI
type: env_var_name
google-project-id:
default: GOOGLE_PROJECT_ID
description: |
Name of environment variable storing the Google project ID. Not required if using a multi-project setup.
type: env_var_name
google-service-account:
default: GOOGLE_SERVICE_ACCOUNT
description: |
Name of environment variable storing the service account address for the Google project. Not required if using a multi-project setup.
type: env_var_name
google-service-key:
default: GOOGLE_SERVICE_KEY
description: |
Name of environment variable storing the full service key JSON file for the Google project. Not required if using a multi-project setup.
type: env_var_name
keypair-email:
default: ""
description: |
Email address to attach to PGP keypair. Only required here if `use-existing-keypair` is set to `false` (required by subsequent commands either way).
type: string
keypair-name:
default: ""
description: |
Name to attach to PGP keypair. Only required if `use-existing-keypair` is set to `false`.
type: string
keypair-passphrase:
default: BIN_AUTHZ_KEYPAIR_PASSPHRASE
description: |
Name of environment variable storing a passphrase to use when generating a PGP keypair. Only required if `use-existing-keypair` is set to `false`.
type: env_var_name
multi-project-setup:
default: false
description: |
Set to `true` if a multi-GCP project Binary Authorization setup is being used. See the following for details: https://cloud.google.com/binary-authorization/docs/multi-project-setup-cli
type: boolean
note-description-long:
default: ""
description: Longer, more detailed description of this note
type: string
note-description-short:
default: Container analysis note from CircleCI job $CIRCLE_JOB, number $CIRCLE_BUILD_NUM, triggered by $CIRCLE_USERNAME
description: One-sentence description of this note
type: string
note-expiration-time:
default: ""
description: |
Timestamp-formatted expiration time for this note (empty if the note does not expire). For details, see the following: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp
type: string
note-filepath:
default: /tmp/note_payload.json
description: |
Path to your container analysis note file. Should be an existing file if `use-note-file` is `true`; otherwise, note will be created at this path.
type: string
note-id:
default: $CIRCLE_USERNAME-note-$CIRCLE_JOB-$CIRCLE_BUILD_NUM
description: |
Name of the container analysis note. Defaults to a combination of values from the attestor parameter, and CircleCI job name and number environment variables.
type: string
note-related-url:
default: $CIRCLE_BUILD_URL
description: Any URL related to the note
type: string
policy-filepath:
default: /tmp/policy.yaml
description: |
Path to a Binary Authorization policy YAML file. Should be an existing file if `use-policy-file` is `true`; otherwise, a policy file will be created at this path.
type: string
private-key:
default: BIN_AUTHZ_PRIVATE_KEY
description: |
Name of environment variable under which to store the private portion of the keypair generated to use with Binary Authorization. Only required here if `use-existing-keypair` is set to `false` and `store-generated-keypair` is set to true (required by subsequent commands either way).
type: env_var_name
public-key:
default: BIN_AUTHZ_PUBLIC_KEY
description: |
Name of environment variable storing or under which to store the public portion of the keypair with which to sign the attestation. Not required if `use-existing-keypair` is set to `false`. Store the public key in Contexts or as a project-level environment variable, as a single-line string, with newlines replaced with the newline string literal `\n`. Use an RSA-2048-type key. See Google's documentation: https://cloud.google.com/binary-authorization/docs/creating-attestors-cli#create_a_pgp_key_pair
type: env_var_name
related-note-names:
default: ""
description: Names of any notes relevant or related to this note
type: string
store-generated-keypair:
default: true
description: |
Store public and private portions of generated keypair as CircleCI environment variables?
type: boolean
use-existing-keypair:
default: true
description: |
Use an existing PGP keypair? If `false`, a keypair will be created on-the-fly
type: boolean
use-note-file:
default: false
description: |
Upload an existing container analysis note file instead of creating one via this command's paramaters?
type: boolean
use-passphrase:
default: false
description: |
Generate a PGP keypair with a passphrase? Only required if `use-existing-keypair` is set to `false`
type: boolean
use-policy-file:
default: false
description: |
Use an existing Binary Authorization policy YAML file instead of creating one via this command's paramaters?
type: boolean
workspace-root:
default: workspace
description: |
Workspace root path that is either an absolute path or a path relative to the working directory.
type: string
steps:
- when:
condition: <<parameters.checkout>>
steps:
- checkout
- when:
condition: <<parameters.attach-workspace>>
steps:
- attach_workspace:
at: <<parameters.workspace-root>>
- run:
command: "if [[ $(command -v pyenv) ]]; then\n PYTHON_VERSION=$(pyenv global | grep 2.7)\n \n if [[ -z \"${PYTHON_VERSION}\" ]]; then\n PYTHON_VERSION='2.7.18'\n pyenv install 2.7.18\n fi\n\n pyenv global \"$PYTHON_VERSION\"\nfi\n\nif [[ $(command -v python2) ]]; then\n PYTHON_DIR=$(command -v python2)\n echo export CLOUDSDK_PYTHON=\"${PYTHON_DIR}\" >> \"${BASH_ENV}\"\nfi"
name: Use python2
- gcp-cli/install
- gcp-cli/initialize:
gcloud-service-key: <<#parameters.multi-project-setup>><<parameters.deployer-service-key>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-service-key>><</parameters.multi-project-setup>>
google-compute-zone: <<parameters.google-compute-zone>>
google-project-id: <<#parameters.multi-project-setup>><<parameters.deployer-project-id>><</parameters.multi-project-setup>><<^parameters.multi-project-setup>><<parameters.google-project-id>><</parameters.multi-project-setup>>
- setup:
admission-whitelist-patterns: <<parameters.admission-whitelist-patterns>>
attestation-project-id: <<parameters.attestation-project-id>>
attestor: <<parameters.attestor>>
attestor-hint: <<parameters.attestor-hint>>
attestor-project-id: <<parameters.attestor-project-id>>
attestor-service-account: <<parameters.attestor-service-account>>
circle-token: <<parameters.circle-token>>
cluster-specific-eval-mode: <<parameters.cluster-specific-eval-mode>>
cluster-specific-required-attestors: <<parameters.cluster-specific-required-attestors>>
cluster-specific-rules: <<parameters.cluster-specific-rules>>
cluster-specific-specifier: <<parameters.cluster-specific-specifier>>
configure-policy: <<parameters.configure-policy>>
create-new-gke-cluster: <<parameters.create-new-gke-cluster>>
default-evaluation-mode: <<parameters.default-evaluation-mode>>
default-required-attestors: <<parameters.default-required-attestors>>
deployer-project-id: <<parameters.deployer-project-id>>
deployer-service-account: <<parameters.deployer-service-account>>
enable-apis: <<parameters.enable-apis>>
gke-cluster-name: <<parameters.gke-cluster-name>>
google-compute-zone: <<parameters.google-compute-zone>>
google-project-id: <<parameters.google-project-id>>
google-service-account: <<parameters.google-service-account>>
keypair-email: <<parameters.keypair-email>>
keypair-name: <<parameters.keypair-name>>
keypair-passphrase: <<parameters.keypair-passphrase>>
multi-project-setup: <<parameters.multi-project-setup>>
note-description-long: <<parameters.note-description-long>>
note-description-short: <<parameters.note-description-short>>
note-expiration-time: <<parameters.note-expiration-time>>
note-filepath: <<parameters.note-filepath>>
note-id: <<parameters.note-id>>
note-related-url: <<parameters.note-related-url>>
policy-filepath: <<parameters.policy-filepath>>
private-key: <<parameters.private-key>>
public-key: <<parameters.public-key>>
related-note-names: <<parameters.related-note-names>>
store-generated-keypair: <<parameters.store-generated-keypair>>
use-existing-keypair: <<parameters.use-existing-keypair>>
use-note-file: <<parameters.use-note-file>>
use-passphrase: <<parameters.use-passphrase>>
use-policy-file: <<parameters.use-policy-file>>
- get-gke-credentials:
deployer-project-id: <<parameters.deployer-project-id>>
gke-cluster-name: <<parameters.gke-cluster-name>>
google-compute-zone: <<parameters.google-compute-zone>>
google-project-id: <<parameters.google-project-id>>
multi-project-setup: <<parameters.multi-project-setup>>
examples:
setup-and-create-keypair:
description: |
Get set up to use Binary Authorization on CircleCI. The `run-setup` job will enable all required GCP APIs; enable Binary Authorization for a given GKE cluster (and first create that cluster, if necessary); create a container analysis note; create an attestor; and, optionally, create a Binary Authorization policy. This example also creates a new PGP keypair and stores it in CircleCI as environment variables for future attestation signing, and otherwise uses the minimum required parameters that do not have default values.
usage:
version: "2.1"
orbs:
bin-authz: circleci/gcp-binary-authorization@x.y.z
workflows:
setup_binary_authorization:
jobs:
- bin-authz/run-setup:
gke-cluster-name: your-cluster
keypair-email: email-for-your-keypair
keypair-name: name-for-your-keypair
use-existing-keypair: false
workflows: null
setup-and-run-binary-authorization:
description: |
Get set up to use Binary Authorization on CircleCI, and complete an attestation signing for a particular container image, all at once. The `create-attestation` job will run all required setup commands, then create and sign an attestation allowing the container image to be successfully deployed. This example uses the minimum required parameters and thus assumes the following: there is an existing GKE cluster to use with Binary Authorization, and there is an existing PGP keypair stored in CircleCI. A container analysis note, attestor, Binary Authorization policy, and attestation are created on-the-fly. Although not shown in this example, a Docker image would likely be built and deployed to a staging/test environment in a previous job, and then deployed to a production cluster in a subsequent job.
usage:
version: "2.1"
orbs:
bin-authz: circleci/gcp-binary-authorization@x.y.z
workflows:
setup_and_run_binary_authorization:
jobs:
- bin-authz/create-attestation:
configure-policy: true
deployment-steps:
- run: |
echo "your deployment logic can live here"
echo "or in a subsequent workflow job"
echo "see `simple-deploy-attested-image` example for sample kubectl deployment syntax"
gke-cluster-name: your-gke-cluster
image-path: e.g., gcr.io/your-project/your-image
image-tag: tag-that-will-be-deployed
keypair-email: email-address@used-to-generate-keypair.com
note-description-long: |
Longform description of container analysis note
run-setup: true
setup-only-simple:
description: |
Get set up to use Binary Authorization on CircleCI. The `run-setup` job will enable all required GCP APIs; enable Binary Authorization for a given GKE cluster (and first create that cluster, if necessary); create a container analysis note; create an attestor; and, optionally, create a Binary Authorization policy. This simple example uses the minimum required parameters that do not have default values.
usage:
version: "2.1"
orbs:
bin-authz: circleci/gcp-binary-authorization@x.y.z
workflows:
setup_binary_authorization:
jobs:
- bin-authz/run-setup:
gke-cluster-name: your-cluster
workflows: null
simple-deploy-attested-image:
description: |
In the first job, use the GCP GCR Orb to push an image to a Google Container Registry. In the second job, use the Binary Authorization Orb to sign the image for release, then deploy the image to Google Kubernetes Engine.
usage:
version: "2.1"
orbs:
bin-authz: circleci/gcp-binary-authorization@x.y.z
gcp-gcr: circleci/gcp-gcr@x.y.z
workflows:
push_sign_deploy:
jobs:
- gcp-gcr/build_and_push_image:
context: your-context
image: your-image
registry-url: gcr.io
tag: your-tag
- bin-authz/create-attestation:
attestor: $CIRCLE_USERNAME
context: your-context
deployment-steps:
- run: |
kubectl run your-server \
--image gcr.io/$GOOGLE_PROJECT_ID/your-image@$YOUR_IMAGE_DIGEST \
--port 8080
gke-cluster-name: your-GKE-cluster-name
image-path: gcr.io/$GOOGLE_PROJECT_ID/your-image
image-tag: your-tag
keypair-email: email.address@used.to.generate.keypair.com
note-filepath: your-container-analysis-note.json
policy-filepath: your-binauthz-policy-file.yaml
requires:
- gcp-gcr/build_and_push_image
use-note-file: true
use-policy-file: true