Continuous Integration
Validating policies in your CI workflows allows you to check for potential policy issues each time a change is made to your policy source code. Common Fate policy validation can be run in CI platforms such as GitHub Actions, GitLab, and BuildKite.
If you use GitHub Actions, our Cedar Policy Validation Action will show annotations on Pull Requests, indicating where issues are in your policy source code.
Prerequisites
If you’re running a BYOC (“Bring-Your-Own-Cloud”) deployment of Common Fate in your own AWS account, you’ll need to be on v1.31.0
or later of the common-fate/common-fate-deployment/aws
Terraform module.
Policy validation in CI
Choose a tab below based on your CI provider.
To validate policies using GitHub Actions, you can use the Download Cedar Schema Action to download the latest Cedar schema, and use the Validate Cedar Policies Action to validate against the schema.
Here’s an example workflow.
As shown above, the workflow requires a few configuration variables to tell the CLI where Common Fate is running (api-url
), and how to authenticate to it (oidc-client-id
, oidc-client-secret
, oidc-issuer
). You can obtain api-url and oidc-issuer from your Terraform provider configuration block:
You can look up the Read-Only client credentials for oidc-client-id and oidc-client-secret by finding it in the deployment outputs following our guide here. Save the OIDC client secret as a GitHub Actions Secret with the name CF_OIDC_CLIENT_SECRET
to keep it out of your source code.
The Read-Only client has read access to the policy and configuration APIs but cannot be used for destructive actions.
Copy the script and signing key into your repository:
You can then install the CLI in your CI workflow by running:
The CLI requires a few configuration variables to tell the CLI where Common Fate is running, and how to authenticate to it. You can obtain these from your Terraform provider configuration block:
You can look up the Terraform OIDC client secret by finding it in the deployment outputs following our guide here.
To use the CLI, you’ll need to export some environment variables:
To install the cedar policy CLI, copy the following script into your repository:
You can then install the CLI in your CI workflow by running:
Then, you can run the validation command:
If you want to validate all *.cedar
policies instead, run:
Access testing in CI
Choose a tab below based on your CI provider.
To run access tests using GitHub Actions, you can use the Install Common Fate CLI Action to install the cf
CLI, and then run cf tests run -f tests.yml
.
You’ll need to add an access test file into your Common Fate configuration repository first.
Here’s an example workflow.
As shown above, the workflow requires a few configuration variables to tell the CLI where Common Fate is running (api-url
), and how to authenticate to it (oidc-client-id
, oidc-client-secret
, oidc-issuer
). You can obtain api-url and oidc-issuer from your Terraform provider configuration block:
You can look up the Read-Only client credentials for oidc-client-id and oidc-client-secret by finding it in the deployment outputs following our guide here. Save the OIDC client secret as a GitHub Actions Secret with the name CF_OIDC_CLIENT_SECRET
to keep it out of your source code.
The Read-Only client has read access to the policy and configuration APIs but cannot be used for destructive actions.
After completing this guide, you should see access tests being executed in GitHub Actions as shown below.
To run access tests using another CI provider, you can install the cf
CLI, and then run cf tests run -f tests.yml
.
You’ll need to add an access test file into your Common Fate configuration repository first.
Copy the script and signing key into your repository:
You can then install the CLI in your CI workflow by running:
The CLI requires a few configuration variables to tell the CLI where Common Fate is running, and how to authenticate to it. You can obtain these from your Terraform provider configuration block:
You can look up the Terraform OIDC client secret by finding it in the deployment outputs following our guide here.
To use the CLI, you’ll need to export some environment variables:
To install the cedar policy CLI, copy the following script into your repository:
You can then install the CLI in your CI workflow by running:
Then, you can add the testing command to your CI pipeline:
You should see output similar to the following when your CI pipeline runs: