Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rego): add result package #62

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/test-rego.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup OPA
uses: ./.github/actions/setup-opa

- name: OPA Format
run: |
files=$(opa fmt --list . | grep -v vendor || true)
Expand All @@ -30,8 +32,6 @@ jobs:
echo "$files"
exit 1
fi
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum

- name: OPA Test
run: make test-rego
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ DYNAMIC_REGO_FOLDER=./checks/kubernetes/policies/dynamic
test:
go test -v ./...


.PHONY: rego
rego: fmt-rego
rego: fmt-rego test-rego

.PHONY: test-rego
test-rego:
opa test checks/ lib/

.PHONY: fmt-rego
fmt-rego:
opa fmt -w checks/
opa fmt -w checks/ lib/

.PHONY: bundle
bundle: create-bundle verify-bundle
Expand Down
2 changes: 2 additions & 0 deletions checks/cloud/aws/iam/filter_iam_pass_role.rego
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# provider: aws
package builtin.aws.iam.aws0342

import data.lib.result

allows_permission(statements, permission, effect) {
statement := statements[_]
statement.Effect == effect
Expand Down
2 changes: 2 additions & 0 deletions checks/cloud/aws/rds/disable_public_access.rego
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

package builtin.aws.rds.aws0180

import data.lib.result

deny[res] {
instance := input.aws.rds.instances[_]
instance.publicaccess.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# provider: aws
package builtin.aws.rds.aws0343

import data.lib.result

deny[res] {
cluster := input.aws.rds.clusters[_]
not cluster.deletionprotection.value
Expand Down
2 changes: 2 additions & 0 deletions checks/cloud/aws/rds/enable_deletion_protection.rego
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# provider: aws
package builtin.aws.rds.aws0177

import data.lib.result

deny[res] {
instance := input.aws.rds.instances[_]
not instance.deletionprotection.value
Expand Down
2 changes: 2 additions & 0 deletions checks/cloud/aws/rds/enable_iam_auth.rego
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# provider: aws
package builtin.aws.rds.aws0176

import data.lib.result

deny[res] {
instance := input.aws.rds.instances[_]
instance.engine.value == ["postgres", "mysql"][_]
Expand Down
2 changes: 2 additions & 0 deletions checks/cloud/aws/s3/dns_compliant_name.rego
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# provider: aws
package builtin.aws.s3.aws0320

import data.lib.result

deny[res] {
bucket := input.aws.s3.buckets[_]
indexof(bucket.name.value, ".") != -1
Expand Down
2 changes: 2 additions & 0 deletions checks/cloud/aws/s3/enable_logging.rego
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# good_examples: "checks/cloud/aws/s3/enable_bucket_logging.cf.go"
package builtin.aws.s3.aws0089

import data.lib.result

deny[res] {
bucket := input.aws.s3.buckets[_]
not bucket.acl.value == "log-delivery-write"
Expand Down
1 change: 1 addition & 0 deletions checks/docker/add_instead_of_copy.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS005

import data.lib.docker
import data.lib.result

get_add[output] {
add := docker.add[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/apt_get_missing_no_install_recommends.rego
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package builtin.dockerfile.DS029

import data.lib.docker
import data.lib.result

deny[res] {
output := get_apt_get[_]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package builtin.dockerfile.DS021

import data.lib.docker
import data.lib.result

deny[res] {
output := get_apt_get[_]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS006

import data.lib.docker
import data.lib.result

get_alias_from_copy[output] {
copies := docker.stage_copies[stage]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS011

import data.lib.docker
import data.lib.result

get_copy_arg[output] {
copy := docker.copy[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/latest_tag.rego
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package builtin.dockerfile.DS001

import data.lib.docker
import data.lib.result

# returns element after AS
get_alias(values) = alias {
Expand Down
1 change: 1 addition & 0 deletions checks/docker/maintainer_is_deprecated.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS022

import data.lib.docker
import data.lib.result

get_maintainer[mntnr] {
mntnr := input.Stages[_].Commands[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/missing_apk_no_cache.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS025

import data.lib.docker
import data.lib.result

get_apk[output] {
run := docker.run[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/missing_dnf_clean_all.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS019

import data.lib.docker
import data.lib.result

install_regex := `(dnf install)|(dnf in)|(dnf reinstall)|(dnf rei)|(dnf install-n)|(dnf install-na)|(dnf install-nevra)`

Expand Down
1 change: 1 addition & 0 deletions checks/docker/missing_microdnf_clean_all.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS027

import data.lib.docker
import data.lib.result

install_regex := `(microdnf install)|(microdnf reinstall)`

Expand Down
1 change: 1 addition & 0 deletions checks/docker/missing_zypper_clean.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS020

import data.lib.docker
import data.lib.result

install_regex := `(zypper in)|(zypper remove)|(zypper rm)|(zypper source-install)|(zypper si)|(zypper patch)|(zypper (-(-)?[a-zA-Z]+ *)*install)`

Expand Down
1 change: 1 addition & 0 deletions checks/docker/multiple_cmd_instructions_listed.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS016

import data.lib.docker
import data.lib.result

deny[res] {
cmds := docker.stage_cmd[name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS007

import data.lib.docker
import data.lib.result

deny[res] {
entrypoints := docker.stage_entrypoints[stage]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/multiple_healthcheck_instructions.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS023

import data.lib.docker
import data.lib.result

deny[res] {
healthchecks := docker.stage_healthcheck[name]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/no_healthcheck_instruction.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS026

import data.lib.docker
import data.lib.result

deny[res] {
count(docker.healthcheck) == 0
Expand Down
1 change: 1 addition & 0 deletions checks/docker/port22.rego
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package builtin.dockerfile.DS004

import data.lib.docker
import data.lib.result

# deny_list contains the port numbers which needs to be denied.
denied_ports := ["22", "22/tcp", "22/udp"]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/root_user.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS002

import data.lib.docker
import data.lib.result

# get_user returns all the usernames from
# the USER command.
Expand Down
1 change: 1 addition & 0 deletions checks/docker/root_user_test.rego
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package builtin.dockerfile.DS002

import data.lib.docker
import data.lib.result

test_not_root_allowed {
r := deny with input as {"Stages": [{
Expand Down
1 change: 1 addition & 0 deletions checks/docker/run_apt_get_dist_upgrade.rego
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package builtin.dockerfile.DS024

import data.lib.docker
import data.lib.result

get_apt_get_dist_upgrade[run] {
run := docker.run[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/run_command_cd_instead_of_workdir.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS013

import data.lib.docker
import data.lib.result

get_cd[output] {
run := docker.run[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/run_using_sudo.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS010

import data.lib.docker
import data.lib.result

has_sudo(commands) {
parts = split(commands, "&&")
Expand Down
1 change: 1 addition & 0 deletions checks/docker/run_using_wget_and_curl.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS014

import data.lib.docker
import data.lib.result

deny[res] {
wget := get_tool_usage(docker.run[_], "wget")
Expand Down
1 change: 1 addition & 0 deletions checks/docker/same_alias_in_different_froms.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS012

import data.lib.docker
import data.lib.result

get_duplicate_alias[output] {
output1 := get_aliased_name[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/unix_ports_out_of_range.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS008

import data.lib.docker
import data.lib.result

invalid_ports[output] {
expose := docker.expose[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/update_instruction_alone.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS017

import data.lib.docker
import data.lib.result

deny[res] {
run := docker.run[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/workdir_path_not_absolute.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS009

import data.lib.docker
import data.lib.result

get_work_dir[output] {
workdir := docker.workdir[_]
Expand Down
1 change: 1 addition & 0 deletions checks/docker/yum_clean_all_missing.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.dockerfile.DS015

import data.lib.docker
import data.lib.result

get_yum[output] {
run := docker.run[_]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package builtin.kubernetes.KSV110

import data.lib.kubernetes
import data.lib.result

default defaultNamespaceInUse = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package builtin.kubernetes.KSV004

import data.lib.kubernetes
import data.lib.result
import data.lib.utils

default failCapsDropAny = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package builtin.kubernetes.KSV007

import data.lib.kubernetes
import data.lib.result
import data.lib.utils

# failHostAliases is true if spec.hostAliases is set (on all controllers)
Expand Down
1 change: 1 addition & 0 deletions checks/kubernetes/advanced/optional/use_limit_range.rego
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.kubernetes.KSV039

import data.lib.kubernetes
import data.lib.result
import data.lib.utils

limitRangeConfigure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package builtin.kubernetes.KSV040

import data.lib.kubernetes
import data.lib.result
import data.lib.utils

resourceQuotaConfigure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package builtin.kubernetes.KSV032

import data.lib.kubernetes
import data.lib.result
import data.lib.utils

default failTrustedAzureRegistry = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package builtin.kubernetes.KSV035

import data.lib.kubernetes
import data.lib.result
import data.lib.utils

default failTrustedECRRegistry = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package builtin.kubernetes.KSV033

import data.lib.kubernetes
import data.lib.result
import data.lib.utils

default failTrustedGCRRegistry = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package builtin.kubernetes.KSV034

import data.lib.kubernetes
import data.lib.result
import data.lib.utils

default failPublicRegistry = false
Expand Down
Loading