|
| 1 | +package aap_policy_examples |
| 2 | + |
| 3 | +import rego.v1 |
| 4 | + |
| 5 | +# Define the allowed playbooks for restricted networks |
| 6 | +allowed_playbooks_for_restricted_networks := ["playbook1.yml", "playbook2.yml", "hello-world.yml"] |
| 7 | + |
| 8 | +# Define the restricted instance groups |
| 9 | +restricted_instance_groups := ["restricted_net1", "restricted_net2"] |
| 10 | + |
| 11 | +# Default policy response indicating allowed status with no violations |
| 12 | +default restricted_networks_checks := { |
| 13 | + "allowed": true, |
| 14 | + "violations": [], |
| 15 | +} |
| 16 | + |
| 17 | +# Evaluate restricted_networks_checks to check if playbook is allowed on restricted instance groups |
| 18 | +restricted_networks_checks := result if { |
| 19 | + # Extract instance group name from input |
| 20 | + instance_group_name := object.get(input, ["instance_group", "name"], "") |
| 21 | + |
| 22 | + # Extract playbook name from input |
| 23 | + playbook_name := object.get(input, ["playbook"], "") |
| 24 | + |
| 25 | + # Check if instance group is restricted and playbook is not allowed |
| 26 | + is_restricted_instance_group(instance_group_name) |
| 27 | + not allowed_playbook_for_restricted_network(playbook_name) |
| 28 | + |
| 29 | + result := { |
| 30 | + "allowed": false, |
| 31 | + "violations": [sprintf("Playbook '%v' is not allowed on restricted instance group '%v'. Allowed playbooks: %v", [playbook_name, instance_group_name, allowed_playbooks_for_restricted_networks])], |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +# Check if a given instance group is restricted |
| 36 | +is_restricted_instance_group(instance_group_name) if { |
| 37 | + some restricted_group in restricted_instance_groups |
| 38 | + instance_group_name == restricted_group |
| 39 | +} |
| 40 | + |
| 41 | +# Check if a given playbook is allowed on restricted networks |
| 42 | +allowed_playbook_for_restricted_network(playbook_name) if { |
| 43 | + some allowed_playbook in allowed_playbooks_for_restricted_networks |
| 44 | + playbook_name == allowed_playbook |
| 45 | +} |
0 commit comments