├── policy ├── infra │ ├── os │ │ ├── README.md │ │ ├── windows │ │ │ ├── check_local_user_accounts.yml │ │ │ ├── README.md │ │ │ └── check_autologon.yml │ │ └── rhel │ │ │ ├── check_pkg.yml │ │ │ └── check_become.yml │ ├── common │ │ ├── README.md │ │ ├── check_file_permission.yml │ │ ├── banned_file_modifications.yml │ │ ├── check_insecure_file_permission.yml │ │ └── no_shell_or_command.yml │ ├── vmware │ │ ├── README.md │ │ └── vmware_checks.yml │ ├── README.md │ ├── k8s │ │ ├── enforce_kubeconfig.yml │ │ └── README.md │ └── containers │ │ └── check_podman.yml ├── app │ ├── database │ │ └── README.md │ ├── webserver │ │ └── README.md │ └── README.md ├── cloud │ ├── common │ │ └── README.md │ ├── google │ │ └── README.md │ ├── aws │ │ ├── README.md │ │ ├── compute │ │ │ ├── check_ec2_instance_name.yml │ │ │ ├── check_ec2_instance_vpc.yml │ │ │ ├── check_ec2_instance_region.yml │ │ │ ├── check_ec2_instance_ami.yml │ │ │ └── check_ec2_instance_type.yml │ │ ├── serverless │ │ │ ├── lambda_checks.yml │ │ │ └── protect_services.yml │ │ ├── storage │ │ │ └── check_s3.yml │ │ ├── database │ │ │ ├── check_rds_access.yml │ │ │ └── check_rds_instance_version.yml │ │ └── common │ │ │ └── disallowed.yml │ ├── azure │ │ ├── README.md │ │ └── compute │ │ │ ├── check_azure_autoscaling.yml │ │ │ └── check_azure_aks_region.yml │ └── README.md ├── network │ ├── common │ │ └── README.md │ ├── vmware │ │ └── README.md │ ├── paloalto │ │ └── README.md │ ├── README.md │ └── cisco │ │ ├── check_ios_config.yml │ │ └── README.md ├── security │ ├── common │ │ ├── README.md │ │ └── check_firewall.yml │ ├── netbox │ │ └── README.md │ ├── crowdstrike │ │ └── README.md │ └── README.md ├── global │ └── README.md ├── vendor │ ├── README.md │ └── redhat │ │ └── common │ │ ├── check_non_fqcn.yml │ │ └── check_collection.yml └── common │ └── validate_ssl.yml ├── README.md ├── .gitignore └── LICENSE /policy/infra/os/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/app/database/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/app/webserver/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/cloud/common/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/cloud/google/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/infra/common/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/infra/vmware/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/network/common/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/network/vmware/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/security/common/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/security/netbox/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/network/paloalto/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/security/crowdstrike/README.md: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /policy/security/README.md: -------------------------------------------------------------------------------- 1 | Security related examples, including some vendor specific ones. 2 | -------------------------------------------------------------------------------- /policy/network/README.md: -------------------------------------------------------------------------------- 1 | Network related examples, some are common or agnostic to vendor specific ones. 2 | -------------------------------------------------------------------------------- /policy/app/README.md: -------------------------------------------------------------------------------- 1 | Application or service related examples, like more applications, webservers, databases etc. 2 | -------------------------------------------------------------------------------- /policy/global/README.md: -------------------------------------------------------------------------------- 1 | This is a reserved placeholder category for AAP specific functionality and integration. 2 | -------------------------------------------------------------------------------- /policy/vendor/README.md: -------------------------------------------------------------------------------- 1 | A broad 'vendor' category which may include compliancy checks for a broad range of products and solutions. 2 | -------------------------------------------------------------------------------- /policy/cloud/aws/README.md: -------------------------------------------------------------------------------- 1 | Some AWS cloud specific policybook examples broken down into categories like compute, database, storage etc. 2 | -------------------------------------------------------------------------------- /policy/cloud/azure/README.md: -------------------------------------------------------------------------------- 1 | Some Azure cloud specific policybook examples broken down into categories like compute, database, storage etc. 2 | -------------------------------------------------------------------------------- /policy/infra/README.md: -------------------------------------------------------------------------------- 1 | A broad section of infrastructure related examples including for OS (RHEL, Windows etc), kubernetes, vmware and others. 2 | -------------------------------------------------------------------------------- /policy/cloud/README.md: -------------------------------------------------------------------------------- 1 | Cloud related policies such as for the most common public cloud offerings like AWS, Azure and GCP. 2 | May also include other internal or private cloud solutions. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Ansible Policybook Examples 3 | 4 | This repo contains examples for Ansible Policybooks which can be used to test for compliance against rules. 5 | 6 | Within the *policy* directory you'll have lots of examples organised by domain type, use case, application or perhaps vendor to form some assemblence of order. 7 | 8 | 9 | -------------------------------------------------------------------------------- /policy/infra/k8s/enforce_kubeconfig.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Enforce use of kubeconfig when using kubernetes modules 3 | hosts: localhost 4 | policies: 5 | - name: check module arguments to only use kubeconfig 6 | target: task 7 | condition: input["kubernetes.core.k8s"].kubeconfig is not defined 8 | actions: 9 | - deny: 10 | msg: use kubeconfig 11 | -------------------------------------------------------------------------------- /policy/infra/containers/check_podman.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Podman related container policies 3 | hosts: localhost 4 | policies: 5 | - name: Disallow pulling of latest container images 6 | target: task 7 | condition: 8 | any: 9 | - input["containers.podman.podman_image"] lacks key tag 10 | - input["containers.podman.podman_image"].tag == "latest" 11 | actions: 12 | - deny: 13 | msg: You are only permitted to pull approved version tagged container images 14 | -------------------------------------------------------------------------------- /policy/vendor/redhat/common/check_non_fqcn.yml: -------------------------------------------------------------------------------- 1 | ### check non-fqcn policy ### 2 | # This policybook check if module is written in fqcn. 3 | # If a module is non-fqcn, a violation will be detected. 4 | --- 5 | - name: Check for non-fqcn module 6 | hosts: localhost 7 | policies: 8 | - name: Check for non-fqcn module 9 | target: task 10 | condition: input._agk.task.module_info.fqcn != input._agk.task.module 11 | actions: 12 | - deny: 13 | msg: module is written in non-fqcn 14 | tags: 15 | - compliance 16 | -------------------------------------------------------------------------------- /policy/cloud/aws/compute/check_ec2_instance_name.yml: -------------------------------------------------------------------------------- 1 | ### check EC2 usage policy ### 2 | # This policybook prohibits EC2 instances without a name tag to help easily identify it. 3 | --- 4 | - name: Prohibit EC2 instances without a Name tag 5 | hosts: localhost 6 | policies: 7 | - name: Prohibit EC2 instances without a Name 8 | target: task 9 | condition: input["amazon.aws.ec2_instance"] lacks key name 10 | actions: 11 | - deny: 12 | msg: You cannot create an EC2 instance without a Name tag 13 | tags: 14 | - compliance 15 | -------------------------------------------------------------------------------- /policy/cloud/aws/serverless/lambda_checks.yml: -------------------------------------------------------------------------------- 1 | ### AWS lambda policy checks ### 2 | --- 3 | - name: AWS Lambda based policy security checks 4 | hosts: localhost 5 | policies: 6 | - name: Ensure use of VPC configuration 7 | target: task 8 | condition: 9 | any: 10 | - input["amazon.aws.lambda"] lacks key vpc_subnet_ids 11 | - input["amazon.aws.lambda"] lacks key vpc_security_group_ids 12 | actions: 13 | - deny: 14 | msg: You need to supply correct VPC parameters (vpc_subnet_ids & vpc_security_group_ids) 15 | tags: 16 | - compliance 17 | -------------------------------------------------------------------------------- /policy/infra/os/windows/check_local_user_accounts.yml: -------------------------------------------------------------------------------- 1 | ### check local Windows user accounts 2 | # This policybook checks and disallows local user accounts 3 | --- 4 | - name: Checking local Windows user accounts 5 | hosts: localhost 6 | 7 | policies: 8 | - name: Check for local user accounts 9 | target: task 10 | condition: input["ansible.windows.win_user"].name is defined and input["ansible.windows.win_user"].state == "present" 11 | actions: 12 | - deny: 13 | msg: Local Windows user accounts are not allowed - refer to company AD standards. 14 | tags: 15 | - compliance 16 | -------------------------------------------------------------------------------- /policy/cloud/aws/storage/check_s3.yml: -------------------------------------------------------------------------------- 1 | ### check AWS S3 policy ### 2 | # Checks for all things related to S3 buckets 3 | --- 4 | - name: Check S3 Policy Compliance 5 | hosts: localhost 6 | vars: 7 | algorithm: AES256 8 | policies: 9 | - name: Check for mandatory use of encryption 2 10 | target: task 11 | condition: 12 | any: 13 | - input["amazon.aws.s3_bucket"].encryption is not defined 14 | - input["amazon.aws.s3_bucket"].encryption != algorithm 15 | actions: 16 | - deny: 17 | msg: AWS S3 bucket encryption does not meet standards 18 | tags: 19 | - compliance 20 | -------------------------------------------------------------------------------- /policy/infra/os/windows/README.md: -------------------------------------------------------------------------------- 1 | Policybooks related to Windows OS tasks. 2 | 3 | You can use something like this windows.yml playbook to test: 4 | ```bash 5 | --- 6 | - name: Run some Windows automation 7 | hosts: localhost 8 | gather_facts: false 9 | vars: 10 | win: dows 11 | 12 | tasks: 13 | - name: Add local user account 14 | ansible.windows.win_user: 15 | name: bob 16 | password: B0bP4ssw0rd 17 | state: present 18 | groups: 19 | - Users 20 | 21 | - name: Set autologon for user 22 | community.windows.win_auto_logon: 23 | username: phil 24 | password: password 25 | ``` 26 | -------------------------------------------------------------------------------- /policy/infra/vmware/vmware_checks.yml: -------------------------------------------------------------------------------- 1 | # Checks for all things related to VMware 2 | --- 3 | - name: Check VMware Policy Compliance 4 | hosts: localhost 5 | vars: 6 | max_cpus: 4 7 | max_memory_mb: 4096 8 | 9 | policies: 10 | - name: Checks for hardware compliance 11 | target: task 12 | condition: 13 | any: 14 | - input["community.vmware.vmware_guest"].hardware.num_cpus > max_cpus 15 | - input["community.vmware.vmware_guest"].hardware.memory_mb > max_memory_mb 16 | actions: 17 | - deny: 18 | msg: This amount of hardware allocation needs further approvals 19 | tags: 20 | - compliance 21 | -------------------------------------------------------------------------------- /policy/cloud/azure/compute/check_azure_autoscaling.yml: -------------------------------------------------------------------------------- 1 | ### Microsoft Azure cloud policies ### 2 | # This policybook checks the usage of Azure autoscale groups and sizing 3 | # Only allow certain sizing for the avoidance of cost sprawl 4 | --- 5 | - name: Policy checks for Azure Autoscaling 6 | hosts: localhost 7 | vars: 8 | allowed_max: 4 9 | policies: 10 | - name: Check Azure autoscaling sizing 11 | target: task 12 | condition: input["azure_rm_autoscale"].profiles[0].max_count > allowed_max 13 | actions: 14 | - deny: 15 | msg: This autoscale sizing violates normal sizing guidelines. 16 | tags: 17 | - compliance 18 | -------------------------------------------------------------------------------- /policy/infra/k8s/README.md: -------------------------------------------------------------------------------- 1 | Here is a sample playbook, let's call it "k8s.yml" which can be used to demonstrate policy rules: 2 | 3 | ```bash 4 | --- 5 | - name: Create a k8s namespace 6 | kubernetes.core.k8s: 7 | name: testing 8 | api_version: v1 9 | kind: Namespace 10 | state: present 11 | ``` 12 | 13 | ```bash 14 | $ ansible-policy -p examples/check_project/k8s.yml --policy-dir ansible-policybook-examples/policy/infra/k8s/ 15 | TASK [Create a k8s namespace] examples/check_project/k8s.yml L2-8 **************************************************************** 16 | ... check_module_arguments_to_only_use_kubeconfig Not Validated 17 | use kubeconfig 18 | ``` 19 | -------------------------------------------------------------------------------- /policy/cloud/aws/compute/check_ec2_instance_vpc.yml: -------------------------------------------------------------------------------- 1 | ### check EC2 usage policy ### 2 | # This policybook prohibit EC2 instances without a VPC. 3 | # If a task using amazon.aws.ec2_instance module does not have vpc_subnet_id option, the violation will be detected. 4 | --- 5 | - name: Prohibit EC2 instances without a VPC 6 | hosts: localhost 7 | policies: 8 | - name: Prohibit EC2 instances without a VPC 9 | target: task 10 | condition: input["amazon.aws.ec2_instance"] lacks key vpc_subnet_id 11 | actions: 12 | - deny: 13 | msg: creating EC2 instances without a VPC is prohibited. specify vpc_subnet_id. 14 | tags: 15 | - compliance -------------------------------------------------------------------------------- /policy/network/cisco/check_ios_config.yml: -------------------------------------------------------------------------------- 1 | ### checks for Cisco IOS configuration compliance 2 | # This policybook checks for IOS misconfigurations 3 | --- 4 | - name: Check Cisco IOS configuration settings 5 | hosts: localhost 6 | vars: 7 | banned_configurations: 8 | telnet: 9 | - line vty 0 10 | - no login 11 | policies: 12 | - name: Check on IOS configuration 13 | target: task 14 | condition: 15 | any: 16 | - input["cisco.ios.ios_config"].lines in banned_configurations.telnet 17 | actions: 18 | - warn: 19 | msg: "WARNING: Cisco IOS settings violation" 20 | tags: 21 | - security 22 | -------------------------------------------------------------------------------- /policy/infra/common/check_file_permission.yml: -------------------------------------------------------------------------------- 1 | ### check read-only permission policy ### 2 | # This policybook ensures that files are protected against unauthorized modification or deletion. 3 | # If the mode option for a task using the ansible.built-in.file module is not 444, a violation will be detected. 4 | --- 5 | - name: Check for file permission 6 | hosts: localhost 7 | policies: 8 | - name: Check for file change 9 | target: task 10 | condition: input["ansible.builtin.file"].mode != "444" 11 | actions: 12 | - deny: 13 | msg: The file permission {{ input["ansible.builtin.file"].mode }} is not allowed 14 | tags: 15 | - compliance 16 | -------------------------------------------------------------------------------- /policy/infra/os/windows/check_autologon.yml: -------------------------------------------------------------------------------- 1 | ### check if autologon is set 2 | --- 3 | - name: Checking Windows Policies 4 | hosts: localhost 5 | 6 | policies: 7 | - name: Check for user account auto logons 8 | target: task 9 | condition: 10 | any: 11 | - input["community.windows.win_auto_logon"] lacks key state # default = present 12 | - input["community.windows.win_auto_logon"].state == "present" # more prescriptive 13 | - input["community.windows.win_auto_logon"].username is defined # mandatory when state = present 14 | actions: 15 | - deny: 16 | msg: Windows user auto logons are not permitted 17 | tags: 18 | - compliance 19 | -------------------------------------------------------------------------------- /policy/cloud/aws/database/check_rds_access.yml: -------------------------------------------------------------------------------- 1 | ### check instance access policy ### 2 | # This policybook prohibit publicly accessible RDS instances. 3 | # If the option publicly_accessible is set to true in a task using amazon.aws.rds_instance, a violation will be detected. 4 | --- 5 | - name: Prohibit publicly accessible RDS instances 6 | hosts: localhost 7 | policies: 8 | - name: Prohibit publicly accessible RDS instances 9 | target: task 10 | condition: 11 | any: 12 | - input["amazon.aws.rds_instance"].publicly_accessible == true 13 | actions: 14 | - deny: 15 | msg: it is not allowed to create publicly accessible RDS instances 16 | tags: 17 | - compliance -------------------------------------------------------------------------------- /policy/cloud/aws/compute/check_ec2_instance_region.yml: -------------------------------------------------------------------------------- 1 | ### check EC2 usage policy ### 2 | # This policybook checks the usage of EC2. 3 | # Only allow deployments into certain EC2 regions 4 | --- 5 | - name: Check for ec2_instance region 6 | hosts: localhost 7 | vars: 8 | allowed_instance_regions: 9 | - us-east-1 10 | - us-east-2 11 | policies: 12 | - name: Check for ec2_instance region 13 | target: task 14 | condition: input["amazon.aws.ec2_instance"].region not in allowed_instance_regions 15 | actions: 16 | - deny: 17 | msg: The instance region {{ input["amazon.aws.ec2_instance"].region }} is not allowed, you can only deploy to one of these {{ allowed_instance_regions }} 18 | tags: 19 | - compliance 20 | -------------------------------------------------------------------------------- /policy/infra/os/rhel/check_pkg.yml: -------------------------------------------------------------------------------- 1 | ### check package policy ### 2 | # This policybook check if only authorized packages are installed. 3 | # If a task using ansible.builtin.package is installing unapproved packages, a violation will be detected. 4 | --- 5 | - name: Check for mysql package installation 6 | hosts: localhost 7 | vars: 8 | allowed_packages: 9 | - "mysql-server" 10 | policies: 11 | - name: Check for package name 12 | target: task 13 | condition: input["ansible.builtin.package"].name not in allowed_packages 14 | actions: 15 | - deny: 16 | msg: The package {{ input["ansible.builtin.package"].name }} is not allowed, allowed packages are one of {{ allowed_packages }} 17 | tags: 18 | - compliance 19 | -------------------------------------------------------------------------------- /policy/cloud/azure/compute/check_azure_aks_region.yml: -------------------------------------------------------------------------------- 1 | ### Microsoft Azure cloud policies ### 2 | # This policybook checks the usage of AKS 3 | # Only allow deployments into certain cloud regions 4 | --- 5 | - name: Check for Azure AKS region 6 | hosts: localhost 7 | vars: 8 | allowed_instance_regions: 9 | - asia 10 | - asiapacific 11 | - australia 12 | policies: 13 | - name: Check for Azure AKS region 14 | target: task 15 | condition: input["azure_rm_aks"].location not in allowed_instance_regions 16 | actions: 17 | - deny: 18 | msg: The Azure location {{ input["azure_rm_aks"].location }} is not allowed, you can only deploy to one of these {{ allowed_instance_regions }} 19 | tags: 20 | - compliance 21 | -------------------------------------------------------------------------------- /policy/vendor/redhat/common/check_collection.yml: -------------------------------------------------------------------------------- 1 | ### check collection policy ### 2 | # This policybook checks that only allowed collections are being used. 3 | # If a task uses a collection that is not in allowed_collections, the violation will be detected. 4 | --- 5 | - name: Check for using collection 6 | hosts: localhost 7 | vars: 8 | allowed_collections: 9 | - ansible.builtin 10 | - amazon.aws 11 | policies: 12 | - name: Check for collection name 13 | target: task 14 | condition: input._agk.task.module_info.collection not in allowed_collections 15 | actions: 16 | - deny: 17 | msg: The collection {{ input._agk.task.module_info.collection }} is not allowed, allowed collection are one of {{ allowed_collections }} 18 | tags: 19 | - compliance 20 | -------------------------------------------------------------------------------- /policy/cloud/aws/compute/check_ec2_instance_ami.yml: -------------------------------------------------------------------------------- 1 | ### check AMI policy ### 2 | # This policybook restricts amazon rds instances with unapproved AMIs. 3 | # If a task using amazon.aws.rds_instance uses the unapproved image, the violation will be detected. 4 | --- 5 | - name: Restrict instances with unapproved AMIs 6 | hosts: localhost 7 | vars: 8 | allowed_image_ids: 9 | - ami-123456 10 | - ami-789011 11 | policies: 12 | - name: Restrict instances with unapproved AMIs 13 | target: task 14 | condition: input["amazon.aws.rds_instance"].image_id not in allowed_image_ids 15 | actions: 16 | - deny: 17 | msg: The image {{ input["amazon.aws.rds_instance"].image_id}} is not allowed, allowed images are one of {{ allowed_image_ids }} 18 | tags: 19 | - compliance -------------------------------------------------------------------------------- /policy/cloud/aws/serverless/protect_services.yml: -------------------------------------------------------------------------------- 1 | ### AWS lambda policy checks ### 2 | --- 3 | - name: AWS Lambda based policy assurance checks 4 | hosts: localhost 5 | vars: 6 | essential_services: 7 | - "HelloWorld" 8 | - "AnotherOne" 9 | policies: 10 | - name: "Ensure we do not remove essential services" 11 | target: task 12 | condition: 13 | any: 14 | - input["amazon.aws.lambda"].name in essential_services and input["amazon.aws.lambda"].state == "absent" # if using FQCN 15 | - input["lambda"].name in essential_services and input["lambda"].state == "absent" # if not using FQCN 16 | actions: 17 | - deny: 18 | msg: Stopping the removal of essential Lambda services {{ essential_services }} 19 | tags: 20 | - compliance 21 | -------------------------------------------------------------------------------- /policy/cloud/aws/database/check_rds_instance_version.yml: -------------------------------------------------------------------------------- 1 | ### check rds_instance version policy ### 2 | # This policybook prohibit using unapproved RDS instance version. 3 | # If a task using amazon.aws.rds_instance uses unapproved engine_version, a violation will be detected. 4 | --- 5 | - name: Check for rds_instance version 6 | hosts: localhost 7 | vars: 8 | allowed_versions: 9 | - "8.0.23" 10 | - "10.0.35" 11 | policies: 12 | - name: Check for rds_instance version 13 | target: task 14 | condition: input["amazon.aws.rds_instance"].engine_version not in allowed_versions 15 | actions: 16 | - deny: 17 | msg: The version {{ input["amazon.aws.rds_instance"].engine_version}} is not allowed, allowed versions are one of {{ allowed_versions }} 18 | tags: 19 | - compliance -------------------------------------------------------------------------------- /policy/infra/common/banned_file_modifications.yml: -------------------------------------------------------------------------------- 1 | ### check critical file changes policy ### 2 | # This policybook checks for changes against critical files which are not allowed to be modified 3 | --- 4 | - name: Check if critical files are attempting to be modified 5 | hosts: localhost 6 | vars: 7 | critical_files: 8 | - /etc/sudoers 9 | policies: 10 | - name: Changes to critical files are not permitted 11 | target: task 12 | condition: 13 | any: 14 | - input["ansible.builtin.file"].path in critical_files 15 | - input["ansible.builtin.copy"].src in critical_files 16 | - input["ansible.builtin.copy"].dest in critical_files 17 | actions: 18 | - deny: 19 | msg: You are not allowed to change {{ critical_files }} 20 | tags: 21 | - compliance 22 | -------------------------------------------------------------------------------- /policy/cloud/aws/compute/check_ec2_instance_type.yml: -------------------------------------------------------------------------------- 1 | ### check EC2 usage policy ### 2 | # This policybook checks the usage of EC2. 3 | # If a task using amazon.aws.ec2_instance uses the unapproved instance_type, the violation will be detected. 4 | --- 5 | - name: Check for ec2_instance type 6 | hosts: localhost 7 | vars: 8 | allowed_instance_types: 9 | - t2.micro 10 | - t3.micro 11 | - t3a.micro 12 | policies: 13 | - name: Check for ec2_instance type 14 | target: task 15 | condition: input["amazon.aws.ec2_instance"].instance_type not in allowed_instance_types 16 | actions: 17 | - deny: 18 | msg: The instance type {{ input["amazon.aws.ec2_instance"].instance_type }} is not allowed, allowed instance types are one of {{ allowed_instance_types }} 19 | tags: 20 | - compliance -------------------------------------------------------------------------------- /policy/cloud/aws/common/disallowed.yml: -------------------------------------------------------------------------------- 1 | # This policybook checks if someone is using automation content that has been banned from use for whatever reason 2 | # That could be for cost control, standards alignment or security reasons 3 | # This will check both FQCN and non-FQCN for module checks 4 | --- 5 | - name: General or common AWS policy checks 6 | hosts: localhost 7 | vars: 8 | disallowed_modules: 9 | - amazon.aws.ec2_instance 10 | - community.aws.eks_fargate_profile 11 | policies: 12 | - name: Check for disallowed module usage 13 | target: task 14 | condition: input._agk.task.module_info.fqcn in disallowed_modules or input._agk.task.module in disallowed_modules 15 | actions: 16 | - deny: 17 | msg: "You are not allowed to use these modules in automation tasks: {{ disallowed_modules }}" 18 | tags: 19 | - compliance 20 | -------------------------------------------------------------------------------- /policy/common/validate_ssl.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check for right SSL settings 3 | hosts: localhost 4 | policies: 5 | - name: validate_certs should not be false 6 | target: task 7 | # neither work without further boolean support 8 | #condition: input._agk.task.module_options.validate_certs == "false" or input._agk.task.module_options.validate_certs == "False" 9 | #condition: input["ansible.builtin.uri"].validate_certs == "false" or input["ansible.builtin.uri"].validate_certs == "False" 10 | actions: 11 | - warn: 12 | msg: validate_certs should be set to true 13 | 14 | 15 | # An example 'certs.yml' playbook for this policy check could be something as simple as: 16 | # 17 | #--- 18 | #- hosts: localhost 19 | # tasks: 20 | # - name: uri fails because we didn't validate certs 21 | # ansible.builtin.uri: 22 | # validate_certs: false 23 | # url: http://example.com 24 | -------------------------------------------------------------------------------- /policy/security/common/check_firewall.yml: -------------------------------------------------------------------------------- 1 | ### checks for firewalls policies ### 2 | # This policybook checks for firewall misconfigurations 3 | --- 4 | - name: Check firewall rules are what they should be 5 | hosts: localhost 6 | vars: 7 | banned_services: 8 | - http 9 | banned_ports: 10 | - 80 11 | banned_protocols: 12 | - icmp 13 | banned_sources: 14 | - 0.0.0.0/24 15 | policies: 16 | - name: Check on firewall policy violations 17 | target: task 18 | condition: 19 | any: 20 | - input["ansible.posix.firewalld"].service in banned_services 21 | - input["ansible.posix.firewalld"].port in banned_ports 22 | - input["ansible.posix.firewalld"].protocol in banned_protocols 23 | - input["ansible.posix.firewalld"].source in banned_sources 24 | actions: 25 | - deny: 26 | msg: Banned firewall configuration attempted 27 | tags: 28 | - security 29 | -------------------------------------------------------------------------------- /policy/network/cisco/README.md: -------------------------------------------------------------------------------- 1 | Here is a sample playbook, let's call it "cisco_ios.yml", which can be used to demonstrate policy checks: 2 | 3 | ```bash 4 | --- 5 | - name: Configure Cisco IOS 6 | cisco.ios.ios_config: 7 | lines: 8 | - hostname foobar 9 | - line vty 0 10 | - password password123 11 | - no login 12 | - set ntp server 127.0.0.1 13 | ``` 14 | 15 | ```bash 16 | $ ansible-policy -p examples/check_project/cisco_ios.yml --policy-dir ansible-policybook-examples/policy/network/cisco/ 17 | TASK [Configure Cisco IOS] examples/check_project/cisco_ios.yml L2-10 ************************************************************ 18 | ... Check_on_IOS_configuration Not Validated 19 | WARNING: Cisco IOS settings violation 20 | 21 | -------------------------------------------------------------------------------------------------------------------------------------------- 22 | SUMMARY 23 | ... Total files: 1, Validated: 0, Not Validated: 1 24 | 25 | Violations are detected! in 1 task 26 | ``` 27 | -------------------------------------------------------------------------------- /policy/infra/common/check_insecure_file_permission.yml: -------------------------------------------------------------------------------- 1 | ### check insecure file permission policy ### 2 | # This policybook prohibit using sticky bit as a file permission. 3 | # If the mode option for a task using the ansible.built-in.file module is 1777, a violation will be detected. 4 | --- 5 | - name: Check for insecure file permission 6 | hosts: localhost 7 | vars: 8 | insecure_file_permission: 9 | - "1777" # sticky bit 10 | recommended_permissions: 11 | - "0755" 12 | policies: 13 | - name: Check for insecure file permission 14 | target: task 15 | condition: 16 | any: 17 | - input["ansible.builtin.file"].mode in insecure_file_permission 18 | - input["ansible.builtin.copy"].mode in insecure_file_permission 19 | - input["ansible.builtin.template"].mode in insecure_file_permission 20 | actions: 21 | - deny: 22 | msg: file permission is insecure, recommended permissions are {{ recommended_permissions }}. 23 | tags: 24 | - compliance 25 | -------------------------------------------------------------------------------- /policy/infra/os/rhel/check_become.yml: -------------------------------------------------------------------------------- 1 | ### check privilege escalation policy ### 2 | # This policybook check if become: true is used and check if only trusted user is used. 3 | --- 4 | - name: Check for privilege escalation 5 | hosts: localhost 6 | vars: 7 | allowed_users: 8 | - "user_1" 9 | policies: 10 | - name: Check for user name in task 11 | target: task 12 | condition: 13 | any: 14 | - input.become == true and input.become_user not in allowed_users 15 | - input.become == true and input lacks key become_user 16 | actions: 17 | - deny: 18 | msg: privilege escalation is detected. allowed users are one of {{ allowed_users }} 19 | tags: 20 | - compliance 21 | - name: Check for user name in play 22 | target: play 23 | condition: 24 | any: 25 | - input.become == true and input.become_user not in allowed_users 26 | - input.become == true and input lacks key become_user 27 | actions: 28 | - deny: 29 | msg: privilege escalation is detected. allowed users are one of {{ allowed_users }} 30 | tags: 31 | - compliance 32 | -------------------------------------------------------------------------------- /policy/infra/common/no_shell_or_command.yml: -------------------------------------------------------------------------------- 1 | ### No shell or command usage policy ### 2 | # This policybook checks if someone is using the shell or command or other similar 'script' modules 3 | # This will check both FQCN and non-FQCN for module checks 4 | --- 5 | - name: Check for disallowed modules usage 6 | hosts: localhost 7 | vars: 8 | disallowed_modules: 9 | - ansible.builtin.shell 10 | - ansible.builtin.command 11 | - ansible.builtin.raw 12 | - ansible.builtin.script 13 | - ansible.windows.win_shell 14 | - ansible.windows.win_command 15 | policies: 16 | - name: Check for disallowed module usage 17 | target: task 18 | condition: input._agk.task.module_info.fqcn in disallowed_modules or input._agk.task.module in disallowed_modules 19 | actions: 20 | - deny: 21 | msg: You are not allowed to run scripts or shell commands in automation jobs 22 | tags: 23 | - compliance 24 | 25 | # 26 | # Here is an example "shell.yml" playbook that could be used to test this enforcement 27 | # 28 | #--- 29 | #- name: Run provisioning commands 30 | # hosts: localhost 31 | # gather_facts: false 32 | # vars: 33 | # # (not required here just an example) 34 | # foo: bar 35 | # 36 | # tasks: 37 | # - name: run shell command (non FQCN usage) 38 | # shell: /usr/bin/logger "test test test" 39 | # 40 | # - name: Return motd to registered var (FQCN usage) 41 | # ansible.builtin.command: cat /etc/motd 42 | # register: mymotd 43 | # 44 | # - name: Run Windows equivalent 45 | # ansible.windows.win_shell: C:\somescript.ps1 >> C:\somelog.txt 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------