├── .gitmodules ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── README.md ├── SECURITY.md ├── action.yaml ├── entrypoint.sh └── scripts └── local.sh /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fugue/regula-action/e47ae38fae32dccedc5ef814acdb2081eb2a351d/.gitmodules -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | - 3.2.1 (2022-02-23) 4 | * Bump regula to v3.2.1 5 | 6 | - 3.1.0 (2023-02-14) 7 | * Bump regula to v3.1.0 8 | * Fix warnings about `::set-output` 9 | 10 | - 2.8.1 (2022-07-19) 11 | * Bump regula to v2.8.1 12 | * Fix bug from non-root Docker user (#31) 13 | 14 | - 1.6.0 (2021-10-15) 15 | * Bump regula to v1.6.0 16 | 17 | - 1.5.0 (2021-09-30) 18 | * Bump regula to v1.5.0 19 | 20 | - 1.4.0 (2021-09-16) 21 | * Bump regula to v1.4.0 22 | 23 | - 1.3.0 (2021-09-02) 24 | * Bump regula to v1.3.0 25 | 26 | - 1.2.0 (2021-08-19) 27 | * Bump regula to v1.2.0 28 | 29 | - 1.1.0 (2021-08-05) 30 | * Bump regula to v1.1.0 31 | 32 | - 1.0.0 (2021-06-29) 33 | * Bump regula to v1.0.0 34 | 35 | - 0.9.0 (2021-05-27) 36 | * Bump regula to v0.9.0 37 | 38 | - 0.8.0 (2021-04-15) 39 | * Bump regula to v0.8.0 40 | 41 | - 0.7.0 (2021-04-01) 42 | * Bump regula to v0.7.0. 43 | 44 | - 0.6.0 (2021-03-18) 45 | * Bump regula to v0.6.0. 46 | 47 | - 0.5.0 (2020-08-21) 48 | * Bump regula to v0.5.0. 49 | 50 | - 0.4.0 (2020-07-07) 51 | * Bump regula to v0.4.0. 52 | 53 | - 0.3.0 (2020-03-20) 54 | * Bump regula to v0.3.0. 55 | * Print the new human-readable error message. 56 | 57 | - 0.2.0 (2020-02-25) 58 | * Update regula to v0.2.0. 59 | 60 | - 0.1.1 (2020-02-24) 61 | * Upgrade terraform to v0.12.20. 62 | 63 | - 0.1.0 (2020-01-23) 64 | * Bump regula to v0.1.0. 65 | * Improve examples and README.md. 66 | 67 | - 0.0.1 (2020-01-14) 68 | * Initial release. 69 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM fugue/regula:v3.2.1 AS regula 2 | USER root 3 | RUN apk add --update bash jq 4 | COPY entrypoint.sh /entrypoint.sh 5 | ENTRYPOINT ["/entrypoint.sh"] 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # regula-action 2 | 3 | [Regula] is a tool that evaluates CloudFormation and Terraform infrastructure-as-code for potential AWS, Azure, and Google Cloud security misconfigurations and compliance violations prior to deployment. This is a [GitHub Action] to run [Regula] against your repository. 4 | 5 | ## Example 6 | 7 | Here's an example workflow file. It checks three different IaC configurations: one Terraform directory and two CloudFormation templates: 8 | 9 | ```yaml 10 | on: [push] 11 | 12 | jobs: 13 | regula_tf_job: 14 | runs-on: ubuntu-latest 15 | name: Regula Terraform 16 | steps: 17 | - uses: actions/checkout@master 18 | - uses: fugue/regula-action@v3.2.1 19 | with: 20 | input_path: infra_tf 21 | include: example_custom_rule 22 | 23 | regula_cfn_job: 24 | runs-on: ubuntu-latest 25 | name: Regula CloudFormation 26 | steps: 27 | - uses: actions/checkout@master 28 | - uses: fugue/regula-action@v3.2.1 29 | with: 30 | input_path: infra_cfn/cloudformation.yaml 31 | 32 | regula_valid_cfn_job: 33 | runs-on: ubuntu-latest 34 | name: Regula Valid CloudFormation 35 | steps: 36 | - uses: actions/checkout@master 37 | - uses: fugue/regula-action@v3.2.1 38 | with: 39 | input_path: infra_valid_cfn/cloudformation.yaml 40 | 41 | regula_multi_cfn_job: 42 | runs-on: ubuntu-latest 43 | name: Regula multiple CloudFormation templates 44 | steps: 45 | - uses: actions/checkout@master 46 | - uses: fugue/regula-action@v3.2.1 47 | with: 48 | input_path: '*/cloudformation.yaml' 49 | 50 | regula_input_list_job: 51 | runs-on: ubuntu-latest 52 | name: Regula on CloudFormation and Terraform 53 | steps: 54 | - uses: actions/checkout@master 55 | - uses: fugue/regula-action@v3.2.1 56 | with: 57 | input_path: | 58 | infra_cfn/cloudformation.yaml 59 | infra_valid_cfn/cloudformation.yaml 60 | infra_tf 61 | 62 | regula_tf_plan_job: 63 | runs-on: ubuntu-latest 64 | name: Regula on a Terraform plan JSON 65 | steps: 66 | - uses: actions/checkout@master 67 | - uses: hashicorp/setup-terraform@v1 68 | with: 69 | # See the note below for why this option is necessary. 70 | terraform_wrapper: false 71 | terraform_version: 1.0.8 72 | - run: | 73 | cd infra_tf 74 | terraform init 75 | terraform plan -refresh=false -out="plan.tfplan" 76 | terraform show -json plan.tfplan > plan.json 77 | env: 78 | AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} 79 | AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 80 | - uses: fugue/regula-action@v2.6.1 81 | with: 82 | input_path: infra_tf/plan.json 83 | input_type: tf-plan 84 | include: example_custom_rule 85 | ``` 86 | 87 | You can see this example in action in the 88 | [regula-ci-example](https://github.com/fugue/regula-ci-example). 89 | 90 | ## Inputs 91 | 92 | - `input_path`: One or more Terraform directories, Terraform JSON plans, or CloudFormation templates. Accepts space-separated or newline-separated filenames and/or globbing expressions. This defaults to `.` (the root of your repository). 93 | - `config`: Path to .regula.yaml file. By default regula will look in the current working directory and its parents. 94 | - `environment_id`: Environment ID in Fugue. 95 | - `exclude`: Rule IDs or names to exclude. This can be a space or newline-separated list. 96 | - `include`: Custom rule and configuration paths passed in to the Regula interpreter. This can be a space or newline-separated list. 97 | - `input_type`: The input types that Regula will evaluate. Defaults to `auto`, which evaluates all supported types. Possible values are: 98 | - `auto` 99 | - `tf-plan` -- Terraform plan JSON files 100 | - `cfn` -- CloudFormation templates in YAML/JSON 101 | - `tf` -- Terraform directories or files 102 | - `k8s` -- Kubernetes manifest in YAML format 103 | - `no_built_ins`: Disable the built-in Regula rules. Set to `"true"` if you only want to run custom rules. 104 | - `no_config`: Do not look for or load a regula config file. Set to `"true"` to enable this option. 105 | - `no_ignore`: Disable use of .gitignore. Set to `"true"` to enable this option. 106 | - `only`: Rule IDs or names to run. All other rules will be excluded. This can be a space or newline-separated list. 107 | - `severity`: The minimum severity where Regula will produce a non-zero exit code for failing rules. Defaults to `unknown`. Use `off` to always produce a zero exit code. Possible values are: 108 | - unknown 109 | - informational 110 | - low 111 | - medium 112 | - high 113 | - critical 114 | - off 115 | - `sync`: Fetch rules and configuration from Fugue. Set to `"true"` to enable this option. 116 | - `upload`: Upload results to Fugue. Set to `"true"` to enable this. Requires `sync` to be set as well. 117 | - `rego_paths`: Custom rule and configuration paths passed in to the Regula interpreter 118 | - `user_only`: Disable the builtin Regula rules. Set to `true` if you only want to run custom rules. 119 | 120 | ### Integration with Fugue 121 | 122 | You can easily integrate this action with Fugue. 123 | 124 | 1. Set `sync` and `upload` to true in the input values: 125 | 126 | ```yaml 127 | - uses: fugue/regula-action@v3.2.1 128 | with: 129 | sync: "true" 130 | upload: "true" 131 | ``` 132 | 133 | Note that setting `upload` will require you to set an environment ID as 134 | well. You can either specify that in the `.regula.yaml` or pass it in as 135 | an input value. 136 | 137 | 2. Set up `FUGUE_API_ID` and `FUGUE_API_SECRET` environment variables for the 138 | action. 139 | 140 | You can find more info about these in the 141 | [Fugue API Documentation](https://docs.fugue.co/api.html). 142 | 143 | ### Deprecated options 144 | 145 | These options still function, but we encourage you to update your configurations before 146 | they are removed in a future release. 147 | 148 | * `user_only` is deprecated. Use `no_built_ins` instead. 149 | * `rego_paths` is deprecated. Use `include` instead. 150 | * `terraform_directory` is deprecated. Use `input_path` instead. 151 | 152 | ### Links to additional information 153 | 154 | [GitHub Action]: https://github.com/features/actions 155 | [Regula]: https://github.com/fugue/regula 156 | 157 | ## How to use this GitHub Action 158 | 159 | To use [Regula] to evaluate the infrastructure-as-code in your own repository via GitHub Actions, see the instructions in [regula-ci-example](https://github.com/fugue/regula-ci-example). The example walks through how to use this GitHub Action in your own repo. 160 | 161 | ## Compatibility with the `hashicorp/setup-terraform` action 162 | 163 | The `hashicorp/setup-terraform` action can be used to generate a Terraform plan JSON file that Regula can evaluate. By default, the `hashicorp/setup-terraform` action wraps the `terraform` binary with a script that outputs some additional information for each command it executes. It's necessary to use the `terraform_wrapper: false` option, as we're doing in the example above, in order for the plan JSON file to be valid. 164 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | For reporting guidelines and general information regarding security at Fugue, 4 | please visit [fugue.co/security](https://fugue.co/security). 5 | -------------------------------------------------------------------------------- /action.yaml: -------------------------------------------------------------------------------- 1 | name: 'Regula' 2 | description: 'Run regula' 3 | inputs: 4 | input_path: 5 | description: | 6 | Input paths for regula. This can be a space or newline-separated list of 7 | terraform directories, terraform JSON plans, or a cloudformation templates. 8 | Defaults to the root of your repository. Globbing expressions can also 9 | be used. 10 | required: false 11 | config: 12 | description: | 13 | Path to .regula.yaml file. By default regula will look in the current working 14 | directory and its parents. 15 | required: false 16 | environment_id: 17 | description: | 18 | Environment ID in Fugue 19 | required: false 20 | exclude: 21 | description: | 22 | Rule IDs or names to exclude. This can be a space or newline-separated list. 23 | required: false 24 | include: 25 | description: | 26 | Custom rule and configuration paths passed in to the Regula interpreter. This can 27 | be a space or newline-separated list. 28 | required: false 29 | input_type: 30 | description: | 31 | Limit which input types that regula will evaluate. Defaults to "auto", which 32 | evaluates all supported types. This can be a space or newline-separated list. 33 | Possible values are: 34 | auto 35 | tf-plan 36 | cfn 37 | tf 38 | k8s 39 | required: false 40 | no_built_ins: 41 | description: | 42 | Disable built-in rules 43 | required: false 44 | default: "false" 45 | no_config: 46 | description: | 47 | Do not look for or load a regula config file. 48 | required: false 49 | default: "false" 50 | no_ignore: 51 | description: | 52 | Disable use of .gitignore 53 | required: false 54 | default: "false" 55 | only: 56 | description: | 57 | Rule IDs or names to run. All other rules will be excluded. This can be a space or 58 | newline-separated list. 59 | required: false 60 | severity: 61 | description: | 62 | The minimum severity where Regula will produce a non-zero exit code for failing 63 | rules. Defaults to "unknown". Use "off" to always produce a zero exit code. 64 | Possible values are: 65 | unknown 66 | informational 67 | low 68 | medium 69 | high 70 | critical 71 | off 72 | required: false 73 | default: unknown 74 | sync: 75 | description: | 76 | Fetch rules and configuration from Fugue 77 | required: false 78 | default: "false" 79 | upload: 80 | description: | 81 | Upload rule results to Fugue 82 | required: false 83 | default: "false" 84 | user_only: 85 | description: | 86 | Deprecated: use `no_built_ins` instead. 87 | Disable the builtin Regula rules. Set to "true" if you only want to run 88 | custom rules. 89 | required: false 90 | default: "false" 91 | terraform_directory: 92 | description: | 93 | Deprecated: use `input_path` instead. 94 | Directory where your terraform files are located. Defaults to the root of 95 | your repository. 96 | required: false 97 | rego_paths: 98 | description: | 99 | Deprecated: use `include` instead. 100 | Custom rule and configuration paths passed in to the Regula interpreter. 101 | required: false 102 | outputs: 103 | rules_passed: 104 | description: 'Number of passed rules' 105 | rules_failed: 106 | description: 'Number of failed rules' 107 | controls_passed: 108 | description: 'Number of passed controls' 109 | controls_failed: 110 | description: 'Number of failed controls' 111 | runs: 112 | using: 'docker' 113 | image: 'Dockerfile' 114 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o nounset -o errexit -o pipefail 3 | 4 | if [[ -v INPUT_INPUT_PATH && -n "$INPUT_INPUT_PATH" ]]; then 5 | INPUT_PATH="$INPUT_INPUT_PATH" 6 | elif [[ -v INPUT_TERRAFORM_DIRECTORY && -n "$INPUT_TERRAFORM_DIRECTORY" ]]; then 7 | # INPUT_TERRAFORM_DIRECTORY is deprecated. 8 | INPUT_PATH="$INPUT_TERRAFORM_DIRECTORY" 9 | else 10 | # Default to the current directory. 11 | INPUT_PATH="." 12 | fi 13 | 14 | REGULA_OPTS=() 15 | 16 | if [[ -v INPUT_CONFIG && -n "${INPUT_CONFIG}" ]]; then 17 | REGULA_OPTS+=("--config" "${INPUT_CONFIG}") 18 | fi 19 | 20 | if [[ -v INPUT_ENVIRONMENT_ID && -n "${INPUT_ENVIRONMENT_ID}" ]]; then 21 | REGULA_OPTS+=("--environment-id" "${INPUT_ENVIRONMENT_ID}") 22 | fi 23 | 24 | for EXCLUDE in ${INPUT_EXCLUDE:-}; do 25 | REGULA_OPTS+=("--exclude" ${EXCLUDE}) 26 | done 27 | 28 | for REGO_PATH in ${INPUT_REGO_PATHS:-} ${INPUT_INCLUDE:-}; do 29 | # Ignore old location of regula rules for backwards compatibility 30 | if [[ "${REGO_PATH}" == "/opt/regula/rules" ]]; then 31 | echo "Ignoring rego path /opt/regula/rules. It is no longer necessary to specify this." 32 | continue 33 | fi 34 | REGULA_OPTS+=("--include" ${REGO_PATH}) 35 | done 36 | 37 | for INPUT_TYPE in ${INPUT_INPUT_TYPE:-}; do 38 | REGULA_OPTS+=("--input-type" ${INPUT_TYPE}) 39 | done 40 | 41 | # Deprecated 42 | if [[ -v INPUT_USER_ONLY && "${INPUT_USER_ONLY}" == "true" ]] || [[ -v INPUT_NO_BUILT_INS && "${INPUT_NO_BUILT_INS}" == "true" ]]; then 43 | REGULA_OPTS+=("--no-built-ins") 44 | fi 45 | 46 | if [[ -v INPUT_NO_CONFIG && "${INPUT_NO_CONFIG}" == "true" ]]; then 47 | REGULA_OPTS+=("--no-config") 48 | fi 49 | 50 | if [[ -v INPUT_NO_IGNORE && "${INPUT_NO_IGNORE}" == "true" ]]; then 51 | REGULA_OPTS+=("--no-ignore") 52 | fi 53 | 54 | for ONLY in ${INPUT_ONLY:-}; do 55 | REGULA_OPTS+=("--only" ${ONLY}) 56 | done 57 | 58 | if [[ -v INPUT_SEVERITY && -n "${INPUT_SEVERITY}" ]]; then 59 | REGULA_OPTS+=("--severity" "${INPUT_SEVERITY}") 60 | fi 61 | 62 | if [[ -v INPUT_SYNC && "${INPUT_SYNC}" == "true" ]]; then 63 | REGULA_OPTS+=("--sync") 64 | fi 65 | 66 | if [[ -v INPUT_UPLOAD && "${INPUT_UPLOAD}" == "true" ]]; then 67 | REGULA_OPTS+=("--upload") 68 | fi 69 | 70 | 71 | if [[ -v DEBUG && -n "${DEBUG}" ]]; then 72 | echo ${REGULA_OPTS[@]} $INPUT_PATH 73 | fi 74 | 75 | EXIT_CODE=0 76 | REGULA_OUTPUT=$(cd "$GITHUB_WORKSPACE" && regula run -f json ${REGULA_OPTS[@]} $INPUT_PATH) || 77 | EXIT_CODE=$? 78 | echo "${REGULA_OUTPUT}" 79 | 80 | RULES_PASSED="$(jq -r '.summary.rule_results.PASS' <<<"$REGULA_OUTPUT")" 81 | RULES_FAILED="$(jq -r '.summary.rule_results.FAIL' <<<"$REGULA_OUTPUT")" 82 | echo "rules_passed=$RULES_PASSED" >>$GITHUB_OUTPUT 83 | echo "rules_failed=$RULES_FAILED" >>$GITHUB_OUTPUT 84 | exit ${EXIT_CODE} 85 | -------------------------------------------------------------------------------- /scripts/local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o pipefail 3 | 4 | # This script emulates the github action locally. Pass it the directory that 5 | # you want to test as a single parameter. 6 | 7 | readlink_exe=readlink 8 | 9 | if [[ $(uname -s) == "Darwin" ]]; then 10 | readlink_exe=greadlink 11 | fi 12 | 13 | WORKSPACE="$(${readlink_exe} -f "$1")" 14 | echo "Using workspace $WORKSPACE..." 1>&2 15 | shift 1 16 | 17 | if [[ $# -lt 1 ]]; then 18 | INPUT_PATH="/github/workspace" 19 | else 20 | INPUT_PATH="$@" 21 | fi 22 | 23 | echo "Updating docker image..." 1>&2 24 | docker build -t regula-action . 25 | 26 | echo "Running action..." 1>&2 27 | docker run --rm \ 28 | --volume "$WORKSPACE":/github/workspace \ 29 | --volume "$HOME/.aws":/root/.aws \ 30 | -e "GITHUB_WORKSPACE=/github/workspace" \ 31 | -e "INPUT_INPUT_PATH=${INPUT_PATH}" \ 32 | -e "INPUT_CONFIG=${CONFIG}" \ 33 | -e "INPUT_ENVIRONMENT_ID=${ENVIRONMENT_ID}" \ 34 | -e "INPUT_EXCLUDE=${EXCLUDE}" \ 35 | -e "INPUT_INCLUDE=${INCLUDE}" \ 36 | -e "INPUT_INPUT_TYPE=${INPUT_TYPE}" \ 37 | -e "INPUT_USER_ONLY=${USER_ONLY:-false}" \ 38 | -e "INPUT_NO_BUILT_INS=${NO_BUILT_INS:-false}" \ 39 | -e "INPUT_NO_CONFIG=${NO_CONFIG:-false}" \ 40 | -e "INPUT_NO_IGNORE=${NO_IGNORE:-false}" \ 41 | -e "INPUT_ONLY=${ONLY}" \ 42 | -e "INPUT_SEVERITY=${SEVERITY:-unknown}" \ 43 | -e "INPUT_REGO_PATHS=${REGO_PATHS}" \ 44 | -e "DEBUG=${DEBUG}" \ 45 | regula-action 46 | --------------------------------------------------------------------------------