diff --git a/tasks/cedar_authorization-248be0325907b508a77a/environment/Dockerfile b/tasks/cedar_authorization-248be0325907b508a77a/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-248be0325907b508a77a/instruction.md b/tasks/cedar_authorization-248be0325907b508a77a/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4e509d46c957bebcc25e13ed4dc2dd0717055a36 --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in LYg::LYY::a::"**", + action == LYg::LYY::Action::"action", + resource in LYg::LYY::a::"**" +) when { + true && (true || ((principal in principal) || (LYg::LYY::a::"" in LYg::LYY::a::"**"))) +}; + +policy1 +forbid( + principal in B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r::"", + action == B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action::"action", + resource in B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r::"" +) when { + true && ((-6727636073941130590) < (-6727627277848107360)) && ((-6727636073947290974) < 48115491182498) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::D"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"}},{"attrs":{},"parents":[],"uid":{"id":"**","type":"LYg::LYY::a"}},{"attrs":{},"parents":[],"uid":{"id":"DDD","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"LYg::LYY::Action"}}] + +Requests +{"action":{"id":"action","type":"LYg::LYY::Action"},"context":{},"principal":{"id":"**","type":"LYg::LYY::a"},"request":"R1","resource":{"id":"**","type":"LYg::LYY::a"}} +{"action":{"id":"action","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action"},"context":{},"principal":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"},"request":"R2","resource":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"}} +{"action":{"id":"action","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action"},"context":{},"principal":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"},"request":"R3","resource":{"id":"**","type":"LYg::LYY::a"}} +{"action":{"id":"action","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action"},"context":{},"principal":{"id":"**","type":"LYg::LYY::a"},"request":"R4","resource":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-248be0325907b508a77a/solution/reference.json b/tasks/cedar_authorization-248be0325907b508a77a/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-248be0325907b508a77a/solution/solve.sh b/tasks/cedar_authorization-248be0325907b508a77a/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-248be0325907b508a77a/task.toml b/tasks/cedar_authorization-248be0325907b508a77a/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3d612ec97329f3083b5fa62280630cde3fd68d8b --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-248be0325907b508a77a" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "20d978fabc2b8c53075bf25fe32df322154d6d42e77ea85e6e3b34cd89c2cc97" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-248be0325907b508a77a/tests/expected.json b/tasks/cedar_authorization-248be0325907b508a77a/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-248be0325907b508a77a/tests/grading.py b/tasks/cedar_authorization-248be0325907b508a77a/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-248be0325907b508a77a/tests/test.sh b/tasks/cedar_authorization-248be0325907b508a77a/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-248be0325907b508a77a/tests/verify.py b/tasks/cedar_authorization-248be0325907b508a77a/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-248be0325907b508a77a/validation/openenv.json b/tasks/cedar_authorization-248be0325907b508a77a/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-248be0325907b508a77a/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/environment/Dockerfile b/tasks/cedar_authorization-25a4b9f7565d170d2c85/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/instruction.md b/tasks/cedar_authorization-25a4b9f7565d170d2c85/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4f0c5d946848d191670662026cb1e8b73682dda5 --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r::"NNN", + action in [r::r::Action::"action",r::r::Action::"action"], + resource is r::r::r +) when { + true && (r::r::r::"NNN" in r::r::r::"NNN") +}; + +policy1 +forbid( + principal in r::r::n::r::a::"", + action in [r::r::n::r::Action::"action",r::r::n::r::Action::"action"], + resource in r::r::n::r::a::"" +) when { + true && (if if [[true]].contains([false, true]) then {"": ""} == {"": ""} else {"": ""} == {"": ""} then {"": {"": ""}} == {"": {"": ""}} else {"": {"": ""}} == {"": {"": ""}}) && ({"": {"": {}}} == {"": {"": {}}}) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::n::r::a"}},{"attrs":{},"parents":[],"tags":{"":{}},"uid":{"id":"NNN","type":"r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::n::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::Action"},"context":{},"principal":{"id":"NNN","type":"r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r"}} +{"action":{"id":"action","type":"r::r::n::r::Action"},"context":{},"principal":{"id":"NNN","type":"r::r::r"},"request":"R2","resource":{"id":"","type":"r::r::n::r::a"}} +{"action":{"id":"action","type":"r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r"}} +{"action":{"id":"action","type":"r::r::n::r::Action"},"context":{},"principal":{"id":"","type":"r::r::n::r::a"},"request":"R4","resource":{"id":"","type":"r::r::n::r::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/solution/reference.json b/tasks/cedar_authorization-25a4b9f7565d170d2c85/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/solution/solve.sh b/tasks/cedar_authorization-25a4b9f7565d170d2c85/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/task.toml b/tasks/cedar_authorization-25a4b9f7565d170d2c85/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f1d9460f7d0d8c61ea3641a53d8824473ae0701e --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-25a4b9f7565d170d2c85" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "4c5d9e2af1e09d9ef0987c1df36968857ca604ecb7b6d741aca31d453c7b7f2e" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/expected.json b/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/grading.py b/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/test.sh b/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/verify.py b/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-25a4b9f7565d170d2c85/validation/openenv.json b/tasks/cedar_authorization-25a4b9f7565d170d2c85/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-25a4b9f7565d170d2c85/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/environment/Dockerfile b/tasks/cedar_authorization-25ac3ef22c533e1dd384/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/instruction.md b/tasks/cedar_authorization-25ac3ef22c533e1dd384/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0f936efff032f19dd06503547b0929864aa1e7e9 --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == r::r::r::r::r::"***((((((((", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::wZ1g::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::wZ1g::"" +) when { + true && ((if "||||||||||||~|" like "|*|*|*|*|*|*" then if false then "||||||||||||~|" else "||||||||||||~|" else if false then "||||||||||||~|" else "||||||||||||~|") like "|*|*|*|*|*|*") && ((if "||||||||||||~|" like "*||**|*|*|*|" then "||||||||||||~|" else "||||||||||||~|") like "*|*|*|*|*|*|") +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::g31000000"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::wZ1g"}},{"attrs":{},"parents":[],"uid":{"id":"***((((((((","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"|","type":"r::r::r::r::r"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"L5c":false,"LYY":false,"PcY":{"__entity":{"id":"***((((((((","type":"r::r::r::r::r"}}},"principal":{"id":"***((((((((","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"***((((((((","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"L5c":true,"LYY":true,"PcY":{"__entity":{"id":"***((((((((","type":"r::r::r::r::r"}}},"principal":{"id":"","type":"r::r::r::r::wZ1g"},"request":"R2","resource":{"id":"***((((((((","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::wZ1g"},"request":"R3","resource":{"id":"","type":"r::r::r::r::wZ1g"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"L5c":true,"LYY":true,"PcY":{"__entity":{"id":"***((((((((","type":"r::r::r::r::r"}}},"principal":{"id":"***((((((((","type":"r::r::r::r::r"},"request":"R4","resource":{"id":"***((((((((","type":"r::r::r::r::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/solution/reference.json b/tasks/cedar_authorization-25ac3ef22c533e1dd384/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..086b845858573703b01390817ea414e77e201181 --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/solution/solve.sh b/tasks/cedar_authorization-25ac3ef22c533e1dd384/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/task.toml b/tasks/cedar_authorization-25ac3ef22c533e1dd384/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..57a4e3b84fdd24b98051f80a8ae4656d8bf2b603 --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-25ac3ef22c533e1dd384" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "f7a935131c8032a9a00b68ad88816c19fd194862fea9e01ecae3d784365b4d65" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/expected.json b/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..086b845858573703b01390817ea414e77e201181 --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/grading.py b/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/test.sh b/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/verify.py b/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-25ac3ef22c533e1dd384/validation/openenv.json b/tasks/cedar_authorization-25ac3ef22c533e1dd384/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-25ac3ef22c533e1dd384/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/environment/Dockerfile b/tasks/cedar_authorization-25acf07b6a632c0438fc/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/instruction.md b/tasks/cedar_authorization-25acf07b6a632c0438fc/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8924bd1418f2dd7bd250f55381e7a9ebe4df5121 --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal is r::r33::r::r::r333333311 in r::r33::r::r::r333333311::"|||||||", + action in [r::r33::r::r::Action::"action"], + resource == r::r33::r::r::r333333311::"|||||||" +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::m::"", + action, + resource +) when { + true && (r::r::r::r::r::"" in r::r::r::r::r::"") +}; + +Entities +[{"attrs":{},"parents":[{"id":"|","type":"r::r33::r::r::r333333311"},{"id":"|||||~|||||x","type":"r::r33::r::r::slW33zzzzzzzzz"}],"uid":{"id":"","type":"r::r33::r::r::slW33zzzzzzzzz"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::m"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r33::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[{"id":"|||||~|||||x","type":"r::r33::r::r::slW33zzzzzzzzz"}],"uid":{"id":"|","type":"r::r33::r::r::r333333311"}},{"attrs":{},"parents":[{"id":"|","type":"r::r33::r::r::r333333311"},{"id":"|||||~|||||x","type":"r::r33::r::r::slW33zzzzzzzzz"}],"uid":{"id":"|||||||","type":"r::r33::r::r::r333333311"}},{"attrs":{},"parents":[],"uid":{"id":"|||||~|||||x","type":"r::r33::r::r::slW33zzzzzzzzz"}}] + +Requests +{"action":{"id":"action","type":"r::r33::r::r::Action"},"context":{},"principal":{"id":"|||||||","type":"r::r33::r::r::r333333311"},"request":"R1","resource":{"id":"|||||||","type":"r::r33::r::r::r333333311"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::m"},"request":"R2","resource":{"id":"|||||||","type":"r::r33::r::r::r333333311"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"|||||||","type":"r::r33::r::r::r333333311"},"request":"R3","resource":{"id":"|||||||","type":"r::r33::r::r::r333333311"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::m"},"request":"R4","resource":{"id":"","type":"r::r::r::r::m"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/solution/reference.json b/tasks/cedar_authorization-25acf07b6a632c0438fc/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..788dc0ce9427ef5c9a9bcdeaa163a57097821748 --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/solution/solve.sh b/tasks/cedar_authorization-25acf07b6a632c0438fc/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/task.toml b/tasks/cedar_authorization-25acf07b6a632c0438fc/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c59f355e7b2cc5c8a920f64ba8ce8454b8c3b48f --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-25acf07b6a632c0438fc" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "50ed7aacb1ef10172f6191671f47511cbffffd9046c6255d0c9004cd1009be01" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/expected.json b/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..788dc0ce9427ef5c9a9bcdeaa163a57097821748 --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/grading.py b/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/test.sh b/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/verify.py b/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-25acf07b6a632c0438fc/validation/openenv.json b/tasks/cedar_authorization-25acf07b6a632c0438fc/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-25acf07b6a632c0438fc/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/environment/Dockerfile b/tasks/cedar_authorization-26667d947850e4de7fd5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/instruction.md b/tasks/cedar_authorization-26667d947850e4de7fd5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a7e0af51f0f8687927e28cec8d0ae12a673305d --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action in [Action::"",Action::""], + resource is a +) when { + true && (!(!(!false))) && (!(!(!false))) +}; + +policy1 +forbid( + principal in g::a::"", + action in [g::Action::"action"], + resource in g::a::"" +) when { + true && (((false == false) == (false == false)) || ((false == false) == (false == false))) && (((false == false) == (false == false)) == ((false == false) == (false == false))) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{"g1c":{"__extn":{"arg":"2097865012305276206ms","fn":"duration"}},"tg9":false},"parents":[],"uid":{"id":"","type":"g::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"g::Action"}}] + +Requests +{"action":{"id":"action","type":"g::Action"},"context":{},"principal":{"id":"","type":"g::a"},"request":"R1","resource":{"id":"","type":"g::a"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"g::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"g::a"},"request":"R4","resource":{"id":"","type":"g::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/solution/reference.json b/tasks/cedar_authorization-26667d947850e4de7fd5/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/solution/solve.sh b/tasks/cedar_authorization-26667d947850e4de7fd5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/task.toml b/tasks/cedar_authorization-26667d947850e4de7fd5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e4b13e95f6a1427a7b461d62494294de5d094ca7 --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-26667d947850e4de7fd5" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "6683dbffc4fdb596d3338bd3c65b4f906732d488b2f07e47595063531598b94a" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/tests/expected.json b/tasks/cedar_authorization-26667d947850e4de7fd5/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/tests/grading.py b/tasks/cedar_authorization-26667d947850e4de7fd5/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/tests/test.sh b/tasks/cedar_authorization-26667d947850e4de7fd5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/tests/verify.py b/tasks/cedar_authorization-26667d947850e4de7fd5/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-26667d947850e4de7fd5/validation/openenv.json b/tasks/cedar_authorization-26667d947850e4de7fd5/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-26667d947850e4de7fd5/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/environment/Dockerfile b/tasks/cedar_authorization-2677f383d43e9632bfcb/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/instruction.md b/tasks/cedar_authorization-2677f383d43e9632bfcb/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3d5e85ee860fa4a71d9c84be1075c7e003a2f74f --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action, + resource +) when { + true && (((false == false) == (false == false)) == ((false == false) == (false == false))) && ((action == action) == true) +}; + +policy1 +forbid( + principal == r::r::r::r::a::"=", + action == r::r::r::r::Action::"action", + resource == r::r::r::r::a::"=" +) when { + true && ({"": action}[""] in {"": action}[""]) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"=","type":"r::r::r::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::a"},"request":"R1","resource":{"id":"","type":"r::r::r::r::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"=","type":"r::r::r::r::a"},"request":"R2","resource":{"id":"=","type":"r::r::r::r::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/solution/reference.json b/tasks/cedar_authorization-2677f383d43e9632bfcb/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..942677315495650e0ac5e80661490d67896ba08f --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/solution/solve.sh b/tasks/cedar_authorization-2677f383d43e9632bfcb/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/task.toml b/tasks/cedar_authorization-2677f383d43e9632bfcb/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..43df01f04529c8ef507cfffc4eaad1214f49043d --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2677f383d43e9632bfcb" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d4bdbdf1eb2b73b8cf6befb3f99b5136980b9c20a913abee0f77e358825b8b04" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/expected.json b/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..942677315495650e0ac5e80661490d67896ba08f --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/grading.py b/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/test.sh b/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/verify.py b/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2677f383d43e9632bfcb/validation/openenv.json b/tasks/cedar_authorization-2677f383d43e9632bfcb/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2677f383d43e9632bfcb/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/environment/Dockerfile b/tasks/cedar_authorization-2694ddba32d4714ac0c7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/instruction.md b/tasks/cedar_authorization-2694ddba32d4714ac0c7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..93a6bb3887ce71bbe964c25e780cc24dd756b890 --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action in [B::G::GTTTTTTTTTTTTTT::r::Action::"action",B::G::GTTTTTTTTTTTTTT::r::Action::"action",B::G::GTTTTTTTTTTTTTT::r::Action::"action"], + resource is B::G::GTTTTTTTTTTTTTT::r::a in B::G::GTTTTTTTTTTTTTT::r::a::"" +) when { + true && (B::G::GTTTTTTTTTTTTTT::r::a::"" == B::G::GTTTTTTTTTTTTTT::r::a::"") && (B::G::GTTTTTTTTTTTTTT::r::a::"" == B::G::GTTTTTTTTTTTTTT::r::a::"") && true +}; + +policy1 +forbid( + principal in LYe::"(", + action in [Action::"action"], + resource in LYe::"(" +) when { + true && (if if if false then false else false then principal in [] else principal in [LYe::"", LYe::"", LYe::""] then true else true) && true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LPY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYX"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYe"}},{"attrs":{},"parents":[{"id":"","type":"LYY"},{"id":"","type":"LYe"}],"uid":{"id":"(","type":"LYe"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"mmmm3333w*","type":"qgg"}}] + +Requests +{"action":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"},"context":{},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R1","resource":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}} +{"action":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"},"context":{},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R2","resource":{"id":"(","type":"LYe"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R3","resource":{"id":"(","type":"LYe"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"(","type":"LYe"},"request":"R4","resource":{"id":"(","type":"LYe"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/solution/reference.json b/tasks/cedar_authorization-2694ddba32d4714ac0c7/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/solution/solve.sh b/tasks/cedar_authorization-2694ddba32d4714ac0c7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/task.toml b/tasks/cedar_authorization-2694ddba32d4714ac0c7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..237b85ae9f5e6a4f5a35f527b4d05077bafe58bc --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2694ddba32d4714ac0c7" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "48aafeed61360e90bec838967d6e04574d8345d5bed65633678bc4f35c8f2508" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/expected.json b/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/grading.py b/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/test.sh b/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/verify.py b/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2694ddba32d4714ac0c7/validation/openenv.json b/tasks/cedar_authorization-2694ddba32d4714ac0c7/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2694ddba32d4714ac0c7/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-279031db86cab4059600/environment/Dockerfile b/tasks/cedar_authorization-279031db86cab4059600/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-279031db86cab4059600/instruction.md b/tasks/cedar_authorization-279031db86cab4059600/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cc5e37cf371c26ac91e24704dfbdcbdac62297c7 --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action in [B::G::GTTTTTTTTTTTTTT::r::Action::"action",B::G::GTTTTTTTTTTTTTT::r::Action::"action",B::G::GTTTTTTTTTTTTTT::r::Action::"action"], + resource is B::G::GTTTTTTTTTTTTTT::r::a in B::G::GTTTTTTTTTTTTTT::r::a::"" +) when { + true && (B::G::GTTTTTTTTTTTTTT::r::a::"" == B::G::GTTTTTTTTTTTTTT::r::a::"") && (B::G::GTTTTTTTTTTTTTT::r::a::"" == B::G::GTTTTTTTTTTTTTT::r::a::"") && true +}; + +policy1 +forbid( + principal is l, + action == Action::"action", + resource is l +) when { + true && ([ip("ffff:a20:6e69:61df:3bdf:dfdf:dfdf:dfdf"), ip("1c1c:1c1c:1c1c:1c1c:1c1c:7201:1c1c:1c1c"), ip("ff00:0:1ff:ffff:ffff:ffff:efff:ffff/126")].containsAny([ip("a0a0:0:20:6e61:6b62:6544:10:8df"), ip("ffff:ffff:ffff:fffb:ffff:ffff:ffff:ffff/126"), ip("ffff:400:0:20:6e61:6962:6544:5aff")]) || (principal in principal) || (resource in resource)) && (resource in resource) && (resource in resource) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"l"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"}}] + +Requests +{"action":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"},"context":{},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R1","resource":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}} +{"action":{"id":"action","type":"Action"},"context":{"B":"","r":{"__extn":{"arg":"1120-05-06","fn":"datetime"}}},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R2","resource":{"id":"","type":"l"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"l"},"request":"R3","resource":{"id":"","type":"l"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R4","resource":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-279031db86cab4059600/solution/reference.json b/tasks/cedar_authorization-279031db86cab4059600/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-279031db86cab4059600/solution/solve.sh b/tasks/cedar_authorization-279031db86cab4059600/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-279031db86cab4059600/task.toml b/tasks/cedar_authorization-279031db86cab4059600/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cd2bac6e0f0eae90fe0a8ef9e94a08f5d12546da --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-279031db86cab4059600" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "a5ba43d15f659bc2d722f176df5a4a2ba3f4b29db16c9890a2c6deb7beb5fe0e" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-279031db86cab4059600/tests/expected.json b/tasks/cedar_authorization-279031db86cab4059600/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-279031db86cab4059600/tests/grading.py b/tasks/cedar_authorization-279031db86cab4059600/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-279031db86cab4059600/tests/test.sh b/tasks/cedar_authorization-279031db86cab4059600/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-279031db86cab4059600/tests/verify.py b/tasks/cedar_authorization-279031db86cab4059600/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-279031db86cab4059600/validation/openenv.json b/tasks/cedar_authorization-279031db86cab4059600/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-279031db86cab4059600/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/environment/Dockerfile b/tasks/cedar_authorization-2811ae0f522c21dd81d4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/instruction.md b/tasks/cedar_authorization-2811ae0f522c21dd81d4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d80872634d1208e1fa26bc04cec3d49f8ed4ee4e --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == a::"r", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal, + action in [r::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::r"},{"id":"VVVVVVVVVV","type":"r::r::r::r::r"}],"uid":{"id":"","type":"r::r::r::r::hN"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"CCCyCCCCCCCCCCC","type":"r::r::r::r::hN"}},{"attrs":{},"parents":[],"uid":{"id":"VVVVVVVVVV","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"r","type":"a"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R1","resource":{"id":"r","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"r","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R3","resource":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R4","resource":{"id":"r","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/solution/reference.json b/tasks/cedar_authorization-2811ae0f522c21dd81d4/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..c1cba6f003dba7ecbcf408f823fd72ec90251bdb --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/solution/solve.sh b/tasks/cedar_authorization-2811ae0f522c21dd81d4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/task.toml b/tasks/cedar_authorization-2811ae0f522c21dd81d4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..63df0efbcbab9682f69a96babef27c706738f303 --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2811ae0f522c21dd81d4" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "7e9b5a7e1f1f6afe92012e00fd820b6144a5c214d223c5ec23a1c4fd12e82b8d" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/expected.json b/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..c1cba6f003dba7ecbcf408f823fd72ec90251bdb --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/grading.py b/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/test.sh b/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/verify.py b/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2811ae0f522c21dd81d4/validation/openenv.json b/tasks/cedar_authorization-2811ae0f522c21dd81d4/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2811ae0f522c21dd81d4/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/environment/Dockerfile b/tasks/cedar_authorization-28435dd0959e03af30d5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/instruction.md b/tasks/cedar_authorization-28435dd0959e03af30d5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9df37d2f2d93271db5cb7f34aa9ea37375f4648a --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action, + resource +) when { + true && (gf00000000000::"" in gf00000000000::"") +}; + +policy1 +forbid( + principal, + action in [j00000YY::i::i::i::i::jm555555::Action::"action"], + resource in j00000YY::i::i::i::i::jm555555::a::"" +) when { + true && (false || ((action in action) || (action in action))) && ({"": action}[""] in {"": action}[""]) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"gf00000000000"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"j00000YY::i::i::i::i::jm555555::a"}},{"attrs":{},"parents":[],"uid":{"id":"\"\"\"\"\"\",\"\"","type":"j00000YY::i::i::i::i::jm555555::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"}}] + +Requests +{"action":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"},"context":{},"principal":{"id":"\"\"\"\"\"\",\"\"","type":"j00000YY::i::i::i::i::jm555555::a"},"request":"R1","resource":{"id":"","type":"j00000YY::i::i::i::i::jm555555::a"}} +{"action":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"},"context":{},"principal":{"id":"","type":"gf00000000000"},"request":"R2","resource":{"id":"","type":"gf00000000000"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"\"\"\"\"\"\",\"\"","type":"j00000YY::i::i::i::i::jm555555::a"},"request":"R3","resource":{"id":"","type":"gf00000000000"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"gf00000000000"},"request":"R4","resource":{"id":"","type":"gf00000000000"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/solution/reference.json b/tasks/cedar_authorization-28435dd0959e03af30d5/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/solution/solve.sh b/tasks/cedar_authorization-28435dd0959e03af30d5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/task.toml b/tasks/cedar_authorization-28435dd0959e03af30d5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..88267d7f96d648ecfb5cd2e33b953dfac03928b8 --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-28435dd0959e03af30d5" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "018322227f29b27dfb32328ac65581c74e211daa81a0680d0e75b485a8b74957" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/tests/expected.json b/tasks/cedar_authorization-28435dd0959e03af30d5/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/tests/grading.py b/tasks/cedar_authorization-28435dd0959e03af30d5/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/tests/test.sh b/tasks/cedar_authorization-28435dd0959e03af30d5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/tests/verify.py b/tasks/cedar_authorization-28435dd0959e03af30d5/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-28435dd0959e03af30d5/validation/openenv.json b/tasks/cedar_authorization-28435dd0959e03af30d5/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-28435dd0959e03af30d5/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/environment/Dockerfile b/tasks/cedar_authorization-28438f950d27f35147f7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/instruction.md b/tasks/cedar_authorization-28438f950d27f35147f7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..efc484dfa28a9c4e2d8b98ac05c7029182af03d4 --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r::"NNN", + action in [r::r::Action::"action",r::r::Action::"action"], + resource is r::r::r +) when { + true && (r::r::r::"NNN" in r::r::r::"NNN") +}; + +policy1 +forbid( + principal is r in r::"", + action in [Action::"action",Action::"action",Action::"action"], + resource is r in r::"" +) when { + true && ((if r::"" in r::"" then r::"".r else r::"".r) in r::"".r.r) && (r::"".r.r in r::"".r.r) && (r::"".r.r in r::"".r.r) +}; + +Entities +[{"attrs":{"r":{"__entity":{"id":"","type":"r"}}},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"tags":{"":{}},"uid":{"id":"NNN","type":"r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::Action"},"context":{},"principal":{"id":"NNN","type":"r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"NNN","type":"r::r::r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r"},"request":"R4","resource":{"id":"","type":"r::r::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/solution/reference.json b/tasks/cedar_authorization-28438f950d27f35147f7/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/solution/solve.sh b/tasks/cedar_authorization-28438f950d27f35147f7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/task.toml b/tasks/cedar_authorization-28438f950d27f35147f7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..872ee1711be3c48a8d5af9b2d31e041dbc292922 --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-28438f950d27f35147f7" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "dc43f6247cabafb7f0151287fcfc94353e618aba1419a464bda9b04bae423cb5" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/tests/expected.json b/tasks/cedar_authorization-28438f950d27f35147f7/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/tests/grading.py b/tasks/cedar_authorization-28438f950d27f35147f7/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/tests/test.sh b/tasks/cedar_authorization-28438f950d27f35147f7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/tests/verify.py b/tasks/cedar_authorization-28438f950d27f35147f7/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-28438f950d27f35147f7/validation/openenv.json b/tasks/cedar_authorization-28438f950d27f35147f7/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-28438f950d27f35147f7/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/environment/Dockerfile b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/instruction.md b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a35f9fea2487207f6eda5b5a99254d195ece9fac --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action, + resource +) when { + true && (resource in resource) && (resource in resource) +}; + +policy1 +forbid( + principal == a::"", + action == Action::"action", + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r::r"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/solution/reference.json b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/solution/solve.sh b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/task.toml b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5aab2ef24a903e3d0e1cc30f4bbda36815636b62 --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-284fc75eaa28d4b43f2e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "c8d83a902855024f501a0dfb667ecf862ad07eb4d4d9e94f06c1564d55cd8f3a" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/expected.json b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/grading.py b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/test.sh b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/verify.py b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-284fc75eaa28d4b43f2e/validation/openenv.json b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-284fc75eaa28d4b43f2e/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/environment/Dockerfile b/tasks/cedar_authorization-28892023b0d487c01b0a/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/instruction.md b/tasks/cedar_authorization-28892023b0d487c01b0a/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ab939a99608021d6588c50ec21da6e5eeadfc098 --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A5cjr9000rrrrEErr::"`", + action == Action::"action", + resource in A5cjr9000rrrrEErr::"`" +) when { + true && ((-2712756478873001310) < ((-983374224517604790) + (-940422246894996750) + duration("13882183529ms").toHours())) && true +}; + +policy1 +forbid( + principal in B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r::"", + action == B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action::"action", + resource in B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r::"" +) when { + true && ((-6727636073941130590) < (-6727627277848107360)) && ((-6727636073947290974) < 48115491182498) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cjr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::D"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"}},{"attrs":{},"parents":[],"uid":{"id":"DDD","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cjr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action"}}] + +Requests +{"action":{"id":"action","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action"},"context":{},"principal":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"},"request":"R1","resource":{"id":"`","type":"A5cjr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"},"request":"R2","resource":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"}} +{"action":{"id":"action","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action"},"context":{},"principal":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"},"request":"R3","resource":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cjr9000rrrrEErr"},"request":"R4","resource":{"id":"`","type":"A5cjr9000rrrrEErr"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/solution/reference.json b/tasks/cedar_authorization-28892023b0d487c01b0a/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/solution/solve.sh b/tasks/cedar_authorization-28892023b0d487c01b0a/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/task.toml b/tasks/cedar_authorization-28892023b0d487c01b0a/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..09c9ec799b46afb572986e5e0a167273b2c1e689 --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-28892023b0d487c01b0a" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "f8483367f78f010c1a9ebf0274f34633db36482d0874d355501c5892656e229b" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/tests/expected.json b/tasks/cedar_authorization-28892023b0d487c01b0a/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/tests/grading.py b/tasks/cedar_authorization-28892023b0d487c01b0a/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/tests/test.sh b/tasks/cedar_authorization-28892023b0d487c01b0a/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/tests/verify.py b/tasks/cedar_authorization-28892023b0d487c01b0a/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-28892023b0d487c01b0a/validation/openenv.json b/tasks/cedar_authorization-28892023b0d487c01b0a/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-28892023b0d487c01b0a/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/environment/Dockerfile b/tasks/cedar_authorization-28981eaf2b4499f5dc15/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/instruction.md b/tasks/cedar_authorization-28981eaf2b4499f5dc15/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0486e09947bb942ddd7c295a539288cf8ea481df --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == LYY::"", + action == Action::"", + resource in LYY::"" +) when { + true +}; + +policy1 +forbid( + principal == r::r32i::A::r::a::"", + action, + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LY7"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r32i::A::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"*********(((","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r32i::A::r::Action"}}] + +Requests +{"action":{"id":"*********(((","type":"Action"},"context":{},"principal":{"id":"","type":"LYY"},"request":"R1","resource":{"id":"","type":"LYY"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"r::r32i::A::r::a"},"request":"R2","resource":{"id":"","type":"r::r32i::A::r::a"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"LYY"},"request":"R3","resource":{"id":"","type":"LYY"}} +{"action":{"id":"action","type":"r::r32i::A::r::Action"},"context":{},"principal":{"id":"","type":"LYY"},"request":"R4","resource":{"id":"","type":"LYY"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/solution/reference.json b/tasks/cedar_authorization-28981eaf2b4499f5dc15/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/solution/solve.sh b/tasks/cedar_authorization-28981eaf2b4499f5dc15/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/task.toml b/tasks/cedar_authorization-28981eaf2b4499f5dc15/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d356e1e0064fe37864c7ba414eec786e5d3ce134 --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-28981eaf2b4499f5dc15" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "6d2080b8504b31456eb612408ab3cbe62f68f01d12a90f35bae6e3f69a52c592" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/expected.json b/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/grading.py b/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/test.sh b/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/verify.py b/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-28981eaf2b4499f5dc15/validation/openenv.json b/tasks/cedar_authorization-28981eaf2b4499f5dc15/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-28981eaf2b4499f5dc15/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/environment/Dockerfile b/tasks/cedar_authorization-2899b107cc8148f868a9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/instruction.md b/tasks/cedar_authorization-2899b107cc8148f868a9/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..7e954e4408469587584cf16ece081ebab01dcd99 --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r::r::r::"", + action in [r::r::r::r::Action::"action"], + resource in r::r::r::r::r::"" +) when { + true +}; + +policy1 +forbid( + principal == A::a::"", + action == A::Action::"action", + resource == A::a::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::A"}},{"attrs":{},"parents":[],"tags":{"":""},"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"A::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"A::Action"},"context":{"vi7Iwwww333333333":""},"principal":{"id":"","type":"A::a"},"request":"R2","resource":{"id":"","type":"A::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"vi7Iwwww333333333":""},"principal":{"id":"","type":"A::a"},"request":"R4","resource":{"id":"","type":"A::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/solution/reference.json b/tasks/cedar_authorization-2899b107cc8148f868a9/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/solution/solve.sh b/tasks/cedar_authorization-2899b107cc8148f868a9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/task.toml b/tasks/cedar_authorization-2899b107cc8148f868a9/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b93405bb3621aa9d6844a47cbf975df422b4db71 --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2899b107cc8148f868a9" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "7ef4d8f309ca092bdb0a0178adfe98a7eee57acb652eb1c6337adc4d86765a79" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/tests/expected.json b/tasks/cedar_authorization-2899b107cc8148f868a9/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/tests/grading.py b/tasks/cedar_authorization-2899b107cc8148f868a9/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/tests/test.sh b/tasks/cedar_authorization-2899b107cc8148f868a9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/tests/verify.py b/tasks/cedar_authorization-2899b107cc8148f868a9/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2899b107cc8148f868a9/validation/openenv.json b/tasks/cedar_authorization-2899b107cc8148f868a9/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2899b107cc8148f868a9/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/environment/Dockerfile b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/instruction.md b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4c1df3cb42a5af47c31085890905de9bc9967b52 --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A5cZr9000rrrrEErr::"`", + action == Action::"action", + resource in A5cZr9000rrrrEErr::"`" +) when { + true && ((-2712756478873001310) < ((-983374224517604774) + (-940422246894996750) + duration("13882183529ms").toMinutes())) && (A5cZr9000rrrrEErr::"" in A5cZr9000rrrrEErr::"") +}; + +policy1 +forbid( + principal in r::r::r::r::r::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::r::"" +) when { + true && ((if "|||||||~|" like "|*|*|*|*|*|*" then if false then "|||||||~|" else "|||||||~|" else if false then "|||||||~|" else "|||||||~|") like "|*|*|*|*|*|*") && ((if "|||||||~|" like "|*|||||" then r::r::r::r::r::"" else r::r::r::r::r::"") in r::r::r::r::r::"") +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cZr9000rrrrEErr"}},{"attrs":{"A0":"|||||||~|"},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::wZgY"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"A5cZr9000rrrrEErr"},"request":"R1","resource":{"id":"","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"`","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R4","resource":{"id":"`","type":"A5cZr9000rrrrEErr"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/solution/reference.json b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/solution/solve.sh b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/task.toml b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..edb1c0a1ca4e6ac7c1fbbf5f52439933fed14137 --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-295a03d17fd5ed81f8fd" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "9392c3a62a78cb24b587ec2314fa142423ebebc941c0c3f4666e0da3d55eb4c2" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/expected.json b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/grading.py b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/test.sh b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/verify.py b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-295a03d17fd5ed81f8fd/validation/openenv.json b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-295a03d17fd5ed81f8fd/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-29c57728e673bd672663/environment/Dockerfile b/tasks/cedar_authorization-29c57728e673bd672663/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-29c57728e673bd672663/instruction.md b/tasks/cedar_authorization-29c57728e673bd672663/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6dce365b417caa3bf439bbf4458743e4af45599b --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action, + resource == d0000k0::A::a::"" +) when { + true +}; + +policy1 +forbid( + principal is r in r::"", + action in [Action::"action",Action::"action",Action::"action"], + resource is r in r::"" +) when { + true && ((if r::"" in r::"" then r::"".r else r::"".r) in r::"".r.r) && (r::"".r.r in r::"".r.r) && (r::"".r.r in r::"".r.r) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"d0000k0::A::a"}},{"attrs":{"r":{"__entity":{"id":"","type":"r"}}},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"d0000k0::A::Action"}}] + +Requests +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"d0000k0::A::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"","type":"d0000k0::A::a"},"request":"R4","resource":{"id":"","type":"r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-29c57728e673bd672663/solution/reference.json b/tasks/cedar_authorization-29c57728e673bd672663/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-29c57728e673bd672663/solution/solve.sh b/tasks/cedar_authorization-29c57728e673bd672663/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-29c57728e673bd672663/task.toml b/tasks/cedar_authorization-29c57728e673bd672663/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..283c3d21da760ae350ebbd073898b7310af9fe83 --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-29c57728e673bd672663" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d80618b02aeb9ac87dcebe3341a7860b63c8bfc6539496f032b20de8f6826e68" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-29c57728e673bd672663/tests/expected.json b/tasks/cedar_authorization-29c57728e673bd672663/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-29c57728e673bd672663/tests/grading.py b/tasks/cedar_authorization-29c57728e673bd672663/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-29c57728e673bd672663/tests/test.sh b/tasks/cedar_authorization-29c57728e673bd672663/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-29c57728e673bd672663/tests/verify.py b/tasks/cedar_authorization-29c57728e673bd672663/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-29c57728e673bd672663/validation/openenv.json b/tasks/cedar_authorization-29c57728e673bd672663/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-29c57728e673bd672663/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/environment/Dockerfile b/tasks/cedar_authorization-29e57d5872fc5061eb05/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/instruction.md b/tasks/cedar_authorization-29e57d5872fc5061eb05/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4df52c3b24ed52e81d7c06512d0f7bb81825dc3a --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == r::r::r::r::r::"***((((((((", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal in r::r::n::r::a::"", + action in [r::r::n::r::Action::"action",r::r::n::r::Action::"action"], + resource in r::r::n::r::a::"" +) when { + true && (if if [[true]].contains([false, true]) then {"": ""} == {"": ""} else {"": ""} == {"": ""} then {"": {"": ""}} == {"": {"": ""}} else {"": {"": ""}} == {"": {"": ""}}) && ({"": {"": {}}} == {"": {"": {}}}) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::n::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"***((((((((","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::n::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::n::r::Action"},"context":{},"principal":{"id":"***((((((((","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::n::r::a"}} +{"action":{"id":"action","type":"r::r::n::r::Action"},"context":{},"principal":{"id":"","type":"r::r::n::r::a"},"request":"R2","resource":{"id":"","type":"r::r::n::r::a"}} +{"action":{"id":"action","type":"r::r::n::r::Action"},"context":{},"principal":{"id":"","type":"r::r::n::r::a"},"request":"R3","resource":{"id":"***((((((((","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"L5c":true,"LYY":true,"PcY":{"__entity":{"id":"***((((((((","type":"r::r::r::r::r"}}},"principal":{"id":"***((((((((","type":"r::r::r::r::r"},"request":"R4","resource":{"id":"***((((((((","type":"r::r::r::r::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/solution/reference.json b/tasks/cedar_authorization-29e57d5872fc5061eb05/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..ae2e3b2cf163e1c5bbe7ab04367395a9826b6a1b --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/solution/solve.sh b/tasks/cedar_authorization-29e57d5872fc5061eb05/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/task.toml b/tasks/cedar_authorization-29e57d5872fc5061eb05/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..815f94136ab504eceec6b0fa862c2c9610725eb6 --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-29e57d5872fc5061eb05" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "325dafc7f5845d99a496848e1bfe9a0f17f801a250e2d6c82a303475f37e6ee1" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/expected.json b/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..ae2e3b2cf163e1c5bbe7ab04367395a9826b6a1b --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/grading.py b/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/test.sh b/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/verify.py b/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-29e57d5872fc5061eb05/validation/openenv.json b/tasks/cedar_authorization-29e57d5872fc5061eb05/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-29e57d5872fc5061eb05/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/environment/Dockerfile b/tasks/cedar_authorization-2a11c29448aa173d8403/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/instruction.md b/tasks/cedar_authorization-2a11c29448aa173d8403/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fc592607b7dc3cd137b59098894bc018c9466bfc --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r3::r::WMMMMM::"", + action in [r::r::r3::r::Action::"action",r::r::r3::r::Action::"action"], + resource in r::r::r3::r::WMMMMM::"" +) when { + true && (if if "1" like "*3*1*10*" then if true then true else true else {"": action} has Euqqqqq.dqqQ.d then {"": action}[""] in {"": r::r::r3::r::jwwwwwwwwwwwwwwww::""}[""] else {"": action}[""] in {"": action}[""]) && ({"": action}[""] in {"": action}[""]) +}; + +policy1 +forbid( + principal, + action in [r::r::j::Action::"action"], + resource == r::r::j::Q::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::j::A0K03333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::j::A3"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::j::Q"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::j::r"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r3::r::j3333j3335"}],"uid":{"id":"","type":"r::r::r3::r::WMMMMM"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::_YlW3333333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::j3333j3335"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::jwwwwwwwww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::jwwwwwwwwwwwwwwww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::j::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r3::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3::r::WMMMMM"},"request":"R1","resource":{"id":"","type":"r::r::r3::r::WMMMMM"}} +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"r::r::j::A0K03333333"},"request":"R2","resource":{"id":"","type":"r::r::r3::r::WMMMMM"}} +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3::r::_YlW3333333333"},"request":"R3","resource":{"id":"","type":"r::r::r3::r::_YlW3333333333"}} +{"action":{"id":"action","type":"r::r::j::Action"},"context":{},"principal":{"id":"","type":"r::r::r3::r::WMMMMM"},"request":"R4","resource":{"id":"","type":"r::r::j::Q"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/solution/reference.json b/tasks/cedar_authorization-2a11c29448aa173d8403/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/solution/solve.sh b/tasks/cedar_authorization-2a11c29448aa173d8403/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/task.toml b/tasks/cedar_authorization-2a11c29448aa173d8403/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4c92a4b71c55a1235f3f93bc46d05b7e1865c2be --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2a11c29448aa173d8403" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "c89c195fa0f9d49ab40a2fa2948a7b776e0d7b920286647ba68f38eee25825d6" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/tests/expected.json b/tasks/cedar_authorization-2a11c29448aa173d8403/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/tests/grading.py b/tasks/cedar_authorization-2a11c29448aa173d8403/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/tests/test.sh b/tasks/cedar_authorization-2a11c29448aa173d8403/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/tests/verify.py b/tasks/cedar_authorization-2a11c29448aa173d8403/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2a11c29448aa173d8403/validation/openenv.json b/tasks/cedar_authorization-2a11c29448aa173d8403/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2a11c29448aa173d8403/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2a26d750840706361cac/environment/Dockerfile b/tasks/cedar_authorization-2a26d750840706361cac/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2a26d750840706361cac/instruction.md b/tasks/cedar_authorization-2a26d750840706361cac/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5f6a5b66bd96d1f1e59a0214beda6e2ab1c433b1 --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r::r::r::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::r::"" +) when { + true && ((if "||" like "|*|*" then if false then "||" else "||" else if false then "||" else "||") like "|*|*") && ((if "||" like "|*|*" then if false then "||" else "||" else if false then "||" else "||") like "|*|*") +}; + +policy1 +forbid( + principal == a::"", + action == Action::"action", + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::wZgY"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2a26d750840706361cac/solution/reference.json b/tasks/cedar_authorization-2a26d750840706361cac/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2a26d750840706361cac/solution/solve.sh b/tasks/cedar_authorization-2a26d750840706361cac/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2a26d750840706361cac/task.toml b/tasks/cedar_authorization-2a26d750840706361cac/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b3d7ffd76a4298e361e05ffe97e6e9d6d2313752 --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2a26d750840706361cac" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "946c26330f941fbf77e3facd61a8825cae148d55bcf1dcb0b68ba4c980565c8c" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2a26d750840706361cac/tests/expected.json b/tasks/cedar_authorization-2a26d750840706361cac/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2a26d750840706361cac/tests/grading.py b/tasks/cedar_authorization-2a26d750840706361cac/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2a26d750840706361cac/tests/test.sh b/tasks/cedar_authorization-2a26d750840706361cac/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2a26d750840706361cac/tests/verify.py b/tasks/cedar_authorization-2a26d750840706361cac/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2a26d750840706361cac/validation/openenv.json b/tasks/cedar_authorization-2a26d750840706361cac/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2a26d750840706361cac/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/environment/Dockerfile b/tasks/cedar_authorization-2a5b2ead40677a7d219e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/instruction.md b/tasks/cedar_authorization-2a5b2ead40677a7d219e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..bd3708b527e84c61fbd2ba30afa6a78f9e9de3c7 --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action, + resource +) when { + true && (((false == false) == (false == false)) == ((false == false) == (false == false))) && (((false == false) == (false == false)) == ((false == false) == (false == false))) +}; + +policy1 +forbid( + principal in r::r::r::r::r::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::r::"" +) when { + true && ((if "||" like "|*|*" then if false then "||" else "||" else if false then "||" else "||") like "|*|*") && ("||" like "|*|*") +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/solution/reference.json b/tasks/cedar_authorization-2a5b2ead40677a7d219e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/solution/solve.sh b/tasks/cedar_authorization-2a5b2ead40677a7d219e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/task.toml b/tasks/cedar_authorization-2a5b2ead40677a7d219e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..201347ac041c74bba9b84b33ba1de607db108bd4 --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2a5b2ead40677a7d219e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "6e3af31974b6e489946c16844222f6fddfa3b137668f69e93a9905e8f40a3f8f" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/expected.json b/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/grading.py b/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/test.sh b/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/verify.py b/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2a5b2ead40677a7d219e/validation/openenv.json b/tasks/cedar_authorization-2a5b2ead40677a7d219e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2a5b2ead40677a7d219e/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/environment/Dockerfile b/tasks/cedar_authorization-2c3f809949587a2efe4c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/instruction.md b/tasks/cedar_authorization-2c3f809949587a2efe4c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..58acfb4114a7859c727c82355495463b0fac9a56 --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == a::"r", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal in a::"", + action in [Action::"action",Action::"action"], + resource == a::"" +) when { + true && ((if (-4123389851770370362) < 198 then principal else principal) in principal) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"r","type":"a"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R1","resource":{"id":"r","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"r","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/solution/reference.json b/tasks/cedar_authorization-2c3f809949587a2efe4c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d3d473e0a7deae2956a2473d224ea927c3732496 --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/solution/solve.sh b/tasks/cedar_authorization-2c3f809949587a2efe4c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/task.toml b/tasks/cedar_authorization-2c3f809949587a2efe4c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..78638f8dd2eeef8d3eec8d5abd03822670ceedfb --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2c3f809949587a2efe4c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "47dfe55e8b25010ce03a60d11144816866472b7f4cc14cb32515692926ca1c14" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/expected.json b/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d3d473e0a7deae2956a2473d224ea927c3732496 --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/grading.py b/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/test.sh b/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/verify.py b/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2c3f809949587a2efe4c/validation/openenv.json b/tasks/cedar_authorization-2c3f809949587a2efe4c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2c3f809949587a2efe4c/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/environment/Dockerfile b/tasks/cedar_authorization-2c4526ee730dc36d9689/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/instruction.md b/tasks/cedar_authorization-2c4526ee730dc36d9689/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..756efd2a6ad1f532d081ab9e89d4017b2df2b182 --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal is a in a::"r", + action in [Action::"action"], + resource == a::"r" +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::m::"", + action, + resource +) when { + true && (r::r::r::r::r::"" in r::r::r::r::r::"") +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::m"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"r","type":"a"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R1","resource":{"id":"r","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::m"},"request":"R2","resource":{"id":"","type":"r::r::r::r::m"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R3","resource":{"id":"","type":"r::r::r::r::m"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::m"},"request":"R4","resource":{"id":"r","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/solution/reference.json b/tasks/cedar_authorization-2c4526ee730dc36d9689/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..788dc0ce9427ef5c9a9bcdeaa163a57097821748 --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/solution/solve.sh b/tasks/cedar_authorization-2c4526ee730dc36d9689/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/task.toml b/tasks/cedar_authorization-2c4526ee730dc36d9689/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a3884182e496d56174c8be2f10015b458b60219d --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2c4526ee730dc36d9689" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "91f8b6b62ef44d92c70b59614a3bb4dc44479290d7d3f9577e6ee7da05432455" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/expected.json b/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..788dc0ce9427ef5c9a9bcdeaa163a57097821748 --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/grading.py b/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/test.sh b/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/verify.py b/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2c4526ee730dc36d9689/validation/openenv.json b/tasks/cedar_authorization-2c4526ee730dc36d9689/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2c4526ee730dc36d9689/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/environment/Dockerfile b/tasks/cedar_authorization-2c753daacc5514a17621/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/instruction.md b/tasks/cedar_authorization-2c753daacc5514a17621/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..891f0291331e1f294f55f15c41d2baadc33216d2 --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action in [Action::"action"], + resource +) when { + true && ((((-144680345676153347) == (-144680345676153347)) == (action is a)) == (action is a)) +}; + +policy1 +forbid( + principal, + action in [Action::"action"], + resource in r::"" +) when { + true && (if if if false then false else false then ip("126.126.126.126").isIpv4() else "" like "" then (if true then "" else "") like "" else (if true then "" else "") like "") && true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"tags":{"":[[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"8>>","type":"r"}}]]],"an >>>":[[[{"__entity":{"id":"","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]]],"~~":[[[{"__entity":{"id":"","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]]]},"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"tags":{"":[[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"8>>","type":"r"}}]]],"~~~":[[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"8>>","type":"r"}}]]]},"uid":{"id":"8>>","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/solution/reference.json b/tasks/cedar_authorization-2c753daacc5514a17621/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..01248b80099480ec0d6ced1df12fa1cd58808166 --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/solution/solve.sh b/tasks/cedar_authorization-2c753daacc5514a17621/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/task.toml b/tasks/cedar_authorization-2c753daacc5514a17621/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8532ec4fdaf9e62535ba41e051086a26a1aaf9bf --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2c753daacc5514a17621" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "c15d89537533d402167bac2d14911bc5a59e1957d5fcaea910a09b0ec6bce8e5" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/tests/expected.json b/tasks/cedar_authorization-2c753daacc5514a17621/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..01248b80099480ec0d6ced1df12fa1cd58808166 --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/tests/grading.py b/tasks/cedar_authorization-2c753daacc5514a17621/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/tests/test.sh b/tasks/cedar_authorization-2c753daacc5514a17621/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/tests/verify.py b/tasks/cedar_authorization-2c753daacc5514a17621/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2c753daacc5514a17621/validation/openenv.json b/tasks/cedar_authorization-2c753daacc5514a17621/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2c753daacc5514a17621/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/environment/Dockerfile b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/instruction.md b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6fed47958bc2d8d425435a5c050b5635ec306435 --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in a::"F", + action in [Action::"action"], + resource == a::"F" +) when { + true && (a::"F" has Evv2999) && (a::"F" has Evv2999) && (if if if false then false else false then a::"F" has Evv2999 else a::"F" has Evv2999 then a::"F" has Evv2999 else false) +}; + +policy1 +forbid( + principal == Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF::"", + action in [Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::Action::""], + resource == Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"}},{"attrs":{"Evv2999":{"__extn":{"arg":"0737-07-13T06:18:18Z","fn":"datetime"}}},"parents":[],"uid":{"id":"F","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"},"request":"R1","resource":{"id":"F","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"F","type":"a"},"request":"R2","resource":{"id":"F","type":"a"}} +{"action":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::Action"},"context":{"I":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"O4444124444444444":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"O444444444YYYYYYY":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"O4iii0iiiiiiiiiii":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"Viiiiiiiiii5e":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"Viiiiiiiiiiii":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"r":[],"r2333333333333333":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"r33333lll":{"__extn":{"arg":"0.0.0.0","fn":"ip"}}},"principal":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"},"request":"R3","resource":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"}} +{"action":{"id":"action","type":"Action"},"context":{"I":{"__extn":{"arg":"236.236.236.236","fn":"ip"}},"Viiiiiiiiii5e":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"Viiiiiiiiiiii":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"r":[],"r2333333333333333":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"r33333lll":{"__extn":{"arg":"0.0.0.0","fn":"ip"}}},"principal":{"id":"F","type":"a"},"request":"R4","resource":{"id":"F","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/solution/reference.json b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..80c6b8bf5de39b2911eafa3ef77992cc11363037 --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/solution/solve.sh b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/task.toml b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..132018cf0fa3300b73b3c0bda5f2d0d8d23b50d7 --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2ccc8f3eae6cf47420aa" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0be99b2d1c23cc516227b77045b6686a124c5a72af11b4cd6563398ca2ac3a36" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/expected.json b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..80c6b8bf5de39b2911eafa3ef77992cc11363037 --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/grading.py b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/test.sh b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/verify.py b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/validation/openenv.json b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2ccc8f3eae6cf47420aa/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/environment/Dockerfile b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/instruction.md b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6212d7f0f1fcbc7f4623aee04b299633af9138e2 --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action in [Action::"action"], + resource +) when { + true +}; + +policy1 +forbid( + principal in j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a::"", + action == j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::Action::"action", + resource in j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a::"" +) when { + true && (datetime("3130-07-29T18:30:30-0030").durationSince(datetime("3130-07-29T18:43:43.147+0750")).toMilliseconds() < 3992736342433) && true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{"j55555cx555":{}},"parents":[],"uid":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::Action"}}] + +Requests +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::Action"},"context":{},"principal":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"},"request":"R1","resource":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"}} +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"},"request":"R4","resource":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/solution/reference.json b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..66b0de41b338c9e27e63416a348a9b6be1bceada --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/solution/solve.sh b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/task.toml b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6b37ef4a43b19d6a44a7333a50c8e2039be4dedf --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2e0768bca4ddbe7f80c3" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "3818da0b3f250c245f89e9eb862a9fc0bf69069f3e8475d7709feb9731381333" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/expected.json b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..66b0de41b338c9e27e63416a348a9b6be1bceada --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/grading.py b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/test.sh b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/verify.py b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/validation/openenv.json b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2e0768bca4ddbe7f80c3/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/environment/Dockerfile b/tasks/cedar_authorization-2e1f2d67307059393e1d/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/instruction.md b/tasks/cedar_authorization-2e1f2d67307059393e1d/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f65808fcb0bed93ac4d3c581180656dea223eef8 --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A5cZr9000rrrrEErr::"`", + action == Action::"action", + resource in A5cZr9000rrrrEErr::"`" +) when { + true && ((-2712756478873001310) < ((-983374224517604774) + (-940422246894996750) + duration("13882183529ms").toMinutes())) && (A5cZr9000rrrrEErr::"" in A5cZr9000rrrrEErr::"") +}; + +policy1 +forbid( + principal is mSSSSSS, + action == Action::"action", + resource == LYY::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[{"id":"","type":"LYY"}],"uid":{"id":"","type":"mSSSSSS"}},{"attrs":{"mSSSSSS":false,"mSSSSSY":false,"qgggggggg":false},"parents":[],"uid":{"id":"","type":"mgggggg"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"A5cZr9000rrrrEErr"},"request":"R1","resource":{"id":"","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R2","resource":{"id":"","type":"LYY"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R3","resource":{"id":"","type":"mSSSSSS"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R4","resource":{"id":"`","type":"A5cZr9000rrrrEErr"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/solution/reference.json b/tasks/cedar_authorization-2e1f2d67307059393e1d/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/solution/solve.sh b/tasks/cedar_authorization-2e1f2d67307059393e1d/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/task.toml b/tasks/cedar_authorization-2e1f2d67307059393e1d/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a80311d414e595f6df8e823f1773df99523bbef4 --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2e1f2d67307059393e1d" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "294f277983c17126523833f5e9c61acf51e21178ea9e23c95971aed912ee4d0d" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/expected.json b/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/grading.py b/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/test.sh b/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/verify.py b/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2e1f2d67307059393e1d/validation/openenv.json b/tasks/cedar_authorization-2e1f2d67307059393e1d/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2e1f2d67307059393e1d/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/environment/Dockerfile b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/instruction.md b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..58cae7084610ebf14f350cf7b71f4be3755e6709 --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action in [Action::"action"], + resource +) when { + true +}; + +policy1 +forbid( + principal is mSSSSSS, + action == Action::"action", + resource == LYY::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[{"id":"","type":"LYY"}],"uid":{"id":"","type":"mSSSSSS"}},{"attrs":{"mSSSSSS":false,"mSSSSSY":false,"qgggggggg":false},"parents":[],"uid":{"id":"","type":"mgggggg"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"LYY"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R2","resource":{"id":"","type":"LYY"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R3","resource":{"id":"","type":"mSSSSSS"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/solution/reference.json b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..942677315495650e0ac5e80661490d67896ba08f --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/solution/solve.sh b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/task.toml b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..130e110c0460f7e9a7e5a365927455e1d44b0604 --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2ea2cbff70c0dbd95d9e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "da2028d3e06f87b4cb979090737863d4e0725c62919c83cd55640b16ca946de0" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/expected.json b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..942677315495650e0ac5e80661490d67896ba08f --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/grading.py b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/test.sh b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/verify.py b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/validation/openenv.json b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2ea2cbff70c0dbd95d9e/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/environment/Dockerfile b/tasks/cedar_authorization-2f3408593f9fb33e9161/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/instruction.md b/tasks/cedar_authorization-2f3408593f9fb33e9161/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f668d67d907b0045d5659298319eb3ef71f5528c --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == _YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a::"", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal, + action in [q::r::r::A333333333333z3::Action::"action"], + resource +) when { + true && (q::r::r::A333333333333z3::q::"~" has wccccccccrgpm0000) && true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"q::r::r::A333333333333z3::Action"}},{"attrs":{"wccccccccrgpm0000":{"__extn":{"arg":"ffff:69ff:ffff:613b:6544::4/126","fn":"ip"}}},"parents":[],"uid":{"id":"~","type":"q::r::r::A333333333333z3::q"}},{"attrs":{},"parents":[],"uid":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"}},{"attrs":{},"parents":[],"uid":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}}] + +Requests +{"action":{"id":"action","type":"q::r::r::A333333333333z3::Action"},"context":{},"principal":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"},"request":"R1","resource":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"}} +{"action":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"},"context":{},"principal":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"},"request":"R2","resource":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"}} +{"action":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"},"context":{},"principal":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"},"request":"R3","resource":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}} +{"action":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"},"context":{},"principal":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"},"request":"R4","resource":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/solution/reference.json b/tasks/cedar_authorization-2f3408593f9fb33e9161/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..02332c6494a5946fcf5d08b6749e23826cd4ac0a --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/solution/solve.sh b/tasks/cedar_authorization-2f3408593f9fb33e9161/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/task.toml b/tasks/cedar_authorization-2f3408593f9fb33e9161/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..99ded2f9eb4f141d7f5d35c122741064ca3430ea --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2f3408593f9fb33e9161" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "382a5b25a5fa5db128c6b3967745af4442827f0722384fb25b98548a250fcff0" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/expected.json b/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..02332c6494a5946fcf5d08b6749e23826cd4ac0a --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/grading.py b/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/test.sh b/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/verify.py b/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2f3408593f9fb33e9161/validation/openenv.json b/tasks/cedar_authorization-2f3408593f9fb33e9161/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2f3408593f9fb33e9161/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/environment/Dockerfile b/tasks/cedar_authorization-2f3e76fa6affa53af931/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/instruction.md b/tasks/cedar_authorization-2f3e76fa6affa53af931/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..965f7af20606331a93f13e9d3eda40d3b33e94ac --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action, + resource +) when { + true && (((false == false) == (false == false)) == ((false == false) == (false == false))) && ({"": {"": {}}}[""][""] == {"": {"": {}}}[""][""]) +}; + +policy1 +forbid( + principal in r::r::r::r::a::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::a::"" +) when { + true && (if [r::r::r::r::a::"", principal, principal].containsAll([]) then action in action else action in action) && (action in action) && (action in action) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::a"},"request":"R1","resource":{"id":"","type":"r::r::r::r::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"r::r::r::r::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::a"},"request":"R3","resource":{"id":"","type":"r::r::r::r::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"r::r::r::r::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/solution/reference.json b/tasks/cedar_authorization-2f3e76fa6affa53af931/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/solution/solve.sh b/tasks/cedar_authorization-2f3e76fa6affa53af931/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/task.toml b/tasks/cedar_authorization-2f3e76fa6affa53af931/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c74b7867cbf50afcf7be11d6c6aa56ca270aa723 --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2f3e76fa6affa53af931" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "160d5af0f06f48fe122cf1199393668bcb73d205bec612bde53cff5bd1448005" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/expected.json b/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/grading.py b/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/test.sh b/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/verify.py b/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-2f3e76fa6affa53af931/validation/openenv.json b/tasks/cedar_authorization-2f3e76fa6affa53af931/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2f3e76fa6affa53af931/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/environment/Dockerfile b/tasks/cedar_authorization-308c76e0f966115a2635/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/instruction.md b/tasks/cedar_authorization-308c76e0f966115a2635/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..aefc31acff46145e1e70a766a4c003a019a51e70 --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal is a in a::"", + action in [Action::""], + resource == a::"" +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::r::"", + action in [r::r::r::r::Action::"action",r::r::r::r::Action::"action"], + resource in r::r::r::r::r::"" +) when { + true && (if if if false then false else false then if false then false else false else if false then false else false then if if false then false else false then if false then false else false else if false then false else false else if if false then true else true then action in action else action in action) && ({"": action}[""] in {"": action}[""]) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::WMMMMM"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::_YlW3333333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/solution/reference.json b/tasks/cedar_authorization-308c76e0f966115a2635/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/solution/solve.sh b/tasks/cedar_authorization-308c76e0f966115a2635/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/task.toml b/tasks/cedar_authorization-308c76e0f966115a2635/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4d27d6e3ecaa3ea07f8dab5b7f20d6da91b8f9dc --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-308c76e0f966115a2635" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "a8ce9e30b00b0b68d03f7698d4f1f57b0943d9e952fc89a388f682d9570ce726" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/tests/expected.json b/tasks/cedar_authorization-308c76e0f966115a2635/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/tests/grading.py b/tasks/cedar_authorization-308c76e0f966115a2635/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/tests/test.sh b/tasks/cedar_authorization-308c76e0f966115a2635/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/tests/verify.py b/tasks/cedar_authorization-308c76e0f966115a2635/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-308c76e0f966115a2635/validation/openenv.json b/tasks/cedar_authorization-308c76e0f966115a2635/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-308c76e0f966115a2635/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/environment/Dockerfile b/tasks/cedar_authorization-30a88504fbad6b96355c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/instruction.md b/tasks/cedar_authorization-30a88504fbad6b96355c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..08be3311ffac789e04f10e407d064a4f5803f8d7 --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r3w333333::r::r::"", + action in [r::r::r3w333333::r::Action::"action"], + resource == r::r::r3w333333::r::r::"" +) when { + true +}; + +policy1 +forbid( + principal, + action in [j00000YY::i::i::i::i::jm555555::Action::"action"], + resource in j00000YY::i::i::i::i::jm555555::a::"" +) when { + true && (false || ((action in action) || (action in action))) && ({"": action}[""] in {"": action}[""]) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"j00000YY::i::i::i::i::jm555555::a"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r3w333333::r::r"}],"uid":{"id":"","type":"r::r::r3w333333::r::fg"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3w333333::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"\"\"\"\"\"\",\"\"","type":"j00000YY::i::i::i::i::jm555555::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r3w333333::r::Action"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r3w333333::r::fg"},{"id":"","type":"r::r::r3w333333::r::r"}],"uid":{"id":"||||||||","type":"r::r::r3w333333::r::r"}}] + +Requests +{"action":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"},"context":{},"principal":{"id":"\"\"\"\"\"\",\"\"","type":"j00000YY::i::i::i::i::jm555555::a"},"request":"R1","resource":{"id":"","type":"j00000YY::i::i::i::i::jm555555::a"}} +{"action":{"id":"action","type":"r::r::r3w333333::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3w333333::r::r"},"request":"R2","resource":{"id":"","type":"r::r::r3w333333::r::r"}} +{"action":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"},"context":{},"principal":{"id":"\"\"\"\"\"\",\"\"","type":"j00000YY::i::i::i::i::jm555555::a"},"request":"R3","resource":{"id":"\"\"\"\"\"\",\"\"","type":"j00000YY::i::i::i::i::jm555555::a"}} +{"action":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"},"context":{},"principal":{"id":"","type":"j00000YY::i::i::i::i::jm555555::a"},"request":"R4","resource":{"id":"","type":"j00000YY::i::i::i::i::jm555555::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/solution/reference.json b/tasks/cedar_authorization-30a88504fbad6b96355c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..644bd01431fddb1b9602e4c5e73687ac6afefb3f --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/solution/solve.sh b/tasks/cedar_authorization-30a88504fbad6b96355c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/task.toml b/tasks/cedar_authorization-30a88504fbad6b96355c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..eded68b75bcbe68ba6f5d996dfc7bb155d0284e7 --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-30a88504fbad6b96355c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d5147296afdef7698aca3b35e11bbdb53f1b0b4dc7b6e5286d72e145cda48be0" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/tests/expected.json b/tasks/cedar_authorization-30a88504fbad6b96355c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..644bd01431fddb1b9602e4c5e73687ac6afefb3f --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/tests/grading.py b/tasks/cedar_authorization-30a88504fbad6b96355c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/tests/test.sh b/tasks/cedar_authorization-30a88504fbad6b96355c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/tests/verify.py b/tasks/cedar_authorization-30a88504fbad6b96355c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-30a88504fbad6b96355c/validation/openenv.json b/tasks/cedar_authorization-30a88504fbad6b96355c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-30a88504fbad6b96355c/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/environment/Dockerfile b/tasks/cedar_authorization-31120b8a4b58cfe9d549/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/instruction.md b/tasks/cedar_authorization-31120b8a4b58cfe9d549/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..da8625d5b136b603ec1831f5b98896c3d397acd2 --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r::r::r::"ttttttttttttttttttt", + action == r::r::r::r::Action::"action", + resource == r::r::r::r::r::"" +) when { + true && (if if if true then true else true then if true then true else false else principal is r::r::r::r::r then principal is r::r::r::r::r else principal is r::r::r::r::r) && (principal is r::r::r::r::r) && (principal is r::r::r::r::r) +}; + +policy1 +forbid( + principal in O4444124::"", + action in [Action::"action",Action::"action"], + resource in iYYYYYf4444444444::"" +) when { + true && {"": [[[[action]]]]}[""].contains(if [[ip("ffff:ffff:ffff:fffe:ffff:ffff:ffff:ffff/126"), ip("9797:8e97:9797:9797:9797:9797:9797:9797/22"), ip("22.22.22.22")], [], [ip("22.22.22.22"), ip("c7c7:c7c7:c7c7:c7c7:c7c7:c7c7:c7c7:c7c7/70")]].containsAll([(-7016996765293437282)]) then if false then [[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]] else [[[action, action]], [[action]]] else {"": [[[action]]]}[""]) && ({"": action}[""] in {"": action}[""]) +}; + +Entities +[{"attrs":{"Tqqqqqqqq":{"__extn":{"arg":"5568-01-01","fn":"datetime"}}},"parents":[],"uid":{"id":"","type":"O4444124"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Tqqqqqqqq"}},{"attrs":{},"parents":[{"id":"","type":"O4444124"},{"id":"","type":"Tqqqqqqqq"}],"uid":{"id":"","type":"iYYYYYf4444444444"}},{"attrs":{"H":{"__entity":{"id":"","type":"r::r::r::r::q"}},"O44444444333":true},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{"H":{"__entity":{"id":"","type":"r::r::r::r::q"}},"O44444444333":true},"parents":[{"id":"","type":"r::r::r::r::r"}],"uid":{"id":"ttttttttttttttttttt","type":"r::r::r::r::r"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"hqqqqqqqq":{"__extn":{"arg":"0606-03-04T14:38:38-0838","fn":"datetime"}}},"principal":{"id":"","type":"O4444124"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{"hqqqqqqqq":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"Tqqqqqqqq"},"request":"R2","resource":{"id":"","type":"iYYYYYf4444444444"}} +{"action":{"id":"action","type":"Action"},"context":{"hqqqqqqqq":{"__extn":{"arg":"0606-03-04T14:38:38-0838","fn":"datetime"}}},"principal":{"id":"","type":"O4444124"},"request":"R3","resource":{"id":"","type":"iYYYYYf4444444444"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"hqqqqqqqq":{"__extn":{"arg":"0606-03-04T14:38:38-0838","fn":"datetime"}}},"principal":{"id":"ttttttttttttttttttt","type":"r::r::r::r::r"},"request":"R4","resource":{"id":"","type":"r::r::r::r::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/solution/reference.json b/tasks/cedar_authorization-31120b8a4b58cfe9d549/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/solution/solve.sh b/tasks/cedar_authorization-31120b8a4b58cfe9d549/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/task.toml b/tasks/cedar_authorization-31120b8a4b58cfe9d549/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..12608daa84c4a75c8c379c691c334025841a261f --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-31120b8a4b58cfe9d549" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ecd52a3209bc9e6f06c02854dbc13fbc8124da1fbb03b540c56916081b8ed162" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/expected.json b/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/grading.py b/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/test.sh b/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/verify.py b/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-31120b8a4b58cfe9d549/validation/openenv.json b/tasks/cedar_authorization-31120b8a4b58cfe9d549/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-31120b8a4b58cfe9d549/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/environment/Dockerfile b/tasks/cedar_authorization-31ae1c43e974ffa74506/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/instruction.md b/tasks/cedar_authorization-31ae1c43e974ffa74506/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2d21a35875e148590ec3cf47a8e7eed23abda57c --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal is a in a::"", + action in [Action::""], + resource == a::"" +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::r::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::r::"" +) when { + true && ((if "||" like "|*|*" then if false then "||" else "||" else if false then "||" else "||") like "|*|*") && ("||" like "|*|*") +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"|||~|","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/solution/reference.json b/tasks/cedar_authorization-31ae1c43e974ffa74506/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/solution/solve.sh b/tasks/cedar_authorization-31ae1c43e974ffa74506/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/task.toml b/tasks/cedar_authorization-31ae1c43e974ffa74506/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..556469a7b9e5f1e6a7324ab9d4d1f3ca52d266ca --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-31ae1c43e974ffa74506" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b9ed2c4115cb8f6749098527b0b3512e94136c9fde8dab755c83e5593e058f20" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/expected.json b/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/grading.py b/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/test.sh b/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/verify.py b/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-31ae1c43e974ffa74506/validation/openenv.json b/tasks/cedar_authorization-31ae1c43e974ffa74506/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-31ae1c43e974ffa74506/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/environment/Dockerfile b/tasks/cedar_authorization-32712eff96bec14dbdde/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/instruction.md b/tasks/cedar_authorization-32712eff96bec14dbdde/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6b06f7be6d55bc39a94c838705f66ec3ac66299c --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == QxxO0xxxxxxxxxx::a::"", + action == QxxO0xxxxxxxxxx::Action::"action", + resource is QxxO0xxxxxxxxxx::a +) when { + true && (true || (true || decimal("128060702.238").lessThanOrEqual(decimal("80846.443!")))) && true && (true || ((context has zzzz) || ({zz: "", "zzzz:z{zz": datetime("0000-01-01")} has ""))) +}; + +policy1 +forbid( + principal, + action in [Action::"action"], + resource +) when { + true && (r::"" has r) && (r::"".r has r) && (r::"" has r) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"QxxO0xxxxxxxxxx::a"}},{"attrs":{"r":{"__entity":{"id":"","type":"r"}}},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"QxxO0xxxxxxxxxx::a"},"request":"R1","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"QxxO0xxxxxxxxxx::a"}} +{"action":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"},"context":{},"principal":{"id":"","type":"QxxO0xxxxxxxxxx::a"},"request":"R4","resource":{"id":"","type":"QxxO0xxxxxxxxxx::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/solution/reference.json b/tasks/cedar_authorization-32712eff96bec14dbdde/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..9ba662580593b53e31a67a8f8f693a2629cbddd7 --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/solution/solve.sh b/tasks/cedar_authorization-32712eff96bec14dbdde/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/task.toml b/tasks/cedar_authorization-32712eff96bec14dbdde/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a28ede577b6444f56a6e048a66cda69d8ce18331 --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-32712eff96bec14dbdde" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0a94468f8712e59c4e1232a5933228d81b8da2bcffa5c19bb0faa0062087140e" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/tests/expected.json b/tasks/cedar_authorization-32712eff96bec14dbdde/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..9ba662580593b53e31a67a8f8f693a2629cbddd7 --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/tests/grading.py b/tasks/cedar_authorization-32712eff96bec14dbdde/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/tests/test.sh b/tasks/cedar_authorization-32712eff96bec14dbdde/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/tests/verify.py b/tasks/cedar_authorization-32712eff96bec14dbdde/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-32712eff96bec14dbdde/validation/openenv.json b/tasks/cedar_authorization-32712eff96bec14dbdde/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-32712eff96bec14dbdde/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/environment/Dockerfile b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/instruction.md b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3ecbecdf3fbd9ac331c88b97db1de7fb7e6ce645 --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/instruction.md @@ -0,0 +1,21 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A5cZr9000rrrrEErr::"`", + action == Action::"action", + resource in A5cZr9000rrrrEErr::"`" +) when { + true && ((-2712756478873001310) < (6510615555426900570 + (-940422246894996750) + duration("4971692651079231812ms").toMinutes())) && (A5cZr9000rrrrEErr::"`" in (if false then {"": action} else {"": principal})[""]) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"A5cZr9000rrrrEErr"},"request":"R1","resource":{"id":"","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R2","resource":{"id":"","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R3","resource":{"id":"`","type":"A5cZr9000rrrrEErr"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/solution/reference.json b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..2e99182fe1dad0aefd69bdb97f2838492ecfe966 --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"}]} diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/solution/solve.sh b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/task.toml b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..94e7535a3be6eefa6ba8ce57ba32732d8441e8a3 --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-32a6a5cb4c96b5e67282" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "2bc1721d3d777584952d77b5e75096c943c4169159e771a2a216fe2b94d63731" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/expected.json b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..2e99182fe1dad0aefd69bdb97f2838492ecfe966 --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"}]} diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/grading.py b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/test.sh b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/verify.py b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-32a6a5cb4c96b5e67282/validation/openenv.json b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-32a6a5cb4c96b5e67282/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/environment/Dockerfile b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/instruction.md b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..dcd5c198f7bca765718d6472bbd1392797fbb747 --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A5cZr9000rrrrEErr::"`", + action == Action::"action", + resource in A5cZr9000rrrrEErr::"`" +) when { + true && ((-2712756478873001310) < (6510615555426900570 + (-940422246894996750) + duration("4971692651079231812ms").toMinutes())) && (A5cZr9000rrrrEErr::"`" in (if false then {"": action} else {"": principal})[""]) +}; + +policy1 +forbid( + principal in a::"", + action in [Action::"action"], + resource in a::"" +) when { + true && resource.getTag("").getTag("").hasTag("") +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"tags":{"":{"__entity":{"id":"","type":"a"}}},"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"`","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R2","resource":{"id":"","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R4","resource":{"id":"`","type":"A5cZr9000rrrrEErr"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/solution/reference.json b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/solution/solve.sh b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/task.toml b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..922111ecda677f0aa6931e352d155848167c415d --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-32fb0d612cd607f2d6f4" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "fdbeeeb9a075be508604cdd57eeab8d5c217714e2ab7c01a1a1bac756434afb8" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/expected.json b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/grading.py b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/test.sh b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/verify.py b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-32fb0d612cd607f2d6f4/validation/openenv.json b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-32fb0d612cd607f2d6f4/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/environment/Dockerfile b/tasks/cedar_authorization-3305c664135f499a5b38/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/instruction.md b/tasks/cedar_authorization-3305c664135f499a5b38/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..32f8de215f2f5de49b027d123dc4b766e7fd03ae --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action, + resource == d0000k0::A::a::"" +) when { + true +}; + +policy1 +forbid( + principal, + action in [r::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"d0000k0::A::a"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::r"},{"id":"VVVVVVVVVV","type":"r::r::r::r::r"}],"uid":{"id":"","type":"r::r::r::r::hN"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"CCCyCCCCCCCCCCC","type":"r::r::r::r::hN"}},{"attrs":{},"parents":[],"uid":{"id":"VVVVVVVVVV","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"d0000k0::A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"d0000k0::A::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"d0000k0::A::a"},"request":"R2","resource":{"id":"","type":"d0000k0::A::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"},"request":"R4","resource":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/solution/reference.json b/tasks/cedar_authorization-3305c664135f499a5b38/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..975b41cdaf25a3c9232cd82f8ea9a647a4a895e5 --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/solution/solve.sh b/tasks/cedar_authorization-3305c664135f499a5b38/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/task.toml b/tasks/cedar_authorization-3305c664135f499a5b38/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f9a61cd27e1997906730c72f21087accbe9018fa --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-3305c664135f499a5b38" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "8973de9856bbc3a61341277fd6105c16f4ca02d2f4464c30c0a2def115433a34" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/tests/expected.json b/tasks/cedar_authorization-3305c664135f499a5b38/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..975b41cdaf25a3c9232cd82f8ea9a647a4a895e5 --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/tests/grading.py b/tasks/cedar_authorization-3305c664135f499a5b38/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/tests/test.sh b/tasks/cedar_authorization-3305c664135f499a5b38/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/tests/verify.py b/tasks/cedar_authorization-3305c664135f499a5b38/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-3305c664135f499a5b38/validation/openenv.json b/tasks/cedar_authorization-3305c664135f499a5b38/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-3305c664135f499a5b38/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/environment/Dockerfile b/tasks/cedar_authorization-338e3e6459af28cd8713/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/instruction.md b/tasks/cedar_authorization-338e3e6459af28cd8713/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5ee4e65c67c4a1e907f635018ad82a0b8983db03 --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == A::a::"", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::A::"", + action in [r::r::r::r::Action::"action"], + resource in r::r::r::r::P::"" +) when { + true && (principal in principal) && (principal in principal) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::a"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::P"},{"id":"","type":"r::r::r::r::_Y333333333333"}],"tags":{"":{"__entity":{"id":"","type":"r::r::r::r::A"}},"*********":{"__entity":{"id":"","type":"r::r::r::r::A"}}},"uid":{"id":"","type":"r::r::r::r::A"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::_Y333333333333"}],"uid":{"id":"","type":"r::r::r::r::P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::_Y333333333333"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::A"},{"id":"","type":"r::r::r::r::_Y333333333333"},{"id":"","type":"r::r::r::r::P"}],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::w"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::A"},"request":"R1","resource":{"id":"","type":"r::r::r::r::_Y333333333333"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"A::a"},"request":"R2","resource":{"id":"","type":"r::r::r::r::P"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::P"},"request":"R3","resource":{"id":"","type":"r::r::r::r::P"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::A"},"request":"R4","resource":{"id":"","type":"r::r::r::r::P"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/solution/reference.json b/tasks/cedar_authorization-338e3e6459af28cd8713/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/solution/solve.sh b/tasks/cedar_authorization-338e3e6459af28cd8713/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/task.toml b/tasks/cedar_authorization-338e3e6459af28cd8713/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a457f9d3439a1594f0dd2918237c47e9b6b939a5 --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-338e3e6459af28cd8713" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "1a46fff35a42b66dd40bdf5c9cdd12017311cb70357c8e3c4928bc18d745fa45" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/tests/expected.json b/tasks/cedar_authorization-338e3e6459af28cd8713/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/tests/grading.py b/tasks/cedar_authorization-338e3e6459af28cd8713/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/tests/test.sh b/tasks/cedar_authorization-338e3e6459af28cd8713/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/tests/verify.py b/tasks/cedar_authorization-338e3e6459af28cd8713/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-338e3e6459af28cd8713/validation/openenv.json b/tasks/cedar_authorization-338e3e6459af28cd8713/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-338e3e6459af28cd8713/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}} diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/environment/Dockerfile b/tasks/cedar_authorization-3409e000ac073a2a2c55/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/instruction.md b/tasks/cedar_authorization-3409e000ac073a2a2c55/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0438dcdf26634d1624d5c421858b9bc02b8cf37a --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal is a, + action == Action::"action", + resource is a +) when { + true && (true || (principal in principal) || (a::"((((((((((((((((" is a)) && (a::"((((((((((((((((" is a) && (a::"((((((((((((((((" is a) +}; + +policy1 +forbid( + principal in a::"", + action in [Action::"action",Action::"action"], + resource in a::"" +) when { + true && (if if if false then false else false then if false then false else false else if false then false else true then a::"" in a::"" else if if false then false else false then if false then false else false else if false then false else false) && (if (if true then "2233" else "2233") like "**33*" then true else true) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"((((((((((((((((","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"((((((((((((((((","type":"a"},"request":"R1","resource":{"id":"((((((((((((((((","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"((((((((((((((((","type":"a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"((((((((((((((((","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/solution/reference.json b/tasks/cedar_authorization-3409e000ac073a2a2c55/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4641d1db584c9d6c16920bace3830201b8a946be --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/solution/solve.sh b/tasks/cedar_authorization-3409e000ac073a2a2c55/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/task.toml b/tasks/cedar_authorization-3409e000ac073a2a2c55/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7da4ddf6b283bc8fd878855130ab4da9e688f534 --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-3409e000ac073a2a2c55" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "3f1f527afca03b5714b3adefce92f56c1171a0afe62837d0567dcd3aadcc0aa2" + +[environment] +docker_image = "public.ecr.aws/docker/library/python@sha256:05a994d2344eb364cc186910f4fc8786a38215f39f00d0acc25bff33a08f4177" +workdir = "/tmp" +cpus = 1 +memory_mb = 512 +storage_mb = 2048 +network_mode = "no-network" + +[agent] +timeout_sec = 120 +network_mode = "no-network" + +[verifier] +timeout_sec = 60 +environment_mode = "separate" +network_mode = "no-network" diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/expected.json b/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4641d1db584c9d6c16920bace3830201b8a946be --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/grading.py b/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/grading.py @@ -0,0 +1,49 @@ +"""Shared JSON grading contract for the environment and rollout controller.""" + +import hashlib +import json +import re + + +def canonical(value) -> bytes: + return json.dumps(value, ensure_ascii=False, sort_keys=True, + separators=(",", ":"), allow_nan=False).encode("utf-8") + + +def payload_sha256(row: dict) -> str: + payload = {key: value for key, value in row.items() if key != "task_sha256"} + return hashlib.sha256(canonical(payload)).hexdigest() + + +def _object(pairs): + result = {} + for key, value in pairs: + if key in result: + raise ValueError(f"Duplicate JSON member {key!r}") + result[key] = value + return result + + +def _bad_number(token): + raise ValueError(f"Non-finite number {token!r}") + + +def parse_answer(text: str) -> dict: + if not isinstance(text, str): + raise ValueError("An answer must be JSON text") + text = text.strip() + fence = re.fullmatch(r"```(?:json)?\s*\n(.*?)\n```", text, flags=re.DOTALL | re.IGNORECASE) + if fence: + text = fence.group(1) + value = json.loads(text, object_pairs_hook=_object, parse_constant=_bad_number) + if not isinstance(value, dict): + raise ValueError("An answer must be a JSON object") + canonical(value) + return value + + +def reward(expected: dict, submitted: object) -> int: + try: + return int(isinstance(submitted, dict) and canonical(expected) == canonical(submitted)) + except (TypeError, ValueError, RecursionError): + return 0 diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/test.sh b/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec /usr/local/bin/python -I -B -S /tests/verify.py diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/verify.py b/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/tests/verify.py @@ -0,0 +1,14 @@ +from pathlib import Path +from runpy import run_path + +contract = run_path('/tests/grading.py') +expected = contract['parse_answer'](Path('/tests/expected.json').read_text()) +answer = Path('/tmp/answer.json') +try: + submitted = None if answer.is_symlink() else contract['parse_answer'](answer.read_text()) +except (OSError, ValueError, RecursionError): + submitted = None +value = contract['reward'](expected, submitted) +log = Path('/logs/verifier') +log.mkdir(parents=True, exist_ok=True) +(log / 'reward.txt').write_text(str(value) + '\n') diff --git a/tasks/cedar_authorization-3409e000ac073a2a2c55/validation/openenv.json b/tasks/cedar_authorization-3409e000ac073a2a2c55/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-3409e000ac073a2a2c55/validation/openenv.json @@ -0,0 +1 @@ +{"profile":"harbor-semantic-v1","requires_credentials":false,"resources":{"cpu":1,"disk_mb":2048,"episode_timeout_s":180,"memory_mb":512},"reward":{"floor_margin":0.1,"oracle_tolerance":0,"range":[0,1]},"reward_key":"reward","types":{"tags":["authorization"]}}