Usage
Use theendorctl validate policy command to validate one or more policies against data from one or more projects.
If the policy is valid, the command returns all matches for the given projects, in the requested format, with the corresponding exit code.
The syntax of the endorctl validate policy command is:
Flags and variables
Theendorctl validate policy command uses the following flags and environment variables:
Specify one or more policies
Use one of the following formats to specify one or more policies:Specify a project or a project filter
Use one of the following formats to specify one or more projects from which to load data:Specify output format
As with the otherendorctl commands, you can specify if you prefer the output as a table, or in json or yaml format.
If the output format is json or yaml the matching findings are listed under "matching_findings" and the results for all other resource kinds are listed under "matching_resources".
For example, endorctl validate policy --policy-uuid 6418dc7a55afcfb7b0d0e025 --uuid 6699c827cd89accb3a017536 --output-type json.
Exit Codes
If the policy is valid and there are no matches the command returns 0. The following table lists the non-zero exit codes returned by theendorctl validate policy command:
For a complete list of endorctl exit codes, see endorctl CLI exit codes.
Example
Below is an example on how to verify that a Rego policy is correctly formatted.-
First, define a Rego policy. Let’s take the example policy below that searches for dependencies with an Endor Labs overall score of less than 7. You can save this to a file called “test_policy.rego”.
-
Next, validate that the policy is correctly formatted.
-
Add a project UUID to validate the policy against real data.
-
Inspect the policy output.
Troubleshooting
- Set
--output-typetojsonoryamlfor formatted output - Add the
--verboseflag for detailed output - Set
--log-level debugfor more information