Common Fate uses authorization policy-as-code powered by Cedar. In this guide, you’ll learn how to validate Cedar policies to catch issues before they are deployed.
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.
You will need the Common Fate cf CLI installed - v1.12.0 or higher. You can check this by running cf --version. You should see an output similar to the below:
You can check this by running cedar --version. You should see an output similar to the below:
Validating Cedar policies using the CLI
Validating policies is a linting step which helps you catch issues quickly during policy development. Validation helps prevent issues like referencing a nonexistent action or a resource attribute in Cedar policies, or simply making a typo in a policy.
To get started, let’s create a sample invalid policy. Create a new folder for our policy testing:
Inside this folder, we’ll create a file called example.cedar. This file will contain an invalid Cedar policy:
The policy above is invalid because Action::"Invalid" does not correspond to any possible actions within Common Fate.
To validate the policy, run:
If you want to validate all *.cedar policies instead, run:
You should see an output similar to below, showing that validation has failed:
Let’s fix the policy. Replace the contents of example.cedar with:
Now validate the policy again, by running:
If you want to validate all *.cedar policies instead, run:
You should see an output similar to the below, showing that validation has succeeded:
Retrieving the Cedar schema
How does Common Fate know which actions are valid, and which aren’t? Common Fate checks the policies against a Cedar schema. The schema contains type definitions for all principals, actions, and resources used in Common Fate.
To see all of these type definitions, you can download the Cedar schema in JSON format:
You should see a JSON output similar to the below:
Fixing common validation issues
The following actions may require you to specify a Grant resource type, such as AWS::IDC::AccountGrant to prevent validation errors:
Access::Action::"Activate"
Access::Action::"Approve"
Access::Action::"Close"
Access::Action::"Extend"
For example:
The following actions may require you to specify an Entitlement resource type, such as AWS::IDC::AccountEntitlement to prevent validation errors:
Access::Action::"Request"
For example:
These are described in more detail below.
Activate, Close, and Approve actions on Grants
If you’ve come from an earlier version of Common Fate prior to the introduction of Cedar schemas, you may have Cedar policies similar referencing resource attributes similar to the below:
When validating this policy using:
If you want to validate all *.cedar policies instead, run:
You will see an error similar to the below:
Cedar is complaining because the Access::Action::"Activate" action can be performed on Grants with different targets, such as AWS accounts, GCP projects, and Okta groups, but only AWS accounts have a tags attribute.
To fix this, we can specify the type of grant to be AWS::IDC::AccountGrant in the policy:
After changing the policy, the cedar validation runs successfully:
The AWS::IDC::AccountGrant entity type represents Grants to different target and role types. Here’s a table with the various grant types:
Resource Type (resource)
Role (resource.role)
Target (resource.target)
AWS::IDC::AccountGrant
AWS::IDC::PermissionSet
AWS::Account
GCP::ProjectGrant
GCP::Role
GCP::Project
GCP::FolderGrant
GCP::Role
GCP::Folder
DataStax::OrganizationGrant
DataStax::Role
DataStax::Organization
Okta::GroupGrant
Okta::GroupRole
Okta::Group
Request actions on Entitlements
Similar the the above, the below policy will fail validation:
When validating this policy using:
If you want to validate all *.cedar policies instead, run:
You will see an error similar to the below:
Cedar is complaining because the Access::Action::"Request" action can be performed on Entitlements with different targets, such as AWS accounts, GCP projects, and Okta groups, but only AWS accounts have a tags attribute.
To fix this, we can specify the type of entitlement to be AWS::IDC::AccountEntitlement in the policy:
After changing the policy, the cedar validation runs successfully:
The AWS::IDC::AccountEntitlement entity type represents Entitlements to different target and role types. Here’s a table with the various entitlement types: