{"id":19652707,"url":"https://github.com/advanced-security/policy-as-code","last_synced_at":"2025-04-28T17:30:51.101Z","repository":{"id":64782472,"uuid":"578167279","full_name":"advanced-security/policy-as-code","owner":"advanced-security","description":"GitHub Advanced Security Policy as Code","archived":false,"fork":false,"pushed_at":"2025-04-24T18:48:08.000Z","size":2294,"stargazers_count":82,"open_issues_count":15,"forks_count":19,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-24T19:30:58.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/advanced-security.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-12-14T12:18:58.000Z","updated_at":"2025-04-24T18:47:50.000Z","dependencies_parsed_at":"2023-12-18T03:20:28.209Z","dependency_job_id":"20881cbe-179a-437a-8ce6-d5e9fcdbb641","html_url":"https://github.com/advanced-security/policy-as-code","commit_stats":{"total_commits":40,"total_committers":2,"mean_commits":20.0,"dds":0.125,"last_synced_commit":"b04726265531361b20756c62f91eb8f54435228c"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/advanced-security%2Fpolicy-as-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/advanced-security%2Fpolicy-as-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/advanced-security%2Fpolicy-as-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/advanced-security%2Fpolicy-as-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/advanced-security","download_url":"https://codeload.github.com/advanced-security/policy-as-code/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251355252,"owners_count":21576321,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T15:11:49.609Z","updated_at":"2025-04-28T17:30:51.093Z","avatar_url":"https://github.com/advanced-security.png","language":"Python","readme":"\u003c!-- markdownlint-disable --\u003e\n\u003cdiv align=\"center\"\u003e\n\u003ch1\u003eGitHub Policy as Code\u003c/h1\u003e\n\n[![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge\u0026logo=github\u0026logoColor=white)][github]\n[![GitHub Actions](https://img.shields.io/github/actions/workflow/status/advanced-security/policy-as-code/main.yml?style=for-the-badge)][github-actions]\n[![GitHub Issues](https://img.shields.io/github/issues/advanced-security/policy-as-code?style=for-the-badge)][github-issues]\n[![GitHub Stars](https://img.shields.io/github/stars/advanced-security/policy-as-code?style=for-the-badge)][github]\n[![Licence](https://img.shields.io/github/license/Ileriayo/markdown-badges?style=for-the-badge)][license]\n\n\u003c/div\u003e\n\u003c!-- markdownlint-restore --\u003e\n\n## Overview\n\n[GitHub's Policy as Code][github] project is designed to allow users and organizations to configure their Risk\nthreshold for security issues reported by GitHub Advanced Security Platform.\nThe main goal is to help make sure that before publishing your application to productions, development, etc.\nyou can validate if the application has any security issues that need to be addressed.\n\n## ✨ Features\n\n- Highly Configurable\n- Re-usable across repositories\n- Supports all [GitHub Advanced Security][advanced-security] Features\n  - [Code Scanning][github-codescanning]\n  - [Secret Scanning][github-secretscanning]\n  - [Supply chain / Dependabot][github-supplychain]\n- Supports GitHub Enterprise Cloud or Server ([see supported features list](#supported-features))\n- Pull Request Summary\n\n## ⚡️ Requirements\n\n- Python +3.9\n\n## Usage\n\n### GitHub Actions\n\nHere is how you can quickly setup policy-as-code.\n\n\u003e [!TIP]\n\u003e Checkout the GitHub Actions [Policy as Code Examples][examples-actions]\n\n```yaml\n# Policy as Code\n- name: Advance Security Policy as Code\n  uses: advanced-security/policy-as-code@v2.10.1\n```\n\n\u003e [!WARNING]\n\u003e The GitHub Action does not install Python on the runner. Please checkout at [the `actions/setup-python` Action][python-setup]\n\n### CLI\n\nThe Policy as Code project is a self-contained Python based CLI tool.\n\n\u003e [!NOTE]\n\u003e All of the Dependencies for [Policy as Code are vendored][vendored] into this repository\n\n**Bash / Zsh:**\n\n```bash\ngit clone --branch \"v2.10.1\" https://github.com/advanced-security/policy-as-code.git \u0026\u0026 cd ./policy-as-code\n\n./policy-as-code --help\n```\n\n**Powershell:**\n\n```Powershell\ngit clone --branch \"v2.10.1\" https://github.com/advanced-security/policy-as-code.git\ncd policy-as-code\n\n.\\policy-as-code.ps1 --help\n```\n\n\u003e [!TIP]\n\u003e Checkout the samples of [how to use / run the cli with examples][examples-cli].\n\n### [GitHub Access Permissions][permissions]\n\nFor Policy as Code to work correctly, you need to have the following permissions for the different features:\n\n- [required] Repository Permissions\n  - [`security_events: read`][permissions]\n    - [Code Scanning][permissions-codescanning]\n  - [`content: read`][permissions]\n    - [Dependency Graph][permissions-dependencygraph] / [Dependency Licenses][permissions-dependencygraph]\n  - [`pull-requests: write`][permissions]\n    - Policy as Code Pull Request Summary\n  - [\"Secret scanning alerts\" repository permissions (read)][permissions-secretscanning]\n    - ⚠️ GitHub App or PAT only, not Actions Token\n  - [\"Dependabot alerts\" repository permissions (read)][permissions-dependabot]\n    - ⚠️ GitHub App or PAT only, not Actions Token\n- [optional] Policy Repository\n  - `content: read` to be able to clone external sources of the policies\n\n\u003e [!WARNING]\n\u003e Secret Scanning and Dependabot Alerts results cannot be accessed using the Actions Token, use a GitHub App\n\n**GitHub App:**\n\n- Contents\n- [Code scanning alerts][permissions-codescanning]\n- [Dependabot alerts][permissions-dependabot]\n- [Secret scanning alerts][permissions-secretscanning]\n\n**[Action Permissions Example][permissions]:**\n\n```yaml\n# workflow or job level\npermissions:\n  contents: read\n  security-events: read\n  # pull request summaries\n  pull-requests: write\n```\n\n## Supported Features\n\n| Feature         | github.com (Br/PR)                      | enterprise server (Br/PR)               | Description                                                                                                |\n| :-------------- | :-------------------------------------- | :-------------------------------------- | :--------------------------------------------------------------------------------------------------------- |\n| Code Scanning   | :white_check_mark: / :white_check_mark: | :white_check_mark: / :white_check_mark: | Code Scanning is a code analysis tool that scans your code for security vulnerabilities and coding errors. |\n| Secret Scanning | :white_check_mark: / :white_check_mark: | :white_check_mark: / :white_check_mark: | Secret Scanning is a code analysis tool that scans your code for secrets.                                  |\n| Dependabot      | :white_check_mark: / :white_check_mark: | :x: [2] / :white_check_mark: [3]        | Dependabot is a tool that automates discovery and remediation of vulnerabilities in your dependencies.     |\n| Dependencies    | :white_check_mark: / :white_check_mark: | :x: [2] / :white_check_mark: [3]        | Dependencies is a tool that scans your code for dependencies.                                              |\n| Licensing       | :white_check_mark: / :white_check_mark: | :x: [2] / :white_check_mark: [3]        | Licensing is a tool that scans your code for licensing issues.                                             |\n\n_Notes:_\n\n1. Br/PR = Branches / Pull Requests\n2. :warning: GraphQL API not supported by GitHub Enterprise Server as of `3.7`\n3. :white_check_mark: Supported as of [GHES `3.6`](https://docs.github.com/en/enterprise-server@3.6/rest/dependency-graph/dependency-review#get-a-diff-of-the-dependencies-between-commits)\n\n## Policy as Code / PaC\n\nHere is an example of using a simple yet cross-organization using Policy as Code:\n\n```yaml\n# Compliance\n- name: Advance Security Policy as Code\n  uses: advanced-security/policy-as-code@2.10.0\n  with:\n    # The owner/repo of where the policy is stored\n    policy: GeekMasher/security-queries\n    # The local (within the workspace) or repository\n    policy-path: policies/default.yml\n    # The branch you want to target\n    policy-branch: main\n```\n\n### PaC Configuration file\n\nThe Policy as Code configuration file is very simple yet powerful allowing a user to define 4 types of rules per technologies you want to use.\n\n```yaml\n# This is the technology you want to write a rule for\nlicensing:\n  # The four main rules types to do everything you need to do for all things\n  #  compliance\n\n  # Warnings will always occur if the rule applies and continues executing to\n  #  other rules.\n  warnings:\n    ids:\n      - Other\n      - NA\n  # Ignores are run next so if an ignored rule is hit that matches the level,\n  #  it will be skipped\n  ignores:\n    ids:\n      - MIT License\n  # Conditions will only trigger and raise an error when an exact match is hit\n  conditions:\n    ids:\n      - GPL-2.0\n    names:\n      - tunnel-agent\n\n  # The simplest and ultimate rule which checks the severity of the alert and\n  #  reports an issue if the level matches or higher (see PaC Levels for more info)\n  level: error\n```\n\n#### PaC Levels\n\nThere are many different levels of severities with the addition of `all` and `none` (self explanatory).\nWhen a level is selected like for example `error`, all higher level severities (`critical` and `high` in this example) will also be added.\n\n```yml\n- critical\n- high\n- error\n- medium\n- moderate\n- low\n- warning\n- notes\n```\n\n#### PaC Rule Blocks\n\nFor each rule you can choose either or both of the two different criteria's matches; `ids` and `names`\n\nYou can also use `imports` to side load data from other files to supplement the data already in the rule block\n\n```yaml\ncodescanning:\n  conditions:\n    # When the `ids` of the technologies/tool alert matches any one of the ID's in\n    #  the list specified, the rule will the triggered and report the alert.\n    ids:\n      # In this example case, the CodeQL rule ID below will always be reported if\n      #  present event if the severity is low or even note.\n      - js/sql-injection\n\n      # Side note: Check to see what different tools consider id's verses names,\n      #  for example `licensing` considers the \"Licence\" name itself as the id\n      #  while the name of the package/library as the \"name\"\n\n    # `names` allows you to specify the names of alerts or packages.\n    names:\n      - \"Missing rate limiting\"\n\n    # The `imports` allows you to supplement your existing data with a list\n    #  from a file on the system.\n    imports:\n      ids: \"path/to/ids/supplement/file.txt\"\n      names: \"path/to/names/supplement/file.txt\"\n```\n\n#### Wildcards\n\nFor both types of criteria matching you can use wildcards to easily match requirements in a quicker way.\nThe matching is done using a Unix shell-style wildcards module called [fnmatch](https://docs.python.org/3/library/fnmatch.html) which supports `*` for matching everything.\n\n```yaml\ncodescanning:\n  conditions:\n    ids:\n      - \"*/sql-injection\"\n```\n\n#### Time to Remediate\n\nThe feature allows a user to define a time frame to which a security alert/vulnerability of a certain severity has before the alert triggered a violation in the Action.\n\nBy default, if this section is not defined in any part of the policy then no checks are done.\nExisting policy files should act the same without the new section.\n\n```yaml\ngeneral:\n  # All other blocks will be inheriting the remediate section if they don't have\n  #  their own defined.\n  remediate:\n    # Only `error`'s and above have got 7 days to remediate according to the\n    #  policy. Any time before that, nothing will occur and post the remediation\n    #  time frame the alert will be raised.\n    error: 7\n\ncodescanning:\n  # the `codescanning` block will inherit the `general` block\n  # ...\n\ndependabot:\n  remediate:\n    # high and critical security issues\n    high: 7\n    # moderate security issues\n    moderate: 30\n    # all other security issues\n    all: 90\n\nsecretscanning:\n  remediate:\n    # All secrets by default are set to 'critical' severity so only `critical`\n    #  or `all` will work\n    critical: 7\n```\n\n##### Time to Remediate Examples\n\n- [Time to Remediate Example](examples/policies/time-to-remediate.yml)\n\n#### Data Importing\n\nSome things to consider when using imports:\n\n- Imports appending to existing lists and do not replace a previously generated list.\n- Imports are relative to:\n  - `Working Directory`\n  - `GitHub Action / CLI directory`\n  - `Cloned Repository Directory`\n- Imports are only allowed from a number of predefined paths to prevent loading data on the system (AKA, path traversal).\n\n## Maintainers / Contributors\n\n- [@GeekMasher](https://github.com/GeekMasher) - Author / Core Maintainer\n\n## Support\n\nPlease create [GitHub Issues][github-issues] if there are bugs or feature requests.\n\nThis project uses [Sematic Versioning (v2)](https://semver.org/) and with major releases, breaking changes will occur.\n\n## License\n\nThis project is licensed under the terms of the MIT open source license.\nPlease refer to [MIT][license] for the full terms.\n\n\u003c!-- Resources --\u003e\n\n[license]: ./LICENSE\n[github]: https://github.com/advanced-security/policy-as-code\n[github-issues]: https://github.com/advanced-security/policy-as-code/issues\n[github-actions]: https://github.com/advanced-security/policy-as-code/actions\n\n[advanced-security]: https://github.com/features/security\n[github-codescanning]: https://docs.github.com/en/code-security/code-scanning/introduction-to-code-scanning/about-code-scanning\n[github-secretscanning]: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning\n[github-supplychain]: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-supply-chain-security\n\n[python-setup]: https://github.com/actions/setup-python\n[vendored]: https://github.com/advanced-security/policy-as-code/tree/main/vendor/README.md\n[examples-actions]: https://github.com/advanced-security/policy-as-code/tree/main/examples/workflows\n[examples-cli]: https://github.com/advanced-security/policy-as-code/tree/main/examples/scripts\n\n[permissions]: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs#overview\n[permissions-codescanning]: https://docs.github.com/en/rest/code-scanning/code-scanning#list-code-scanning-alerts-for-a-repository\n[permissions-secretscanning]: https://docs.github.com/en/rest/secret-scanning/secret-scanning#list-secret-scanning-alerts-for-a-repository\n[permissions-dependabot]: https://docs.github.com/en/rest/dependabot/alerts#list-dependabot-alerts-for-a-repository\n[permissions-dependencygraph]: https://docs.github.com/en/graphql/reference/objects#dependencygraphmanifestconnection\n","funding_links":[],"categories":["Policy"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadvanced-security%2Fpolicy-as-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadvanced-security%2Fpolicy-as-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadvanced-security%2Fpolicy-as-code/lists"}