diff --git a/tasks/cedar_authorization-c7237c3edd491d9f7c3c/environment/Dockerfile b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c7237c3edd491d9f7c3c/instruction.md b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e52fe4716522ea28f7c0d95ed5cd9a8d263b64ac --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/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 == Agoppp0000000::"" +) when { + 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":"Agoppp0000000"}},{"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":"mmmm3333w*","type":"qgg"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"Agoppp0000000"},"request":"R1","resource":{"id":"(","type":"LYe"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"(","type":"LYe"},"request":"R2","resource":{"id":"(","type":"LYe"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"Agoppp0000000"},"request":"R3","resource":{"id":"","type":"Agoppp0000000"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"(","type":"LYe"},"request":"R4","resource":{"id":"","type":"Agoppp0000000"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-c7237c3edd491d9f7c3c/solution/reference.json b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..0798ad417f7dc7737b402a05e09354f2f60dc990 --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/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":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-c7237c3edd491d9f7c3c/solution/solve.sh b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c7237c3edd491d9f7c3c/task.toml b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..505a15118e13a22131f8bacef50a19942435d9ef --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c7237c3edd491d9f7c3c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d3b629c9bc76e94e138e70a1295096995a7288cd13a96fecf5f21007e3663f62" + +[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-c7237c3edd491d9f7c3c/tests/expected.json b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..0798ad417f7dc7737b402a05e09354f2f60dc990 --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/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":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-c7237c3edd491d9f7c3c/tests/grading.py b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/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-c7237c3edd491d9f7c3c/tests/test.sh b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/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-c7237c3edd491d9f7c3c/tests/verify.py b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/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-c7237c3edd491d9f7c3c/validation/openenv.json b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c7237c3edd491d9f7c3c/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-c738d257013a4ed37f8f/environment/Dockerfile b/tasks/cedar_authorization-c738d257013a4ed37f8f/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c738d257013a4ed37f8f/instruction.md b/tasks/cedar_authorization-c738d257013a4ed37f8f/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..76dda45f92b0abf8be9d8bd02f123b20d4809116 --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/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 is r::r::r::r::r, + action == r::r::r::r::Action::"action", + resource is r::r::r::r::r +) when { + true && (["", ""].contains("") || false || ["", ""].contains("")) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"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"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"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-c738d257013a4ed37f8f/solution/reference.json b/tasks/cedar_authorization-c738d257013a4ed37f8f/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/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-c738d257013a4ed37f8f/solution/solve.sh b/tasks/cedar_authorization-c738d257013a4ed37f8f/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c738d257013a4ed37f8f/task.toml b/tasks/cedar_authorization-c738d257013a4ed37f8f/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..88da5eccf398c3760bc32fcf28248d4efcf40653 --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c738d257013a4ed37f8f" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "aa573565b071f0f30e3dfab1c2dc979c3578d4f2e52abf223f236cadf1b876dc" + +[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-c738d257013a4ed37f8f/tests/expected.json b/tasks/cedar_authorization-c738d257013a4ed37f8f/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/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-c738d257013a4ed37f8f/tests/grading.py b/tasks/cedar_authorization-c738d257013a4ed37f8f/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/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-c738d257013a4ed37f8f/tests/test.sh b/tasks/cedar_authorization-c738d257013a4ed37f8f/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/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-c738d257013a4ed37f8f/tests/verify.py b/tasks/cedar_authorization-c738d257013a4ed37f8f/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/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-c738d257013a4ed37f8f/validation/openenv.json b/tasks/cedar_authorization-c738d257013a4ed37f8f/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c738d257013a4ed37f8f/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-c747d0a466a49cc2f418/environment/Dockerfile b/tasks/cedar_authorization-c747d0a466a49cc2f418/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c747d0a466a49cc2f418/instruction.md b/tasks/cedar_authorization-c747d0a466a49cc2f418/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a7f6eeaf89778389cbbbced32960c1979240b3b0 --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/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::q::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::q::"" +) when { + true && ((datetime("5654-11-23T22:22:22-0722") < datetime("5654-11-23T22:22:01.937Z")) || (action in action) || ({"": action}[""] in {"": action}[""])) && ({"": action}[""] in {"": action}[""]) +}; + +policy1 +forbid( + principal is LYY, + action in [Action::"action",Action::"action",Action::"action"], + resource == PcY::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYYYY5c"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"PcY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::W"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::u"}},{"attrs":{},"parents":[],"uid":{"id":"**************************","type":"LYY"}},{"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":{"LYY":[["","**)))))))))))))UUUUUUUUUUUUUU"]]},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R1","resource":{"id":"","type":"PcY"}} +{"action":{"id":"action","type":"Action"},"context":{"LYY":[[""]]},"principal":{"id":"**************************","type":"LYY"},"request":"R2","resource":{"id":"","type":"PcY"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"r":false},"principal":{"id":"**************************","type":"LYY"},"request":"R3","resource":{"id":"","type":"r::r::r::r::q"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"r":false},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R4","resource":{"id":"","type":"r::r::r::r::q"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-c747d0a466a49cc2f418/solution/reference.json b/tasks/cedar_authorization-c747d0a466a49cc2f418/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/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-c747d0a466a49cc2f418/solution/solve.sh b/tasks/cedar_authorization-c747d0a466a49cc2f418/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c747d0a466a49cc2f418/task.toml b/tasks/cedar_authorization-c747d0a466a49cc2f418/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1f9b21d0044d3a658b1342c3b65ae2114d616ab6 --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c747d0a466a49cc2f418" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "a6f0c6d6759e9a094d50d4b10b61f7746ca00f8c3abda4d4c28fb4e0d64ef5bb" + +[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-c747d0a466a49cc2f418/tests/expected.json b/tasks/cedar_authorization-c747d0a466a49cc2f418/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/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-c747d0a466a49cc2f418/tests/grading.py b/tasks/cedar_authorization-c747d0a466a49cc2f418/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/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-c747d0a466a49cc2f418/tests/test.sh b/tasks/cedar_authorization-c747d0a466a49cc2f418/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/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-c747d0a466a49cc2f418/tests/verify.py b/tasks/cedar_authorization-c747d0a466a49cc2f418/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/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-c747d0a466a49cc2f418/validation/openenv.json b/tasks/cedar_authorization-c747d0a466a49cc2f418/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c747d0a466a49cc2f418/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-c7bceaaf8d3c727cb820/environment/Dockerfile b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c7bceaaf8d3c727cb820/instruction.md b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..01bc16a166745a2343f690a3e36f7f9bc4d57ff0 --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/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 r32333333::"", + action in [Action::"action"], + resource == r32333333::"" +) when { + true +}; + +policy1 +forbid( + principal in _Yl10999999999::"<===", + action in [Action::""], + resource +) when { + true && (if if "33333" like "" then decimal("--33322776644779955008800441177..22009944").lessThan(decimal("-332764795055152.6959")) else [ip("2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b/43"), ip("2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b/43"), ip("194.194.194.194")].containsAll([datetime("5534-04-08T15:15:15.427+0015").offset(duration("-59393h2248146945m1s1ms")), datetime("7219-08-08T15:15:07.347+0015").offset(duration("0h")), datetime("2827-12-12T11:11:11.827+1111")]) then !(!true) else !(!true)) +}; + +Entities +[{"attrs":{},"parents":[{"id":"000000000000000e","type":"Action"}],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Kww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"PDw"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Pww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"_Yl10999999999"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"fww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r32333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r444G444444444"}},{"attrs":{},"parents":[],"uid":{"id":"000000000000000e","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"<===","type":"_Yl10999999999"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r32333333"},"request":"R1","resource":{"id":"","type":"r32333333"}} +{"action":{"id":"000000000000000e","type":"Action"},"context":{},"principal":{"id":"","type":"_Yl10999999999"},"request":"R2","resource":{"id":"<===","type":"_Yl10999999999"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"<===","type":"_Yl10999999999"},"request":"R3","resource":{"id":"","type":"_Yl10999999999"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"<===","type":"_Yl10999999999"},"request":"R4","resource":{"id":"","type":"r32333333"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-c7bceaaf8d3c727cb820/solution/reference.json b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/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-c7bceaaf8d3c727cb820/solution/solve.sh b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c7bceaaf8d3c727cb820/task.toml b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a1262fdece4ed1aa8313eb1353fbab93f87c8cdd --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c7bceaaf8d3c727cb820" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "33a9b0c42ceda4bdfae7d92a6a68a578fa11fadc5a290a52970a1aa2148e4986" + +[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-c7bceaaf8d3c727cb820/tests/expected.json b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/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-c7bceaaf8d3c727cb820/tests/grading.py b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/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-c7bceaaf8d3c727cb820/tests/test.sh b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/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-c7bceaaf8d3c727cb820/tests/verify.py b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/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-c7bceaaf8d3c727cb820/validation/openenv.json b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c7bceaaf8d3c727cb820/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-c7d5932f2aa3655940db/environment/Dockerfile b/tasks/cedar_authorization-c7d5932f2aa3655940db/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c7d5932f2aa3655940db/instruction.md b/tasks/cedar_authorization-c7d5932f2aa3655940db/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cff21ed7a11fec784acf262712962825d5657e02 --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/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 a::"", + action in [Action::"action",Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cZr9000rrrrEErr"}},{"attrs":{"A0":"*******"},"parents":[],"tags":{"":[[[[]]]],"****":[[[]],[[],[[]]],[[[]]]]},"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":"A5cZr9000rrrrEErr"},"request":"R1","resource":{"id":"","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"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-c7d5932f2aa3655940db/solution/reference.json b/tasks/cedar_authorization-c7d5932f2aa3655940db/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/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-c7d5932f2aa3655940db/solution/solve.sh b/tasks/cedar_authorization-c7d5932f2aa3655940db/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c7d5932f2aa3655940db/task.toml b/tasks/cedar_authorization-c7d5932f2aa3655940db/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3af0a94e900a0f612351a8e926b67aa03c3d277e --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c7d5932f2aa3655940db" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "fddd5cf48e8c43c2ea3afe14d261b0ae1cab7076f0c9827e00e9ab626419838a" + +[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-c7d5932f2aa3655940db/tests/expected.json b/tasks/cedar_authorization-c7d5932f2aa3655940db/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/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-c7d5932f2aa3655940db/tests/grading.py b/tasks/cedar_authorization-c7d5932f2aa3655940db/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/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-c7d5932f2aa3655940db/tests/test.sh b/tasks/cedar_authorization-c7d5932f2aa3655940db/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/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-c7d5932f2aa3655940db/tests/verify.py b/tasks/cedar_authorization-c7d5932f2aa3655940db/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/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-c7d5932f2aa3655940db/validation/openenv.json b/tasks/cedar_authorization-c7d5932f2aa3655940db/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c7d5932f2aa3655940db/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-c800372242914a5a0271/environment/Dockerfile b/tasks/cedar_authorization-c800372242914a5a0271/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c800372242914a5a0271/instruction.md b/tasks/cedar_authorization-c800372242914a5a0271/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..85f0608e5aa637791dfd33a36fe6b2792acf906c --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/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, + action == errrr::errrr::err::r::Action::"action", + resource is errrr::errrr::err::r::a +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"errrr::errrr::err::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"44","type":"errrr::errrr::err::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"errrr::errrr::err::r::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"44","type":"errrr::errrr::err::r::a"},"request":"R1","resource":{"id":"44","type":"errrr::errrr::err::r::a"}} +{"action":{"id":"action","type":"errrr::errrr::err::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"44","type":"errrr::errrr::err::r::a"}} +{"action":{"id":"action","type":"errrr::errrr::err::r::Action"},"context":{},"principal":{"id":"44","type":"errrr::errrr::err::r::a"},"request":"R3","resource":{"id":"44","type":"errrr::errrr::err::r::a"}} +{"action":{"id":"action","type":"errrr::errrr::err::r::Action"},"context":{},"principal":{"id":"44","type":"errrr::errrr::err::r::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-c800372242914a5a0271/solution/reference.json b/tasks/cedar_authorization-c800372242914a5a0271/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..78e57d9be7a2e9442cf9a94a1de6c980ed3bc682 --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/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":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-c800372242914a5a0271/solution/solve.sh b/tasks/cedar_authorization-c800372242914a5a0271/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c800372242914a5a0271/task.toml b/tasks/cedar_authorization-c800372242914a5a0271/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..77a0e4dd953e84ee1c1c50cc9f6fe71e6ca74953 --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c800372242914a5a0271" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ad881372ee4dc7691054fad3ab5910901974b325e8a99f461fd6c582a8d63348" + +[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-c800372242914a5a0271/tests/expected.json b/tasks/cedar_authorization-c800372242914a5a0271/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..78e57d9be7a2e9442cf9a94a1de6c980ed3bc682 --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/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":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-c800372242914a5a0271/tests/grading.py b/tasks/cedar_authorization-c800372242914a5a0271/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/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-c800372242914a5a0271/tests/test.sh b/tasks/cedar_authorization-c800372242914a5a0271/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/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-c800372242914a5a0271/tests/verify.py b/tasks/cedar_authorization-c800372242914a5a0271/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/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-c800372242914a5a0271/validation/openenv.json b/tasks/cedar_authorization-c800372242914a5a0271/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c800372242914a5a0271/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-c80b21613351edac8fd8/environment/Dockerfile b/tasks/cedar_authorization-c80b21613351edac8fd8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c80b21613351edac8fd8/instruction.md b/tasks/cedar_authorization-c80b21613351edac8fd8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..296f7ec9852a4f6d30bf6c0cda6e5ea7a45a4f5e --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/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 O::j5w33333::r::r::r::j550L556::r::"", + action, + resource in O::j5w33333::r::r::r::j550L556::r::"" +) when { + true && (if if if false then false else false then true else true then true else true) && true +}; + +policy1 +forbid( + principal in r::r::r::r::r::"", + action in [r::r::r::r::Action::"action"], + resource == r::r::r::r::r3hMH::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::r"}],"uid":{"id":"","type":"r::r::r::r::X"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::X"},{"id":"","type":"r::r::r::r::r"}],"uid":{"id":"","type":"r::r::r::r::r3hMH"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"O::j5w33333::r::r::r::j550L556::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"O::j5w33333::r::r::r::j550L556::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r3hMH"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r3hMH"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r3hMH"},"request":"R2","resource":{"id":"","type":"r::r::r::r::r3hMH"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"},"request":"R3","resource":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r3hMH"},"request":"R4","resource":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-c80b21613351edac8fd8/solution/reference.json b/tasks/cedar_authorization-c80b21613351edac8fd8/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/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-c80b21613351edac8fd8/solution/solve.sh b/tasks/cedar_authorization-c80b21613351edac8fd8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c80b21613351edac8fd8/task.toml b/tasks/cedar_authorization-c80b21613351edac8fd8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..87fa7e9c9fe3db9710ea67d9321334624bf188ab --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c80b21613351edac8fd8" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "a4d62080a43632dff70466c09add7cb9d56de0636af9ab018dc9d2aed9cbf068" + +[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-c80b21613351edac8fd8/tests/expected.json b/tasks/cedar_authorization-c80b21613351edac8fd8/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/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-c80b21613351edac8fd8/tests/grading.py b/tasks/cedar_authorization-c80b21613351edac8fd8/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/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-c80b21613351edac8fd8/tests/test.sh b/tasks/cedar_authorization-c80b21613351edac8fd8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/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-c80b21613351edac8fd8/tests/verify.py b/tasks/cedar_authorization-c80b21613351edac8fd8/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/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-c80b21613351edac8fd8/validation/openenv.json b/tasks/cedar_authorization-c80b21613351edac8fd8/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c80b21613351edac8fd8/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-c8681c23112780d9ee11/environment/Dockerfile b/tasks/cedar_authorization-c8681c23112780d9ee11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c8681c23112780d9ee11/instruction.md b/tasks/cedar_authorization-c8681c23112780d9ee11/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0b8ea0f0c3028499a85b9db3e39170fb312facfe --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/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 == A::A0000000009::A::a::"" +) when { + true +}; + +policy1 +forbid( + principal == A::a::"", + action in [A::Action::""], + resource == A::a::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::A0000000009::A::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"A::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::A0000000009::A::Action"}}] + +Requests +{"action":{"id":"","type":"A::Action"},"context":{},"principal":{"id":"","type":"A::A0000000009::A::a"},"request":"R1","resource":{"id":"","type":"A::a"}} +{"action":{"id":"","type":"A::Action"},"context":{},"principal":{"id":"","type":"A::a"},"request":"R2","resource":{"id":"","type":"A::a"}} +{"action":{"id":"action","type":"A::A0000000009::A::Action"},"context":{},"principal":{"id":"","type":"A::A0000000009::A::a"},"request":"R3","resource":{"id":"","type":"A::A0000000009::A::a"}} +{"action":{"id":"action","type":"A::A0000000009::A::Action"},"context":{},"principal":{"id":"","type":"A::A0000000009::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-c8681c23112780d9ee11/solution/reference.json b/tasks/cedar_authorization-c8681c23112780d9ee11/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/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-c8681c23112780d9ee11/solution/solve.sh b/tasks/cedar_authorization-c8681c23112780d9ee11/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c8681c23112780d9ee11/task.toml b/tasks/cedar_authorization-c8681c23112780d9ee11/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0f41e41bc02be686891021d43cfeb929a870f72c --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c8681c23112780d9ee11" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b9dbd23288e83ef0a85acf4dbdfe70f5a7c85020f45fb959d2219935554bcfe5" + +[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-c8681c23112780d9ee11/tests/expected.json b/tasks/cedar_authorization-c8681c23112780d9ee11/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/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-c8681c23112780d9ee11/tests/grading.py b/tasks/cedar_authorization-c8681c23112780d9ee11/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/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-c8681c23112780d9ee11/tests/test.sh b/tasks/cedar_authorization-c8681c23112780d9ee11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/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-c8681c23112780d9ee11/tests/verify.py b/tasks/cedar_authorization-c8681c23112780d9ee11/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/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-c8681c23112780d9ee11/validation/openenv.json b/tasks/cedar_authorization-c8681c23112780d9ee11/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c8681c23112780d9ee11/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-c8894ae91025da0ca3b2/environment/Dockerfile b/tasks/cedar_authorization-c8894ae91025da0ca3b2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c8894ae91025da0ca3b2/instruction.md b/tasks/cedar_authorization-c8894ae91025da0ca3b2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6c3f2b4f91b7ae29c6227f378ebcb2d9f72349b8 --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/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::A::"", + action == r::r::r::r::Action::"action", + resource == r::r::r::r::A::"" +) 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":{"_le333333eeee":{"__extn":{"arg":"166.42.42.62/15","fn":"ip"}}},"parents":[],"uid":{"id":"","type":"r::r::r::r::A"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::_YlW33F3333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r33333333333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::w"}},{"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":"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":"r::r::r::r::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-c8894ae91025da0ca3b2/solution/reference.json b/tasks/cedar_authorization-c8894ae91025da0ca3b2/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/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-c8894ae91025da0ca3b2/solution/solve.sh b/tasks/cedar_authorization-c8894ae91025da0ca3b2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c8894ae91025da0ca3b2/task.toml b/tasks/cedar_authorization-c8894ae91025da0ca3b2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9add529a0a7d2d1fa2da79dcb3742da08b95873a --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c8894ae91025da0ca3b2" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "6dd5b89012a8fcbf51c14b87dbea2709c3d22002aeeeb1ae705efec8f4389d1c" + +[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-c8894ae91025da0ca3b2/tests/expected.json b/tasks/cedar_authorization-c8894ae91025da0ca3b2/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/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-c8894ae91025da0ca3b2/tests/grading.py b/tasks/cedar_authorization-c8894ae91025da0ca3b2/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/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-c8894ae91025da0ca3b2/tests/test.sh b/tasks/cedar_authorization-c8894ae91025da0ca3b2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/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-c8894ae91025da0ca3b2/tests/verify.py b/tasks/cedar_authorization-c8894ae91025da0ca3b2/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/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-c8894ae91025da0ca3b2/validation/openenv.json b/tasks/cedar_authorization-c8894ae91025da0ca3b2/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c8894ae91025da0ca3b2/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-c935fe009e4606ca34ef/environment/Dockerfile b/tasks/cedar_authorization-c935fe009e4606ca34ef/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c935fe009e4606ca34ef/instruction.md b/tasks/cedar_authorization-c935fe009e4606ca34ef/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4c6d2d43f4a440f4674a713a0f13da2af00669d6 --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/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::A::A::r::r::r::r::F3OYlW0xI99A92ar0::A333333333333333::"", + action in [A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::Action::"action"], + resource == A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::A333333333333333::"" +) when { + true +}; + +policy1 +forbid( + principal, + action == errrr::errrr::err::r::Action::"action", + resource is errrr::errrr::err::r::a +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::A333333333333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::L333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::Ro33333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::Roooooo"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"errrr::errrr::err::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"44","type":"errrr::errrr::err::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"errrr::errrr::err::r::Action"}}] + +Requests +{"action":{"id":"action","type":"errrr::errrr::err::r::Action"},"context":{},"principal":{"id":"44","type":"errrr::errrr::err::r::a"},"request":"R1","resource":{"id":"44","type":"errrr::errrr::err::r::a"}} +{"action":{"id":"action","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::Action"},"context":{},"principal":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::A333333333333333"},"request":"R2","resource":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::A333333333333333"}} +{"action":{"id":"action","type":"errrr::errrr::err::r::Action"},"context":{},"principal":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::A333333333333333"},"request":"R3","resource":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::A333333333333333"}} +{"action":{"id":"action","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::Action"},"context":{},"principal":{"id":"","type":"A::A::A::A::r::r::r::r::F3OYlW0xI99A92ar0::A333333333333333"},"request":"R4","resource":{"id":"44","type":"errrr::errrr::err::r::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-c935fe009e4606ca34ef/solution/reference.json b/tasks/cedar_authorization-c935fe009e4606ca34ef/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/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-c935fe009e4606ca34ef/solution/solve.sh b/tasks/cedar_authorization-c935fe009e4606ca34ef/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c935fe009e4606ca34ef/task.toml b/tasks/cedar_authorization-c935fe009e4606ca34ef/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7f61939ff8e7e0cd82ebee21e7b32d55515e3010 --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c935fe009e4606ca34ef" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "dfb98315ae6c8292f45926cb94de405c7df8a5d18ac1fad88fb62b237f77a77e" + +[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-c935fe009e4606ca34ef/tests/expected.json b/tasks/cedar_authorization-c935fe009e4606ca34ef/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/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-c935fe009e4606ca34ef/tests/grading.py b/tasks/cedar_authorization-c935fe009e4606ca34ef/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/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-c935fe009e4606ca34ef/tests/test.sh b/tasks/cedar_authorization-c935fe009e4606ca34ef/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/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-c935fe009e4606ca34ef/tests/verify.py b/tasks/cedar_authorization-c935fe009e4606ca34ef/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/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-c935fe009e4606ca34ef/validation/openenv.json b/tasks/cedar_authorization-c935fe009e4606ca34ef/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c935fe009e4606ca34ef/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-c9ee5a97ed23deaf3a06/environment/Dockerfile b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/instruction.md b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1186fa37675e5c5b4d3f88f7758b4e46684a711f --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/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, + action in [Action::"action"], + resource +) when { + true && (r::"yyyyyyyyyyyyyyyye" has r) && (r::"yyyyyyyyyyyyyyyye" has r) && (r::"yyyyyyyyyyyyyyyye".r has r) +}; + +Entities +[{"attrs":{"r":{"__entity":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}},"parents":[],"uid":{"id":"","type":"r"}},{"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"}},{"attrs":{"r":{"__entity":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}},"parents":[],"uid":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"ttttttttttttttttttt","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":"r"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"ttttttttttttttttttt","type":"r::r::r::r::r"},"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-c9ee5a97ed23deaf3a06/solution/reference.json b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/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-c9ee5a97ed23deaf3a06/solution/solve.sh b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/task.toml b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9b7a4373d6870b42f72b9344b6e257dce1653453 --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c9ee5a97ed23deaf3a06" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "a30ac697d2fc6b2e4ee8fe239bd1192eee2e9192aa00a5249dafdac8b52de1f0" + +[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-c9ee5a97ed23deaf3a06/tests/expected.json b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/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-c9ee5a97ed23deaf3a06/tests/grading.py b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/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-c9ee5a97ed23deaf3a06/tests/test.sh b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/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-c9ee5a97ed23deaf3a06/tests/verify.py b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/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-c9ee5a97ed23deaf3a06/validation/openenv.json b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c9ee5a97ed23deaf3a06/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-c9f088b366ce56b972c6/environment/Dockerfile b/tasks/cedar_authorization-c9f088b366ce56b972c6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c9f088b366ce56b972c6/instruction.md b/tasks/cedar_authorization-c9f088b366ce56b972c6/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..342a671c26b09fa2e43f22e19b11ffcb77381845 --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/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::LXY::LYY::LQg::qggEggg5c::sYYY::a::"", + action in [LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action::"action"], + resource == LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a::"" +) when { + true +}; + +policy1 +forbid( + principal is r::r::r::r::r, + action == r::r::r::r::Action::"action", + resource is r::r::r::r::r +) when { + true && (["", ""].contains("") || false || ["", ""].contains("")) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::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::r"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"},"context":{},"principal":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"},"request":"R2","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} +{"action":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"},"context":{},"principal":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R4","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-c9f088b366ce56b972c6/solution/reference.json b/tasks/cedar_authorization-c9f088b366ce56b972c6/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/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-c9f088b366ce56b972c6/solution/solve.sh b/tasks/cedar_authorization-c9f088b366ce56b972c6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c9f088b366ce56b972c6/task.toml b/tasks/cedar_authorization-c9f088b366ce56b972c6/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..12fcca4c55aae3eb936c98ab6c38e1e2d962a661 --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c9f088b366ce56b972c6" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "87a1423bab22c3f8ddfe0bb20204f87072d0b97ddf89fd0854a5a218a972a9eb" + +[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-c9f088b366ce56b972c6/tests/expected.json b/tasks/cedar_authorization-c9f088b366ce56b972c6/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/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-c9f088b366ce56b972c6/tests/grading.py b/tasks/cedar_authorization-c9f088b366ce56b972c6/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/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-c9f088b366ce56b972c6/tests/test.sh b/tasks/cedar_authorization-c9f088b366ce56b972c6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/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-c9f088b366ce56b972c6/tests/verify.py b/tasks/cedar_authorization-c9f088b366ce56b972c6/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/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-c9f088b366ce56b972c6/validation/openenv.json b/tasks/cedar_authorization-c9f088b366ce56b972c6/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c9f088b366ce56b972c6/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-c9feb10bfbda6f9294ba/environment/Dockerfile b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-c9feb10bfbda6f9294ba/instruction.md b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5877cbddd2882d554d18b970578cc8d0e915c477 --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/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 in iYYYYYY4Z44444444::"", + action in [Action::"action",Action::"action"], + resource in iYYYYYY4Z44444444::"" +) when { + true && [[[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]], [[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]]].contains(if [[resource, resource], [resource, resource]].contains([resource, resource]) then if false then [[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]] else [[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]] else [[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]]) && (if false then {"": decimal("-441275054312267.7054")} else {"": decimal("-557019330853190.3822")})[""].lessThan(decimal("0.0")) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"O4444124"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Tqqqqqqqq"}},{"attrs":{},"parents":[{"id":"","type":"O4444124"},{"id":"","type":"Tqqqqqqqq"}],"uid":{"id":"","type":"iYYYYYY4Z44444444"}},{"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":"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::r3::r::_YlW3333333333"},"request":"R2","resource":{"id":"","type":"r::r::r3::r::_YlW3333333333"}} +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"iYYYYYY4Z44444444"},"request":"R3","resource":{"id":"","type":"r::r::r3::r::WMMMMM"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"iYYYYYY4Z44444444"},"request":"R4","resource":{"id":"","type":"iYYYYYY4Z44444444"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-c9feb10bfbda6f9294ba/solution/reference.json b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/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-c9feb10bfbda6f9294ba/solution/solve.sh b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-c9feb10bfbda6f9294ba/task.toml b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b7df6749676aeea7c4838b88a925a8ecc24b6340 --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-c9feb10bfbda6f9294ba" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "c33a04141203c6daa0ec8d6120b9583e5eb7a72c26e9cf04a324cabb0b04d46b" + +[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-c9feb10bfbda6f9294ba/tests/expected.json b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/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-c9feb10bfbda6f9294ba/tests/grading.py b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/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-c9feb10bfbda6f9294ba/tests/test.sh b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/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-c9feb10bfbda6f9294ba/tests/verify.py b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/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-c9feb10bfbda6f9294ba/validation/openenv.json b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-c9feb10bfbda6f9294ba/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-ca0fe120d73c6142f358/environment/Dockerfile b/tasks/cedar_authorization-ca0fe120d73c6142f358/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ca0fe120d73c6142f358/instruction.md b/tasks/cedar_authorization-ca0fe120d73c6142f358/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9567a3402465a347dbef71c48b66c732f64b9355 --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/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 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":"d0000k0::A::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::g31000000"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::wZ1g"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"d0000k0::A::Action"}},{"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":"d0000k0::A::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::wZ1g"},"request":"R1","resource":{"id":"","type":"r::r::r::r::wZ1g"}} +{"action":{"id":"action","type":"d0000k0::A::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":"","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":{},"principal":{"id":"","type":"d0000k0::A::a"},"request":"R4","resource":{"id":"","type":"r::r::r::r::wZ1g"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-ca0fe120d73c6142f358/solution/reference.json b/tasks/cedar_authorization-ca0fe120d73c6142f358/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/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-ca0fe120d73c6142f358/solution/solve.sh b/tasks/cedar_authorization-ca0fe120d73c6142f358/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ca0fe120d73c6142f358/task.toml b/tasks/cedar_authorization-ca0fe120d73c6142f358/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6fb05de9b81ee559fc1fda0301eaa873014f7165 --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ca0fe120d73c6142f358" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ac0330786d22fdaefb47a1bf29675beee5faeb2c2525fbd00fc375ab2f3da54b" + +[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-ca0fe120d73c6142f358/tests/expected.json b/tasks/cedar_authorization-ca0fe120d73c6142f358/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/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-ca0fe120d73c6142f358/tests/grading.py b/tasks/cedar_authorization-ca0fe120d73c6142f358/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/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-ca0fe120d73c6142f358/tests/test.sh b/tasks/cedar_authorization-ca0fe120d73c6142f358/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/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-ca0fe120d73c6142f358/tests/verify.py b/tasks/cedar_authorization-ca0fe120d73c6142f358/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/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-ca0fe120d73c6142f358/validation/openenv.json b/tasks/cedar_authorization-ca0fe120d73c6142f358/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ca0fe120d73c6142f358/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-ca5529549069d1f995ab/environment/Dockerfile b/tasks/cedar_authorization-ca5529549069d1f995ab/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ca5529549069d1f995ab/instruction.md b/tasks/cedar_authorization-ca5529549069d1f995ab/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..68f8b659c36645c571b66c519a4cb6c45773c8f6 --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/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::"3333333PP", + action == r::r::r::r::Action::"action", + resource == r::r::r::r::r::"3333333PP" +) when { + true && ({"": action}[""] in {"": action}[""]) +}; + +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":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{},"parents":[],"uid":{"id":"3333333PP","type":"r::r::r::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::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"3333333PP","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"3333333PP","type":"r::r::r::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":"R2","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":"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":"3333333PP","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-ca5529549069d1f995ab/solution/reference.json b/tasks/cedar_authorization-ca5529549069d1f995ab/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/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-ca5529549069d1f995ab/solution/solve.sh b/tasks/cedar_authorization-ca5529549069d1f995ab/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ca5529549069d1f995ab/task.toml b/tasks/cedar_authorization-ca5529549069d1f995ab/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0fb90b515ad4ae425735713f841f6350e946c7d4 --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ca5529549069d1f995ab" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "082c6e9e9e91aa944b7d54a8e89728400015a389bf07704c94491bec98e3bc90" + +[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-ca5529549069d1f995ab/tests/expected.json b/tasks/cedar_authorization-ca5529549069d1f995ab/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/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-ca5529549069d1f995ab/tests/grading.py b/tasks/cedar_authorization-ca5529549069d1f995ab/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/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-ca5529549069d1f995ab/tests/test.sh b/tasks/cedar_authorization-ca5529549069d1f995ab/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/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-ca5529549069d1f995ab/tests/verify.py b/tasks/cedar_authorization-ca5529549069d1f995ab/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/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-ca5529549069d1f995ab/validation/openenv.json b/tasks/cedar_authorization-ca5529549069d1f995ab/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ca5529549069d1f995ab/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-ca8b8531ebeba4de5dba/environment/Dockerfile b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ca8b8531ebeba4de5dba/instruction.md b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b3807dd13b344d34ea18a39de51e479baf761a36 --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/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::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::a"}},{"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":"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":"action","type":"r::r::r::r::Action"},"context":{},"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-ca8b8531ebeba4de5dba/solution/reference.json b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/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-ca8b8531ebeba4de5dba/solution/solve.sh b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ca8b8531ebeba4de5dba/task.toml b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fe8842823cd6133d8b1ed8d31796b50c43c51135 --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ca8b8531ebeba4de5dba" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "9b46d9146fee01b12e71bf1ed0af7c4a4c077d89a17c5b8786f69ab4600aa7ec" + +[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-ca8b8531ebeba4de5dba/tests/expected.json b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/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-ca8b8531ebeba4de5dba/tests/grading.py b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/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-ca8b8531ebeba4de5dba/tests/test.sh b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/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-ca8b8531ebeba4de5dba/tests/verify.py b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/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-ca8b8531ebeba4de5dba/validation/openenv.json b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ca8b8531ebeba4de5dba/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-caafb208a69f3149f490/environment/Dockerfile b/tasks/cedar_authorization-caafb208a69f3149f490/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-caafb208a69f3149f490/instruction.md b/tasks/cedar_authorization-caafb208a69f3149f490/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..97060d0569a9542425dbd8ef8da9f60b76e9eaa9 --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/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::"3333333PP", + action == r::r::r::r::Action::"action", + resource == r::r::r::r::r::"3333333PP" +) when { + true && ({"": action}[""] in {"": action}[""]) +}; + +policy1 +forbid( + principal == r::r::r::r::q::"", + action == r::r::r::r::Action::"action", + resource == r::r::r::r::q::"" +) when { + true && (if false then {"": ip("0.0.194.194")} else {"": ip("238.238.32.1")})[""].isMulticast() +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::h"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::n"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::h"}],"tags":{"":[[[[]]]]},"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"3333333PP","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":"3333333PP","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"3333333PP","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R2","resource":{"id":"3333333PP","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"3333333PP","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r::r::q"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R4","resource":{"id":"","type":"r::r::r::r::q"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-caafb208a69f3149f490/solution/reference.json b/tasks/cedar_authorization-caafb208a69f3149f490/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/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-caafb208a69f3149f490/solution/solve.sh b/tasks/cedar_authorization-caafb208a69f3149f490/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-caafb208a69f3149f490/task.toml b/tasks/cedar_authorization-caafb208a69f3149f490/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..10a21c44c0364e70434b4cdf7079802cbb0c07ae --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-caafb208a69f3149f490" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "1a327a34c65e0dda9e57e8585460a99f2390aded48873371b0e1b9dd742733e6" + +[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-caafb208a69f3149f490/tests/expected.json b/tasks/cedar_authorization-caafb208a69f3149f490/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/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-caafb208a69f3149f490/tests/grading.py b/tasks/cedar_authorization-caafb208a69f3149f490/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/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-caafb208a69f3149f490/tests/test.sh b/tasks/cedar_authorization-caafb208a69f3149f490/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/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-caafb208a69f3149f490/tests/verify.py b/tasks/cedar_authorization-caafb208a69f3149f490/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/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-caafb208a69f3149f490/validation/openenv.json b/tasks/cedar_authorization-caafb208a69f3149f490/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-caafb208a69f3149f490/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-cadf7a4476859709c969/environment/Dockerfile b/tasks/cedar_authorization-cadf7a4476859709c969/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cadf7a4476859709c969/instruction.md b/tasks/cedar_authorization-cadf7a4476859709c969/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6b2acf9386f243be8b0dd9f445a216edc1c74ffb --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/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 == 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":{},"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":"action","type":"r::r33::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":{"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":"|||||||","type":"r::r33::r::r::r333333311"},"request":"R1","resource":{"id":"|||||||","type":"r::r33::r::r::r333333311"}} +{"action":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::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":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"},"request":"R2","resource":{"id":"|||||||","type":"r::r33::r::r::r333333311"}} +{"action":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::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":"|||||||","type":"r::r33::r::r::r333333311"},"request":"R3","resource":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"}} +{"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":"R4","resource":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cadf7a4476859709c969/solution/reference.json b/tasks/cedar_authorization-cadf7a4476859709c969/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/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-cadf7a4476859709c969/solution/solve.sh b/tasks/cedar_authorization-cadf7a4476859709c969/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cadf7a4476859709c969/task.toml b/tasks/cedar_authorization-cadf7a4476859709c969/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..516d5f7571ebfbe8d1b03038bfb7dcd26acf70b9 --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cadf7a4476859709c969" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "9374da5da688b7397e5c7cd088f6c4d185973b4b8f00131855bad26f52a6e5c8" + +[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-cadf7a4476859709c969/tests/expected.json b/tasks/cedar_authorization-cadf7a4476859709c969/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/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-cadf7a4476859709c969/tests/grading.py b/tasks/cedar_authorization-cadf7a4476859709c969/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/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-cadf7a4476859709c969/tests/test.sh b/tasks/cedar_authorization-cadf7a4476859709c969/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/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-cadf7a4476859709c969/tests/verify.py b/tasks/cedar_authorization-cadf7a4476859709c969/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/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-cadf7a4476859709c969/validation/openenv.json b/tasks/cedar_authorization-cadf7a4476859709c969/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cadf7a4476859709c969/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-cb5dfd79eb7a5218249b/environment/Dockerfile b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cb5dfd79eb7a5218249b/instruction.md b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fdc3f1957c0c9f1bd109fe85a51ee568c3884214 --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/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 Knnn3h00105cZWg3l::rF333333Y3333::r::r::V, + action == Knnn3h00105cZWg3l::rF333333Y3333::r::r::Action::"action", + resource is Knnn3h00105cZWg3l::rF333333Y3333::r::r::V +) when { + true && ((principal in principal) || (principal in principal)) && (principal in principal) && (principal in principal) +}; + +policy1 +forbid( + principal, + action in [q::r::r::A33333333333333::Action::""], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::w"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A33333333333333::Action"}},{"attrs":{},"parents":[{"id":">","type":"q::r::r::A33333333333333::r"}],"uid":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A33333333333333::r"}},{"attrs":{},"parents":[],"uid":{"id":">","type":"q::r::r::A33333333333333::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::Action"}}] + +Requests +{"action":{"id":"","type":"q::r::r::A33333333333333::Action"},"context":{},"principal":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"},"request":"R1","resource":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"}} +{"action":{"id":"action","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::Action"},"context":{},"principal":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"},"request":"R2","resource":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"}} +{"action":{"id":"action","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::Action"},"context":{},"principal":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"},"request":"R3","resource":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"}} +{"action":{"id":"","type":"q::r::r::A33333333333333::Action"},"context":{"Zwwwwwwwwwwwwww":false,"r":{"":{"__entity":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"}}}},"principal":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"},"request":"R4","resource":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cb5dfd79eb7a5218249b/solution/reference.json b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..644bd01431fddb1b9602e4c5e73687ac6afefb3f --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/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-cb5dfd79eb7a5218249b/solution/solve.sh b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cb5dfd79eb7a5218249b/task.toml b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e04d0174cf6a9857e4675b9b58efe9300bb58159 --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cb5dfd79eb7a5218249b" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "5b849fe5632e66b70d9c6d7090e507f2abe722cb5efcd1c07f15c71588577abd" + +[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-cb5dfd79eb7a5218249b/tests/expected.json b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..644bd01431fddb1b9602e4c5e73687ac6afefb3f --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/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-cb5dfd79eb7a5218249b/tests/grading.py b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/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-cb5dfd79eb7a5218249b/tests/test.sh b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/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-cb5dfd79eb7a5218249b/tests/verify.py b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/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-cb5dfd79eb7a5218249b/validation/openenv.json b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cb5dfd79eb7a5218249b/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-cb7ee499a0a72734e267/environment/Dockerfile b/tasks/cedar_authorization-cb7ee499a0a72734e267/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cb7ee499a0a72734e267/instruction.md b/tasks/cedar_authorization-cb7ee499a0a72734e267/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0fff1c9f1e9519afbc602c5a10f1174d6427fe26 --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/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 _Yl10999999999::"<===", + action in [Action::""], + resource +) when { + true && (if if "33333" like "" then decimal("--33322776644779955008800441177..22009944").lessThan(decimal("-332764795055152.6959")) else [ip("2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b/43"), ip("2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b/43"), ip("194.194.194.194")].containsAll([datetime("5534-04-08T15:15:15.427+0015").offset(duration("-59393h2248146945m1s1ms")), datetime("7219-08-08T15:15:07.347+0015").offset(duration("0h")), datetime("2827-12-12T11:11:11.827+1111")]) then !(!true) else !(!true)) +}; + +Entities +[{"attrs":{},"parents":[{"id":"000000000000000e","type":"Action"}],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"_Yl10999999999"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"000000000000000e","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"<===","type":"_Yl10999999999"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"<===","type":"_Yl10999999999"},"request":"R1","resource":{"id":"","type":"_Yl10999999999"}} +{"action":{"id":"000000000000000e","type":"Action"},"context":{},"principal":{"id":"","type":"_Yl10999999999"},"request":"R2","resource":{"id":"<===","type":"_Yl10999999999"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"_Yl10999999999"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"<===","type":"_Yl10999999999"},"request":"R4","resource":{"id":"","type":"_Yl10999999999"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cb7ee499a0a72734e267/solution/reference.json b/tasks/cedar_authorization-cb7ee499a0a72734e267/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..5907ea08f4c3472da019908a4e34c1917cfaf662 --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-cb7ee499a0a72734e267/solution/solve.sh b/tasks/cedar_authorization-cb7ee499a0a72734e267/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cb7ee499a0a72734e267/task.toml b/tasks/cedar_authorization-cb7ee499a0a72734e267/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3a0217f44efab64297d9e6244a7c28ce24177ab6 --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cb7ee499a0a72734e267" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "6e70825a7a7433ac217522d6267faba136dd04e5531c6e375844d6c8a839fab4" + +[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-cb7ee499a0a72734e267/tests/expected.json b/tasks/cedar_authorization-cb7ee499a0a72734e267/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..5907ea08f4c3472da019908a4e34c1917cfaf662 --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-cb7ee499a0a72734e267/tests/grading.py b/tasks/cedar_authorization-cb7ee499a0a72734e267/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/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-cb7ee499a0a72734e267/tests/test.sh b/tasks/cedar_authorization-cb7ee499a0a72734e267/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/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-cb7ee499a0a72734e267/tests/verify.py b/tasks/cedar_authorization-cb7ee499a0a72734e267/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/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-cb7ee499a0a72734e267/validation/openenv.json b/tasks/cedar_authorization-cb7ee499a0a72734e267/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cb7ee499a0a72734e267/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-cba90974c01b83f8d28e/environment/Dockerfile b/tasks/cedar_authorization-cba90974c01b83f8d28e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cba90974c01b83f8d28e/instruction.md b/tasks/cedar_authorization-cba90974c01b83f8d28e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b0679db1a0ca086e7d925d2a45fd0b8f8932aa8d --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/instruction.md @@ -0,0 +1,22 @@ +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::fg::"", + action in [r::r::r3w333333::r::Action::"action"], + resource == r::r::r3w333333::r::r::"" +) when { + true && [context, context].contains(context) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3w333333::r::r"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r3w333333::r::r"}],"uid":{"id":"","type":"r::r::r3w333333::r::fg"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r3w333333::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r3w333333::r::Action"},"context":{"DEkkgkkk":false,"DkkkkkMM":{"__extn":{"arg":"0.0","fn":"decimal"}}},"principal":{"id":"","type":"r::r::r3w333333::r::fg"},"request":"R1","resource":{"id":"","type":"r::r::r3w333333::r::r"}} +{"action":{"id":"action","type":"r::r::r3w333333::r::Action"},"context":{"DEkkgkkk":true},"principal":{"id":"","type":"r::r::r3w333333::r::r"},"request":"R2","resource":{"id":"","type":"r::r::r3w333333::r::r"}} +{"action":{"id":"action","type":"r::r::r3w333333::r::Action"},"context":{"DEkkgkkk":false,"DkkkkkMM":{"__extn":{"arg":"159148380243768.6806","fn":"decimal"}}},"principal":{"id":"","type":"r::r::r3w333333::r::fg"},"request":"R3","resource":{"id":"","type":"r::r::r3w333333::r::r"}} +{"action":{"id":"action","type":"r::r::r3w333333::r::Action"},"context":{"DEkkgkkk":true,"DkkkkkMM":{"__extn":{"arg":"-231501136668085.4528","fn":"decimal"}}},"principal":{"id":"","type":"r::r::r3w333333::r::r"},"request":"R4","resource":{"id":"","type":"r::r::r3w333333::r::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cba90974c01b83f8d28e/solution/reference.json b/tasks/cedar_authorization-cba90974c01b83f8d28e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..c664fbfd678c2b71191af574f122e0748c1cb8f9 --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-cba90974c01b83f8d28e/solution/solve.sh b/tasks/cedar_authorization-cba90974c01b83f8d28e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cba90974c01b83f8d28e/task.toml b/tasks/cedar_authorization-cba90974c01b83f8d28e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0e2ebbcd119040c06514155c643720ae2c44f803 --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cba90974c01b83f8d28e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "2990bf596e680827c725d182404a16581584df8f6ca54bfb646e22a9f2eba63b" + +[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-cba90974c01b83f8d28e/tests/expected.json b/tasks/cedar_authorization-cba90974c01b83f8d28e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..c664fbfd678c2b71191af574f122e0748c1cb8f9 --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-cba90974c01b83f8d28e/tests/grading.py b/tasks/cedar_authorization-cba90974c01b83f8d28e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/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-cba90974c01b83f8d28e/tests/test.sh b/tasks/cedar_authorization-cba90974c01b83f8d28e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/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-cba90974c01b83f8d28e/tests/verify.py b/tasks/cedar_authorization-cba90974c01b83f8d28e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/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-cba90974c01b83f8d28e/validation/openenv.json b/tasks/cedar_authorization-cba90974c01b83f8d28e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cba90974c01b83f8d28e/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-cbbd900c2efca31c2e4e/environment/Dockerfile b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cbbd900c2efca31c2e4e/instruction.md b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..53ddd1873ea5dd501106470f9d6892d2b7a38e03 --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/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::fg::"", + action in [r::r::r3w333333::r::Action::"action"], + resource == r::r::r3w333333::r::r::"" +) when { + true && [context, context].contains(context) +}; + +policy1 +forbid( + principal in T::r::r::r::r3::"", + action in [T::r::r::r::Action::"action",T::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"T::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"T::r::r::r::r3"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"T::r::r::r::uG"}},{"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":"action","type":"T::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r3w333333::r::Action"}}] + +Requests +{"action":{"id":"action","type":"T::r::r::r::Action"},"context":{"CZZZZZZ33":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"CZZZZZZZZ":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"IzzzzTTTCpm":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44444444444":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44p44444333zzzzz":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"r::r::r3w333333::r::fg"},"request":"R1","resource":{"id":"","type":"T::r::r::r::uG"}} +{"action":{"id":"action","type":"r::r::r3w333333::r::Action"},"context":{"DEkkgkkk":false,"DkkkkkMM":{"__extn":{"arg":"0.0","fn":"decimal"}}},"principal":{"id":"","type":"r::r::r3w333333::r::fg"},"request":"R2","resource":{"id":"","type":"r::r::r3w333333::r::r"}} +{"action":{"id":"action","type":"r::r::r3w333333::r::Action"},"context":{"DEkkgkkk":true},"principal":{"id":"","type":"r::r::r3w333333::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r3w333333::r::r"}} +{"action":{"id":"action","type":"T::r::r::r::Action"},"context":{"CZZZZZZ33":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"CZZZZZZZZ":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"IzzzzTTTCpm":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44444444444":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44p44444333zzzzz":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"T::r::r::r::r3"},"request":"R4","resource":{"id":"","type":"T::r::r::r::uG"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cbbd900c2efca31c2e4e/solution/reference.json b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/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-cbbd900c2efca31c2e4e/solution/solve.sh b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cbbd900c2efca31c2e4e/task.toml b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b1546210a62acf27942eaf7af9e614ba75a133e3 --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cbbd900c2efca31c2e4e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "94d2b6aa12a0914816df5bed089029791af0b929e2a355411f19ae3cac2d7c60" + +[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-cbbd900c2efca31c2e4e/tests/expected.json b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/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-cbbd900c2efca31c2e4e/tests/grading.py b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/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-cbbd900c2efca31c2e4e/tests/test.sh b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/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-cbbd900c2efca31c2e4e/tests/verify.py b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/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-cbbd900c2efca31c2e4e/validation/openenv.json b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cbbd900c2efca31c2e4e/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-cbc1203b525eae19d4f2/environment/Dockerfile b/tasks/cedar_authorization-cbc1203b525eae19d4f2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cbc1203b525eae19d4f2/instruction.md b/tasks/cedar_authorization-cbc1203b525eae19d4f2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9c1ea08c786de1915379e8dc656886edc4eb51f2 --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/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*3*10*" then {"": action} has n99999qqqqqq.dqQ0.dqqq else action in r::r::r3::r::jwwwwwwwwwwwwwwww::"" then {"": action}[""] in {"": action}[""] else {"": action}[""] in {"": action}[""]) && ({"": action}[""] in {"": action}[""]) +}; + +policy1 +forbid( + principal is mSSSSSS, + action == Action::"action", + resource == LYY::"" +) when { + true +}; + +Entities +[{"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":[{"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":"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::_YlW3333333333"},"request":"R1","resource":{"id":"","type":"r::r::r3::r::jwwwwwwwww"}} +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3::r::WMMMMM"},"request":"R2","resource":{"id":"","type":"r::r::r3::r::WMMMMM"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R3","resource":{"id":"","type":"LYY"}} +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R4","resource":{"id":"","type":"r::r::r3::r::WMMMMM"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cbc1203b525eae19d4f2/solution/reference.json b/tasks/cedar_authorization-cbc1203b525eae19d4f2/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/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-cbc1203b525eae19d4f2/solution/solve.sh b/tasks/cedar_authorization-cbc1203b525eae19d4f2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cbc1203b525eae19d4f2/task.toml b/tasks/cedar_authorization-cbc1203b525eae19d4f2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..28578e9189fd577fe635810fa7b0e1a266562962 --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cbc1203b525eae19d4f2" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "61e91549545964bd2cf2524936848c6c9cda3527a02767a46197567cc9358358" + +[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-cbc1203b525eae19d4f2/tests/expected.json b/tasks/cedar_authorization-cbc1203b525eae19d4f2/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/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-cbc1203b525eae19d4f2/tests/grading.py b/tasks/cedar_authorization-cbc1203b525eae19d4f2/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/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-cbc1203b525eae19d4f2/tests/test.sh b/tasks/cedar_authorization-cbc1203b525eae19d4f2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/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-cbc1203b525eae19d4f2/tests/verify.py b/tasks/cedar_authorization-cbc1203b525eae19d4f2/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/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-cbc1203b525eae19d4f2/validation/openenv.json b/tasks/cedar_authorization-cbc1203b525eae19d4f2/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cbc1203b525eae19d4f2/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-cc2252d5aff119aa67bd/environment/Dockerfile b/tasks/cedar_authorization-cc2252d5aff119aa67bd/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cc2252d5aff119aa67bd/instruction.md b/tasks/cedar_authorization-cc2252d5aff119aa67bd/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..33c04b706b4086858bf6f8a71ce6c9ebc49ef155 --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/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::ERRRRRRRRRRRR::r::a::"", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::j55555555::"", + action in [r::r::r::r::Action::"action"], + resource == r::r::r::r::j55555555::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::j55555555"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"tags":{"":{"__entity":{"id":"","type":"r::r::r::r::r"}}},"uid":{"id":"","type":"r::r::r::r::r333"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::Action"},"context":{"r":"g"},"principal":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"},"request":"R1","resource":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"},"request":"R2","resource":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"}} +{"action":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"request":"R3","resource":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"request":"R4","resource":{"id":"","type":"r::r::r::r::j55555555"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cc2252d5aff119aa67bd/solution/reference.json b/tasks/cedar_authorization-cc2252d5aff119aa67bd/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d3d473e0a7deae2956a2473d224ea927c3732496 --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/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-cc2252d5aff119aa67bd/solution/solve.sh b/tasks/cedar_authorization-cc2252d5aff119aa67bd/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cc2252d5aff119aa67bd/task.toml b/tasks/cedar_authorization-cc2252d5aff119aa67bd/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3bfa491c27a0ee15e6e403a37986a0c7fcf95d00 --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cc2252d5aff119aa67bd" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "9b67adc7cc1c5cad91b517006e49376e9028d734c1701e97df1cd21bbff8d9bb" + +[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-cc2252d5aff119aa67bd/tests/expected.json b/tasks/cedar_authorization-cc2252d5aff119aa67bd/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d3d473e0a7deae2956a2473d224ea927c3732496 --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/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-cc2252d5aff119aa67bd/tests/grading.py b/tasks/cedar_authorization-cc2252d5aff119aa67bd/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/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-cc2252d5aff119aa67bd/tests/test.sh b/tasks/cedar_authorization-cc2252d5aff119aa67bd/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/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-cc2252d5aff119aa67bd/tests/verify.py b/tasks/cedar_authorization-cc2252d5aff119aa67bd/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/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-cc2252d5aff119aa67bd/validation/openenv.json b/tasks/cedar_authorization-cc2252d5aff119aa67bd/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cc2252d5aff119aa67bd/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-cc97e1626dbb084f44a8/environment/Dockerfile b/tasks/cedar_authorization-cc97e1626dbb084f44a8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cc97e1626dbb084f44a8/instruction.md b/tasks/cedar_authorization-cc97e1626dbb084f44a8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ed3a595d1f230dfcda54065cc86cc003dc6217a8 --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/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 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":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{"r":{"__entity":{"id":"","type":"r"}}},"parents":[],"uid":{"id":"","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":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"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-cc97e1626dbb084f44a8/solution/reference.json b/tasks/cedar_authorization-cc97e1626dbb084f44a8/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/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-cc97e1626dbb084f44a8/solution/solve.sh b/tasks/cedar_authorization-cc97e1626dbb084f44a8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cc97e1626dbb084f44a8/task.toml b/tasks/cedar_authorization-cc97e1626dbb084f44a8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fb8c24de5eb312ba6b570c5488fa5659d67cad8c --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cc97e1626dbb084f44a8" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "09adc1505d2f381a00dc9294c90f294acfb74fa20d629f1fec5756d8cc56f918" + +[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-cc97e1626dbb084f44a8/tests/expected.json b/tasks/cedar_authorization-cc97e1626dbb084f44a8/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/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-cc97e1626dbb084f44a8/tests/grading.py b/tasks/cedar_authorization-cc97e1626dbb084f44a8/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/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-cc97e1626dbb084f44a8/tests/test.sh b/tasks/cedar_authorization-cc97e1626dbb084f44a8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/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-cc97e1626dbb084f44a8/tests/verify.py b/tasks/cedar_authorization-cc97e1626dbb084f44a8/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/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-cc97e1626dbb084f44a8/validation/openenv.json b/tasks/cedar_authorization-cc97e1626dbb084f44a8/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cc97e1626dbb084f44a8/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-ccf8c14ab7c968bda4d4/environment/Dockerfile b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/instruction.md b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cf3a2daa122c462c107b180dceba18a14b338fa3 --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/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 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":"QxxO0xxxxxxxxxx::a"}},{"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":"QxxO0xxxxxxxxxx::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":"QxxO0xxxxxxxxxx::a"},"request":"R1","resource":{"id":"","type":"QxxO0xxxxxxxxxx::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::m"},"request":"R2","resource":{"id":"","type":"QxxO0xxxxxxxxxx::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::m"},"request":"R3","resource":{"id":"","type":"r::r::r::r::m"}} +{"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-ccf8c14ab7c968bda4d4/solution/reference.json b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a02a773956337c2871158a2450ef0fc830a4d908 --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/solution/solve.sh b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/task.toml b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fd716e258120eee1d84eb6ebad98f1f7d0cdcc40 --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ccf8c14ab7c968bda4d4" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "63beb1b668b4afcbf66c652d42a6d5f42af7233b4e0520b1c19df35afa40fb51" + +[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-ccf8c14ab7c968bda4d4/tests/expected.json b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a02a773956337c2871158a2450ef0fc830a4d908 --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/tests/grading.py b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/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-ccf8c14ab7c968bda4d4/tests/test.sh b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/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-ccf8c14ab7c968bda4d4/tests/verify.py b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/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-ccf8c14ab7c968bda4d4/validation/openenv.json b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ccf8c14ab7c968bda4d4/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-cd358bfa6c3d295b3390/environment/Dockerfile b/tasks/cedar_authorization-cd358bfa6c3d295b3390/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cd358bfa6c3d295b3390/instruction.md b/tasks/cedar_authorization-cd358bfa6c3d295b3390/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..29f206d1c95592cefcb98f5bb386565c6da80706 --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/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 A100120000000040::A::B::a::"", + action == A100120000000040::A::B::Action::"action", + resource in A100120000000040::A::B::a::"" +) when { + true && (A100120000000040::A::B::a::"" in A100120000000040::A::B::a::"") && (A100120000000040::A::B::a::"" in A100120000000040::A::B::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":"A100120000000040::A::B::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":"A100120000000040::A::B::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"A100120000000040::A::B::Action"},"context":{},"principal":{"id":"","type":"A100120000000040::A::B::a"},"request":"R1","resource":{"id":"","type":"A100120000000040::A::B::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"A100120000000040::A::B::Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"A100120000000040::A::B::Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R4","resource":{"id":"","type":"A100120000000040::A::B::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cd358bfa6c3d295b3390/solution/reference.json b/tasks/cedar_authorization-cd358bfa6c3d295b3390/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/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-cd358bfa6c3d295b3390/solution/solve.sh b/tasks/cedar_authorization-cd358bfa6c3d295b3390/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cd358bfa6c3d295b3390/task.toml b/tasks/cedar_authorization-cd358bfa6c3d295b3390/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8fbf030c950e6ee680c81518de35a22b08658e07 --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cd358bfa6c3d295b3390" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "865cedb3716bf4805a0af97086b49520a749fb55d991b3b882d42095bcdc31e6" + +[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-cd358bfa6c3d295b3390/tests/expected.json b/tasks/cedar_authorization-cd358bfa6c3d295b3390/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/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-cd358bfa6c3d295b3390/tests/grading.py b/tasks/cedar_authorization-cd358bfa6c3d295b3390/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/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-cd358bfa6c3d295b3390/tests/test.sh b/tasks/cedar_authorization-cd358bfa6c3d295b3390/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/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-cd358bfa6c3d295b3390/tests/verify.py b/tasks/cedar_authorization-cd358bfa6c3d295b3390/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/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-cd358bfa6c3d295b3390/validation/openenv.json b/tasks/cedar_authorization-cd358bfa6c3d295b3390/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cd358bfa6c3d295b3390/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-cdc6cde6ec5882b44d9f/environment/Dockerfile b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/instruction.md b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1fe2416c14f0f20971acc5120beeec9447f916e2 --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/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::A::A::A::A::A::A::A::A::a in A::A::A::A::A::A::A::A::A::a::"", + action in [A::A::A::A::A::A::A::A::A::Action::"action"], + resource is A::A::A::A::A::A::A::A::A::a in A::A::A::A::A::A::A::A::A::a::"" +) when { + true && (true || (false || ("HHHHH" == ""))) +}; + +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":"r::r::r::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::A::A::A::A::A::A::A::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::a"}} +{"action":{"id":"action","type":"A::A::A::A::A::A::A::A::A::Action"},"context":{},"principal":{"id":"","type":"A::A::A::A::A::A::A::A::A::a"},"request":"R2","resource":{"id":"","type":"A::A::A::A::A::A::A::A::A::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"=","type":"r::r::r::r::a"},"request":"R3","resource":{"id":"=","type":"r::r::r::r::a"}} +{"action":{"id":"action","type":"A::A::A::A::A::A::A::A::A::Action"},"context":{},"principal":{"id":"=","type":"r::r::r::r::a"},"request":"R4","resource":{"id":"","type":"A::A::A::A::A::A::A::A::A::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/solution/reference.json b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/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-cdc6cde6ec5882b44d9f/solution/solve.sh b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/task.toml b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..877e928b6c222487ab5a2c84e0d41b02492016d5 --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cdc6cde6ec5882b44d9f" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "a664202b1e05e7378218339344db33925cccf6ba0bebbb8bf7ca608ade292fe4" + +[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-cdc6cde6ec5882b44d9f/tests/expected.json b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/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-cdc6cde6ec5882b44d9f/tests/grading.py b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/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-cdc6cde6ec5882b44d9f/tests/test.sh b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/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-cdc6cde6ec5882b44d9f/tests/verify.py b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/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-cdc6cde6ec5882b44d9f/validation/openenv.json b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cdc6cde6ec5882b44d9f/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-cdd85504f640ab930f94/environment/Dockerfile b/tasks/cedar_authorization-cdd85504f640ab930f94/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cdd85504f640ab930f94/instruction.md b/tasks/cedar_authorization-cdd85504f640ab930f94/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd33e3ab0a14c2bb8884670b8e24fa7245d0d396 --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/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 == PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEEEEEEEEEE::"", + action in [PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action::"action",PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action::"action",PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action::"action"], + resource +) when { + true +}; + +policy1 +forbid( + principal in a::"", + action, + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::dEEEEEEEEE"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEEEEEEEEEE"},"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":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"},"context":{},"principal":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEEEEEEEEEE"},"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-cdd85504f640ab930f94/solution/reference.json b/tasks/cedar_authorization-cdd85504f640ab930f94/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..9ba662580593b53e31a67a8f8f693a2629cbddd7 --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/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-cdd85504f640ab930f94/solution/solve.sh b/tasks/cedar_authorization-cdd85504f640ab930f94/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cdd85504f640ab930f94/task.toml b/tasks/cedar_authorization-cdd85504f640ab930f94/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fe065f87b73336b8d206ed55047218ef88b8bdf4 --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cdd85504f640ab930f94" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b6e526bf60cf82c11f2c4a9e6478413af11c785dc7c1ff63ede835373a930bf3" + +[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-cdd85504f640ab930f94/tests/expected.json b/tasks/cedar_authorization-cdd85504f640ab930f94/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..9ba662580593b53e31a67a8f8f693a2629cbddd7 --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/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-cdd85504f640ab930f94/tests/grading.py b/tasks/cedar_authorization-cdd85504f640ab930f94/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/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-cdd85504f640ab930f94/tests/test.sh b/tasks/cedar_authorization-cdd85504f640ab930f94/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/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-cdd85504f640ab930f94/tests/verify.py b/tasks/cedar_authorization-cdd85504f640ab930f94/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/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-cdd85504f640ab930f94/validation/openenv.json b/tasks/cedar_authorization-cdd85504f640ab930f94/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cdd85504f640ab930f94/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-cdf6dab8513c217fac80/environment/Dockerfile b/tasks/cedar_authorization-cdf6dab8513c217fac80/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cdf6dab8513c217fac80/instruction.md b/tasks/cedar_authorization-cdf6dab8513c217fac80/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..000836e4cb589b81b8436d6fdf5346c685cb8737 --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/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 == G::u::A::_qqqqqqqqqqp::a::"", + action in [G::u::A::_qqqqqqqqqqp::Action::"action"], + resource is G::u::A::_qqqqqqqqqqp::a in G::u::A::_qqqqqqqqqqp::a::"" +) when { + true && ((-1736164148113840153) <= (-1736164148113840153)) && ((-1736164148113840153) <= (-1736164148113840153)) && ((-1736164148113840153) <= 2522015791327471591) +}; + +policy1 +forbid( + principal is l, + action == Action::"action", + resource is l +) when { + true && ([ip("ffff:a20:6e61:693b:dfdf:dfdf:dfdf:dfdf"), ip("ffff:ffff:ffff:fff:ffff:ffff:2dff:feff/126"), ip("160.160.160.160/25")].containsAny([]) || (principal in principal) || (resource in resource)) && (resource in resource) && (resource in resource) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"G::u::A::_qqqqqqqqqqp::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":"G::u::A::_qqqqqqqqqqp::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"B":"","r":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"r3":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"l"},"request":"R1","resource":{"id":"","type":"l"}} +{"action":{"id":"action","type":"Action"},"context":{"B":"","r":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"r3":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"G::u::A::_qqqqqqqqqqp::Action"},"context":{},"principal":{"id":"","type":"G::u::A::_qqqqqqqqqqp::a"},"request":"R3","resource":{"id":"","type":"G::u::A::_qqqqqqqqqqp::a"}} +{"action":{"id":"action","type":"G::u::A::_qqqqqqqqqqp::Action"},"context":{"B":"","r":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"r3":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"l"},"request":"R4","resource":{"id":"","type":"l"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-cdf6dab8513c217fac80/solution/reference.json b/tasks/cedar_authorization-cdf6dab8513c217fac80/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..ecc7429c3aab3dbfe2a2125625275d7b1455c87a --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-cdf6dab8513c217fac80/solution/solve.sh b/tasks/cedar_authorization-cdf6dab8513c217fac80/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cdf6dab8513c217fac80/task.toml b/tasks/cedar_authorization-cdf6dab8513c217fac80/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f14262801d5236c4aa8c28645511344f7397e3ce --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cdf6dab8513c217fac80" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b6d5688853f659f4add44228664100f13a0614f46146bfe1a834fc9029e6e15c" + +[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-cdf6dab8513c217fac80/tests/expected.json b/tasks/cedar_authorization-cdf6dab8513c217fac80/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..ecc7429c3aab3dbfe2a2125625275d7b1455c87a --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-cdf6dab8513c217fac80/tests/grading.py b/tasks/cedar_authorization-cdf6dab8513c217fac80/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/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-cdf6dab8513c217fac80/tests/test.sh b/tasks/cedar_authorization-cdf6dab8513c217fac80/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/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-cdf6dab8513c217fac80/tests/verify.py b/tasks/cedar_authorization-cdf6dab8513c217fac80/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/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-cdf6dab8513c217fac80/validation/openenv.json b/tasks/cedar_authorization-cdf6dab8513c217fac80/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cdf6dab8513c217fac80/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-ce6f902c4f8571bdcf3e/environment/Dockerfile b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/instruction.md b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..deecd61e0782698a996dc721fb34507a522ccd62 --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/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 in rXXXXXXXXXXXXX::"````````" +) when { + true && (if if if false then false else false then if false then false else false else {"": ""} == {"": ""} then {"": {"": ""}} == {"": {"": ""}} else {"": {"": ""}} == {"": {"": ""}}) && (context == context) +}; + +policy1 +forbid( + principal in T::r::r::r::r3::"", + action in [T::r::r::r::Action::"action",T::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"T::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"T::r::r::r::r3"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"T::r::r::r::uG"}},{"attrs":{},"parents":[],"uid":{"id":"````````","type":"rXXXXXXXXXXXXX"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"T::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"T::r::r::r::r3"},"request":"R1","resource":{"id":"````````","type":"rXXXXXXXXXXXXX"}} +{"action":{"id":"action","type":"T::r::r::r::Action"},"context":{},"principal":{"id":"","type":"T::r::r::r::r3"},"request":"R2","resource":{"id":"","type":"T::r::r::r::uG"}} +{"action":{"id":"action","type":"Action"},"context":{"CZZZZZZ33":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"CZZZZZZZZ":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"IzzzzTTTCpm":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44444444444":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44p44444333zzzzz":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"T::r::r::r::r3"},"request":"R3","resource":{"id":"","type":"T::r::r::r::uG"}} +{"action":{"id":"action","type":"T::r::r::r::Action"},"context":{"CZZZZZZ33":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"CZZZZZZZZ":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"IzzzzTTTCpm":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44444444444":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44p44444333zzzzz":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"T::r::r::r::r3"},"request":"R4","resource":{"id":"","type":"T::r::r::r::uG"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/solution/reference.json b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..788dc0ce9427ef5c9a9bcdeaa163a57097821748 --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/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-ce6f902c4f8571bdcf3e/solution/solve.sh b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/task.toml b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fd44628b2217faba2e5694d55b771a36e5fb474c --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ce6f902c4f8571bdcf3e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "87f1b81b132cb2d4fb844064f08d308d1017ed424060f50deb4d7795e36badc9" + +[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-ce6f902c4f8571bdcf3e/tests/expected.json b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..788dc0ce9427ef5c9a9bcdeaa163a57097821748 --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/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-ce6f902c4f8571bdcf3e/tests/grading.py b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/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-ce6f902c4f8571bdcf3e/tests/test.sh b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/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-ce6f902c4f8571bdcf3e/tests/verify.py b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/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-ce6f902c4f8571bdcf3e/validation/openenv.json b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ce6f902c4f8571bdcf3e/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-ceef9aa3d3635029cb5e/environment/Dockerfile b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ceef9aa3d3635029cb5e/instruction.md b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1c360f1d114fe5b13eb9b7487afa13574402e320 --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/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::"yyyyyyyyyyyyyyyye" has r) && (r::"yyyyyyyyyyyyyyyye" has r) && (r::"yyyyyyyyyyyyyyyye".r has r) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"QxxO0xxxxxxxxxx::a"}},{"attrs":{"r":{"__entity":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"}},{"attrs":{"r":{"__entity":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}},"parents":[],"uid":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"QxxO0xxxxxxxxxx::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":"QxxO0xxxxxxxxxx::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-ceef9aa3d3635029cb5e/solution/reference.json b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..71c6642e43a201e0274d8a8eec52b73ac1282893 --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"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-ceef9aa3d3635029cb5e/solution/solve.sh b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ceef9aa3d3635029cb5e/task.toml b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0fa03137098cf4fa6c47433deb5c24bf02d17135 --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ceef9aa3d3635029cb5e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "e0a63a33a3cc4afc7f8c7f70a30f1b8b8d624d82b1c5c6bd68b521492d7452d7" + +[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-ceef9aa3d3635029cb5e/tests/expected.json b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..71c6642e43a201e0274d8a8eec52b73ac1282893 --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"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-ceef9aa3d3635029cb5e/tests/grading.py b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/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-ceef9aa3d3635029cb5e/tests/test.sh b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/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-ceef9aa3d3635029cb5e/tests/verify.py b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/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-ceef9aa3d3635029cb5e/validation/openenv.json b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ceef9aa3d3635029cb5e/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-ceefe97b2ff20c48e7c1/environment/Dockerfile b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/instruction.md b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..109b84362ae422d8a7bf3eff18f427ac70b549ca --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/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 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 "|**|*|***") +}; + +Entities +[{"attrs":{"A0":"||||||||||||||~|"},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::wZgY"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"r::r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::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":{},"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-ceefe97b2ff20c48e7c1/solution/reference.json b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4641d1db584c9d6c16920bace3830201b8a946be --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/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-ceefe97b2ff20c48e7c1/solution/solve.sh b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/task.toml b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a1d18de195a7d1b4709800ab5e0ae41465cda3f7 --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ceefe97b2ff20c48e7c1" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "861ef24fcd226385d8b01f01fcba660457a43e98c67b68f20af683311abcbca7" + +[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-ceefe97b2ff20c48e7c1/tests/expected.json b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4641d1db584c9d6c16920bace3830201b8a946be --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/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-ceefe97b2ff20c48e7c1/tests/grading.py b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/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-ceefe97b2ff20c48e7c1/tests/test.sh b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/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-ceefe97b2ff20c48e7c1/tests/verify.py b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/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-ceefe97b2ff20c48e7c1/validation/openenv.json b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ceefe97b2ff20c48e7c1/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-cff7a407627177f76037/environment/Dockerfile b/tasks/cedar_authorization-cff7a407627177f76037/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-cff7a407627177f76037/instruction.md b/tasks/cedar_authorization-cff7a407627177f76037/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2842424426aabb3ec88fe7f09bf2c88f6d46f229 --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/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::A::A::A::A::s0000_0000000::a::"", + action, + resource +) 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 "|*|*|*|*|*|*") && ((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":"A::A::A::A::A::A::s0000_0000000::a"}},{"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":"action","type":"A::A::A::A::A::A::s0000_0000000::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"A::A::A::A::A::A::s0000_0000000::Action"},"context":{},"principal":{"id":"","type":"A::A::A::A::A::A::s0000_0000000::a"},"request":"R1","resource":{"id":"","type":"A::A::A::A::A::A::s0000_0000000::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"A::A::A::A::A::A::s0000_0000000::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":{},"principal":{"id":"","type":"A::A::A::A::A::A::s0000_0000000::a"},"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-cff7a407627177f76037/solution/reference.json b/tasks/cedar_authorization-cff7a407627177f76037/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..086b845858573703b01390817ea414e77e201181 --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/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-cff7a407627177f76037/solution/solve.sh b/tasks/cedar_authorization-cff7a407627177f76037/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-cff7a407627177f76037/task.toml b/tasks/cedar_authorization-cff7a407627177f76037/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2a5787b066e036c557ddd6cb63d69946e9584388 --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-cff7a407627177f76037" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "1ccddcfced5f78b6df313fcb7c6d238932d5a0b0391db817bbbca590bdf1c104" + +[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-cff7a407627177f76037/tests/expected.json b/tasks/cedar_authorization-cff7a407627177f76037/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..086b845858573703b01390817ea414e77e201181 --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/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-cff7a407627177f76037/tests/grading.py b/tasks/cedar_authorization-cff7a407627177f76037/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/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-cff7a407627177f76037/tests/test.sh b/tasks/cedar_authorization-cff7a407627177f76037/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/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-cff7a407627177f76037/tests/verify.py b/tasks/cedar_authorization-cff7a407627177f76037/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/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-cff7a407627177f76037/validation/openenv.json b/tasks/cedar_authorization-cff7a407627177f76037/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-cff7a407627177f76037/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-d0121aabe85fb259e2de/environment/Dockerfile b/tasks/cedar_authorization-d0121aabe85fb259e2de/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d0121aabe85fb259e2de/instruction.md b/tasks/cedar_authorization-d0121aabe85fb259e2de/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..815add7c760f5a6c490c6f9e398c4116066601ad --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/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 == PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEEEEEEEEEE::"", + action in [PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action::"action",PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action::"action",PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action::"action"], + resource +) when { + true +}; + +policy1 +forbid( + principal is LYY, + action in [Action::"action",Action::"action",Action::"action"], + resource == PcY::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYYYY5c"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"PcY"}},{"attrs":{},"parents":[],"uid":{"id":"**************************","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"LYY":[[""]]},"principal":{"id":"**************************","type":"LYY"},"request":"R1","resource":{"id":"","type":"PcY"}} +{"action":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"},"context":{"LYY":[["","**)))))))))))))UUUUUUUUUUUUUU"]]},"principal":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEEEEEEEEEE"},"request":"R2","resource":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::dEEEEEEEEE"}} +{"action":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"},"context":{"LYY":[["","**)))))))))))))UUUUUUUUUUUUUU"]]},"principal":{"id":"**************************","type":"LYY"},"request":"R3","resource":{"id":"","type":"PcY"}} +{"action":{"id":"action","type":"Action"},"context":{"LYY":[["","**)))))))))))))UUUUUUUUUUUUUU"]]},"principal":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEEEEEEEEEE"},"request":"R4","resource":{"id":"","type":"PcY"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-d0121aabe85fb259e2de/solution/reference.json b/tasks/cedar_authorization-d0121aabe85fb259e2de/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/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-d0121aabe85fb259e2de/solution/solve.sh b/tasks/cedar_authorization-d0121aabe85fb259e2de/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d0121aabe85fb259e2de/task.toml b/tasks/cedar_authorization-d0121aabe85fb259e2de/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..813bd69758c69e7c5dcfd0dc4acefed3cac82cc2 --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d0121aabe85fb259e2de" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "4310bfc8f21edd9aab91dd563448e53d1864298045b71cabb7ce7300fc6586ad" + +[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-d0121aabe85fb259e2de/tests/expected.json b/tasks/cedar_authorization-d0121aabe85fb259e2de/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/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-d0121aabe85fb259e2de/tests/grading.py b/tasks/cedar_authorization-d0121aabe85fb259e2de/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/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-d0121aabe85fb259e2de/tests/test.sh b/tasks/cedar_authorization-d0121aabe85fb259e2de/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/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-d0121aabe85fb259e2de/tests/verify.py b/tasks/cedar_authorization-d0121aabe85fb259e2de/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/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-d0121aabe85fb259e2de/validation/openenv.json b/tasks/cedar_authorization-d0121aabe85fb259e2de/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d0121aabe85fb259e2de/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-d09a6dd84c6a99502cc2/environment/Dockerfile b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d09a6dd84c6a99502cc2/instruction.md b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ded171d04e43902da8a198151b00b141eef24ac3 --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/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::"", + action, + resource +) when { + true && ((if true then resource is a else false == false) == ((false == false) == (false == false))) && ((([true] == []) == true) == false) +}; + +policy1 +forbid( + principal == r::r::r::r::P::"", + action in [r::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::O44_______44"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::_YlW33c3333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::j"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::n"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::o"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r333333333"}},{"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":"r::r::r::r::P"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::P"},"request":"R2","resource":{"id":"","type":"r::r::r::r::P"}} +{"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-d09a6dd84c6a99502cc2/solution/reference.json b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..0798ad417f7dc7737b402a05e09354f2f60dc990 --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/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":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d09a6dd84c6a99502cc2/solution/solve.sh b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d09a6dd84c6a99502cc2/task.toml b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0ad13ed91b5b82f2ced9ffebc95a4188d3966569 --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d09a6dd84c6a99502cc2" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "8c49e27baf76c39c451157153afd1946ba9eeba689d3bbf4cd88ede57339e43c" + +[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-d09a6dd84c6a99502cc2/tests/expected.json b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..0798ad417f7dc7737b402a05e09354f2f60dc990 --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/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":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d09a6dd84c6a99502cc2/tests/grading.py b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/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-d09a6dd84c6a99502cc2/tests/test.sh b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/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-d09a6dd84c6a99502cc2/tests/verify.py b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/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-d09a6dd84c6a99502cc2/validation/openenv.json b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d09a6dd84c6a99502cc2/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-d1cc1d7c83f66d17b59f/environment/Dockerfile b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/instruction.md b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e775d12dcca8e40ae054b020eb44f91ecc1dc829 --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/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 O::l::Z3333333::r::r::j5555556::r::"", + action in [O::l::Z3333333::r::r::j5555556::Action::"action"], + resource == O::l::Z3333333::r::r::j5555556::r::"" +) when { + true && (if if if true then false else false then decimal("ccccc711256967.6482").lessThan(decimal("441275057113cccccc26")) 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 false else false then if false then false else false else false == false) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"O::l::Z3333333::r::r::j5555556::r"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"O::l::Z3333333::r::r::j5555556::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"A5cZr9000rrrrEErr"},"request":"R1","resource":{"id":"","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"O::l::Z3333333::r::r::j5555556::Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R2","resource":{"id":"","type":"O::l::Z3333333::r::r::j5555556::r"}} +{"action":{"id":"action","type":"O::l::Z3333333::r::r::j5555556::Action"},"context":{},"principal":{"id":"","type":"O::l::Z3333333::r::r::j5555556::r"},"request":"R3","resource":{"id":"","type":"O::l::Z3333333::r::r::j5555556::r"}} +{"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-d1cc1d7c83f66d17b59f/solution/reference.json b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/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-d1cc1d7c83f66d17b59f/solution/solve.sh b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/task.toml b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..12a032859778f9fdf32d2edff738289b7cf3f814 --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d1cc1d7c83f66d17b59f" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "7065ef0854e647268825050ed480a301fd3b8633bc254037b42391625dc9e11e" + +[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-d1cc1d7c83f66d17b59f/tests/expected.json b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/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-d1cc1d7c83f66d17b59f/tests/grading.py b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/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-d1cc1d7c83f66d17b59f/tests/test.sh b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/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-d1cc1d7c83f66d17b59f/tests/verify.py b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/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-d1cc1d7c83f66d17b59f/validation/openenv.json b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d1cc1d7c83f66d17b59f/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-d1d33bf17452a802397a/environment/Dockerfile b/tasks/cedar_authorization-d1d33bf17452a802397a/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d1d33bf17452a802397a/instruction.md b/tasks/cedar_authorization-d1d33bf17452a802397a/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f166fad6f34088b3730251c604d50f390fb544c6 --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/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 == r::r::r::r::q::"", + action == r::r::r::r::Action::"action", + resource == r::r::r::r::q::"" +) when { + true && (if false then {"": ip("0.0.194.194")} else {"": ip("238.238.32.1")})[""].isMulticast() +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"gf00000000000"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::h"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::n"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::h"}],"tags":{"":[[[[]]]]},"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"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"gf00000000000"},"request":"R1","resource":{"id":"","type":"gf00000000000"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R2","resource":{"id":"","type":"r::r::r::r::q"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"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-d1d33bf17452a802397a/solution/reference.json b/tasks/cedar_authorization-d1d33bf17452a802397a/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..942677315495650e0ac5e80661490d67896ba08f --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/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-d1d33bf17452a802397a/solution/solve.sh b/tasks/cedar_authorization-d1d33bf17452a802397a/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d1d33bf17452a802397a/task.toml b/tasks/cedar_authorization-d1d33bf17452a802397a/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..05527d310cdb923c790f52c9f27ce47df5d9cd8f --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d1d33bf17452a802397a" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ae51f56124500d16ce6c80b02db93072859a19f0586b130f818218eea7849eb8" + +[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-d1d33bf17452a802397a/tests/expected.json b/tasks/cedar_authorization-d1d33bf17452a802397a/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..942677315495650e0ac5e80661490d67896ba08f --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/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-d1d33bf17452a802397a/tests/grading.py b/tasks/cedar_authorization-d1d33bf17452a802397a/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/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-d1d33bf17452a802397a/tests/test.sh b/tasks/cedar_authorization-d1d33bf17452a802397a/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/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-d1d33bf17452a802397a/tests/verify.py b/tasks/cedar_authorization-d1d33bf17452a802397a/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/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-d1d33bf17452a802397a/validation/openenv.json b/tasks/cedar_authorization-d1d33bf17452a802397a/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d1d33bf17452a802397a/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-d1e2dcfc0d895197c4d2/environment/Dockerfile b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/instruction.md b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b211b212a95ba380dba5183d151207d7e9932e09 --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/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 A100120000000040::A::B::a::"", + action == A100120000000040::A::B::Action::"action", + resource in A100120000000040::A::B::a::"" +) when { + true && (A100120000000040::A::B::a::"" in A100120000000040::A::B::a::"") && (A100120000000040::A::B::a::"" in A100120000000040::A::B::a::"") +}; + +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":"A100120000000040::A::B::a"}},{"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":"A100120000000040::A::B::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"}}] + +Requests +{"action":{"id":"action","type":"A100120000000040::A::B::Action"},"context":{},"principal":{"id":"","type":"A100120000000040::A::B::a"},"request":"R1","resource":{"id":"","type":"A100120000000040::A::B::a"}} +{"action":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"},"context":{},"principal":{"id":"\"\"\"\"\"\",\"\"","type":"j00000YY::i::i::i::i::jm555555::a"},"request":"R2","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":"A100120000000040::A::B::a"},"request":"R3","resource":{"id":"","type":"A100120000000040::A::B::a"}} +{"action":{"id":"action","type":"j00000YY::i::i::i::i::jm555555::Action"},"context":{},"principal":{"id":"","type":"A100120000000040::A::B::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-d1e2dcfc0d895197c4d2/solution/reference.json b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/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-d1e2dcfc0d895197c4d2/solution/solve.sh b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/task.toml b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..394694ebd7a71332bf8f04ad22371be0405457eb --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d1e2dcfc0d895197c4d2" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ddf97e24890b91d97512762d7729c35eedce099199323f008de60033d933ebff" + +[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-d1e2dcfc0d895197c4d2/tests/expected.json b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/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-d1e2dcfc0d895197c4d2/tests/grading.py b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/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-d1e2dcfc0d895197c4d2/tests/test.sh b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/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-d1e2dcfc0d895197c4d2/tests/verify.py b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/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-d1e2dcfc0d895197c4d2/validation/openenv.json b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d1e2dcfc0d895197c4d2/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-d27aa2736243e9982d3d/environment/Dockerfile b/tasks/cedar_authorization-d27aa2736243e9982d3d/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d27aa2736243e9982d3d/instruction.md b/tasks/cedar_authorization-d27aa2736243e9982d3d/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a630d063082d3117edaa82b8dcc12a56e66a763e --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/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 == A::a::"", + action == A::Action::"action", + resource == A::a::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"d0000k0::A::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"d0000k0::A::Action"}}] + +Requests +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"","type":"A::a"},"request":"R1","resource":{"id":"","type":"d0000k0::A::a"}} +{"action":{"id":"action","type":"A::Action"},"context":{"vi7Iwwww333333333":""},"principal":{"id":"","type":"A::a"},"request":"R2","resource":{"id":"","type":"A::a"}} +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"","type":"d0000k0::A::a"},"request":"R3","resource":{"id":"","type":"d0000k0::A::a"}} +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"","type":"d0000k0::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-d27aa2736243e9982d3d/solution/reference.json b/tasks/cedar_authorization-d27aa2736243e9982d3d/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..71f20c7a0ceb2275c51bc5c9942efbee30dccd47 --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d27aa2736243e9982d3d/solution/solve.sh b/tasks/cedar_authorization-d27aa2736243e9982d3d/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d27aa2736243e9982d3d/task.toml b/tasks/cedar_authorization-d27aa2736243e9982d3d/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d0ed5ba5b732d356680f74c16cff20c05767742d --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d27aa2736243e9982d3d" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "3d19f4f9c9f24513676ba82214a16ede8e934402ea7169319b8fa745b3e85db4" + +[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-d27aa2736243e9982d3d/tests/expected.json b/tasks/cedar_authorization-d27aa2736243e9982d3d/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..71f20c7a0ceb2275c51bc5c9942efbee30dccd47 --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d27aa2736243e9982d3d/tests/grading.py b/tasks/cedar_authorization-d27aa2736243e9982d3d/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/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-d27aa2736243e9982d3d/tests/test.sh b/tasks/cedar_authorization-d27aa2736243e9982d3d/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/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-d27aa2736243e9982d3d/tests/verify.py b/tasks/cedar_authorization-d27aa2736243e9982d3d/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/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-d27aa2736243e9982d3d/validation/openenv.json b/tasks/cedar_authorization-d27aa2736243e9982d3d/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d27aa2736243e9982d3d/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-d29c28ab7289a15b0f95/environment/Dockerfile b/tasks/cedar_authorization-d29c28ab7289a15b0f95/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d29c28ab7289a15b0f95/instruction.md b/tasks/cedar_authorization-d29c28ab7289a15b0f95/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a1a47e463510e03c6709722705d869a99dd9b823 --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/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::"", + action == Action::"action", + resource in r::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"tags":{"":{"__extn":{"arg":"5934-03-01T14:52:52Z","fn":"datetime"}}},"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"AYY":true},"principal":{"id":"","type":"r"},"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":{"r":false,"r3":{"__extn":{"arg":"0.0.232.232","fn":"ip"}},"r33":false,"w":{"__extn":{"arg":"0.0.0.0","fn":"ip"}}},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"r"}} +{"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-d29c28ab7289a15b0f95/solution/reference.json b/tasks/cedar_authorization-d29c28ab7289a15b0f95/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..52c9ee99f4b52918ab85a046213fcdeb2ff1b790 --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d29c28ab7289a15b0f95/solution/solve.sh b/tasks/cedar_authorization-d29c28ab7289a15b0f95/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d29c28ab7289a15b0f95/task.toml b/tasks/cedar_authorization-d29c28ab7289a15b0f95/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0675c42f69dbf8a5fb7da7251f527ec1978758b2 --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d29c28ab7289a15b0f95" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "23f2dc659db2cb0d11d0bd1217ff8c38ac31d183bf1d6051f4bae3c0d53042ca" + +[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-d29c28ab7289a15b0f95/tests/expected.json b/tasks/cedar_authorization-d29c28ab7289a15b0f95/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..52c9ee99f4b52918ab85a046213fcdeb2ff1b790 --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d29c28ab7289a15b0f95/tests/grading.py b/tasks/cedar_authorization-d29c28ab7289a15b0f95/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/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-d29c28ab7289a15b0f95/tests/test.sh b/tasks/cedar_authorization-d29c28ab7289a15b0f95/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/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-d29c28ab7289a15b0f95/tests/verify.py b/tasks/cedar_authorization-d29c28ab7289a15b0f95/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/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-d29c28ab7289a15b0f95/validation/openenv.json b/tasks/cedar_authorization-d29c28ab7289a15b0f95/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d29c28ab7289a15b0f95/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-d2b48baa5b7505bb868f/environment/Dockerfile b/tasks/cedar_authorization-d2b48baa5b7505bb868f/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d2b48baa5b7505bb868f/instruction.md b/tasks/cedar_authorization-d2b48baa5b7505bb868f/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6f9005db76afa6f14d2776cfa4d67f04d5726d3d --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/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 Knnn3h00105cZWg3l::rF333333Y3333::r::r::V, + action == Knnn3h00105cZWg3l::rF333333Y3333::r::r::Action::"action", + resource is Knnn3h00105cZWg3l::rF333333Y3333::r::r::V +) when { + true && ((principal in principal) || (principal in principal)) && (principal in principal) && (principal in principal) +}; + +policy1 +forbid( + principal in a::"", + action in [Action::"action",Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::w"}},{"attrs":{"A0":"*******"},"parents":[],"tags":{"":[[[[]]]],"****":[[[]],[[],[[]]],[[[]]]]},"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"}} +{"action":{"id":"action","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::Action"},"context":{},"principal":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"},"request":"R2","resource":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"}} +{"action":{"id":"action","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"Knnn3h00105cZWg3l::rF333333Y3333::r::r::V"}} +{"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-d2b48baa5b7505bb868f/solution/reference.json b/tasks/cedar_authorization-d2b48baa5b7505bb868f/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..644bd01431fddb1b9602e4c5e73687ac6afefb3f --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/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-d2b48baa5b7505bb868f/solution/solve.sh b/tasks/cedar_authorization-d2b48baa5b7505bb868f/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d2b48baa5b7505bb868f/task.toml b/tasks/cedar_authorization-d2b48baa5b7505bb868f/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7ab23e4113b1413bcf8526d3087c06732bf19cf8 --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d2b48baa5b7505bb868f" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "a0dd4679d52d087201a407fc4cfda938043aaabd3c22087281d640b414b1d9d2" + +[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-d2b48baa5b7505bb868f/tests/expected.json b/tasks/cedar_authorization-d2b48baa5b7505bb868f/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..644bd01431fddb1b9602e4c5e73687ac6afefb3f --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/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-d2b48baa5b7505bb868f/tests/grading.py b/tasks/cedar_authorization-d2b48baa5b7505bb868f/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/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-d2b48baa5b7505bb868f/tests/test.sh b/tasks/cedar_authorization-d2b48baa5b7505bb868f/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/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-d2b48baa5b7505bb868f/tests/verify.py b/tasks/cedar_authorization-d2b48baa5b7505bb868f/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/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-d2b48baa5b7505bb868f/validation/openenv.json b/tasks/cedar_authorization-d2b48baa5b7505bb868f/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d2b48baa5b7505bb868f/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-d34d4ac7af119e0ad462/environment/Dockerfile b/tasks/cedar_authorization-d34d4ac7af119e0ad462/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d34d4ac7af119e0ad462/instruction.md b/tasks/cedar_authorization-d34d4ac7af119e0ad462/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e33a4f7a14ae030df9225922b37bd7089abc9fec --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/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::"", + action == Action::"action", + resource +) when { + true +}; + +policy1 +forbid( + principal, + action in [q::r::r::A33333333333333::Action::""], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A33333333333333::Action"}},{"attrs":{},"parents":[{"id":">","type":"q::r::r::A33333333333333::r"}],"uid":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A33333333333333::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":">","type":"q::r::r::A33333333333333::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"","type":"q::r::r::A33333333333333::Action"},"context":{"Zwwwwwwwwwwwwww":false,"r":{"":{"__entity":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"}}}},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"}} +{"action":{"id":"","type":"q::r::r::A33333333333333::Action"},"context":{},"principal":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"},"request":"R2","resource":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"q::r::r::A33333333333333::Zwwwwwwwwwwwwww"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"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-d34d4ac7af119e0ad462/solution/reference.json b/tasks/cedar_authorization-d34d4ac7af119e0ad462/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..71c6642e43a201e0274d8a8eec52b73ac1282893 --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"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-d34d4ac7af119e0ad462/solution/solve.sh b/tasks/cedar_authorization-d34d4ac7af119e0ad462/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d34d4ac7af119e0ad462/task.toml b/tasks/cedar_authorization-d34d4ac7af119e0ad462/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..75fb2f2e6f2f7626c6b8e91708a824db30661ca9 --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d34d4ac7af119e0ad462" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "4ec01bc09b500aec81f6c7c602a83335d1a1589817fed8db6f28d979cf921036" + +[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-d34d4ac7af119e0ad462/tests/expected.json b/tasks/cedar_authorization-d34d4ac7af119e0ad462/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..71c6642e43a201e0274d8a8eec52b73ac1282893 --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"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-d34d4ac7af119e0ad462/tests/grading.py b/tasks/cedar_authorization-d34d4ac7af119e0ad462/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/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-d34d4ac7af119e0ad462/tests/test.sh b/tasks/cedar_authorization-d34d4ac7af119e0ad462/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/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-d34d4ac7af119e0ad462/tests/verify.py b/tasks/cedar_authorization-d34d4ac7af119e0ad462/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/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-d34d4ac7af119e0ad462/validation/openenv.json b/tasks/cedar_authorization-d34d4ac7af119e0ad462/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d34d4ac7af119e0ad462/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-d369908a16c7e72604f0/environment/Dockerfile b/tasks/cedar_authorization-d369908a16c7e72604f0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d369908a16c7e72604f0/instruction.md b/tasks/cedar_authorization-d369908a16c7e72604f0/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ae9c1f2cc03bd6513e48b1c5cb4751122ad4d651 --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/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 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 "|**|*|***") +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"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":"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":"r::r::r::r::r"}} +{"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-d369908a16c7e72604f0/solution/reference.json b/tasks/cedar_authorization-d369908a16c7e72604f0/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..0798ad417f7dc7737b402a05e09354f2f60dc990 --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/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":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d369908a16c7e72604f0/solution/solve.sh b/tasks/cedar_authorization-d369908a16c7e72604f0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d369908a16c7e72604f0/task.toml b/tasks/cedar_authorization-d369908a16c7e72604f0/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3540865f1a7edea5095d39574ee9c20f750e4fe5 --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d369908a16c7e72604f0" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b4fa9b43e6ae8a2d12d7fcb6e5c8442dda931fa7f8fcd58c8ad1961728e73532" + +[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-d369908a16c7e72604f0/tests/expected.json b/tasks/cedar_authorization-d369908a16c7e72604f0/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..0798ad417f7dc7737b402a05e09354f2f60dc990 --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/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":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d369908a16c7e72604f0/tests/grading.py b/tasks/cedar_authorization-d369908a16c7e72604f0/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/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-d369908a16c7e72604f0/tests/test.sh b/tasks/cedar_authorization-d369908a16c7e72604f0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/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-d369908a16c7e72604f0/tests/verify.py b/tasks/cedar_authorization-d369908a16c7e72604f0/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/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-d369908a16c7e72604f0/validation/openenv.json b/tasks/cedar_authorization-d369908a16c7e72604f0/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d369908a16c7e72604f0/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-d382680c92c56eea0139/environment/Dockerfile b/tasks/cedar_authorization-d382680c92c56eea0139/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d382680c92c56eea0139/instruction.md b/tasks/cedar_authorization-d382680c92c56eea0139/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..75da927995ae45dfeb38c7c76a21a98e85c599dc --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/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 r::r::r::r::j55555555::"", + action in [r::r::r::r::Action::"action"], + resource == r::r::r::r::j55555555::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::j55555555"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"tags":{"":{"__entity":{"id":"","type":"r::r::r::r::r"}}},"uid":{"id":"","type":"r::r::r::r::r333"}},{"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":"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":"r::r::r::r::j55555555"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"request":"R3","resource":{"id":"","type":"r::r::r::r::j55555555"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"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-d382680c92c56eea0139/solution/reference.json b/tasks/cedar_authorization-d382680c92c56eea0139/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/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-d382680c92c56eea0139/solution/solve.sh b/tasks/cedar_authorization-d382680c92c56eea0139/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d382680c92c56eea0139/task.toml b/tasks/cedar_authorization-d382680c92c56eea0139/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a9aad9837bf13524568be00c1fde0ad2113b82ec --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d382680c92c56eea0139" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "e9359e9160b23775e4b9f1e2f74feca4d849a69f5621050363346a6b5cfc6f66" + +[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-d382680c92c56eea0139/tests/expected.json b/tasks/cedar_authorization-d382680c92c56eea0139/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/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-d382680c92c56eea0139/tests/grading.py b/tasks/cedar_authorization-d382680c92c56eea0139/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/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-d382680c92c56eea0139/tests/test.sh b/tasks/cedar_authorization-d382680c92c56eea0139/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/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-d382680c92c56eea0139/tests/verify.py b/tasks/cedar_authorization-d382680c92c56eea0139/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/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-d382680c92c56eea0139/validation/openenv.json b/tasks/cedar_authorization-d382680c92c56eea0139/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d382680c92c56eea0139/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-d412486a3631fa2a389a/environment/Dockerfile b/tasks/cedar_authorization-d412486a3631fa2a389a/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d412486a3631fa2a389a/instruction.md b/tasks/cedar_authorization-d412486a3631fa2a389a/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..52b8e26e60eb4d8e516c28e6d8a2c19919864dac --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/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 in a::"", + action in [Action::"action"], + resource in a::"" +) when { + true && (if if ip("198.198.198.198").isMulticast() then action in [a::"", a::"", a::""] else ip("198.198.198.198").isMulticast() then true else [true, true, true].contains(true)) && true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"QxxO0xxxxxxxxxx::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"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":"a"},"request":"R1","resource":{"id":"","type":"QxxO0xxxxxxxxxx::a"}} +{"action":{"id":"action","type":"QxxO0xxxxxxxxxx::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":"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-d412486a3631fa2a389a/solution/reference.json b/tasks/cedar_authorization-d412486a3631fa2a389a/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/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-d412486a3631fa2a389a/solution/solve.sh b/tasks/cedar_authorization-d412486a3631fa2a389a/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d412486a3631fa2a389a/task.toml b/tasks/cedar_authorization-d412486a3631fa2a389a/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5967edd3570350c239e9605af57f1e2130305c78 --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d412486a3631fa2a389a" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d702dcad24332b1cd0a1f97e965a5852fa22b06309bb870946e0db22f3a32808" + +[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-d412486a3631fa2a389a/tests/expected.json b/tasks/cedar_authorization-d412486a3631fa2a389a/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/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-d412486a3631fa2a389a/tests/grading.py b/tasks/cedar_authorization-d412486a3631fa2a389a/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/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-d412486a3631fa2a389a/tests/test.sh b/tasks/cedar_authorization-d412486a3631fa2a389a/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/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-d412486a3631fa2a389a/tests/verify.py b/tasks/cedar_authorization-d412486a3631fa2a389a/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/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-d412486a3631fa2a389a/validation/openenv.json b/tasks/cedar_authorization-d412486a3631fa2a389a/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d412486a3631fa2a389a/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-d4ef69ce3dff2706a6e7/environment/Dockerfile b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/instruction.md b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..406ec136719aeddda20a9c762d63a8c66f52b113 --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/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 r32333333::"", + action in [Action::"action"], + resource == r32333333::"" +) when { + true +}; + +policy1 +forbid( + principal, + action in [r::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Kww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"PDw"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Pww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"fww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r32333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r444G444444444"}},{"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"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"r32333333"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r32333333"},"request":"R2","resource":{"id":"","type":"r32333333"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r32333333"},"request":"R3","resource":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::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-d4ef69ce3dff2706a6e7/solution/reference.json b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..9017fb683404c1768bbabd179282a51f25161eb7 --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/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":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/solution/solve.sh b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/task.toml b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d1c8b98a377044045d6f632f56a0dc9ac2509dda --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d4ef69ce3dff2706a6e7" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "9e5c317f286f731f7426099ccee568b66147008d474cc73c6cbbc7fdb18786bf" + +[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-d4ef69ce3dff2706a6e7/tests/expected.json b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..9017fb683404c1768bbabd179282a51f25161eb7 --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/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":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/tests/grading.py b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/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-d4ef69ce3dff2706a6e7/tests/test.sh b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/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-d4ef69ce3dff2706a6e7/tests/verify.py b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/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-d4ef69ce3dff2706a6e7/validation/openenv.json b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d4ef69ce3dff2706a6e7/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-d646f647b57739696750/environment/Dockerfile b/tasks/cedar_authorization-d646f647b57739696750/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d646f647b57739696750/instruction.md b/tasks/cedar_authorization-d646f647b57739696750/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e4ca3f1c9663160a8931dc59a1686bcf474e5f3d --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/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 in a::"", + action in [Action::"action"], + resource in a::"" +) when { + true && resource.getTag("").getTag("").hasTag("") +}; + +Entities +[{"attrs":{},"parents":[],"tags":{"":{"__entity":{"id":"","type":"a"}}},"uid":{"id":"","type":"a"}},{"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":"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":"Action"},"context":{},"principal":{"id":"","type":"a"},"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::WMMMMM"},"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-d646f647b57739696750/solution/reference.json b/tasks/cedar_authorization-d646f647b57739696750/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/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-d646f647b57739696750/solution/solve.sh b/tasks/cedar_authorization-d646f647b57739696750/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d646f647b57739696750/task.toml b/tasks/cedar_authorization-d646f647b57739696750/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6c7c98c3166f482e4f0a2fee8b51020ab5abb199 --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d646f647b57739696750" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "49c5ff8551e06392b973c05f52b098d4618907e436c3eec54bbd57cc151c2510" + +[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-d646f647b57739696750/tests/expected.json b/tasks/cedar_authorization-d646f647b57739696750/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/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-d646f647b57739696750/tests/grading.py b/tasks/cedar_authorization-d646f647b57739696750/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/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-d646f647b57739696750/tests/test.sh b/tasks/cedar_authorization-d646f647b57739696750/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/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-d646f647b57739696750/tests/verify.py b/tasks/cedar_authorization-d646f647b57739696750/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/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-d646f647b57739696750/validation/openenv.json b/tasks/cedar_authorization-d646f647b57739696750/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d646f647b57739696750/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-d6cc06a9d9ef0eab3cb1/environment/Dockerfile b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/instruction.md b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3d1cb6cf0ba2e77e5830fde44df0a7ee539134ba --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/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 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 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 false else false then if false then false else false else true) && ((if ["", "", ""].contains("*****") then action else action) in action) +}; + +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-d6cc06a9d9ef0eab3cb1/solution/reference.json b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/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-d6cc06a9d9ef0eab3cb1/solution/solve.sh b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/task.toml b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..42b5d01d474bc559e63fe415d166a8182bc72395 --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d6cc06a9d9ef0eab3cb1" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "24f01796dd91f3c30122364392454dc033e18a3fc5bca9e5b9bb9f87f48f9929" + +[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-d6cc06a9d9ef0eab3cb1/tests/expected.json b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/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-d6cc06a9d9ef0eab3cb1/tests/grading.py b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/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-d6cc06a9d9ef0eab3cb1/tests/test.sh b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/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-d6cc06a9d9ef0eab3cb1/tests/verify.py b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/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-d6cc06a9d9ef0eab3cb1/validation/openenv.json b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d6cc06a9d9ef0eab3cb1/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-d6f34d8ea5b9efc7b647/environment/Dockerfile b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/instruction.md b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5aad2d2139bd0fbfa9ea55317049b8b841d8da45 --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/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 is mSSSSSS, + action == Action::"action", + resource == LYY::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::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"}},{"attrs":{},"parents":[],"uid":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R1","resource":{"id":"","type":"LYY"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R2","resource":{"id":"","type":"mSSSSSS"}} +{"action":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"},"context":{},"principal":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"},"request":"R3","resource":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}} +{"action":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"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-d6f34d8ea5b9efc7b647/solution/reference.json b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..ecc7429c3aab3dbfe2a2125625275d7b1455c87a --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/solution/solve.sh b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/task.toml b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1407a075bea46aba9e1128cd32d1328c39b4f030 --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d6f34d8ea5b9efc7b647" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "245b859980b6cc16df4156f38167a71f06ad5bea322d0113b835fd2473bccb14" + +[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-d6f34d8ea5b9efc7b647/tests/expected.json b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..ecc7429c3aab3dbfe2a2125625275d7b1455c87a --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/tests/grading.py b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/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-d6f34d8ea5b9efc7b647/tests/test.sh b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/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-d6f34d8ea5b9efc7b647/tests/verify.py b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/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-d6f34d8ea5b9efc7b647/validation/openenv.json b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d6f34d8ea5b9efc7b647/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-d7b0a00b4a02b7042516/environment/Dockerfile b/tasks/cedar_authorization-d7b0a00b4a02b7042516/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d7b0a00b4a02b7042516/instruction.md b/tasks/cedar_authorization-d7b0a00b4a02b7042516/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2c6ee3fd33baa99bc8e190b9b3a19793b707411b --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/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, + action, + resource is j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a +) when { + true && (resource.j5555555333.j5555555333 in resource.j5555555333.j5555555333) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cjr9000rrrrEErr"}},{"attrs":{"j5555555333":{"__entity":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"}}},"parents":[],"uid":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cjr9000rrrrEErr"}},{"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":"Action"},"context":{},"principal":{"id":"`","type":"A5cjr9000rrrrEErr"},"request":"R2","resource":{"id":"`","type":"A5cjr9000rrrrEErr"}} +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::Action"},"context":{},"principal":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"},"request":"R3","resource":{"id":"`","type":"A5cjr9000rrrrEErr"}} +{"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-d7b0a00b4a02b7042516/solution/reference.json b/tasks/cedar_authorization-d7b0a00b4a02b7042516/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..644bd01431fddb1b9602e4c5e73687ac6afefb3f --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/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-d7b0a00b4a02b7042516/solution/solve.sh b/tasks/cedar_authorization-d7b0a00b4a02b7042516/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d7b0a00b4a02b7042516/task.toml b/tasks/cedar_authorization-d7b0a00b4a02b7042516/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..24965c4a22872e2044093c32d6843e32a1045261 --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d7b0a00b4a02b7042516" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "17a0db73b67df4d8815216a7c7ad18d022c61f5df90e8fa6a7f80422a4d8e7c7" + +[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-d7b0a00b4a02b7042516/tests/expected.json b/tasks/cedar_authorization-d7b0a00b4a02b7042516/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..644bd01431fddb1b9602e4c5e73687ac6afefb3f --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/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-d7b0a00b4a02b7042516/tests/grading.py b/tasks/cedar_authorization-d7b0a00b4a02b7042516/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/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-d7b0a00b4a02b7042516/tests/test.sh b/tasks/cedar_authorization-d7b0a00b4a02b7042516/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/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-d7b0a00b4a02b7042516/tests/verify.py b/tasks/cedar_authorization-d7b0a00b4a02b7042516/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/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-d7b0a00b4a02b7042516/validation/openenv.json b/tasks/cedar_authorization-d7b0a00b4a02b7042516/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d7b0a00b4a02b7042516/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-d8aa8d5c61b6492a436e/environment/Dockerfile b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d8aa8d5c61b6492a436e/instruction.md b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d94ef5731ae55ee393d8afe425c55638fc12e352 --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/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 +}; + +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":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"(((((((((","type":"LYY"},"request":"R1","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"LYY"},"request":"R2","resource":{"id":"","type":"LYY"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"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-d8aa8d5c61b6492a436e/solution/reference.json b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/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-d8aa8d5c61b6492a436e/solution/solve.sh b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d8aa8d5c61b6492a436e/task.toml b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9ac0f369ed43517b26f1e5136fcae7f5ae164e80 --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d8aa8d5c61b6492a436e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "84c5d9a8d8f4ed7677d15a5ad28cb9aa7a62e59795614180852efc799e82d9c8" + +[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-d8aa8d5c61b6492a436e/tests/expected.json b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/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-d8aa8d5c61b6492a436e/tests/grading.py b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/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-d8aa8d5c61b6492a436e/tests/test.sh b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/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-d8aa8d5c61b6492a436e/tests/verify.py b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/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-d8aa8d5c61b6492a436e/validation/openenv.json b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d8aa8d5c61b6492a436e/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-d98caaa4e2d6e618ede5/environment/Dockerfile b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-d98caaa4e2d6e618ede5/instruction.md b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..bb92307c8e8ee4644de09e1b363038c1b8be163d --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/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 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":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::Action"},"context":{},"principal":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::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-d98caaa4e2d6e618ede5/solution/reference.json b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/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-d98caaa4e2d6e618ede5/solution/solve.sh b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-d98caaa4e2d6e618ede5/task.toml b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f5d0f5c82e5768418415991d3c148269d335a52b --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-d98caaa4e2d6e618ede5" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "cc0c66a6f8169e02dfb227c7ac7f2c805be53c5ae15863f4b15b79d66e0aa11c" + +[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-d98caaa4e2d6e618ede5/tests/expected.json b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/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-d98caaa4e2d6e618ede5/tests/grading.py b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/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-d98caaa4e2d6e618ede5/tests/test.sh b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/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-d98caaa4e2d6e618ede5/tests/verify.py b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/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-d98caaa4e2d6e618ede5/validation/openenv.json b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-d98caaa4e2d6e618ede5/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-da777da875ea048e570c/environment/Dockerfile b/tasks/cedar_authorization-da777da875ea048e570c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-da777da875ea048e570c/instruction.md b/tasks/cedar_authorization-da777da875ea048e570c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..c201cf995338490d62938d3ce69ec1a2707b0185 --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/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*3*10*" then {"": action} has n99999qqqqqq.dqQ0.dqqq else action in r::r::r3::r::jwwwwwwwwwwwwwwww::"" then {"": action}[""] in {"": action}[""] else {"": action}[""] in {"": action}[""]) && ({"": action}[""] in {"": action}[""]) +}; + +policy1 +forbid( + principal == A::a::"", + action in [A::Action::""], + resource == A::a::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"A::a"}},{"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::r3::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3::r::_YlW3333333333"},"request":"R1","resource":{"id":"","type":"r::r::r3::r::jwwwwwwwww"}} +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3::r::WMMMMM"},"request":"R2","resource":{"id":"","type":"r::r::r3::r::WMMMMM"}} +{"action":{"id":"","type":"A::Action"},"context":{},"principal":{"id":"","type":"A::a"},"request":"R3","resource":{"id":"","type":"A::a"}} +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"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-da777da875ea048e570c/solution/reference.json b/tasks/cedar_authorization-da777da875ea048e570c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/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-da777da875ea048e570c/solution/solve.sh b/tasks/cedar_authorization-da777da875ea048e570c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-da777da875ea048e570c/task.toml b/tasks/cedar_authorization-da777da875ea048e570c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c89ce3753e0f8802cb3c0e78d62137f59aee3665 --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-da777da875ea048e570c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0dd748cb6fd967132875d2c443b26ee9e739eb2d313ee52ef0a16185811366ca" + +[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-da777da875ea048e570c/tests/expected.json b/tasks/cedar_authorization-da777da875ea048e570c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/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-da777da875ea048e570c/tests/grading.py b/tasks/cedar_authorization-da777da875ea048e570c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/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-da777da875ea048e570c/tests/test.sh b/tasks/cedar_authorization-da777da875ea048e570c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/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-da777da875ea048e570c/tests/verify.py b/tasks/cedar_authorization-da777da875ea048e570c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/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-da777da875ea048e570c/validation/openenv.json b/tasks/cedar_authorization-da777da875ea048e570c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-da777da875ea048e570c/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-dac1068bbd1f8615fa15/environment/Dockerfile b/tasks/cedar_authorization-dac1068bbd1f8615fa15/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-dac1068bbd1f8615fa15/instruction.md b/tasks/cedar_authorization-dac1068bbd1f8615fa15/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..199cde09133891593533337db2828bdbc599d31e --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/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 == r::"", + action == Action::"action", + resource in r::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"tags":{"":{"__extn":{"arg":"5934-03-01T14:52:52Z","fn":"datetime"}}},"uid":{"id":"","type":"r"}},{"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":"Action"},"context":{"AYY":true},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"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"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"AYY":true},"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-dac1068bbd1f8615fa15/solution/reference.json b/tasks/cedar_authorization-dac1068bbd1f8615fa15/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/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-dac1068bbd1f8615fa15/solution/solve.sh b/tasks/cedar_authorization-dac1068bbd1f8615fa15/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-dac1068bbd1f8615fa15/task.toml b/tasks/cedar_authorization-dac1068bbd1f8615fa15/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0c11a43ca0097a698cb3c0b761cacc2998f81b25 --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-dac1068bbd1f8615fa15" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b7345122882ccb7400f6a6c798763c582463aa0c9ef37467ec376b26f4c7c3a3" + +[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-dac1068bbd1f8615fa15/tests/expected.json b/tasks/cedar_authorization-dac1068bbd1f8615fa15/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..564f041bb2ce936be09502cfe7712f458949792a --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/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-dac1068bbd1f8615fa15/tests/grading.py b/tasks/cedar_authorization-dac1068bbd1f8615fa15/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/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-dac1068bbd1f8615fa15/tests/test.sh b/tasks/cedar_authorization-dac1068bbd1f8615fa15/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/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-dac1068bbd1f8615fa15/tests/verify.py b/tasks/cedar_authorization-dac1068bbd1f8615fa15/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/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-dac1068bbd1f8615fa15/validation/openenv.json b/tasks/cedar_authorization-dac1068bbd1f8615fa15/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-dac1068bbd1f8615fa15/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-dadc5617acb1033ef98e/environment/Dockerfile b/tasks/cedar_authorization-dadc5617acb1033ef98e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-dadc5617acb1033ef98e/instruction.md b/tasks/cedar_authorization-dadc5617acb1033ef98e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a1aff78f3e91f8de325ca79c09825769f591015d --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/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 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":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::g31000000"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::wZ1g"}},{"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":{},"principal":{"id":"","type":"r::r::r::r::wZ1g"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::wZ1g"},"request":"R2","resource":{"id":"","type":"r::r::r::r::wZ1g"}} +{"action":{"id":"","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":"r::r::r::r::wZ1g"},"request":"R4","resource":{"id":"","type":"r::r::r::r::wZ1g"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-dadc5617acb1033ef98e/solution/reference.json b/tasks/cedar_authorization-dadc5617acb1033ef98e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..93a7415544211bc62c788bff4057a9aa5ccc1ae3 --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/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"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-dadc5617acb1033ef98e/solution/solve.sh b/tasks/cedar_authorization-dadc5617acb1033ef98e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-dadc5617acb1033ef98e/task.toml b/tasks/cedar_authorization-dadc5617acb1033ef98e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bb466214bbdc58864042f884743a407a17988984 --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-dadc5617acb1033ef98e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "43d59df2d0ea53dac446c08ef43e32b4fb3083761a2d113f3cf601abf1a4df41" + +[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-dadc5617acb1033ef98e/tests/expected.json b/tasks/cedar_authorization-dadc5617acb1033ef98e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..93a7415544211bc62c788bff4057a9aa5ccc1ae3 --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/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"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-dadc5617acb1033ef98e/tests/grading.py b/tasks/cedar_authorization-dadc5617acb1033ef98e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/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-dadc5617acb1033ef98e/tests/test.sh b/tasks/cedar_authorization-dadc5617acb1033ef98e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/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-dadc5617acb1033ef98e/tests/verify.py b/tasks/cedar_authorization-dadc5617acb1033ef98e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/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-dadc5617acb1033ef98e/validation/openenv.json b/tasks/cedar_authorization-dadc5617acb1033ef98e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-dadc5617acb1033ef98e/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-db92fe40a954c9bfbaff/environment/Dockerfile b/tasks/cedar_authorization-db92fe40a954c9bfbaff/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-db92fe40a954c9bfbaff/instruction.md b/tasks/cedar_authorization-db92fe40a954c9bfbaff/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f3255eff946943ffd794649fa0231de02b0c6b04 --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/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::"", + action == Action::"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":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"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"}}] + +Requests +{"action":{"id":"action","type":"q::r::r::A333333333333z3::Action"},"context":{},"principal":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"},"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":"q::r::r::A333333333333z3::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"},"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-db92fe40a954c9bfbaff/solution/reference.json b/tasks/cedar_authorization-db92fe40a954c9bfbaff/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..55c203044233f8d169b78f8e2de1829d4c21708e --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-db92fe40a954c9bfbaff/solution/solve.sh b/tasks/cedar_authorization-db92fe40a954c9bfbaff/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-db92fe40a954c9bfbaff/task.toml b/tasks/cedar_authorization-db92fe40a954c9bfbaff/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c85b12b9dff5b17aa8d71bf6388741369368e3f6 --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-db92fe40a954c9bfbaff" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "8e41e11fc7ce64707b444903bbc6a660f1c5d390edede2217d1d928ab1d89b47" + +[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-db92fe40a954c9bfbaff/tests/expected.json b/tasks/cedar_authorization-db92fe40a954c9bfbaff/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..55c203044233f8d169b78f8e2de1829d4c21708e --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-db92fe40a954c9bfbaff/tests/grading.py b/tasks/cedar_authorization-db92fe40a954c9bfbaff/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/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-db92fe40a954c9bfbaff/tests/test.sh b/tasks/cedar_authorization-db92fe40a954c9bfbaff/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/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-db92fe40a954c9bfbaff/tests/verify.py b/tasks/cedar_authorization-db92fe40a954c9bfbaff/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/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-db92fe40a954c9bfbaff/validation/openenv.json b/tasks/cedar_authorization-db92fe40a954c9bfbaff/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-db92fe40a954c9bfbaff/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-dca3a616f77b9190cf2e/environment/Dockerfile b/tasks/cedar_authorization-dca3a616f77b9190cf2e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-dca3a616f77b9190cf2e/instruction.md b/tasks/cedar_authorization-dca3a616f77b9190cf2e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..7eb363987e3c6357ad4d8eea37d879035d7b6377 --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/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 _Yl10999999999::"<===", + action in [Action::""], + resource +) when { + true && (if if "33333" like "" then decimal("--33322776644779955008800441177..22009944").lessThan(decimal("-332764795055152.6959")) else [ip("2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b/43"), ip("2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b:2b2b/43"), ip("194.194.194.194")].containsAll([datetime("5534-04-08T15:15:15.427+0015").offset(duration("-59393h2248146945m1s1ms")), datetime("7219-08-08T15:15:07.347+0015").offset(duration("0h")), datetime("2827-12-12T11:11:11.827+1111")]) then !(!true) else !(!true)) +}; + +Entities +[{"attrs":{},"parents":[{"id":"000000000000000e","type":"Action"}],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"_Yl10999999999"}},{"attrs":{},"parents":[],"uid":{"id":"***((((((((","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"000000000000000e","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"<===","type":"_Yl10999999999"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"000000000000000e","type":"Action"},"context":{},"principal":{"id":"","type":"_Yl10999999999"},"request":"R1","resource":{"id":"<===","type":"_Yl10999999999"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"***((((((((","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"_Yl10999999999"}} +{"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":"_Yl10999999999"},"request":"R4","resource":{"id":"","type":"_Yl10999999999"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-dca3a616f77b9190cf2e/solution/reference.json b/tasks/cedar_authorization-dca3a616f77b9190cf2e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..3ffa2505a6a1f29cfec26eac33da1d6fd8f03189 --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"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-dca3a616f77b9190cf2e/solution/solve.sh b/tasks/cedar_authorization-dca3a616f77b9190cf2e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-dca3a616f77b9190cf2e/task.toml b/tasks/cedar_authorization-dca3a616f77b9190cf2e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3b0fbf61a222223ffe07c9e1eab86c6db8cf4db5 --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-dca3a616f77b9190cf2e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "8a26e33e42f65bc7d1ba471e9ed85558265e489af067b443bcd868c02c093c70" + +[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-dca3a616f77b9190cf2e/tests/expected.json b/tasks/cedar_authorization-dca3a616f77b9190cf2e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..3ffa2505a6a1f29cfec26eac33da1d6fd8f03189 --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"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-dca3a616f77b9190cf2e/tests/grading.py b/tasks/cedar_authorization-dca3a616f77b9190cf2e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/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-dca3a616f77b9190cf2e/tests/test.sh b/tasks/cedar_authorization-dca3a616f77b9190cf2e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/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-dca3a616f77b9190cf2e/tests/verify.py b/tasks/cedar_authorization-dca3a616f77b9190cf2e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/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-dca3a616f77b9190cf2e/validation/openenv.json b/tasks/cedar_authorization-dca3a616f77b9190cf2e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-dca3a616f77b9190cf2e/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-dcdf157622e5af6f00c0/environment/Dockerfile b/tasks/cedar_authorization-dcdf157622e5af6f00c0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-dcdf157622e5af6f00c0/instruction.md b/tasks/cedar_authorization-dcdf157622e5af6f00c0/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a7258e19f8a728baaa0902f956e4e83793dffcc --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/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, + 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":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"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"}}] + +Requests +{"action":{"id":"action","type":"q::r::r::A333333333333z3::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"},"request":"R2","resource":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"}} +{"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-dcdf157622e5af6f00c0/solution/reference.json b/tasks/cedar_authorization-dcdf157622e5af6f00c0/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/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-dcdf157622e5af6f00c0/solution/solve.sh b/tasks/cedar_authorization-dcdf157622e5af6f00c0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-dcdf157622e5af6f00c0/task.toml b/tasks/cedar_authorization-dcdf157622e5af6f00c0/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a14f45d1de7091e0272bc5427c0ea5ddb45cda79 --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-dcdf157622e5af6f00c0" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0c9de4725887e25ba2ba3d4be43e3189564b6e6101b8828c1225ab87fd3b5fae" + +[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-dcdf157622e5af6f00c0/tests/expected.json b/tasks/cedar_authorization-dcdf157622e5af6f00c0/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..771730ad8444d8a11608de78d1cc90984fbf7038 --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/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-dcdf157622e5af6f00c0/tests/grading.py b/tasks/cedar_authorization-dcdf157622e5af6f00c0/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/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-dcdf157622e5af6f00c0/tests/test.sh b/tasks/cedar_authorization-dcdf157622e5af6f00c0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/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-dcdf157622e5af6f00c0/tests/verify.py b/tasks/cedar_authorization-dcdf157622e5af6f00c0/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/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-dcdf157622e5af6f00c0/validation/openenv.json b/tasks/cedar_authorization-dcdf157622e5af6f00c0/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-dcdf157622e5af6f00c0/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-dd8efe20cc274ba3a7fe/environment/Dockerfile b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/instruction.md b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0b6ef44642ad2c1f655dd902eb8d8ff48ba9fd40 --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/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::j55555555::"", + action in [r::r::r::r::Action::"action"], + resource == r::r::r::r::j55555555::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::j55555555"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"tags":{"":{"__entity":{"id":"","type":"r::r::r::r::r"}}},"uid":{"id":"","type":"r::r::r::r::r333"}},{"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":"r::r::r::r::j55555555"},"request":"R1","resource":{"id":"","type":"r::r::r::r::j55555555"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"request":"R3","resource":{"id":"","type":"r::r::r::r::j55555555"}} +{"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-dd8efe20cc274ba3a7fe/solution/reference.json b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/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-dd8efe20cc274ba3a7fe/solution/solve.sh b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/task.toml b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fb58168b4af6581211449d8ab19579149e63794a --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-dd8efe20cc274ba3a7fe" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "69856700feb2c6b62624ee307eed4a083ca881ea132fd18ae5cc61d6d5d77ed9" + +[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-dd8efe20cc274ba3a7fe/tests/expected.json b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/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-dd8efe20cc274ba3a7fe/tests/grading.py b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/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-dd8efe20cc274ba3a7fe/tests/test.sh b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/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-dd8efe20cc274ba3a7fe/tests/verify.py b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/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-dd8efe20cc274ba3a7fe/validation/openenv.json b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-dd8efe20cc274ba3a7fe/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-dda170516ed09cbe3127/environment/Dockerfile b/tasks/cedar_authorization-dda170516ed09cbe3127/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-dda170516ed09cbe3127/instruction.md b/tasks/cedar_authorization-dda170516ed09cbe3127/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..655c99026d602edcfbcc710942cec584b2661ded --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/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) < ((-983374224517606822) + (-940422246894996750) + duration("742193319788760937ms").toHours())) && (A5cZr9000rrrrEErr::"" in A5cZr9000rrrrEErr::"") +}; + +policy1 +forbid( + principal, + action in [j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action::"action"], + resource +) when { + true && (j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a::"" has r) && true && (j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a::"" in resource.j5530000000.j5530000000) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cZr9000rrrrEErr"}},{"attrs":{"j5530000000":{"__entity":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}},"r":""},"parents":[],"uid":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action"}}] + +Requests +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R1","resource":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"A5cZr9000rrrrEErr"},"request":"R2","resource":{"id":"","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"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-dda170516ed09cbe3127/solution/reference.json b/tasks/cedar_authorization-dda170516ed09cbe3127/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..3ab6047998bab41a5021c3334dd51e3bd7677e03 --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":["policy1"],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-dda170516ed09cbe3127/solution/solve.sh b/tasks/cedar_authorization-dda170516ed09cbe3127/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-dda170516ed09cbe3127/task.toml b/tasks/cedar_authorization-dda170516ed09cbe3127/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e354a74de124e9dda82093d5e057d800a8c01723 --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-dda170516ed09cbe3127" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "3378b2cc8f2c113aa88a04d17e25cf98ebb18f45b95194376c1581f37deb4255" + +[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-dda170516ed09cbe3127/tests/expected.json b/tasks/cedar_authorization-dda170516ed09cbe3127/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..3ab6047998bab41a5021c3334dd51e3bd7677e03 --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":["policy1"],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-dda170516ed09cbe3127/tests/grading.py b/tasks/cedar_authorization-dda170516ed09cbe3127/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/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-dda170516ed09cbe3127/tests/test.sh b/tasks/cedar_authorization-dda170516ed09cbe3127/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/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-dda170516ed09cbe3127/tests/verify.py b/tasks/cedar_authorization-dda170516ed09cbe3127/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/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-dda170516ed09cbe3127/validation/openenv.json b/tasks/cedar_authorization-dda170516ed09cbe3127/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-dda170516ed09cbe3127/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-ddbb43c49e15fce86efc/environment/Dockerfile b/tasks/cedar_authorization-ddbb43c49e15fce86efc/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ddbb43c49e15fce86efc/instruction.md b/tasks/cedar_authorization-ddbb43c49e15fce86efc/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..14122b68a3d916319061cb4697ac6a326ce94ec9 --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/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::LXY::LYY::LQg::qggEggg5c::sYYY::a::"", + action in [LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action::"action"], + resource == LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a::"" +) when { + 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":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::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":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"B":"","r":{"__extn":{"arg":"1120-05-06","fn":"datetime"}}},"principal":{"id":"","type":"l"},"request":"R1","resource":{"id":"","type":"l"}} +{"action":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"},"context":{},"principal":{"id":"","type":"l"},"request":"R2","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} +{"action":{"id":"action","type":"Action"},"context":{"B":"","r":{"__extn":{"arg":"1120-05-06","fn":"datetime"}}},"principal":{"id":"","type":"l"},"request":"R3","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} +{"action":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"},"context":{"B":"","r":{"__extn":{"arg":"1120-05-06","fn":"datetime"}}},"principal":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"},"request":"R4","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-ddbb43c49e15fce86efc/solution/reference.json b/tasks/cedar_authorization-ddbb43c49e15fce86efc/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-ddbb43c49e15fce86efc/solution/solve.sh b/tasks/cedar_authorization-ddbb43c49e15fce86efc/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ddbb43c49e15fce86efc/task.toml b/tasks/cedar_authorization-ddbb43c49e15fce86efc/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..939b182900a429276186df48fed50644012b12cb --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ddbb43c49e15fce86efc" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "1f6e3d9f75f67f66eb0e1ef268d4654ec079236f41b9962bc72f900beb4e2a44" + +[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-ddbb43c49e15fce86efc/tests/expected.json b/tasks/cedar_authorization-ddbb43c49e15fce86efc/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-ddbb43c49e15fce86efc/tests/grading.py b/tasks/cedar_authorization-ddbb43c49e15fce86efc/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/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-ddbb43c49e15fce86efc/tests/test.sh b/tasks/cedar_authorization-ddbb43c49e15fce86efc/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/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-ddbb43c49e15fce86efc/tests/verify.py b/tasks/cedar_authorization-ddbb43c49e15fce86efc/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/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-ddbb43c49e15fce86efc/validation/openenv.json b/tasks/cedar_authorization-ddbb43c49e15fce86efc/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ddbb43c49e15fce86efc/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-de3671757eaa7feadd97/environment/Dockerfile b/tasks/cedar_authorization-de3671757eaa7feadd97/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-de3671757eaa7feadd97/instruction.md b/tasks/cedar_authorization-de3671757eaa7feadd97/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ebed8170b379f557e2ae3cd66fbfe665fc5d9e10 --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/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::"", + action in [Action::"action",Action::"action"], + resource is a +) when { + true && ((if true then {"": a::""} else {"": a::""})[""] in (if true then {"": [principal]} else context)[""]) && ({"": action}[""] in {"": [action]}[""]) && 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":"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":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::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-de3671757eaa7feadd97/solution/reference.json b/tasks/cedar_authorization-de3671757eaa7feadd97/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-de3671757eaa7feadd97/solution/solve.sh b/tasks/cedar_authorization-de3671757eaa7feadd97/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-de3671757eaa7feadd97/task.toml b/tasks/cedar_authorization-de3671757eaa7feadd97/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7ae8a1c9e6317917367c935fe5a30186db1b0d8e --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-de3671757eaa7feadd97" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "dda45e842d0c11749a6247047ea21ca5fba5a3b07baee6790e49427f27a6a74e" + +[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-de3671757eaa7feadd97/tests/expected.json b/tasks/cedar_authorization-de3671757eaa7feadd97/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-de3671757eaa7feadd97/tests/grading.py b/tasks/cedar_authorization-de3671757eaa7feadd97/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/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-de3671757eaa7feadd97/tests/test.sh b/tasks/cedar_authorization-de3671757eaa7feadd97/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/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-de3671757eaa7feadd97/tests/verify.py b/tasks/cedar_authorization-de3671757eaa7feadd97/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/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-de3671757eaa7feadd97/validation/openenv.json b/tasks/cedar_authorization-de3671757eaa7feadd97/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-de3671757eaa7feadd97/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-de436df83c8c0dad1432/environment/Dockerfile b/tasks/cedar_authorization-de436df83c8c0dad1432/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-de436df83c8c0dad1432/instruction.md b/tasks/cedar_authorization-de436df83c8c0dad1432/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..979d9227222aeab73e9de6e1e3ebbf29d1f8c7ef --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/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 in a::"", + action == Action::"action", + resource == a::"" +) when { + 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":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"},"request":"R2","resource":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::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-de436df83c8c0dad1432/solution/reference.json b/tasks/cedar_authorization-de436df83c8c0dad1432/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..ffb2f051a7f9bd165f222e264638c800ced39987 --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-de436df83c8c0dad1432/solution/solve.sh b/tasks/cedar_authorization-de436df83c8c0dad1432/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-de436df83c8c0dad1432/task.toml b/tasks/cedar_authorization-de436df83c8c0dad1432/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1868a545cff1663f858badd62991f0cbb1c8d78e --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-de436df83c8c0dad1432" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "c921b0a22243ce080511f05235ba81738c02416d7a766ef2356b7f34f10835c1" + +[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-de436df83c8c0dad1432/tests/expected.json b/tasks/cedar_authorization-de436df83c8c0dad1432/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..ffb2f051a7f9bd165f222e264638c800ced39987 --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-de436df83c8c0dad1432/tests/grading.py b/tasks/cedar_authorization-de436df83c8c0dad1432/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/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-de436df83c8c0dad1432/tests/test.sh b/tasks/cedar_authorization-de436df83c8c0dad1432/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/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-de436df83c8c0dad1432/tests/verify.py b/tasks/cedar_authorization-de436df83c8c0dad1432/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/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-de436df83c8c0dad1432/validation/openenv.json b/tasks/cedar_authorization-de436df83c8c0dad1432/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-de436df83c8c0dad1432/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-e07e4ae7e395c9b9a144/environment/Dockerfile b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e07e4ae7e395c9b9a144/instruction.md b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f00a85e3d7263e35bb92038b5a09ea9af16a0204 --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/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 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":"A::a"}},{"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":"action","type":"A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::Action"}}] + +Requests +{"action":{"id":"action","type":"A::Action"},"context":{},"principal":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"},"request":"R1","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":"A::a"},"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":"A::Action"},"context":{},"principal":{"id":"","type":"B::A::A::r::r::r::r::r::S3OYlX0xI99Ar0000::r"},"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-e07e4ae7e395c9b9a144/solution/reference.json b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/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-e07e4ae7e395c9b9a144/solution/solve.sh b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e07e4ae7e395c9b9a144/task.toml b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fc3f6dcdf2f1efb23855c68e425f32e3ce922ad1 --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e07e4ae7e395c9b9a144" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0e9b702a8edfadb295230e0dbe2db52c522b80ef424e6d3ede9d019323fa3c6e" + +[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-e07e4ae7e395c9b9a144/tests/expected.json b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/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-e07e4ae7e395c9b9a144/tests/grading.py b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/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-e07e4ae7e395c9b9a144/tests/test.sh b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/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-e07e4ae7e395c9b9a144/tests/verify.py b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/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-e07e4ae7e395c9b9a144/validation/openenv.json b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e07e4ae7e395c9b9a144/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-e089283d8d02ca8442d7/environment/Dockerfile b/tasks/cedar_authorization-e089283d8d02ca8442d7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e089283d8d02ca8442d7/instruction.md b/tasks/cedar_authorization-e089283d8d02ca8442d7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..bb957a9c1bdada8be5dc0a755f2d086309900527 --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/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 == r::r::r::r::Action::"action", + resource == r::r::r::r::r::"" +) when { + true && (if if if true then false else false then principal is r::r::r::r::r 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 a::"", + action in [Action::"action"], + resource in a::"" +) when { + true && resource.getTag("").getTag("").hasTag("") +}; + +Entities +[{"attrs":{},"parents":[],"tags":{"":{"__entity":{"id":"","type":"a"}}},"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{"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":{"O44444444333":true},"parents":[{"id":"","type":"r::r::r::r::r"}],"uid":{"id":"tttttttttt","type":"r::r::r::r::r"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"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":"Action"},"context":{},"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-e089283d8d02ca8442d7/solution/reference.json b/tasks/cedar_authorization-e089283d8d02ca8442d7/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/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-e089283d8d02ca8442d7/solution/solve.sh b/tasks/cedar_authorization-e089283d8d02ca8442d7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e089283d8d02ca8442d7/task.toml b/tasks/cedar_authorization-e089283d8d02ca8442d7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b7ea1941c4152a1fb39860c0a787a825b825476e --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e089283d8d02ca8442d7" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "3414bcc4af58688946eae75ca3e2400915048ae60450d2267db812c869ec19f9" + +[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-e089283d8d02ca8442d7/tests/expected.json b/tasks/cedar_authorization-e089283d8d02ca8442d7/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/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-e089283d8d02ca8442d7/tests/grading.py b/tasks/cedar_authorization-e089283d8d02ca8442d7/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/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-e089283d8d02ca8442d7/tests/test.sh b/tasks/cedar_authorization-e089283d8d02ca8442d7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/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-e089283d8d02ca8442d7/tests/verify.py b/tasks/cedar_authorization-e089283d8d02ca8442d7/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/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-e089283d8d02ca8442d7/validation/openenv.json b/tasks/cedar_authorization-e089283d8d02ca8442d7/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e089283d8d02ca8442d7/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-e0dc43f58481a1357708/environment/Dockerfile b/tasks/cedar_authorization-e0dc43f58481a1357708/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e0dc43f58481a1357708/instruction.md b/tasks/cedar_authorization-e0dc43f58481a1357708/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..37f7400ab80b40c8781ea98ab3e1ea7d2ad6c840 --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/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::A::A::A::A::A::A::A::A::a in A::A::A::A::A::A::A::A::A::a::"", + action in [A::A::A::A::A::A::A::A::A::Action::"action"], + resource is A::A::A::A::A::A::A::A::A::a in A::A::A::A::A::A::A::A::A::a::"" +) when { + true && (true || (false || ("HHHHH" == ""))) +}; + +policy1 +forbid( + principal == q::r::r::A333333333333z3::r::"", + action == q::r::r::A333333333333z3::Action::"", + resource == q::r::r::A333333333333z3::r::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A333333333333z3::A"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A333333333333z3::A00_______3333063"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A333333333333z3::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A333333333333z3::r"}},{"attrs":{},"parents":[{"id":"","type":"q::r::r::A333333333333z3::A"},{"id":"","type":"q::r::r::A333333333333z3::r"},{"id":"","type":"q::r::r::A333333333333z3::A00_______3333063"},{"id":">","type":"q::r::r::A333333333333z3::r33"},{"id":">>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>","type":"q::r::r::A333333333333z3::r33"}],"uid":{"id":"","type":"q::r::r::A333333333333z3::r33"}},{"attrs":{},"parents":[{"id":"","type":"q::r::r::A333333333333z3::r"},{"id":"","type":"q::r::r::A333333333333z3::A"},{"id":">>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>","type":"q::r::r::A333333333333z3::r33"},{"id":"","type":"q::r::r::A333333333333z3::A00_______3333063"}],"uid":{"id":">","type":"q::r::r::A333333333333z3::r33"}},{"attrs":{},"parents":[{"id":"","type":"q::r::r::A333333333333z3::r"},{"id":"","type":"q::r::r::A333333333333z3::A00_______3333063"}],"uid":{"id":">>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>","type":"q::r::r::A333333333333z3::r33"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::A::A::A::A::A::A::A::A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::Action"}}] + +Requests +{"action":{"id":"~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::Action"},"context":{},"principal":{"id":"","type":"q::r::r::A333333333333z3::A"},"request":"R1","resource":{"id":"","type":"q::r::r::A333333333333z3::r"}} +{"action":{"id":"action","type":"A::A::A::A::A::A::A::A::A::Action"},"context":{},"principal":{"id":"","type":"A::A::A::A::A::A::A::A::A::a"},"request":"R2","resource":{"id":"","type":"A::A::A::A::A::A::A::A::A::a"}} +{"action":{"id":"action","type":"A::A::A::A::A::A::A::A::A::Action"},"context":{},"principal":{"id":"","type":"A::A::A::A::A::A::A::A::A::a"},"request":"R3","resource":{"id":"","type":"q::r::r::A333333333333z3::r"}} +{"action":{"id":"","type":"q::r::r::A333333333333z3::Action"},"context":{},"principal":{"id":"","type":"q::r::r::A333333333333z3::r"},"request":"R4","resource":{"id":"","type":"q::r::r::A333333333333z3::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e0dc43f58481a1357708/solution/reference.json b/tasks/cedar_authorization-e0dc43f58481a1357708/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/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-e0dc43f58481a1357708/solution/solve.sh b/tasks/cedar_authorization-e0dc43f58481a1357708/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e0dc43f58481a1357708/task.toml b/tasks/cedar_authorization-e0dc43f58481a1357708/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..07557b65a2eb0a98f0ce38ec55ea39b0058c89ea --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e0dc43f58481a1357708" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "47f1b8fcf332f0656ba6435f2d3c4aec87a8a6af30e9ec43365fed6cdea59d40" + +[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-e0dc43f58481a1357708/tests/expected.json b/tasks/cedar_authorization-e0dc43f58481a1357708/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/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-e0dc43f58481a1357708/tests/grading.py b/tasks/cedar_authorization-e0dc43f58481a1357708/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/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-e0dc43f58481a1357708/tests/test.sh b/tasks/cedar_authorization-e0dc43f58481a1357708/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/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-e0dc43f58481a1357708/tests/verify.py b/tasks/cedar_authorization-e0dc43f58481a1357708/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/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-e0dc43f58481a1357708/validation/openenv.json b/tasks/cedar_authorization-e0dc43f58481a1357708/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e0dc43f58481a1357708/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-e15ee523a38ee9f6516b/environment/Dockerfile b/tasks/cedar_authorization-e15ee523a38ee9f6516b/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e15ee523a38ee9f6516b/instruction.md b/tasks/cedar_authorization-e15ee523a38ee9f6516b/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4e83285ea9e5a25a5cdbb2a73cda514fb214f420 --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/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 == r::r::r::r::P::"", + action in [r::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::O44_______44"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::_YlW33c3333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::j"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::n"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::o"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r333333333"}},{"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":"","type":"r::r::r::r::P"},"request":"R1","resource":{"id":"r","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"r","type":"a"},"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":"","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":"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-e15ee523a38ee9f6516b/solution/reference.json b/tasks/cedar_authorization-e15ee523a38ee9f6516b/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/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-e15ee523a38ee9f6516b/solution/solve.sh b/tasks/cedar_authorization-e15ee523a38ee9f6516b/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e15ee523a38ee9f6516b/task.toml b/tasks/cedar_authorization-e15ee523a38ee9f6516b/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5b63abc0e95975a375d6208c4daeac9ab6e4a4b7 --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e15ee523a38ee9f6516b" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "7c65af8a5937e9c5dfa53fe634c5f1984e2490738cba85f245eeba94fb0f4678" + +[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-e15ee523a38ee9f6516b/tests/expected.json b/tasks/cedar_authorization-e15ee523a38ee9f6516b/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/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-e15ee523a38ee9f6516b/tests/grading.py b/tasks/cedar_authorization-e15ee523a38ee9f6516b/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/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-e15ee523a38ee9f6516b/tests/test.sh b/tasks/cedar_authorization-e15ee523a38ee9f6516b/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/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-e15ee523a38ee9f6516b/tests/verify.py b/tasks/cedar_authorization-e15ee523a38ee9f6516b/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/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-e15ee523a38ee9f6516b/validation/openenv.json b/tasks/cedar_authorization-e15ee523a38ee9f6516b/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e15ee523a38ee9f6516b/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-e21dcd6f63da5838042b/environment/Dockerfile b/tasks/cedar_authorization-e21dcd6f63da5838042b/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e21dcd6f63da5838042b/instruction.md b/tasks/cedar_authorization-e21dcd6f63da5838042b/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..74e04f102b9c14b4120830239ae9fb83dc5eeec7 --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/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::LXY::LYY::LQg::qggEggg5c::sYYY::a::"", + action in [LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action::"action"], + resource == LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a::"" +) when { + 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":"LPY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYX"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}},{"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":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"}},{"attrs":{},"parents":[],"uid":{"id":"mmmm3333w*","type":"qgg"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"(","type":"LYe"},"request":"R1","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"(","type":"LYe"},"request":"R2","resource":{"id":"(","type":"LYe"}} +{"action":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"},"context":{},"principal":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"},"request":"R3","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} +{"action":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"},"context":{},"principal":{"id":"(","type":"LYe"},"request":"R4","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e21dcd6f63da5838042b/solution/reference.json b/tasks/cedar_authorization-e21dcd6f63da5838042b/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/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-e21dcd6f63da5838042b/solution/solve.sh b/tasks/cedar_authorization-e21dcd6f63da5838042b/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e21dcd6f63da5838042b/task.toml b/tasks/cedar_authorization-e21dcd6f63da5838042b/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..86db6c55dcf96e036c1f69e8c5473ec5f257f866 --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e21dcd6f63da5838042b" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "29f6a9525b995b09e95fcce41e38b1a569df899c8f8fb8d6f8c01196fc9c20b9" + +[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-e21dcd6f63da5838042b/tests/expected.json b/tasks/cedar_authorization-e21dcd6f63da5838042b/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/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-e21dcd6f63da5838042b/tests/grading.py b/tasks/cedar_authorization-e21dcd6f63da5838042b/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/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-e21dcd6f63da5838042b/tests/test.sh b/tasks/cedar_authorization-e21dcd6f63da5838042b/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/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-e21dcd6f63da5838042b/tests/verify.py b/tasks/cedar_authorization-e21dcd6f63da5838042b/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/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-e21dcd6f63da5838042b/validation/openenv.json b/tasks/cedar_authorization-e21dcd6f63da5838042b/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e21dcd6f63da5838042b/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-e25d797fb11052dd026c/environment/Dockerfile b/tasks/cedar_authorization-e25d797fb11052dd026c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e25d797fb11052dd026c/instruction.md b/tasks/cedar_authorization-e25d797fb11052dd026c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e64f20b703c20b25cea893890bc8f60ce0636afc --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/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 == PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEEEEEEEEEE::"", + action in [PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action::"action",PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action::"action",PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action::"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":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"}},{"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"}}] + +Requests +{"action":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"},"context":{},"principal":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEEEEEEEEEE"},"request":"R1","resource":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::dEEEEEEEEE"}} +{"action":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"},"context":{},"principal":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::lHHHHHHH"},"request":"R2","resource":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEch0005"}} +{"action":{"id":"action","type":"q::r::r::A333333333333z3::Action"},"context":{},"principal":{"id":"~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::r"},"request":"R3","resource":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::dEEEEEEEEE"}} +{"action":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"},"context":{},"principal":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::r"},"request":"R4","resource":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEEEEEEH"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e25d797fb11052dd026c/solution/reference.json b/tasks/cedar_authorization-e25d797fb11052dd026c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/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-e25d797fb11052dd026c/solution/solve.sh b/tasks/cedar_authorization-e25d797fb11052dd026c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e25d797fb11052dd026c/task.toml b/tasks/cedar_authorization-e25d797fb11052dd026c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f7a553de1c5e36745c5f4d1cf89283b265bb4bfa --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e25d797fb11052dd026c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "18d26a3f694014c6fdb9ce4edd79c11398b7e29c88d89cdbdd16ec9eb1092cff" + +[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-e25d797fb11052dd026c/tests/expected.json b/tasks/cedar_authorization-e25d797fb11052dd026c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/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-e25d797fb11052dd026c/tests/grading.py b/tasks/cedar_authorization-e25d797fb11052dd026c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/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-e25d797fb11052dd026c/tests/test.sh b/tasks/cedar_authorization-e25d797fb11052dd026c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/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-e25d797fb11052dd026c/tests/verify.py b/tasks/cedar_authorization-e25d797fb11052dd026c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/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-e25d797fb11052dd026c/validation/openenv.json b/tasks/cedar_authorization-e25d797fb11052dd026c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e25d797fb11052dd026c/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-e260488c2906994bc6e4/environment/Dockerfile b/tasks/cedar_authorization-e260488c2906994bc6e4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e260488c2906994bc6e4/instruction.md b/tasks/cedar_authorization-e260488c2906994bc6e4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d5d6f6894adf3d632b8705eb9d76921a92e9b08d --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/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, + action == errrr::errrr::err::r::Action::"action", + resource is errrr::errrr::err::r::a +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"errrr::errrr::err::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"**","type":"LYg::LYY::a"}},{"attrs":{},"parents":[],"uid":{"id":"44","type":"errrr::errrr::err::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"LYg::LYY::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"errrr::errrr::err::r::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":"errrr::errrr::err::r::Action"},"context":{},"principal":{"id":"44","type":"errrr::errrr::err::r::a"},"request":"R2","resource":{"id":"44","type":"errrr::errrr::err::r::a"}} +{"action":{"id":"action","type":"errrr::errrr::err::r::Action"},"context":{},"principal":{"id":"44","type":"errrr::errrr::err::r::a"},"request":"R3","resource":{"id":"**","type":"LYg::LYY::a"}} +{"action":{"id":"action","type":"LYg::LYY::Action"},"context":{},"principal":{"id":"44","type":"errrr::errrr::err::r::a"},"request":"R4","resource":{"id":"44","type":"errrr::errrr::err::r::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e260488c2906994bc6e4/solution/reference.json b/tasks/cedar_authorization-e260488c2906994bc6e4/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/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-e260488c2906994bc6e4/solution/solve.sh b/tasks/cedar_authorization-e260488c2906994bc6e4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e260488c2906994bc6e4/task.toml b/tasks/cedar_authorization-e260488c2906994bc6e4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ba43e0e1bde37a02575918622f3a8e8595a5c57e --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e260488c2906994bc6e4" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "4000f87ed0b2bb5da53fc004cb65d4f6068827f2ef1a49a28ed8fef8a128d3a5" + +[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-e260488c2906994bc6e4/tests/expected.json b/tasks/cedar_authorization-e260488c2906994bc6e4/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/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-e260488c2906994bc6e4/tests/grading.py b/tasks/cedar_authorization-e260488c2906994bc6e4/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/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-e260488c2906994bc6e4/tests/test.sh b/tasks/cedar_authorization-e260488c2906994bc6e4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/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-e260488c2906994bc6e4/tests/verify.py b/tasks/cedar_authorization-e260488c2906994bc6e4/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/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-e260488c2906994bc6e4/validation/openenv.json b/tasks/cedar_authorization-e260488c2906994bc6e4/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e260488c2906994bc6e4/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-e2c56b165d209780383f/environment/Dockerfile b/tasks/cedar_authorization-e2c56b165d209780383f/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e2c56b165d209780383f/instruction.md b/tasks/cedar_authorization-e2c56b165d209780383f/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..922e376bd41670530dd008837d33016ef37bf9ae --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/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, + action in [j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action::"action"], + resource +) when { + true && (j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a::"" has r) && true && (j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a::"" in resource.j5530000000.j5530000000) +}; + +Entities +[{"attrs":{"j5530000000":{"__entity":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}},"r":""},"parents":[],"uid":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}},{"attrs":{},"parents":[],"uid":{"id":"**","type":"LYg::LYY::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"LYg::LYY::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action"}}] + +Requests +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action"},"context":{},"principal":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"},"request":"R1","resource":{"id":"**","type":"LYg::LYY::a"}} +{"action":{"id":"action","type":"LYg::LYY::Action"},"context":{},"principal":{"id":"**","type":"LYg::LYY::a"},"request":"R2","resource":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}} +{"action":{"id":"action","type":"LYg::LYY::Action"},"context":{},"principal":{"id":"**","type":"LYg::LYY::a"},"request":"R3","resource":{"id":"**","type":"LYg::LYY::a"}} +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action"},"context":{},"principal":{"id":"**","type":"LYg::LYY::a"},"request":"R4","resource":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e2c56b165d209780383f/solution/reference.json b/tasks/cedar_authorization-e2c56b165d209780383f/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..fecf70cd3b6d5f0c26c9612fffeb0675378d2208 --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":["policy1"],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-e2c56b165d209780383f/solution/solve.sh b/tasks/cedar_authorization-e2c56b165d209780383f/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e2c56b165d209780383f/task.toml b/tasks/cedar_authorization-e2c56b165d209780383f/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ebde8a6ede351277e5c65ddde15eacd8fdb1ee1e --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e2c56b165d209780383f" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ebea2eaae7f13802eb53dab82862dcd16160042c21b03cfbb5dbdb5810b8f882" + +[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-e2c56b165d209780383f/tests/expected.json b/tasks/cedar_authorization-e2c56b165d209780383f/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..fecf70cd3b6d5f0c26c9612fffeb0675378d2208 --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":["policy1"],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-e2c56b165d209780383f/tests/grading.py b/tasks/cedar_authorization-e2c56b165d209780383f/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/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-e2c56b165d209780383f/tests/test.sh b/tasks/cedar_authorization-e2c56b165d209780383f/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/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-e2c56b165d209780383f/tests/verify.py b/tasks/cedar_authorization-e2c56b165d209780383f/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/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-e2c56b165d209780383f/validation/openenv.json b/tasks/cedar_authorization-e2c56b165d209780383f/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e2c56b165d209780383f/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-e2d09b3b33fa23189e6c/environment/Dockerfile b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e2d09b3b33fa23189e6c/instruction.md b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4a6c25ee0fdacc36b29eea1dd71040ca129ad17a --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/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))) && (!(!(principal is a))) +}; + +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":{},"parents":[],"uid":{"id":"","type":"Action"}},{"attrs":{"Tqqqqqqqq":{"__extn":{"arg":"5568-01-01","fn":"datetime"}}},"parents":[],"uid":{"id":"","type":"O4444124"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Tqqqqqqqq"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[{"id":"","type":"O4444124"},{"id":"","type":"Tqqqqqqqq"}],"uid":{"id":"","type":"iYYYYYf4444444444"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"hqqqqqqqq":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"Tqqqqqqqq"},"request":"R1","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":"R2","resource":{"id":"","type":"iYYYYYf4444444444"}} +{"action":{"id":"","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-e2d09b3b33fa23189e6c/solution/reference.json b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/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-e2d09b3b33fa23189e6c/solution/solve.sh b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e2d09b3b33fa23189e6c/task.toml b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..949c95bfab856d04fcf90f9a594a9f214bcd97df --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e2d09b3b33fa23189e6c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "25742bfd41f7abfb0f718ade8e42684d9c6d3aec9f2c995826f16bb832318df8" + +[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-e2d09b3b33fa23189e6c/tests/expected.json b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/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-e2d09b3b33fa23189e6c/tests/grading.py b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/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-e2d09b3b33fa23189e6c/tests/test.sh b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/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-e2d09b3b33fa23189e6c/tests/verify.py b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/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-e2d09b3b33fa23189e6c/validation/openenv.json b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e2d09b3b33fa23189e6c/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-e3b56a533cde8977eb0a/environment/Dockerfile b/tasks/cedar_authorization-e3b56a533cde8977eb0a/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e3b56a533cde8977eb0a/instruction.md b/tasks/cedar_authorization-e3b56a533cde8977eb0a/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..dcd7924444e58ac59de9f2c0f46f5a3eba869e27 --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/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 O::j5w33333::r::r::r::j550L556::r::"", + action, + resource in O::j5w33333::r::r::r::j550L556::r::"" +) when { + true && (if if if false then false else false then true else true then true else true) && true +}; + +policy1 +forbid( + principal in r::r::r::r::j55555555::"", + action in [r::r::r::r::Action::"action"], + resource == r::r::r::r::j55555555::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::j55555555"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"tags":{"":{"__entity":{"id":"","type":"r::r::r::r::r"}}},"uid":{"id":"","type":"r::r::r::r::r333"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"O::j5w33333::r::r::r::j550L556::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":"O::j5w33333::r::r::r::j550L556::r"},"request":"R1","resource":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"request":"R2","resource":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}} +{"action":{"id":"action","type":"O::j5w33333::r::r::r::j550L556::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"request":"R3","resource":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"request":"R4","resource":{"id":"","type":"r::r::r::r::j55555555"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e3b56a533cde8977eb0a/solution/reference.json b/tasks/cedar_authorization-e3b56a533cde8977eb0a/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/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-e3b56a533cde8977eb0a/solution/solve.sh b/tasks/cedar_authorization-e3b56a533cde8977eb0a/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e3b56a533cde8977eb0a/task.toml b/tasks/cedar_authorization-e3b56a533cde8977eb0a/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..37c45980363d2a9d3e34500ff79ca86c91ce3957 --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e3b56a533cde8977eb0a" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "19c1bbfb8b617371a9f50d6ce115c2031b62a8cec8dcc319e3d3ef6951bc7341" + +[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-e3b56a533cde8977eb0a/tests/expected.json b/tasks/cedar_authorization-e3b56a533cde8977eb0a/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/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-e3b56a533cde8977eb0a/tests/grading.py b/tasks/cedar_authorization-e3b56a533cde8977eb0a/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/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-e3b56a533cde8977eb0a/tests/test.sh b/tasks/cedar_authorization-e3b56a533cde8977eb0a/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/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-e3b56a533cde8977eb0a/tests/verify.py b/tasks/cedar_authorization-e3b56a533cde8977eb0a/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/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-e3b56a533cde8977eb0a/validation/openenv.json b/tasks/cedar_authorization-e3b56a533cde8977eb0a/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e3b56a533cde8977eb0a/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-e436f00201ad4d33762c/environment/Dockerfile b/tasks/cedar_authorization-e436f00201ad4d33762c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e436f00201ad4d33762c/instruction.md b/tasks/cedar_authorization-e436f00201ad4d33762c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b32b2a9ea50932cf5cff7650e457b478aa36cca4 --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/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 in r::E::oKKKKKKKK33::a::"", + action in [r::E::oKKKKKKKK33::Action::"action"], + resource in r::E::oKKKKKKKK33::a::"" +) when { + true && (!(!(!false))) && (!(!(!false))) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::E::oKKKKKKKK33::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::E::oKKKKKKKK33::Action"}}] + +Requests +{"action":{"id":"action","type":"r::E::oKKKKKKKK33::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::E::oKKKKKKKK33::Action"},"context":{},"principal":{"id":"","type":"r::E::oKKKKKKKK33::a"},"request":"R2","resource":{"id":"","type":"r::E::oKKKKKKKK33::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":"r::E::oKKKKKKKK33::a"},"request":"R4","resource":{"id":"","type":"r::E::oKKKKKKKK33::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e436f00201ad4d33762c/solution/reference.json b/tasks/cedar_authorization-e436f00201ad4d33762c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..942677315495650e0ac5e80661490d67896ba08f --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/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-e436f00201ad4d33762c/solution/solve.sh b/tasks/cedar_authorization-e436f00201ad4d33762c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e436f00201ad4d33762c/task.toml b/tasks/cedar_authorization-e436f00201ad4d33762c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8169d7351dc69281590451ca71033e206878c1b9 --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e436f00201ad4d33762c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "80989c904b5d4a71c1ae6cf633cd4130ce4c3c00977c18c902d3b38bcd847168" + +[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-e436f00201ad4d33762c/tests/expected.json b/tasks/cedar_authorization-e436f00201ad4d33762c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..942677315495650e0ac5e80661490d67896ba08f --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/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-e436f00201ad4d33762c/tests/grading.py b/tasks/cedar_authorization-e436f00201ad4d33762c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/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-e436f00201ad4d33762c/tests/test.sh b/tasks/cedar_authorization-e436f00201ad4d33762c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/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-e436f00201ad4d33762c/tests/verify.py b/tasks/cedar_authorization-e436f00201ad4d33762c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/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-e436f00201ad4d33762c/validation/openenv.json b/tasks/cedar_authorization-e436f00201ad4d33762c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e436f00201ad4d33762c/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-e482e6756fa4319e1971/environment/Dockerfile b/tasks/cedar_authorization-e482e6756fa4319e1971/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e482e6756fa4319e1971/instruction.md b/tasks/cedar_authorization-e482e6756fa4319e1971/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b5bd710e4ebfa0fab1d5836971e3005b54cf0e05 --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/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::LXY::LYY::LQg::qggEggg5c::sYYY::a::"", + action in [LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action::"action"], + resource == LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a::"" +) when { + true +}; + +policy1 +forbid( + principal in a::"", + action in [Action::"action"], + resource in a::"" +) when { + true && (if if ip("198.198.198.198").isMulticast() then action in [a::"", a::"", a::""] else ip("198.198.198.198").isMulticast() then true else [true, true, true].contains(true)) && true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"}}] + +Requests +{"action":{"id":"action","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::Action"},"context":{},"principal":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"},"request":"R1","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"},"request":"R2","resource":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"LYY::LXY::LYY::LQg::qggEggg5c::sYYY::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-e482e6756fa4319e1971/solution/reference.json b/tasks/cedar_authorization-e482e6756fa4319e1971/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/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-e482e6756fa4319e1971/solution/solve.sh b/tasks/cedar_authorization-e482e6756fa4319e1971/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e482e6756fa4319e1971/task.toml b/tasks/cedar_authorization-e482e6756fa4319e1971/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f9c677bf3f7ce04399b6bea0b09d5f944f29fdb2 --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e482e6756fa4319e1971" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "c3ba91ec3aea7d4fcd612d9ea7fe07db08876064e26fbbae0a1d8048ca3e6d31" + +[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-e482e6756fa4319e1971/tests/expected.json b/tasks/cedar_authorization-e482e6756fa4319e1971/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/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-e482e6756fa4319e1971/tests/grading.py b/tasks/cedar_authorization-e482e6756fa4319e1971/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/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-e482e6756fa4319e1971/tests/test.sh b/tasks/cedar_authorization-e482e6756fa4319e1971/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/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-e482e6756fa4319e1971/tests/verify.py b/tasks/cedar_authorization-e482e6756fa4319e1971/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/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-e482e6756fa4319e1971/validation/openenv.json b/tasks/cedar_authorization-e482e6756fa4319e1971/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e482e6756fa4319e1971/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-e57c9af7eb25ef6bb089/environment/Dockerfile b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e57c9af7eb25ef6bb089/instruction.md b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8823ab7b534651acf1401c09133d3a1168506222 --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/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 is LYY, + action in [Action::"action",Action::"action",Action::"action"], + resource == PcY::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYYYY5c"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"PcY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"QxxO0xxxxxxxxxx::a"}},{"attrs":{},"parents":[],"uid":{"id":"**************************","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"}}] + +Requests +{"action":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"},"context":{"LYY":[["","**)))))))))))))UUUUUUUUUUUUUU"]]},"principal":{"id":"","type":"QxxO0xxxxxxxxxx::a"},"request":"R1","resource":{"id":"","type":"QxxO0xxxxxxxxxx::a"}} +{"action":{"id":"action","type":"Action"},"context":{"LYY":[[""]]},"principal":{"id":"**************************","type":"LYY"},"request":"R2","resource":{"id":"","type":"PcY"}} +{"action":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"},"context":{"LYY":[["","**)))))))))))))UUUUUUUUUUUUUU"]]},"principal":{"id":"**************************","type":"LYY"},"request":"R3","resource":{"id":"","type":"PcY"}} +{"action":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"},"context":{},"principal":{"id":"","type":"QxxO0xxxxxxxxxx::a"},"request":"R4","resource":{"id":"","type":"PcY"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e57c9af7eb25ef6bb089/solution/reference.json b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/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-e57c9af7eb25ef6bb089/solution/solve.sh b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e57c9af7eb25ef6bb089/task.toml b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7204efecbf840f989f0183b38fa21029ceb76c14 --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e57c9af7eb25ef6bb089" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "e34c059b9ddf3ad3eee57a2a6e9b573cf6dadf35cff106ba117994546232f214" + +[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-e57c9af7eb25ef6bb089/tests/expected.json b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/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-e57c9af7eb25ef6bb089/tests/grading.py b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/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-e57c9af7eb25ef6bb089/tests/test.sh b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/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-e57c9af7eb25ef6bb089/tests/verify.py b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/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-e57c9af7eb25ef6bb089/validation/openenv.json b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e57c9af7eb25ef6bb089/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-e68b6c09d807fc013898/environment/Dockerfile b/tasks/cedar_authorization-e68b6c09d807fc013898/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e68b6c09d807fc013898/instruction.md b/tasks/cedar_authorization-e68b6c09d807fc013898/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35ef9834bc1156611cd902c28358e60090159982 --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/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 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":{"g1c":{"__extn":{"arg":"2097865012305276206ms","fn":"duration"}},"tg9":false},"parents":[],"uid":{"id":"","type":"g::a"}},{"attrs":{},"parents":[],"tags":{"":{}},"uid":{"id":"NNN","type":"r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"g::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":"g::Action"},"context":{},"principal":{"id":"","type":"g::a"},"request":"R2","resource":{"id":"","type":"g::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":"g::Action"},"context":{},"principal":{"id":"NNN","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-e68b6c09d807fc013898/solution/reference.json b/tasks/cedar_authorization-e68b6c09d807fc013898/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/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-e68b6c09d807fc013898/solution/solve.sh b/tasks/cedar_authorization-e68b6c09d807fc013898/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e68b6c09d807fc013898/task.toml b/tasks/cedar_authorization-e68b6c09d807fc013898/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7507390b456a529f42a18a929276de5899ec750f --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e68b6c09d807fc013898" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d647b723b1e5073817dec022f96152964dcf0c0bc8be4e04ee309614d6605b4f" + +[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-e68b6c09d807fc013898/tests/expected.json b/tasks/cedar_authorization-e68b6c09d807fc013898/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/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-e68b6c09d807fc013898/tests/grading.py b/tasks/cedar_authorization-e68b6c09d807fc013898/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/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-e68b6c09d807fc013898/tests/test.sh b/tasks/cedar_authorization-e68b6c09d807fc013898/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/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-e68b6c09d807fc013898/tests/verify.py b/tasks/cedar_authorization-e68b6c09d807fc013898/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/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-e68b6c09d807fc013898/validation/openenv.json b/tasks/cedar_authorization-e68b6c09d807fc013898/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e68b6c09d807fc013898/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-e72247367a16b2abafce/environment/Dockerfile b/tasks/cedar_authorization-e72247367a16b2abafce/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e72247367a16b2abafce/instruction.md b/tasks/cedar_authorization-e72247367a16b2abafce/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a904837fa506e9db8f60c5e4e3bc204dccff11e3 --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/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::Q::R77::R77::R77::R77::R77::U30::A::a::"", + action in [r::Q::R77::R77::R77::R77::R77::U30::A::Action::"action",r::Q::R77::R77::R77::R77::R77::U30::A::Action::"action"], + resource in r::Q::R77::R77::R77::R77::R77::U30::A::a::"" +) when { + true && (if true then true else true) && 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":"r::Q::R77::R77::R77::R77::R77::U30::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":"r::Q::R77::R77::R77::R77::R77::U30::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::Q::R77::R77::R77::R77::R77::U30::A::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::_Y333333333333"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::A"},"request":"R3","resource":{"id":"","type":"r::r::r::r::P"}} +{"action":{"id":"action","type":"r::Q::R77::R77::R77::R77::R77::U30::A::Action"},"context":{},"principal":{"id":"","type":"r::Q::R77::R77::R77::R77::R77::U30::A::a"},"request":"R4","resource":{"id":"","type":"r::Q::R77::R77::R77::R77::R77::U30::A::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e72247367a16b2abafce/solution/reference.json b/tasks/cedar_authorization-e72247367a16b2abafce/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/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-e72247367a16b2abafce/solution/solve.sh b/tasks/cedar_authorization-e72247367a16b2abafce/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e72247367a16b2abafce/task.toml b/tasks/cedar_authorization-e72247367a16b2abafce/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..98c9fbcdd2eb16dcfa20a34d8b08d608316750f1 --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e72247367a16b2abafce" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "9ec70b295ecadf3bfba2a36caa1ec27fe1ed57683af1ea6b2727fe69f1598ec9" + +[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-e72247367a16b2abafce/tests/expected.json b/tasks/cedar_authorization-e72247367a16b2abafce/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/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-e72247367a16b2abafce/tests/grading.py b/tasks/cedar_authorization-e72247367a16b2abafce/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/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-e72247367a16b2abafce/tests/test.sh b/tasks/cedar_authorization-e72247367a16b2abafce/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/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-e72247367a16b2abafce/tests/verify.py b/tasks/cedar_authorization-e72247367a16b2abafce/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/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-e72247367a16b2abafce/validation/openenv.json b/tasks/cedar_authorization-e72247367a16b2abafce/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e72247367a16b2abafce/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-e73185b98b211c8dbf17/environment/Dockerfile b/tasks/cedar_authorization-e73185b98b211c8dbf17/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e73185b98b211c8dbf17/instruction.md b/tasks/cedar_authorization-e73185b98b211c8dbf17/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..afdc87caeac3c566d7d336f1bb5bc16ffa87f1ab --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/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 == 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":[{"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":"r::r::r::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r3w333333::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::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":"r::r::r::r::Action"},"context":{},"principal":{"id":"=","type":"r::r::r::r::a"},"request":"R1","resource":{"id":"","type":"r::r::r3w333333::r::r"}} +{"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":"r::r::r::r::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":"r::r::r3w333333::r::r"},"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-e73185b98b211c8dbf17/solution/reference.json b/tasks/cedar_authorization-e73185b98b211c8dbf17/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/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-e73185b98b211c8dbf17/solution/solve.sh b/tasks/cedar_authorization-e73185b98b211c8dbf17/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e73185b98b211c8dbf17/task.toml b/tasks/cedar_authorization-e73185b98b211c8dbf17/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bcf4159abf4710bb3331acf29acb3212cf8bcd72 --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e73185b98b211c8dbf17" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "cc103c1a13ca3af5f6ab2ffdf07cf135dd5942e6737dda9703431e599958351a" + +[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-e73185b98b211c8dbf17/tests/expected.json b/tasks/cedar_authorization-e73185b98b211c8dbf17/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/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-e73185b98b211c8dbf17/tests/grading.py b/tasks/cedar_authorization-e73185b98b211c8dbf17/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/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-e73185b98b211c8dbf17/tests/test.sh b/tasks/cedar_authorization-e73185b98b211c8dbf17/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/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-e73185b98b211c8dbf17/tests/verify.py b/tasks/cedar_authorization-e73185b98b211c8dbf17/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/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-e73185b98b211c8dbf17/validation/openenv.json b/tasks/cedar_authorization-e73185b98b211c8dbf17/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e73185b98b211c8dbf17/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-e7b97bf31c264e8981ef/environment/Dockerfile b/tasks/cedar_authorization-e7b97bf31c264e8981ef/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e7b97bf31c264e8981ef/instruction.md b/tasks/cedar_authorization-e7b97bf31c264e8981ef/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..14346f548355e8d90edb8af48922d9fc4a347f91 --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/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 [r::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::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":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"},"request":"R1","resource":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"}} +{"action":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"},"context":{},"principal":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"},"request":"R3","resource":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}} +{"action":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::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-e7b97bf31c264e8981ef/solution/reference.json b/tasks/cedar_authorization-e7b97bf31c264e8981ef/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..aa62584ade49d5763b142d30b1244f873a0bf8f3 --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-e7b97bf31c264e8981ef/solution/solve.sh b/tasks/cedar_authorization-e7b97bf31c264e8981ef/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e7b97bf31c264e8981ef/task.toml b/tasks/cedar_authorization-e7b97bf31c264e8981ef/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..56b29d31787745f35c26b34e8f57c4b7d6a7b60e --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e7b97bf31c264e8981ef" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "78a95eebdcfd6a3cb29aa0442f09e54a4398c16c64db59506360e3b28f6d47f9" + +[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-e7b97bf31c264e8981ef/tests/expected.json b/tasks/cedar_authorization-e7b97bf31c264e8981ef/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..aa62584ade49d5763b142d30b1244f873a0bf8f3 --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-e7b97bf31c264e8981ef/tests/grading.py b/tasks/cedar_authorization-e7b97bf31c264e8981ef/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/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-e7b97bf31c264e8981ef/tests/test.sh b/tasks/cedar_authorization-e7b97bf31c264e8981ef/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/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-e7b97bf31c264e8981ef/tests/verify.py b/tasks/cedar_authorization-e7b97bf31c264e8981ef/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/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-e7b97bf31c264e8981ef/validation/openenv.json b/tasks/cedar_authorization-e7b97bf31c264e8981ef/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e7b97bf31c264e8981ef/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-e82e9660ca04bfee98cd/environment/Dockerfile b/tasks/cedar_authorization-e82e9660ca04bfee98cd/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e82e9660ca04bfee98cd/instruction.md b/tasks/cedar_authorization-e82e9660ca04bfee98cd/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4ffddfd3c753054596ea038f68b0c17b8e5ee7f9 --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/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 == G::u::A::_qqqqqqqqqqp::a::"", + action in [G::u::A::_qqqqqqqqqqp::Action::"action"], + resource is G::u::A::_qqqqqqqqqqp::a in G::u::A::_qqqqqqqqqqp::a::"" +) when { + true && ((-1736164148113840153) <= (-1736164148113840153)) && ((-1736164148113840153) <= (-1736164148113840153)) && ((-1736164148113840153) <= 2522015791327471591) +}; + +policy1 +forbid( + principal is r::r::r::r::r, + action == r::r::r::r::Action::"action", + resource is r::r::r::r::r +) when { + true && (["", ""].contains("") || false || ["", ""].contains("")) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"G::u::A::_qqqqqqqqqqp::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"G::u::A::_qqqqqqqqqqp::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"G::u::A::_qqqqqqqqqqp::Action"},"context":{},"principal":{"id":"","type":"G::u::A::_qqqqqqqqqqp::a"},"request":"R1","resource":{"id":"","type":"G::u::A::_qqqqqqqqqqp::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":"G::u::A::_qqqqqqqqqqp::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"G::u::A::_qqqqqqqqqqp::Action"},"context":{},"principal":{"id":"","type":"G::u::A::_qqqqqqqqqqp::a"},"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-e82e9660ca04bfee98cd/solution/reference.json b/tasks/cedar_authorization-e82e9660ca04bfee98cd/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/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-e82e9660ca04bfee98cd/solution/solve.sh b/tasks/cedar_authorization-e82e9660ca04bfee98cd/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e82e9660ca04bfee98cd/task.toml b/tasks/cedar_authorization-e82e9660ca04bfee98cd/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a67e4706bf621ab86ce67329dde444d96f5cc963 --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e82e9660ca04bfee98cd" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b1c363de630518c1a077f7f78b5983c6212274194f560031bf25b95febae50c0" + +[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-e82e9660ca04bfee98cd/tests/expected.json b/tasks/cedar_authorization-e82e9660ca04bfee98cd/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/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-e82e9660ca04bfee98cd/tests/grading.py b/tasks/cedar_authorization-e82e9660ca04bfee98cd/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/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-e82e9660ca04bfee98cd/tests/test.sh b/tasks/cedar_authorization-e82e9660ca04bfee98cd/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/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-e82e9660ca04bfee98cd/tests/verify.py b/tasks/cedar_authorization-e82e9660ca04bfee98cd/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/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-e82e9660ca04bfee98cd/validation/openenv.json b/tasks/cedar_authorization-e82e9660ca04bfee98cd/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e82e9660ca04bfee98cd/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-e8f3930e4a9c951d5800/environment/Dockerfile b/tasks/cedar_authorization-e8f3930e4a9c951d5800/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e8f3930e4a9c951d5800/instruction.md b/tasks/cedar_authorization-e8f3930e4a9c951d5800/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8cc8332fe68be4381b75968502b727b0b472ff37 --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/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::E::oKKKKKKKK33::a::"", + action in [r::E::oKKKKKKKK33::Action::"action"], + resource in r::E::oKKKKKKKK33::a::"" +) when { + true && (!(!(!false))) && (!(!(!false))) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::E::oKKKKKKKK33::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::E::oKKKKKKKK33::Action"}},{"attrs":{},"parents":[],"uid":{"id":"r","type":"a"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R1","resource":{"id":"","type":"r::E::oKKKKKKKK33::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R2","resource":{"id":"r","type":"a"}} +{"action":{"id":"action","type":"r::E::oKKKKKKKK33::Action"},"context":{},"principal":{"id":"","type":"r::E::oKKKKKKKK33::a"},"request":"R3","resource":{"id":"r","type":"a"}} +{"action":{"id":"action","type":"r::E::oKKKKKKKK33::Action"},"context":{},"principal":{"id":"","type":"r::E::oKKKKKKKK33::a"},"request":"R4","resource":{"id":"","type":"r::E::oKKKKKKKK33::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e8f3930e4a9c951d5800/solution/reference.json b/tasks/cedar_authorization-e8f3930e4a9c951d5800/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/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-e8f3930e4a9c951d5800/solution/solve.sh b/tasks/cedar_authorization-e8f3930e4a9c951d5800/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e8f3930e4a9c951d5800/task.toml b/tasks/cedar_authorization-e8f3930e4a9c951d5800/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2f20ff60e8a67675a21b51c912479b622c13c1bd --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e8f3930e4a9c951d5800" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "a7f98fef02a50cb344798c084e5f9eee2f6b22b0a8ede57d03ee27dfb96b1a8f" + +[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-e8f3930e4a9c951d5800/tests/expected.json b/tasks/cedar_authorization-e8f3930e4a9c951d5800/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/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-e8f3930e4a9c951d5800/tests/grading.py b/tasks/cedar_authorization-e8f3930e4a9c951d5800/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/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-e8f3930e4a9c951d5800/tests/test.sh b/tasks/cedar_authorization-e8f3930e4a9c951d5800/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/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-e8f3930e4a9c951d5800/tests/verify.py b/tasks/cedar_authorization-e8f3930e4a9c951d5800/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/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-e8f3930e4a9c951d5800/validation/openenv.json b/tasks/cedar_authorization-e8f3930e4a9c951d5800/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e8f3930e4a9c951d5800/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-e9415a5fbd9c4c8d5667/environment/Dockerfile b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/instruction.md b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9e4a11f409b7a6617d53814b936110c392415088 --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/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 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":{"g1c":{"__extn":{"arg":"2097865012305276206ms","fn":"duration"}},"tg9":false},"parents":[],"uid":{"id":"","type":"g::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"g::Action"}},{"attrs":{},"parents":[],"uid":{"id":"r","type":"a"}}] + +Requests +{"action":{"id":"action","type":"g::Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R1","resource":{"id":"","type":"g::a"}} +{"action":{"id":"action","type":"g::Action"},"context":{},"principal":{"id":"","type":"g::a"},"request":"R2","resource":{"id":"","type":"g::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"r","type":"a"},"request":"R3","resource":{"id":"r","type":"a"}} +{"action":{"id":"action","type":"g::Action"},"context":{},"principal":{"id":"","type":"g::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-e9415a5fbd9c4c8d5667/solution/reference.json b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..71f20c7a0ceb2275c51bc5c9942efbee30dccd47 --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/solution/solve.sh b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/task.toml b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..683aebad2e3c292f8dc6770b50e7dea35a163b46 --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e9415a5fbd9c4c8d5667" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "3c6f136bded691d18cd7a731bf5ea164706fdb69e92203e9f223ebe7bc05b094" + +[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-e9415a5fbd9c4c8d5667/tests/expected.json b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..71f20c7a0ceb2275c51bc5c9942efbee30dccd47 --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/tests/grading.py b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/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-e9415a5fbd9c4c8d5667/tests/test.sh b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/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-e9415a5fbd9c4c8d5667/tests/verify.py b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/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-e9415a5fbd9c4c8d5667/validation/openenv.json b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e9415a5fbd9c4c8d5667/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-e9deff6512532d210e87/environment/Dockerfile b/tasks/cedar_authorization-e9deff6512532d210e87/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-e9deff6512532d210e87/instruction.md b/tasks/cedar_authorization-e9deff6512532d210e87/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9823ec3ec77ce3c261eb987557d7135a27a7d37b --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/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::ERRRRRRRRRRRR::r::a::"", + action, + resource +) when { + 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":"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":"r::r::ERRRRRRRRRRRR::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::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"}}] + +Requests +{"action":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::Action"},"context":{"r":"g"},"principal":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"},"request":"R1","resource":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::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":"","type":"r::r::ERRRRRRRRRRRR::r::Action"},"context":{},"principal":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"},"request":"R3","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":"R4","resource":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-e9deff6512532d210e87/solution/reference.json b/tasks/cedar_authorization-e9deff6512532d210e87/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..71f20c7a0ceb2275c51bc5c9942efbee30dccd47 --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-e9deff6512532d210e87/solution/solve.sh b/tasks/cedar_authorization-e9deff6512532d210e87/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-e9deff6512532d210e87/task.toml b/tasks/cedar_authorization-e9deff6512532d210e87/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b0e29e3e997032f6f736a9dc7adde9b0ab136cc1 --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-e9deff6512532d210e87" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "1d37460c9e69a5026b27ed8591a2b5ea0d27c0f6f0e4488bb2be23727459299e" + +[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-e9deff6512532d210e87/tests/expected.json b/tasks/cedar_authorization-e9deff6512532d210e87/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..71f20c7a0ceb2275c51bc5c9942efbee30dccd47 --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/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":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-e9deff6512532d210e87/tests/grading.py b/tasks/cedar_authorization-e9deff6512532d210e87/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/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-e9deff6512532d210e87/tests/test.sh b/tasks/cedar_authorization-e9deff6512532d210e87/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/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-e9deff6512532d210e87/tests/verify.py b/tasks/cedar_authorization-e9deff6512532d210e87/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/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-e9deff6512532d210e87/validation/openenv.json b/tasks/cedar_authorization-e9deff6512532d210e87/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-e9deff6512532d210e87/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-ea2a6b2fd719d0e90520/environment/Dockerfile b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ea2a6b2fd719d0e90520/instruction.md b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45fbb93a0ad924fcf10cea1c6e6dbbb642ab5917 --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/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::i::WMMMMM::_qqqqqqqqqqp::a::"", + action == A::i::WMMMMM::_qqqqqqqqqqp::Action::"action", + resource in A::i::WMMMMM::_qqqqqqqqqqp::a::"" +) when { + true && (((-1736200431997606937) <= (-1736445623090550809)) || ((-1736164105164167193) <= (-1736164148113840153)) || ((-1736164148113840153) <= (-1736164148113840153))) && ((-65536) <= 7627775) +}; + +policy1 +forbid( + principal, + action in [r::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::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":"A::i::WMMMMM::_qqqqqqqqqqp::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"A::i::WMMMMM::_qqqqqqqqqqp::Action"},"context":{},"principal":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"},"request":"R1","resource":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"},"request":"R2","resource":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"}} +{"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":"A::i::WMMMMM::_qqqqqqqqqqp::Action"},"context":{},"principal":{"id":"VVVVVVVVVVV","type":"r::r::r::r::r"},"request":"R4","resource":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-ea2a6b2fd719d0e90520/solution/reference.json b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..975b41cdaf25a3c9232cd82f8ea9a647a4a895e5 --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/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-ea2a6b2fd719d0e90520/solution/solve.sh b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ea2a6b2fd719d0e90520/task.toml b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b608b732fad316d5f83f853ee943af71d368932d --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ea2a6b2fd719d0e90520" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0981762dd833aada48d6b1b5019c6db24db7e13aeeb07d40c63aca803ab6cad7" + +[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-ea2a6b2fd719d0e90520/tests/expected.json b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..975b41cdaf25a3c9232cd82f8ea9a647a4a895e5 --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/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-ea2a6b2fd719d0e90520/tests/grading.py b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/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-ea2a6b2fd719d0e90520/tests/test.sh b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/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-ea2a6b2fd719d0e90520/tests/verify.py b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/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-ea2a6b2fd719d0e90520/validation/openenv.json b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ea2a6b2fd719d0e90520/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-ead63071d502c8221d03/environment/Dockerfile b/tasks/cedar_authorization-ead63071d502c8221d03/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ead63071d502c8221d03/instruction.md b/tasks/cedar_authorization-ead63071d502c8221d03/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6710a2c7364d699d0b4bcd6e59e33a6ccbb05806 --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/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::q::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::q::"" +) when { + true && (false || (true || (action in action))) && ({"": action}[""] in {"": action}[""]) +}; + +policy1 +forbid( + principal, + action in [Action::"action"], + resource +) when { + true && (r::"yyyyyyyyyyyyyyyye" has r) && (r::"yyyyyyyyyyyyyyyye" has r) && (r::"yyyyyyyyyyyyyyyye".r has r) +}; + +Entities +[{"attrs":{"r":{"__entity":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::PcZgYlW"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::W"}},{"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":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{"r":{"__entity":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}},"parents":[],"uid":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R3","resource":{"id":"","type":"r::r::r::r::q"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R4","resource":{"id":"","type":"r::r::r::r::q"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-ead63071d502c8221d03/solution/reference.json b/tasks/cedar_authorization-ead63071d502c8221d03/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..9ba662580593b53e31a67a8f8f693a2629cbddd7 --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/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-ead63071d502c8221d03/solution/solve.sh b/tasks/cedar_authorization-ead63071d502c8221d03/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ead63071d502c8221d03/task.toml b/tasks/cedar_authorization-ead63071d502c8221d03/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..04d728b7860be8e68e7d8feee187d43692743628 --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ead63071d502c8221d03" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "2a2df27448fd91faca377a4f50b183d34acaf890a935022baa20f81d6f55f724" + +[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-ead63071d502c8221d03/tests/expected.json b/tasks/cedar_authorization-ead63071d502c8221d03/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..9ba662580593b53e31a67a8f8f693a2629cbddd7 --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/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-ead63071d502c8221d03/tests/grading.py b/tasks/cedar_authorization-ead63071d502c8221d03/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/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-ead63071d502c8221d03/tests/test.sh b/tasks/cedar_authorization-ead63071d502c8221d03/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/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-ead63071d502c8221d03/tests/verify.py b/tasks/cedar_authorization-ead63071d502c8221d03/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/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-ead63071d502c8221d03/validation/openenv.json b/tasks/cedar_authorization-ead63071d502c8221d03/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ead63071d502c8221d03/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-ead6b25ad209d477b59d/environment/Dockerfile b/tasks/cedar_authorization-ead6b25ad209d477b59d/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ead6b25ad209d477b59d/instruction.md b/tasks/cedar_authorization-ead6b25ad209d477b59d/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0c49e358f44e10e824fb878a72f48ba97567cae3 --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/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 in LYc::"", + action in [Action::"E"], + resource +) when { + true && (if if (-4412750543122711235) == (-4412964684863978814) then ip("194.210.194.194").isMulticast() else ip("194.194.194.194").isInRange(ip("42.42.42.4")) then {"": resource}[""] in {"": resource}[""] else {"": decimal("-441289735163997.3182")}[""].lessThan({"": decimal("214141746998.7714")}[""])) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYc"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"d0000k0::A::a"}},{"attrs":{},"parents":[],"uid":{"id":"E","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"d0000k0::A::Action"}}] + +Requests +{"action":{"id":"E","type":"Action"},"context":{},"principal":{"id":"","type":"LYc"},"request":"R1","resource":{"id":"","type":"d0000k0::A::a"}} +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"","type":"LYc"},"request":"R2","resource":{"id":"","type":"LYY"}} +{"action":{"id":"E","type":"Action"},"context":{},"principal":{"id":"","type":"d0000k0::A::a"},"request":"R3","resource":{"id":"","type":"d0000k0::A::a"}} +{"action":{"id":"action","type":"d0000k0::A::Action"},"context":{},"principal":{"id":"","type":"LYc"},"request":"R4","resource":{"id":"","type":"d0000k0::A::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-ead6b25ad209d477b59d/solution/reference.json b/tasks/cedar_authorization-ead6b25ad209d477b59d/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..66b0de41b338c9e27e63416a348a9b6be1bceada --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/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-ead6b25ad209d477b59d/solution/solve.sh b/tasks/cedar_authorization-ead6b25ad209d477b59d/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ead6b25ad209d477b59d/task.toml b/tasks/cedar_authorization-ead6b25ad209d477b59d/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..63c51f99605a4dc7ddd88263035b5960b7a8b7a0 --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ead6b25ad209d477b59d" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b66465aaf81d486f9475aa3adc5696dd9a493dfdc1bf958d0351d7cbb840a565" + +[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-ead6b25ad209d477b59d/tests/expected.json b/tasks/cedar_authorization-ead6b25ad209d477b59d/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..66b0de41b338c9e27e63416a348a9b6be1bceada --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/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-ead6b25ad209d477b59d/tests/grading.py b/tasks/cedar_authorization-ead6b25ad209d477b59d/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/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-ead6b25ad209d477b59d/tests/test.sh b/tasks/cedar_authorization-ead6b25ad209d477b59d/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/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-ead6b25ad209d477b59d/tests/verify.py b/tasks/cedar_authorization-ead6b25ad209d477b59d/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/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-ead6b25ad209d477b59d/validation/openenv.json b/tasks/cedar_authorization-ead6b25ad209d477b59d/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ead6b25ad209d477b59d/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-eb499140940df2e328f8/environment/Dockerfile b/tasks/cedar_authorization-eb499140940df2e328f8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-eb499140940df2e328f8/instruction.md b/tasks/cedar_authorization-eb499140940df2e328f8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5f5060d8ce7910d3d5ca05b7e7a4d7db9b298813 --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/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 in r::E::oKKKKKKKK33::a::"", + action in [r::E::oKKKKKKKK33::Action::"action"], + resource in r::E::oKKKKKKKK33::a::"" +) when { + true && (!(!(!false))) && (!(!(!false))) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::E::oKKKKKKKK33::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":"action","type":"r::E::oKKKKKKKK33::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":"r::r::r3w333333::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3w333333::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r3w333333::r::r"}} +{"action":{"id":"action","type":"r::r::r3w333333::r::Action"},"context":{},"principal":{"id":"","type":"r::E::oKKKKKKKK33::a"},"request":"R2","resource":{"id":"","type":"r::r::r3w333333::r::r"}} +{"action":{"id":"action","type":"r::E::oKKKKKKKK33::Action"},"context":{},"principal":{"id":"","type":"r::E::oKKKKKKKK33::a"},"request":"R3","resource":{"id":"","type":"r::E::oKKKKKKKK33::a"}} +{"action":{"id":"action","type":"r::E::oKKKKKKKK33::Action"},"context":{},"principal":{"id":"","type":"r::E::oKKKKKKKK33::a"},"request":"R4","resource":{"id":"","type":"r::r::r3w333333::r::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-eb499140940df2e328f8/solution/reference.json b/tasks/cedar_authorization-eb499140940df2e328f8/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/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-eb499140940df2e328f8/solution/solve.sh b/tasks/cedar_authorization-eb499140940df2e328f8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-eb499140940df2e328f8/task.toml b/tasks/cedar_authorization-eb499140940df2e328f8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..81be2e65d98b96164704e1b11fb527c120a02c4c --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-eb499140940df2e328f8" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "86edea4b581e4a505afc8458442738e4dc4832c492c2419aa317ebe7a8a8e5af" + +[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-eb499140940df2e328f8/tests/expected.json b/tasks/cedar_authorization-eb499140940df2e328f8/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/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-eb499140940df2e328f8/tests/grading.py b/tasks/cedar_authorization-eb499140940df2e328f8/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/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-eb499140940df2e328f8/tests/test.sh b/tasks/cedar_authorization-eb499140940df2e328f8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/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-eb499140940df2e328f8/tests/verify.py b/tasks/cedar_authorization-eb499140940df2e328f8/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/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-eb499140940df2e328f8/validation/openenv.json b/tasks/cedar_authorization-eb499140940df2e328f8/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-eb499140940df2e328f8/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-eb82edf0f933670d8fd7/environment/Dockerfile b/tasks/cedar_authorization-eb82edf0f933670d8fd7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-eb82edf0f933670d8fd7/instruction.md b/tasks/cedar_authorization-eb82edf0f933670d8fd7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9eb2ae3af7b7e310eae1ea953ccb015c35a0d7c4 --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/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 r32333333::"", + action in [Action::"action"], + resource == r32333333::"" +) when { + true +}; + +policy1 +forbid( + principal in a::"", + action == Action::"action", + resource == a::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Kww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"PDw"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Pww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"fww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r32333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r444G444444444"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r32333333"},"request":"R1","resource":{"id":"","type":"r32333333"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r32333333"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"r32333333"}} +{"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-eb82edf0f933670d8fd7/solution/reference.json b/tasks/cedar_authorization-eb82edf0f933670d8fd7/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/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-eb82edf0f933670d8fd7/solution/solve.sh b/tasks/cedar_authorization-eb82edf0f933670d8fd7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-eb82edf0f933670d8fd7/task.toml b/tasks/cedar_authorization-eb82edf0f933670d8fd7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a1efbe55241d8c42947106229ad758c8bc052e53 --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-eb82edf0f933670d8fd7" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d22b80310a4d3f40e35b8a2dfb0c69b840ee404bd9825a7fb84adb0d07873b76" + +[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-eb82edf0f933670d8fd7/tests/expected.json b/tasks/cedar_authorization-eb82edf0f933670d8fd7/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/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-eb82edf0f933670d8fd7/tests/grading.py b/tasks/cedar_authorization-eb82edf0f933670d8fd7/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/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-eb82edf0f933670d8fd7/tests/test.sh b/tasks/cedar_authorization-eb82edf0f933670d8fd7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/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-eb82edf0f933670d8fd7/tests/verify.py b/tasks/cedar_authorization-eb82edf0f933670d8fd7/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/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-eb82edf0f933670d8fd7/validation/openenv.json b/tasks/cedar_authorization-eb82edf0f933670d8fd7/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-eb82edf0f933670d8fd7/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-ebd3ba6e4e60dd7845a4/environment/Dockerfile b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/instruction.md b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fb98e653dc0939f8c6f554333acef710f077dacc --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/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 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 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 false else false then if false then false else false else true) && ((if ["", "", ""].contains("*****") then action else action) in action) +}; + +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":"r::r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"r::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::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-ebd3ba6e4e60dd7845a4/solution/reference.json b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/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-ebd3ba6e4e60dd7845a4/solution/solve.sh b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/task.toml b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..041e42bc8429452ca4e07a64fdab85bafa9b1ebb --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ebd3ba6e4e60dd7845a4" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "1315027d5e6defe90ccf5abae8a27f01be25dc4214ff860af6544c49a338b11c" + +[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-ebd3ba6e4e60dd7845a4/tests/expected.json b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/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-ebd3ba6e4e60dd7845a4/tests/grading.py b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/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-ebd3ba6e4e60dd7845a4/tests/test.sh b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/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-ebd3ba6e4e60dd7845a4/tests/verify.py b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/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-ebd3ba6e4e60dd7845a4/validation/openenv.json b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ebd3ba6e4e60dd7845a4/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-ebf608b908a94d15c3a1/environment/Dockerfile b/tasks/cedar_authorization-ebf608b908a94d15c3a1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ebf608b908a94d15c3a1/instruction.md b/tasks/cedar_authorization-ebf608b908a94d15c3a1/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..41c3db658e51767e39ecf74cbea4b4d3da3e88a1 --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/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::I::a::"", + action == A::I::Action::"action", + resource == A::I::a::"" +) when { + true +}; + +policy1 +forbid( + principal is r::r::sLW00000z3333333 in r::r::sLW00000z3333333::"", + action in [r::r::Action::"action"], + resource == r::r::sLW00000z3333333::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::I::a"}},{"attrs":{},"parents":[{"id":"******","type":"r::r::r"}],"uid":{"id":"","type":"r::r::sLW00000z3333333"}},{"attrs":{},"parents":[],"uid":{"id":"******","type":"r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::I::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"A::I::Action"},"context":{},"principal":{"id":"","type":"A::I::a"},"request":"R1","resource":{"id":"","type":"r::r::sLW00000z3333333"}} +{"action":{"id":"action","type":"r::r::Action"},"context":{"WMMM0M":{},"g":false,"r":[[[],[[]]],[[[]]]]},"principal":{"id":"******","type":"r::r::r"},"request":"R2","resource":{"id":"******","type":"r::r::r"}} +{"action":{"id":"action","type":"r::r::Action"},"context":{"WMMM0M":{},"g":false,"r":[[[[]]]]},"principal":{"id":"","type":"r::r::sLW00000z3333333"},"request":"R3","resource":{"id":"","type":"r::r::sLW00000z3333333"}} +{"action":{"id":"action","type":"A::I::Action"},"context":{},"principal":{"id":"","type":"A::I::a"},"request":"R4","resource":{"id":"","type":"A::I::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-ebf608b908a94d15c3a1/solution/reference.json b/tasks/cedar_authorization-ebf608b908a94d15c3a1/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/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-ebf608b908a94d15c3a1/solution/solve.sh b/tasks/cedar_authorization-ebf608b908a94d15c3a1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ebf608b908a94d15c3a1/task.toml b/tasks/cedar_authorization-ebf608b908a94d15c3a1/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b80943764c2fc087bf2319d90ca677982fe32400 --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ebf608b908a94d15c3a1" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b2ee0dc83b2091a4e204e528630979b841147dc48ddd093619407e3bebd481fd" + +[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-ebf608b908a94d15c3a1/tests/expected.json b/tasks/cedar_authorization-ebf608b908a94d15c3a1/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/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-ebf608b908a94d15c3a1/tests/grading.py b/tasks/cedar_authorization-ebf608b908a94d15c3a1/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/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-ebf608b908a94d15c3a1/tests/test.sh b/tasks/cedar_authorization-ebf608b908a94d15c3a1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/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-ebf608b908a94d15c3a1/tests/verify.py b/tasks/cedar_authorization-ebf608b908a94d15c3a1/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/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-ebf608b908a94d15c3a1/validation/openenv.json b/tasks/cedar_authorization-ebf608b908a94d15c3a1/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ebf608b908a94d15c3a1/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-ec082a47010992655bdf/environment/Dockerfile b/tasks/cedar_authorization-ec082a47010992655bdf/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ec082a47010992655bdf/instruction.md b/tasks/cedar_authorization-ec082a47010992655bdf/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..7548559be27e3682a3b085d0ffe166e42856e50a --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/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 == r::r32i::A::r::a::"", + action, + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r32i::A::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r32i::A::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r32i::A::r::Action"},"context":{},"principal":{"id":"","type":"r::r32i::A::r::a"},"request":"R1","resource":{"id":"","type":"r::r32i::A::r::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r32i::A::r::a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r32i::A::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r32i::A::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"r::r32i::A::r::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-ec082a47010992655bdf/solution/reference.json b/tasks/cedar_authorization-ec082a47010992655bdf/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..01248b80099480ec0d6ced1df12fa1cd58808166 --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/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-ec082a47010992655bdf/solution/solve.sh b/tasks/cedar_authorization-ec082a47010992655bdf/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ec082a47010992655bdf/task.toml b/tasks/cedar_authorization-ec082a47010992655bdf/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d7c1a2180e7a008391dbf58f263b346135e8be90 --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ec082a47010992655bdf" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0413db318c4ce742847d40b1c9eb8d12a5fc21ca8bfb242928807977479b96ac" + +[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-ec082a47010992655bdf/tests/expected.json b/tasks/cedar_authorization-ec082a47010992655bdf/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..01248b80099480ec0d6ced1df12fa1cd58808166 --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/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-ec082a47010992655bdf/tests/grading.py b/tasks/cedar_authorization-ec082a47010992655bdf/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/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-ec082a47010992655bdf/tests/test.sh b/tasks/cedar_authorization-ec082a47010992655bdf/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/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-ec082a47010992655bdf/tests/verify.py b/tasks/cedar_authorization-ec082a47010992655bdf/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/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-ec082a47010992655bdf/validation/openenv.json b/tasks/cedar_authorization-ec082a47010992655bdf/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ec082a47010992655bdf/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-ec29253bdb106c955e89/environment/Dockerfile b/tasks/cedar_authorization-ec29253bdb106c955e89/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ec29253bdb106c955e89/instruction.md b/tasks/cedar_authorization-ec29253bdb106c955e89/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a68a7dfd7bf389dd852580a07103830cec5758df --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/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 == r::r::r::r::Action::"action", + resource == r::r::r::r::r::"" +) when { + true && (if if if true then false else false then principal is r::r::r::r::r 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, + action in [Action::"action"], + resource +) when { + true && (r::"" has r) && (r::"".r has r) && (r::"" has r) +}; + +Entities +[{"attrs":{"r":{"__entity":{"id":"","type":"r"}}},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{"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":{"O44444444333":true},"parents":[{"id":"","type":"r::r::r::r::r"}],"uid":{"id":"tttttttttt","type":"r::r::r::r::r"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"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":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"tttttttttt","type":"r::r::r::r::r"},"request":"R4","resource":{"id":"tttttttttt","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-ec29253bdb106c955e89/solution/reference.json b/tasks/cedar_authorization-ec29253bdb106c955e89/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/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-ec29253bdb106c955e89/solution/solve.sh b/tasks/cedar_authorization-ec29253bdb106c955e89/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ec29253bdb106c955e89/task.toml b/tasks/cedar_authorization-ec29253bdb106c955e89/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4776e5954a48857331320b6d426680ba322d6355 --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ec29253bdb106c955e89" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "e9c4b4588288f6c20ad21e51e498ea4e7d7f41194318e925e2e0e7c143c1e2d1" + +[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-ec29253bdb106c955e89/tests/expected.json b/tasks/cedar_authorization-ec29253bdb106c955e89/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/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-ec29253bdb106c955e89/tests/grading.py b/tasks/cedar_authorization-ec29253bdb106c955e89/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/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-ec29253bdb106c955e89/tests/test.sh b/tasks/cedar_authorization-ec29253bdb106c955e89/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/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-ec29253bdb106c955e89/tests/verify.py b/tasks/cedar_authorization-ec29253bdb106c955e89/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/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-ec29253bdb106c955e89/validation/openenv.json b/tasks/cedar_authorization-ec29253bdb106c955e89/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ec29253bdb106c955e89/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-ecb746020bf9afd14df5/environment/Dockerfile b/tasks/cedar_authorization-ecb746020bf9afd14df5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-ecb746020bf9afd14df5/instruction.md b/tasks/cedar_authorization-ecb746020bf9afd14df5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d3a8c68d3dc6a9adff1b24caacbf922a139c75af --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/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::A::A::A::A::s0000_0000000::a::"", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal in a::"", + action, + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::A::A::A::A::A::s0000_0000000::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::A::A::A::A::A::s0000_0000000::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"A::A::A::A::A::A::s0000_0000000::Action"},"context":{},"principal":{"id":"","type":"A::A::A::A::A::A::s0000_0000000::a"},"request":"R1","resource":{"id":"","type":"A::A::A::A::A::A::s0000_0000000::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"A::A::A::A::A::A::s0000_0000000::a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"A::A::A::A::A::A::s0000_0000000::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"A::A::A::A::A::A::s0000_0000000::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-ecb746020bf9afd14df5/solution/reference.json b/tasks/cedar_authorization-ecb746020bf9afd14df5/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..bd4fd0eb699a873ba7bc2e91ddbbb21857ecf781 --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/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":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-ecb746020bf9afd14df5/solution/solve.sh b/tasks/cedar_authorization-ecb746020bf9afd14df5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-ecb746020bf9afd14df5/task.toml b/tasks/cedar_authorization-ecb746020bf9afd14df5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5ba01c8ead50b19985d129aa9ac4ef2a3d1a746e --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-ecb746020bf9afd14df5" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "7501a652f738df20a25f8a76e4f5692cd7731f17483a4a4314f4d7c0957fcb25" + +[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-ecb746020bf9afd14df5/tests/expected.json b/tasks/cedar_authorization-ecb746020bf9afd14df5/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..bd4fd0eb699a873ba7bc2e91ddbbb21857ecf781 --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/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":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-ecb746020bf9afd14df5/tests/grading.py b/tasks/cedar_authorization-ecb746020bf9afd14df5/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/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-ecb746020bf9afd14df5/tests/test.sh b/tasks/cedar_authorization-ecb746020bf9afd14df5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/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-ecb746020bf9afd14df5/tests/verify.py b/tasks/cedar_authorization-ecb746020bf9afd14df5/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/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-ecb746020bf9afd14df5/validation/openenv.json b/tasks/cedar_authorization-ecb746020bf9afd14df5/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-ecb746020bf9afd14df5/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-edd41e3f180cfd4d4db2/environment/Dockerfile b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-edd41e3f180cfd4d4db2/instruction.md b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..565e592fcfa1dc6d0eb617854416b574ff38097e --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/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::Q::R77::R77::R77::R77::R77::U30::A::a::"", + action in [r::Q::R77::R77::R77::R77::R77::U30::A::Action::"action",r::Q::R77::R77::R77::R77::R77::U30::A::Action::"action"], + resource in r::Q::R77::R77::R77::R77::R77::U30::A::a::"" +) when { + true && (if true then true else true) && true +}; + +policy1 +forbid( + principal, + action, + resource is j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a +) when { + true && (resource.j5555555333.j5555555333 in resource.j5555555333.j5555555333) +}; + +Entities +[{"attrs":{"j5555555333":{"__entity":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"}}},"parents":[],"uid":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::Q::R77::R77::R77::R77::R77::U30::A::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::Q::R77::R77::R77::R77::R77::U30::A::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":"r::Q::R77::R77::R77::R77::R77::U30::A::a"},"request":"R2","resource":{"id":"","type":"r::Q::R77::R77::R77::R77::R77::U30::A::a"}} +{"action":{"id":"action","type":"r::Q::R77::R77::R77::R77::R77::U30::A::Action"},"context":{},"principal":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::a"},"request":"R3","resource":{"id":"","type":"r::Q::R77::R77::R77::R77::R77::U30::A::a"}} +{"action":{"id":"action","type":"r::Q::R77::R77::R77::R77::R77::U30::A::Action"},"context":{},"principal":{"id":"","type":"r::Q::R77::R77::R77::R77::R77::U30::A::a"},"request":"R4","resource":{"id":"","type":"r::Q::R77::R77::R77::R77::R77::U30::A::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-edd41e3f180cfd4d4db2/solution/reference.json b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-edd41e3f180cfd4d4db2/solution/solve.sh b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-edd41e3f180cfd4d4db2/task.toml b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..863a9a6e1bb47709bd48cf8c030c624ec68b0ce2 --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-edd41e3f180cfd4d4db2" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d3a4bb42818f9659b6044f051703c301fd94268aa43d5e3c2f6b4b87952824f8" + +[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-edd41e3f180cfd4d4db2/tests/expected.json b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-edd41e3f180cfd4d4db2/tests/grading.py b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/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-edd41e3f180cfd4d4db2/tests/test.sh b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/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-edd41e3f180cfd4d4db2/tests/verify.py b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/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-edd41e3f180cfd4d4db2/validation/openenv.json b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-edd41e3f180cfd4d4db2/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-eea7322a10f6b746102e/environment/Dockerfile b/tasks/cedar_authorization-eea7322a10f6b746102e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-eea7322a10f6b746102e/instruction.md b/tasks/cedar_authorization-eea7322a10f6b746102e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9fc31609e39c471a0736f816ca5f7971f8de5f4f --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/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 LYYY0YYYYYYYX::"~Debian ((", + action in [Action::"action",Action::"action"], + resource in LYZ::"" +) when { + true && (if if if false then true else false then principal in [] else principal in [] then context[""] in [] else {"": LYYY0YYYYYYYX::"((( ((((((((((((((~ (((((((((((("}[""] in {"": [LYYY0YYYYYYYX::"((( ((((((((((((((~ ((((((((((((", LYYY0YYYYYYYX::"~Debian ((", resource]}[""]) && (if if if false then false else false then if false then true else false else if false then false else false then if if false then false else false then false else false else 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":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYZ"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Lgg"}},{"attrs":{},"parents":[],"uid":{"id":"(","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"((( ((((((((((((((~ ((((((((((((","type":"LYYY0YYYYYYYX"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"~Debian ((","type":"LYYY0YYYYYYYX"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"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":{},"principal":{"id":"~Debian ((","type":"LYYY0YYYYYYYX"},"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":"action","type":"Action"},"context":{},"principal":{"id":"~Debian ((","type":"LYYY0YYYYYYYX"},"request":"R4","resource":{"id":"","type":"LYZ"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-eea7322a10f6b746102e/solution/reference.json b/tasks/cedar_authorization-eea7322a10f6b746102e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/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-eea7322a10f6b746102e/solution/solve.sh b/tasks/cedar_authorization-eea7322a10f6b746102e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-eea7322a10f6b746102e/task.toml b/tasks/cedar_authorization-eea7322a10f6b746102e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ba0f1928f3f3c0ba944ed240f1b313cb6d87de00 --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-eea7322a10f6b746102e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "302cacab0560826b3001736569b65a28957530dd6c50fc624218017bb9ae24f2" + +[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-eea7322a10f6b746102e/tests/expected.json b/tasks/cedar_authorization-eea7322a10f6b746102e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/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-eea7322a10f6b746102e/tests/grading.py b/tasks/cedar_authorization-eea7322a10f6b746102e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/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-eea7322a10f6b746102e/tests/test.sh b/tasks/cedar_authorization-eea7322a10f6b746102e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/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-eea7322a10f6b746102e/tests/verify.py b/tasks/cedar_authorization-eea7322a10f6b746102e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/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-eea7322a10f6b746102e/validation/openenv.json b/tasks/cedar_authorization-eea7322a10f6b746102e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-eea7322a10f6b746102e/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-eecba852fb8bccc484d8/environment/Dockerfile b/tasks/cedar_authorization-eecba852fb8bccc484d8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-eecba852fb8bccc484d8/instruction.md b/tasks/cedar_authorization-eecba852fb8bccc484d8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9f026b301a65610f12ee526c71b17aca62408f11 --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/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 T::r::r::r::r3::"", + action in [T::r::r::r::Action::"action",T::r::r::r::Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"T::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"T::r::r::r::r3"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"T::r::r::r::uG"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"T::r::r::r::Action"}}] + +Requests +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"T::r::r::r::uG"}} +{"action":{"id":"action","type":"T::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"T::r::r::r::r3"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"T::r::r::r::Action"},"context":{"CZZZZZZ33":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"CZZZZZZZZ":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"IzzzzTTTCpm":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44444444444":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"O44p44444333zzzzz":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"T::r::r::r::r3"},"request":"R4","resource":{"id":"","type":"T::r::r::r::uG"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-eecba852fb8bccc484d8/solution/reference.json b/tasks/cedar_authorization-eecba852fb8bccc484d8/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..93a7415544211bc62c788bff4057a9aa5ccc1ae3 --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/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"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-eecba852fb8bccc484d8/solution/solve.sh b/tasks/cedar_authorization-eecba852fb8bccc484d8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-eecba852fb8bccc484d8/task.toml b/tasks/cedar_authorization-eecba852fb8bccc484d8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..37bc6798582ba76103cae977c318dfc90d251981 --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-eecba852fb8bccc484d8" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "083404767f762def5a467ca30df38fc127a2c2af30cc4eaa9a80076dc7cd5780" + +[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-eecba852fb8bccc484d8/tests/expected.json b/tasks/cedar_authorization-eecba852fb8bccc484d8/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..93a7415544211bc62c788bff4057a9aa5ccc1ae3 --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/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"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-eecba852fb8bccc484d8/tests/grading.py b/tasks/cedar_authorization-eecba852fb8bccc484d8/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/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-eecba852fb8bccc484d8/tests/test.sh b/tasks/cedar_authorization-eecba852fb8bccc484d8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/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-eecba852fb8bccc484d8/tests/verify.py b/tasks/cedar_authorization-eecba852fb8bccc484d8/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/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-eecba852fb8bccc484d8/validation/openenv.json b/tasks/cedar_authorization-eecba852fb8bccc484d8/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-eecba852fb8bccc484d8/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-f00293d2b13c438a512e/environment/Dockerfile b/tasks/cedar_authorization-f00293d2b13c438a512e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-f00293d2b13c438a512e/instruction.md b/tasks/cedar_authorization-f00293d2b13c438a512e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..bacae80e867c3b5ff67accaa1665b0eb160447c5 --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/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 in LYc::"", + action in [Action::"E"], + resource +) when { + true && (if if (-4412750543122711235) == (-4412964684863978814) then ip("194.210.194.194").isMulticast() else ip("194.194.194.194").isInRange(ip("42.42.42.4")) then {"": resource}[""] in {"": resource}[""] else {"": decimal("-441289735163997.3182")}[""].lessThan({"": decimal("214141746998.7714")}[""])) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYc"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}},{"attrs":{},"parents":[],"uid":{"id":"E","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}}] + +Requests +{"action":{"id":"E","type":"Action"},"context":{},"principal":{"id":"","type":"LYc"},"request":"R1","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":"R2","resource":{"id":"","type":"LYY"}} +{"action":{"id":"E","type":"Action"},"context":{},"principal":{"id":"","type":"LYY"},"request":"R3","resource":{"id":"","type":"LYY"}} +{"action":{"id":"E","type":"Action"},"context":{},"principal":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"},"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-f00293d2b13c438a512e/solution/reference.json b/tasks/cedar_authorization-f00293d2b13c438a512e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..02332c6494a5946fcf5d08b6749e23826cd4ac0a --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/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-f00293d2b13c438a512e/solution/solve.sh b/tasks/cedar_authorization-f00293d2b13c438a512e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-f00293d2b13c438a512e/task.toml b/tasks/cedar_authorization-f00293d2b13c438a512e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..20b6e63435f8f9b485200c50cc1b5a7a69d5f8ae --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-f00293d2b13c438a512e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "01fcc625fa4f2452d9b342e322b9103d32e0b9e107edb75f18e4a122c3a1a00c" + +[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-f00293d2b13c438a512e/tests/expected.json b/tasks/cedar_authorization-f00293d2b13c438a512e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..02332c6494a5946fcf5d08b6749e23826cd4ac0a --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/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-f00293d2b13c438a512e/tests/grading.py b/tasks/cedar_authorization-f00293d2b13c438a512e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/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-f00293d2b13c438a512e/tests/test.sh b/tasks/cedar_authorization-f00293d2b13c438a512e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/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-f00293d2b13c438a512e/tests/verify.py b/tasks/cedar_authorization-f00293d2b13c438a512e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/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-f00293d2b13c438a512e/validation/openenv.json b/tasks/cedar_authorization-f00293d2b13c438a512e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-f00293d2b13c438a512e/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-f0a09051b65d8bfc1a67/environment/Dockerfile b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-f0a09051b65d8bfc1a67/instruction.md b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b80093741d3a6a8b5cb4fb2a612dde94dd5f60a3 --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/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::q::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::q::"" +) when { + true && (false || (true || (action in action))) && ({"": action}[""] in {"": action}[""]) +}; + +policy1 +forbid( + principal in r::E::oKKKKKKKK33::a::"", + action in [r::E::oKKKKKKKK33::Action::"action"], + resource in r::E::oKKKKKKKK33::a::"" +) when { + true && (!(!(!false))) && (!(!(!false))) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::E::oKKKKKKKK33::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::PcZgYlW"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::W"}},{"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::E::oKKKKKKKK33::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::E::oKKKKKKKK33::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R1","resource":{"id":"","type":"r::r::r::r::q"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R2","resource":{"id":"","type":"r::r::r::r::q"}} +{"action":{"id":"action","type":"r::E::oKKKKKKKK33::Action"},"context":{},"principal":{"id":"","type":"r::E::oKKKKKKKK33::a"},"request":"R3","resource":{"id":"","type":"r::E::oKKKKKKKK33::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R4","resource":{"id":"","type":"r::E::oKKKKKKKK33::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-f0a09051b65d8bfc1a67/solution/reference.json b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/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-f0a09051b65d8bfc1a67/solution/solve.sh b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-f0a09051b65d8bfc1a67/task.toml b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cc2c2cbaf1db3391f701e565ab9beedfa69e7ea8 --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-f0a09051b65d8bfc1a67" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "2e3f5735fb3aa0be74763ddd94e2059388b79d596b8b03a649d457f5aa147617" + +[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-f0a09051b65d8bfc1a67/tests/expected.json b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/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-f0a09051b65d8bfc1a67/tests/grading.py b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/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-f0a09051b65d8bfc1a67/tests/test.sh b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/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-f0a09051b65d8bfc1a67/tests/verify.py b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/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-f0a09051b65d8bfc1a67/validation/openenv.json b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-f0a09051b65d8bfc1a67/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"]}}