Skip to content

Commit a077147

Browse files
author
James Alseth
committed
Add v1
1 parent fe4e291 commit a077147

File tree

10 files changed

+555
-26
lines changed

10 files changed

+555
-26
lines changed

.github/test/policy/always_warn.rego

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package always_warn
2+
3+
warn["a warning! you should probably fix this"]

.github/test/resources/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: test

.github/workflows/pull_request.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Pull Request
2+
on: ["pull_request"]
3+
4+
jobs:
5+
go-tests:
6+
name: Go Tests
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: setup go
10+
uses: actions/setup-go@v2
11+
with:
12+
go-version: 1.14.x
13+
14+
- name: checkout
15+
uses: actions/checkout@v2
16+
17+
- name: unit test
18+
run: go test -v ./...
19+
20+
- name: test build
21+
run: go build -o build/action-conftest
22+
23+
- name: test docker build
24+
run: docker build .
25+
26+
test-run-action:
27+
name: Test the Action
28+
needs: go-tests
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: checkout
32+
uses: actions/checkout@v2
33+
34+
- name: run action
35+
uses: './'
36+
with:
37+
files: '.github/test/resources'
38+
policy: '.github/test/policy/always_warn.rego'
39+
gh-token: ${{ secrets.GITHUB_TOKEN }}
40+
gh-comment-url: ${{ github.event.pull_request.comments_url }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
gcs.json

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM instrumenta/conftest:latest as conftest
2+
3+
FROM golang:1.14-alpine as builder
4+
COPY main.go .
5+
RUN go build -o /entrypoint
6+
7+
FROM alpine:3
8+
COPY --from=conftest /conftest /usr/local/bin/conftest
9+
COPY --from=builder /entrypoint /usr/local/bin/entrypoint
10+
CMD [ "/usr/local/bin/entrypoint" ]

LICENSE

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -174,28 +174,3 @@
174174
of your accepting any such warranty or additional liability.
175175

176176
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.

README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,67 @@
11
# action-conftest
2-
A GitHub Action for easily using conftest in your CI
2+
3+
A GitHub Action for easily using [conftest](https://github.com/open-policy-agent/conftest) in your CI. It allows for pulling policies from another source and can surface the violations and warnings into the comments of the pull request.
4+
5+
**NOTE:** This action only supports pull secrets for S3, GCS, and HTTP remotes. If you are pulling from an OCI registry, it is assumed that you have already authenticated using `docker login` in a previous step in the GitHub Actions `job` and you should not supply a `pull-secret` argument.
6+
7+
## Options
8+
9+
| Option | Description | Default | Required |
10+
|----------------|------------------------------------------------|---------|------------------------|
11+
| files | Files for Conftest to test (space delimited) | | yes |
12+
| policy | Where to find the policy folder or file | policy | no |
13+
| data | Files or folder with supplemental test data | | no |
14+
| all-namespaces | Whether to use all namespaces in testing | true | no |
15+
| combine | Whether to combine input files | false | no |
16+
| pull-url | URL to pull policies from | | no |
17+
| pull-secret | Secret that allows the policies to be pulled | | no |
18+
| add-comment | Whether or not to add a comment to the PR | true | no |
19+
| docs-url | Documentation URL to link to in the PR comment | | no |
20+
| gh-token | Token to authorize adding the PR comment | | if add-comment is true |
21+
| gh-comment-url | The URL of the comments for the PR | | if add-comment is true |
22+
23+
## Example Usage
24+
25+
### Using policies already in the repo
26+
27+
This is a basic example. It assumes the policies already exist in the repository in the default `policy/` directory.
28+
29+
```yaml
30+
name: conftest
31+
on: [pull_request]
32+
jobs:
33+
conftest:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: checkout
37+
uses: actions/checkout@v2
38+
- name: conftest
39+
uses: YubicoLabs/action-conftest@v1
40+
with:
41+
files: some_deployment.yaml another_resource.yaml
42+
gh-token: ${{ secrets.GITHUB_TOKEN }}
43+
gh-comment-url: ${{ github.event.pull_request.comments_url }}
44+
```
45+
46+
### Pulling policies from a Google Cloud Storage bucket
47+
48+
This example shows pulling the policy directory from a GCS bucket. In this case, the `pull-secret` variable is the JSON key for a service account with read acccess to the bucket.
49+
50+
```yaml
51+
name: conftest-with-pull
52+
on: [pull_request]
53+
jobs:
54+
conftest:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: checkout
58+
uses: actions/checkout@v2
59+
- name: conftest
60+
uses: YubicoLabs/action-conftest@v1
61+
with:
62+
files: some_deployment.yaml another_resource.yaml
63+
pull-url: gcs::https://www.googleapis.com/storage/v1/bucket_name/policy
64+
pull-secret: ${{ secrets.POLICY_PULL_SECRET }}
65+
gh-token: ${{ secrets.GITHUB_TOKEN }}
66+
gh-comment-url: ${{ github.event.pull_request.comments_url }}
67+
```

action.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: "Conftest"
2+
description: "Write tests against structured configuration data using Open Policy Agent"
3+
branding:
4+
icon: "check"
5+
color: "green"
6+
inputs:
7+
files:
8+
description: "Files for Conftest to test (space delimited)"
9+
required: true
10+
policy:
11+
description: "Where to find the policy folder or file"
12+
default: "policy"
13+
data:
14+
description: "Files or folder with supplemental test data"
15+
all-namespaces:
16+
description: "Whether to use all namespaces in testing"
17+
default: true
18+
combine:
19+
description: "Whether to combine input files"
20+
pull-url:
21+
description: "URL to pull policies from"
22+
pull-secret:
23+
description: "Secret that allows the policies to be pulled"
24+
add-comment:
25+
description: "Whether or not to add a comment to the PR"
26+
default: true
27+
docs-url:
28+
description: "The URL where users can find out more about the policies"
29+
gh-token:
30+
description: "The token that allows us to post a comment in the PR"
31+
gh-comment-url:
32+
description: "The URL of the comments for the PR"
33+
runs:
34+
using: 'docker'
35+
image: 'Dockerfile'
36+
env:
37+
FILES: ${{ inputs.files }}
38+
POLICY: ${{ inputs.policy }}
39+
DATA: ${{ inputs.data }}
40+
ALL_NAMESPACES: ${{ inputs.all-namespaces }}
41+
COMBINE: ${{ inputs.combine }}
42+
PULL_URL: ${{ inputs.pull-url }}
43+
PULL_SECRET: ${{ inputs.pull-secret }}
44+
ADD_COMMENT: ${{ inputs.add-comment }}
45+
DOCS_URL: ${{ inputs.docs-url }}
46+
GITHUB_TOKEN: ${{ inputs.gh-token }}
47+
GITHUB_COMMENT_URL: ${{ inputs.gh-comment-url }}

0 commit comments

Comments
 (0)