Skip to content

Instantly share code, notes, and snippets.

View anderseknert's full-sized avatar
👨‍💻
Hacking on all things OPA

Anders Eknert anderseknert

👨‍💻
Hacking on all things OPA
View GitHub Profile
@anderseknert
anderseknert / main.go
Created February 26, 2025 11:19
From AST JSON to Rego
package main
import (
"encoding/json"
"fmt"
"io"
"os"
"github.com/open-policy-agent/opa/v1/ast"
"github.com/open-policy-agent/opa/v1/format"
@anderseknert
anderseknert / input.json
Created December 5, 2024 11:10
Cost of custom function calls / caching
{
"package": {
"location": "1:1:1:8",
"path": [
{
"type": "var",
"value": "data"
},
{
"location": "1:9:1:14",
@anderseknert
anderseknert / dependabot.yml
Created November 4, 2024 10:51
Dependabot group PRs
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
groups:
dependencies:
patterns:
- "*"
@anderseknert
anderseknert / google_sql_database_instance.rego
Last active May 27, 2024 07:47
google_sql_database_instance policy
package google_sql_database_instance
import rego.v1
violations contains db_instance.id if {
some db_instance in input.google_sql_database_instance
not valid_db_instance(db_instance)
}
valid_db_instance(db_instance) if every setting in db_instance.config.settings {
@anderseknert
anderseknert / db_setting.rego
Last active May 25, 2024 08:47
Terrascan DB settings policy
package accurics
import rego.v1
violations contains db_instance.id if {
some db_instance in input.google_sql_database_instance
some setting in db_instance.config.settings
invalid_db_instance_setting(setting)
}
@anderseknert
anderseknert / or_array.rego
Created September 20, 2023 12:54
Or array
arr := [x | some x in input.my_array]
@anderseknert
anderseknert / or_array.js
Created September 20, 2023 12:53
Imperative OR array
arr = my_array || []
@anderseknert
anderseknert / object_get.rego
Created September 20, 2023 12:52
object.get
allow if {
# return input.user.name, or "anyomous" if the lookup fails
user := object.get(input, ["user", "name"], "anonymous")
user != "anonymous"
# ... more conditions
}
@anderseknert
anderseknert / object_or.rego
Created September 20, 2023 12:51
Object-based OR
deny := message if {
code_reason_map := {
400: "Bad request",
404: "Not found",
500: "Internal server error",
}
message := code_reason_map[status_code]
}
allow {
# Simple way to "inline" an OR check — turn it into a "contains" problem
input.request.method in {“HEAD”, “GET”}
}