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 / funcs.json
Created September 22, 2022 12:37
Funcs
{
"funcs": {
"funcs": [
{
"name": "g0.data.policy.is_admin",
"params": [
0,
1
],
"return": 2,
@anderseknert
anderseknert / plans.json
Created September 21, 2022 13:30
Plans
{
"plans": {
"plans": [
{
"name": "policy/allow",
"blocks": [
{
"stmts": [
{
"type": "CallStmt",
@anderseknert
anderseknert / static.json
Created September 21, 2022 11:05
Static block
{
"static": {
"strings": [{"value": "result"}, {"value": "user"}, {"value": "roles"}, {"value": "admin"}],
"builtin_funcs": [
{
"name": "internal.member_2",
"decl": {
"args": [{"type": "any"}, {"type": "any"}],
"result": {"type": "boolean"},
"type": "function"
@anderseknert
anderseknert / policy.rego
Created September 21, 2022 11:02
policy.rego
package policy
import future.keywords.if
import future.keywords.in
allow if is_admin
is_admin if "admin" in input.user.roles
@anderseknert
anderseknert / policy.rego
Last active September 7, 2022 15:12
CVE-2022-36085
package policy
# Note the use of the allowed is_object function here
response := is_object({
"method": "GET",
"url": "https://www.openpolicyagent.org"
})
# This would work (and send a HTTP request) even though
# the http.send built-in function had been declared unsafe
@anderseknert
anderseknert / cleanup.py
Created June 27, 2022 19:58
Horrendous cleanup script
#!/usr/bin/env python3
import json
import os
import subprocess
import tempfile
import yaml
yaml.SafeDumper.org_represent_str = yaml.SafeDumper.represent_str
deny["S3 Bucket: 'AccessControl' attribute value must be 'Private'"] {
not bucket_is_private
}
bucket_is_private {
input.resource.properties.AccessControl == "Private"
}
@anderseknert
anderseknert / s3bucket.json
Created April 7, 2022 10:19
Example S3 bucket
{
"myS3Bucket": {
"Type": "AWS::S3::Bucket"
}
}
@anderseknert
anderseknert / resourcetypes.py
Last active April 2, 2022 19:59
Crawling AWS docs for all CloudFormation resource types. Python vs. Rego!
#!/usr/bin/env python3
import requests
def main():
base = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide"
resp = requests.get(f"{base}/toc-contents.json")
body = resp.json()