diff --git a/tasks/cedar_authorization-0062a76719bc2b2148d7/environment/Dockerfile b/tasks/cedar_authorization-0062a76719bc2b2148d7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0062a76719bc2b2148d7/instruction.md b/tasks/cedar_authorization-0062a76719bc2b2148d7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a5042aaeba3a53e585a5063b52c57aa9b5dcc0e5 --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal is a in a::"", + action in [Action::""], + resource == a::"" +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::a::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::a::"" +) when { + true && (if [r::r::r::r::a::"", principal, principal].containsAll([]) then action in action else action in action) && (action in action) && (action in action) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::a"}},{"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":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"r::r::r::r::a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-0062a76719bc2b2148d7/solution/reference.json b/tasks/cedar_authorization-0062a76719bc2b2148d7/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/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-0062a76719bc2b2148d7/solution/solve.sh b/tasks/cedar_authorization-0062a76719bc2b2148d7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0062a76719bc2b2148d7/task.toml b/tasks/cedar_authorization-0062a76719bc2b2148d7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..321dae913d3cb69a6cc3a162a3559e96fd3bcf6a --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0062a76719bc2b2148d7" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "8187e97f7f2fa976740bb4590e8d46ac26bc70ceff56228d74512a442eede482" + +[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-0062a76719bc2b2148d7/tests/expected.json b/tasks/cedar_authorization-0062a76719bc2b2148d7/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..22d408bac455e54260927f7558e80f91b4f5b320 --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/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-0062a76719bc2b2148d7/tests/grading.py b/tasks/cedar_authorization-0062a76719bc2b2148d7/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/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-0062a76719bc2b2148d7/tests/test.sh b/tasks/cedar_authorization-0062a76719bc2b2148d7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/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-0062a76719bc2b2148d7/tests/verify.py b/tasks/cedar_authorization-0062a76719bc2b2148d7/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/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-0062a76719bc2b2148d7/validation/openenv.json b/tasks/cedar_authorization-0062a76719bc2b2148d7/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0062a76719bc2b2148d7/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-00a804ddf1ad7b45e29f/environment/Dockerfile b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-00a804ddf1ad7b45e29f/instruction.md b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..10b8f2e771a7c4a3249d2a7215d1383d9fb2d7c4 --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/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 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":"A::I::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::I::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"A::I::a"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"A::I::Action"},"context":{},"principal":{"id":"","type":"A::I::a"},"request":"R2","resource":{"id":"","type":"A::I::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"A::I::Action"},"context":{},"principal":{"id":"","type":"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-00a804ddf1ad7b45e29f/solution/reference.json b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/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-00a804ddf1ad7b45e29f/solution/solve.sh b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-00a804ddf1ad7b45e29f/task.toml b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f8801810004b0d74345e98c0fa26c9e5be3451b8 --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-00a804ddf1ad7b45e29f" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "8af42c14f8fe913c49404a39da91f7d1a0f6ee2af078d8d9ea5f677302789fe2" + +[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-00a804ddf1ad7b45e29f/tests/expected.json b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/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-00a804ddf1ad7b45e29f/tests/grading.py b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/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-00a804ddf1ad7b45e29f/tests/test.sh b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/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-00a804ddf1ad7b45e29f/tests/verify.py b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/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-00a804ddf1ad7b45e29f/validation/openenv.json b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-00a804ddf1ad7b45e29f/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-01a20e9cc8514ec4d2e5/environment/Dockerfile b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/instruction.md b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6145bfa604b4fadd803e8206a3389850bb01b809 --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/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 == 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::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"=","type":"r::r::r::r::a"}},{"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::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::r::r"},"request":"R2","resource":{"id":"=","type":"r::r::r::r::a"}} +{"action":{"id":"action","type":"r::r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r::r"},"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::r::r::a"},"request":"R4","resource":{"id":"=","type":"r::r::r::r::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/solution/reference.json b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4641d1db584c9d6c16920bace3830201b8a946be --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/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-01a20e9cc8514ec4d2e5/solution/solve.sh b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/task.toml b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..daf67ba8b4f3c2f405f136fe49f51c307f9f2ad8 --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-01a20e9cc8514ec4d2e5" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ffe36263309154737791a7051840b09bb34cd13be2b05f089afd8b8d70afe59d" + +[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-01a20e9cc8514ec4d2e5/tests/expected.json b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4641d1db584c9d6c16920bace3830201b8a946be --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/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-01a20e9cc8514ec4d2e5/tests/grading.py b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/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-01a20e9cc8514ec4d2e5/tests/test.sh b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/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-01a20e9cc8514ec4d2e5/tests/verify.py b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/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-01a20e9cc8514ec4d2e5/validation/openenv.json b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-01a20e9cc8514ec4d2e5/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-01c2f93d495f34df9bc8/environment/Dockerfile b/tasks/cedar_authorization-01c2f93d495f34df9bc8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-01c2f93d495f34df9bc8/instruction.md b/tasks/cedar_authorization-01c2f93d495f34df9bc8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..bcda687ec0146d09dcb4a5b5a7e8133ac2e415d5 --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/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 LYY::"", + action in [Action::"E"], + resource +) when { + true && (if if (-4412750543122711235) == (-4412964684863978814) then false == false else decimal("-441275054312267.7054").lessThan(decimal("-325532544215600.324")) then {"": resource}[""] in {"": resource}[""] else {"": decimal("-441289735163997.3182")}[""].lessThan({"": decimal("214141746698.7714")}[""], if true then decimal("-441275054312267.7054") else decimal("0.1"))) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYc"}},{"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":"E","type":"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":"E","type":"Action"},"context":{},"principal":{"id":"","type":"LYY"},"request":"R2","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":"R3","resource":{"id":"","type":"LYY"}} +{"action":{"id":"E","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r3w333333::r::r"},"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-01c2f93d495f34df9bc8/solution/reference.json b/tasks/cedar_authorization-01c2f93d495f34df9bc8/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/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-01c2f93d495f34df9bc8/solution/solve.sh b/tasks/cedar_authorization-01c2f93d495f34df9bc8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-01c2f93d495f34df9bc8/task.toml b/tasks/cedar_authorization-01c2f93d495f34df9bc8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d86ab1f4c66582b8b6e2c66700f50dc3d4e30496 --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-01c2f93d495f34df9bc8" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "bce32064a811de2a736ed5549e057710cc8c8f25caabc82cd2fb1afc868e4679" + +[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-01c2f93d495f34df9bc8/tests/expected.json b/tasks/cedar_authorization-01c2f93d495f34df9bc8/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/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-01c2f93d495f34df9bc8/tests/grading.py b/tasks/cedar_authorization-01c2f93d495f34df9bc8/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/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-01c2f93d495f34df9bc8/tests/test.sh b/tasks/cedar_authorization-01c2f93d495f34df9bc8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/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-01c2f93d495f34df9bc8/tests/verify.py b/tasks/cedar_authorization-01c2f93d495f34df9bc8/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/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-01c2f93d495f34df9bc8/validation/openenv.json b/tasks/cedar_authorization-01c2f93d495f34df9bc8/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-01c2f93d495f34df9bc8/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-03d55858a8ef7108f16f/environment/Dockerfile b/tasks/cedar_authorization-03d55858a8ef7108f16f/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-03d55858a8ef7108f16f/instruction.md b/tasks/cedar_authorization-03d55858a8ef7108f16f/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..85164dd144d2cb7a2efd35594185102f626352a0 --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/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 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":"l"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"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":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"},"context":{},"principal":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::lHHHHHHH"},"request":"R1","resource":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::YEEEch0005"}} +{"action":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"},"context":{},"principal":{"id":"","type":"l"},"request":"R2","resource":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::dEEEEEEEEE"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"l"},"request":"R3","resource":{"id":"","type":"l"}} +{"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":"l"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-03d55858a8ef7108f16f/solution/reference.json b/tasks/cedar_authorization-03d55858a8ef7108f16f/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/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-03d55858a8ef7108f16f/solution/solve.sh b/tasks/cedar_authorization-03d55858a8ef7108f16f/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-03d55858a8ef7108f16f/task.toml b/tasks/cedar_authorization-03d55858a8ef7108f16f/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ce2172e7c69b4365544b5318ec931aad3ec2d554 --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-03d55858a8ef7108f16f" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "c71c9b942e055c538ee99f4d0ad911e56f3566c27d40476b85b8ce5cf7fb0cf1" + +[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-03d55858a8ef7108f16f/tests/expected.json b/tasks/cedar_authorization-03d55858a8ef7108f16f/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/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-03d55858a8ef7108f16f/tests/grading.py b/tasks/cedar_authorization-03d55858a8ef7108f16f/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/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-03d55858a8ef7108f16f/tests/test.sh b/tasks/cedar_authorization-03d55858a8ef7108f16f/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/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-03d55858a8ef7108f16f/tests/verify.py b/tasks/cedar_authorization-03d55858a8ef7108f16f/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/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-03d55858a8ef7108f16f/validation/openenv.json b/tasks/cedar_authorization-03d55858a8ef7108f16f/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-03d55858a8ef7108f16f/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-040f038efb163e6e809c/environment/Dockerfile b/tasks/cedar_authorization-040f038efb163e6e809c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-040f038efb163e6e809c/instruction.md b/tasks/cedar_authorization-040f038efb163e6e809c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6d3c5aead26f0b870be77bfcb252cc84ce6a4efb --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/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 l, + action == Action::"action", + resource is l +) when { + true && (true || (l::"" in [l::"", l::"", l::""]) || ("" like "")) && ((if true then true else true) || true || true) && 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":"l"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"B":"","L":"","r":"","r3":""},"principal":{"id":"","type":"l"},"request":"R1","resource":{"id":"","type":"l"}} +{"action":{"id":"action","type":"Action"},"context":{"B":"","L":"","r":"","r3":""},"principal":{"id":"","type":"l"},"request":"R2","resource":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}} +{"action":{"id":"~~~~~~~~~~~~~~~","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::Action"},"context":{"B":"","L":"","r":"","r3":""},"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":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"},"request":"R4","resource":{"id":"","type":"_YlW333gaowwl0::r3l::E0000001arSgm__::r3333333335333Dc::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-040f038efb163e6e809c/solution/reference.json b/tasks/cedar_authorization-040f038efb163e6e809c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..66b0de41b338c9e27e63416a348a9b6be1bceada --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/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-040f038efb163e6e809c/solution/solve.sh b/tasks/cedar_authorization-040f038efb163e6e809c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-040f038efb163e6e809c/task.toml b/tasks/cedar_authorization-040f038efb163e6e809c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..03814e2e2d811c06a944143ad609041aa01fff30 --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-040f038efb163e6e809c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "84902f6434d590a6f8aac71f03dd0e1d4ae39284f6487f13640993c3655c734e" + +[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-040f038efb163e6e809c/tests/expected.json b/tasks/cedar_authorization-040f038efb163e6e809c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..66b0de41b338c9e27e63416a348a9b6be1bceada --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/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-040f038efb163e6e809c/tests/grading.py b/tasks/cedar_authorization-040f038efb163e6e809c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/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-040f038efb163e6e809c/tests/test.sh b/tasks/cedar_authorization-040f038efb163e6e809c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/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-040f038efb163e6e809c/tests/verify.py b/tasks/cedar_authorization-040f038efb163e6e809c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/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-040f038efb163e6e809c/validation/openenv.json b/tasks/cedar_authorization-040f038efb163e6e809c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-040f038efb163e6e809c/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-0457c752d76f5b7cafd3/environment/Dockerfile b/tasks/cedar_authorization-0457c752d76f5b7cafd3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0457c752d76f5b7cafd3/instruction.md b/tasks/cedar_authorization-0457c752d76f5b7cafd3/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5ee99587fa7906249eccb4ae52d0d8c44c382c35 --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/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 is l, + action == Action::"action", + resource is l +) when { + true && (true || (l::"" in [l::"", l::"", l::""]) || ("" like "")) && ((if true then true else true) || true || true) && true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"l"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"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":{"B":"","L":"","r":"","r3":""},"principal":{"id":"","type":"l"},"request":"R1","resource":{"id":"","type":"l"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::A"},"request":"R2","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":"R3","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":"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-0457c752d76f5b7cafd3/solution/reference.json b/tasks/cedar_authorization-0457c752d76f5b7cafd3/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..ecc7429c3aab3dbfe2a2125625275d7b1455c87a --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/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-0457c752d76f5b7cafd3/solution/solve.sh b/tasks/cedar_authorization-0457c752d76f5b7cafd3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0457c752d76f5b7cafd3/task.toml b/tasks/cedar_authorization-0457c752d76f5b7cafd3/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bdbee57227abeeb12768893f2a1f1a72961f3697 --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0457c752d76f5b7cafd3" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d524e04d8472072730300c750e636f29553c2c1c62812395707e24894e68da7d" + +[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-0457c752d76f5b7cafd3/tests/expected.json b/tasks/cedar_authorization-0457c752d76f5b7cafd3/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..ecc7429c3aab3dbfe2a2125625275d7b1455c87a --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/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-0457c752d76f5b7cafd3/tests/grading.py b/tasks/cedar_authorization-0457c752d76f5b7cafd3/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/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-0457c752d76f5b7cafd3/tests/test.sh b/tasks/cedar_authorization-0457c752d76f5b7cafd3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/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-0457c752d76f5b7cafd3/tests/verify.py b/tasks/cedar_authorization-0457c752d76f5b7cafd3/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/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-0457c752d76f5b7cafd3/validation/openenv.json b/tasks/cedar_authorization-0457c752d76f5b7cafd3/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0457c752d76f5b7cafd3/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-047d052d276fefc37c1b/environment/Dockerfile b/tasks/cedar_authorization-047d052d276fefc37c1b/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-047d052d276fefc37c1b/instruction.md b/tasks/cedar_authorization-047d052d276fefc37c1b/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b52505e74a1628f6f608207911dc4ca27241729 --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/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, + 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":"r::r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"44","type":"errrr::errrr::err::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"errrr::errrr::err::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":"44","type":"errrr::errrr::err::r::a"},"request":"R1","resource":{"id":"44","type":"errrr::errrr::err::r::a"}} +{"action":{"id":"action","type":"r::r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r::r"},"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":"r::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-047d052d276fefc37c1b/solution/reference.json b/tasks/cedar_authorization-047d052d276fefc37c1b/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/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-047d052d276fefc37c1b/solution/solve.sh b/tasks/cedar_authorization-047d052d276fefc37c1b/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-047d052d276fefc37c1b/task.toml b/tasks/cedar_authorization-047d052d276fefc37c1b/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..aec2a2fa84458c1d8e8740f29d4a7d7da72c83b3 --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-047d052d276fefc37c1b" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ea9ba6e829ad71d1d21e983f1667247b2d6baad56a1d4aaf0d3f89731fd0f35f" + +[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-047d052d276fefc37c1b/tests/expected.json b/tasks/cedar_authorization-047d052d276fefc37c1b/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/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-047d052d276fefc37c1b/tests/grading.py b/tasks/cedar_authorization-047d052d276fefc37c1b/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/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-047d052d276fefc37c1b/tests/test.sh b/tasks/cedar_authorization-047d052d276fefc37c1b/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/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-047d052d276fefc37c1b/tests/verify.py b/tasks/cedar_authorization-047d052d276fefc37c1b/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/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-047d052d276fefc37c1b/validation/openenv.json b/tasks/cedar_authorization-047d052d276fefc37c1b/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-047d052d276fefc37c1b/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-04caf01dc9324c502ab1/environment/Dockerfile b/tasks/cedar_authorization-04caf01dc9324c502ab1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-04caf01dc9324c502ab1/instruction.md b/tasks/cedar_authorization-04caf01dc9324c502ab1/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eecc2b5dd81d55f8da10492c386e8dbe00ed4439 --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/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 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":"O::l::Z3333333::r::r::j5555556::r"}},{"attrs":{},"parents":[],"uid":{"id":"````````","type":"rXXXXXXXXXXXXX"}},{"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":"O::l::Z3333333::r::r::j5555556::Action"},"context":{},"principal":{"id":"````````","type":"rXXXXXXXXXXXXX"},"request":"R1","resource":{"id":"````````","type":"rXXXXXXXXXXXXX"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"O::l::Z3333333::r::r::j5555556::r"},"request":"R2","resource":{"id":"","type":"O::l::Z3333333::r::r::j5555556::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"````````","type":"rXXXXXXXXXXXXX"},"request":"R3","resource":{"id":"````````","type":"rXXXXXXXXXXXXX"}} +{"action":{"id":"action","type":"O::l::Z3333333::r::r::j5555556::Action"},"context":{},"principal":{"id":"","type":"O::l::Z3333333::r::r::j5555556::r"},"request":"R4","resource":{"id":"","type":"O::l::Z3333333::r::r::j5555556::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-04caf01dc9324c502ab1/solution/reference.json b/tasks/cedar_authorization-04caf01dc9324c502ab1/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..93a7415544211bc62c788bff4057a9aa5ccc1ae3 --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/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-04caf01dc9324c502ab1/solution/solve.sh b/tasks/cedar_authorization-04caf01dc9324c502ab1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-04caf01dc9324c502ab1/task.toml b/tasks/cedar_authorization-04caf01dc9324c502ab1/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e7f17a12e61f85a3d1a944d2a08878aba9a269ae --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-04caf01dc9324c502ab1" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "864014793664ea3b34c1ec46738c5782de9659e00864eed2bf00e06d0d568322" + +[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-04caf01dc9324c502ab1/tests/expected.json b/tasks/cedar_authorization-04caf01dc9324c502ab1/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..93a7415544211bc62c788bff4057a9aa5ccc1ae3 --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/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-04caf01dc9324c502ab1/tests/grading.py b/tasks/cedar_authorization-04caf01dc9324c502ab1/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/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-04caf01dc9324c502ab1/tests/test.sh b/tasks/cedar_authorization-04caf01dc9324c502ab1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/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-04caf01dc9324c502ab1/tests/verify.py b/tasks/cedar_authorization-04caf01dc9324c502ab1/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/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-04caf01dc9324c502ab1/validation/openenv.json b/tasks/cedar_authorization-04caf01dc9324c502ab1/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-04caf01dc9324c502ab1/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-05132ddc67b65184d9fa/environment/Dockerfile b/tasks/cedar_authorization-05132ddc67b65184d9fa/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-05132ddc67b65184d9fa/instruction.md b/tasks/cedar_authorization-05132ddc67b65184d9fa/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..10c02e65687fd19a22a85fd9ccaf22269a3313c9 --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A5cjr9000rrrrEErr::"`", + action == Action::"action", + resource in A5cjr9000rrrrEErr::"`" +) when { + true && ((-2712756478873001310) < ((-983374224517604790) + (-940422246894996750) + duration("13882183529ms").toHours())) && true +}; + +policy1 +forbid( + principal in 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":"A5cjr9000rrrrEErr"}},{"attrs":{"j55555cx555":{}},"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":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::Action"},"context":{},"principal":{"id":"`","type":"A5cjr9000rrrrEErr"},"request":"R2","resource":{"id":"`","type":"A5cjr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cjr9000rrrrEErr"},"request":"R3","resource":{"id":"`","type":"A5cjr9000rrrrEErr"}} +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55555::j55yzzz5::Action"},"context":{},"principal":{"id":"`","type":"A5cjr9000rrrrEErr"},"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-05132ddc67b65184d9fa/solution/reference.json b/tasks/cedar_authorization-05132ddc67b65184d9fa/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..ecc7429c3aab3dbfe2a2125625275d7b1455c87a --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/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-05132ddc67b65184d9fa/solution/solve.sh b/tasks/cedar_authorization-05132ddc67b65184d9fa/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-05132ddc67b65184d9fa/task.toml b/tasks/cedar_authorization-05132ddc67b65184d9fa/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0554e55aa5b194f1fc524f5cafb005ba6a503dc2 --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-05132ddc67b65184d9fa" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "67d1452e8bd8017b21bfa7fdbb730dd6b6aabb863da4ce851bcb62b6b51b2ad0" + +[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-05132ddc67b65184d9fa/tests/expected.json b/tasks/cedar_authorization-05132ddc67b65184d9fa/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..ecc7429c3aab3dbfe2a2125625275d7b1455c87a --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/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-05132ddc67b65184d9fa/tests/grading.py b/tasks/cedar_authorization-05132ddc67b65184d9fa/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/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-05132ddc67b65184d9fa/tests/test.sh b/tasks/cedar_authorization-05132ddc67b65184d9fa/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/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-05132ddc67b65184d9fa/tests/verify.py b/tasks/cedar_authorization-05132ddc67b65184d9fa/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/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-05132ddc67b65184d9fa/validation/openenv.json b/tasks/cedar_authorization-05132ddc67b65184d9fa/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-05132ddc67b65184d9fa/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-059c77c205b511617ee4/environment/Dockerfile b/tasks/cedar_authorization-059c77c205b511617ee4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-059c77c205b511617ee4/instruction.md b/tasks/cedar_authorization-059c77c205b511617ee4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a8ca9db8b686e9e0b843f822435e9d70f5aa608a --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/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 a::"", + action in [Action::"action",Action::"action"], + resource in a::"" +) when { + true && (if false then true else true) && true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"O::j5w33333::r::r::r::j550L556::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"},"request":"R2","resource":{"id":"","type":"O::j5w33333::r::r::r::j550L556::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"O::j5w33333::r::r::r::j550L556::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-059c77c205b511617ee4/solution/reference.json b/tasks/cedar_authorization-059c77c205b511617ee4/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/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-059c77c205b511617ee4/solution/solve.sh b/tasks/cedar_authorization-059c77c205b511617ee4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-059c77c205b511617ee4/task.toml b/tasks/cedar_authorization-059c77c205b511617ee4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9741b8448cb8474328654e385902bfb04734a31e --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-059c77c205b511617ee4" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "804a9626e961b2a3b0fd86b11934e451c9fc38fff6b4c0ae3f4848abdd45ea7c" + +[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-059c77c205b511617ee4/tests/expected.json b/tasks/cedar_authorization-059c77c205b511617ee4/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/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-059c77c205b511617ee4/tests/grading.py b/tasks/cedar_authorization-059c77c205b511617ee4/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/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-059c77c205b511617ee4/tests/test.sh b/tasks/cedar_authorization-059c77c205b511617ee4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/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-059c77c205b511617ee4/tests/verify.py b/tasks/cedar_authorization-059c77c205b511617ee4/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/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-059c77c205b511617ee4/validation/openenv.json b/tasks/cedar_authorization-059c77c205b511617ee4/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-059c77c205b511617ee4/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-05f117aaad2c86a6a615/environment/Dockerfile b/tasks/cedar_authorization-05f117aaad2c86a6a615/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-05f117aaad2c86a6a615/instruction.md b/tasks/cedar_authorization-05f117aaad2c86a6a615/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..95ed0b3ceb066e0399dd9ab3d4e827d969ec5dbf --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action in [B::G::GTTTTTTTTTTTTTT::r::Action::"action",B::G::GTTTTTTTTTTTTTT::r::Action::"action",B::G::GTTTTTTTTTTTTTT::r::Action::"action"], + resource is B::G::GTTTTTTTTTTTTTT::r::a in B::G::GTTTTTTTTTTTTTT::r::a::"" +) when { + true && (B::G::GTTTTTTTTTTTTTT::r::a::"" == B::G::GTTTTTTTTTTTTTT::r::a::"") && (B::G::GTTTTTTTTTTTTTT::r::a::"" == B::G::GTTTTTTTTTTTTTT::r::a::"") && true +}; + +policy1 +forbid( + principal == 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":"B::G::GTTTTTTTTTTTTTT::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"}}] + +Requests +{"action":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"},"context":{},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R1","resource":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"}} +{"action":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"},"context":{},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R2","resource":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}} +{"action":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"},"context":{},"principal":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"},"request":"R3","resource":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}} +{"action":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::Action"},"context":{"I":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"O4444124444444444":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"O444444444YYYYYYY":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"O4iii0iiiiiiiiiii":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"Viiiiiiiiii5e":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"Viiiiiiiiiiii":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"r":[],"r2333333333333333":{"__extn":{"arg":"0.0.0.0","fn":"ip"}},"r33333lll":{"__extn":{"arg":"0.0.0.0","fn":"ip"}}},"principal":{"id":"","type":"Viiiiiiiiiiii::Viiiiiiiiiii0::P::r::tF"},"request":"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-05f117aaad2c86a6a615/solution/reference.json b/tasks/cedar_authorization-05f117aaad2c86a6a615/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..3ffa2505a6a1f29cfec26eac33da1d6fd8f03189 --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/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-05f117aaad2c86a6a615/solution/solve.sh b/tasks/cedar_authorization-05f117aaad2c86a6a615/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-05f117aaad2c86a6a615/task.toml b/tasks/cedar_authorization-05f117aaad2c86a6a615/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..361b38c6b392683293fb10b2c4b280338b104e63 --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-05f117aaad2c86a6a615" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "063abf5f20c37aaf8395cc0a44be290b991e7035f5f62d6e6a1b7e51c203cfa4" + +[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-05f117aaad2c86a6a615/tests/expected.json b/tasks/cedar_authorization-05f117aaad2c86a6a615/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..3ffa2505a6a1f29cfec26eac33da1d6fd8f03189 --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/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-05f117aaad2c86a6a615/tests/grading.py b/tasks/cedar_authorization-05f117aaad2c86a6a615/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/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-05f117aaad2c86a6a615/tests/test.sh b/tasks/cedar_authorization-05f117aaad2c86a6a615/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/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-05f117aaad2c86a6a615/tests/verify.py b/tasks/cedar_authorization-05f117aaad2c86a6a615/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/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-05f117aaad2c86a6a615/validation/openenv.json b/tasks/cedar_authorization-05f117aaad2c86a6a615/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-05f117aaad2c86a6a615/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-05ffc7ef55b5d73f87bb/environment/Dockerfile b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/instruction.md b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..edf2cced8159eb3ce3192590ac2199e389debc27 --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/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::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":"","type":"r::r::r::r::wZgY"}},{"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":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"r::r::r::r::P"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::P"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r"}} +{"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-05ffc7ef55b5d73f87bb/solution/reference.json b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..c1cba6f003dba7ecbcf408f823fd72ec90251bdb --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/solution/solve.sh b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/task.toml b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3bf1f694e2d03726bdf8ab67892308f6990a5ce6 --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-05ffc7ef55b5d73f87bb" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "a4da1308092dca847cabe64f23325b0c197331edce568dd9bc8e2987080bfff8" + +[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-05ffc7ef55b5d73f87bb/tests/expected.json b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..c1cba6f003dba7ecbcf408f823fd72ec90251bdb --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/tests/grading.py b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/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-05ffc7ef55b5d73f87bb/tests/test.sh b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/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-05ffc7ef55b5d73f87bb/tests/verify.py b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/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-05ffc7ef55b5d73f87bb/validation/openenv.json b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-05ffc7ef55b5d73f87bb/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-077101032b9eb8dfb629/environment/Dockerfile b/tasks/cedar_authorization-077101032b9eb8dfb629/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-077101032b9eb8dfb629/instruction.md b/tasks/cedar_authorization-077101032b9eb8dfb629/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..bb7ff60595b2bc559d4d4ac261dc48b8e37e114a --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/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 is mSSSSSS, + action == Action::"action", + resource == LYY::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"LYY"}},{"attrs":{},"parents":[{"id":"","type":"LYY"}],"uid":{"id":"","type":"mSSSSSS"}},{"attrs":{"mSSSSSS":false,"mSSSSSY":false,"qgggggggg":false},"parents":[],"uid":{"id":"","type":"mgggggg"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::i::WMMMMM::_qqqqqqqqqqp::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"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":"Action"},"context":{},"principal":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"},"request":"R2","resource":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"request":"R3","resource":{"id":"","type":"LYY"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"mSSSSSS"},"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-077101032b9eb8dfb629/solution/reference.json b/tasks/cedar_authorization-077101032b9eb8dfb629/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/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-077101032b9eb8dfb629/solution/solve.sh b/tasks/cedar_authorization-077101032b9eb8dfb629/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-077101032b9eb8dfb629/task.toml b/tasks/cedar_authorization-077101032b9eb8dfb629/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..214bbd1c02d3e829dcbac285f2d2be186df1df43 --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-077101032b9eb8dfb629" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "d166e19293e11e9f9b9841e1a1cad5ffccb4ad381f2bfd8856ece85807c0a829" + +[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-077101032b9eb8dfb629/tests/expected.json b/tasks/cedar_authorization-077101032b9eb8dfb629/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/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-077101032b9eb8dfb629/tests/grading.py b/tasks/cedar_authorization-077101032b9eb8dfb629/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/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-077101032b9eb8dfb629/tests/test.sh b/tasks/cedar_authorization-077101032b9eb8dfb629/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/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-077101032b9eb8dfb629/tests/verify.py b/tasks/cedar_authorization-077101032b9eb8dfb629/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/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-077101032b9eb8dfb629/validation/openenv.json b/tasks/cedar_authorization-077101032b9eb8dfb629/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-077101032b9eb8dfb629/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-09c2d942f5eb39859a30/environment/Dockerfile b/tasks/cedar_authorization-09c2d942f5eb39859a30/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-09c2d942f5eb39859a30/instruction.md b/tasks/cedar_authorization-09c2d942f5eb39859a30/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..869bc4205727890ea0d0564814f813ce85a7149e --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A5cZr9000rrrrEErr::"`", + action == Action::"action", + resource in A5cZr9000rrrrEErr::"`" +) when { + true && ((-2712756478873001310) < ((-983374224517604774) + (-940422246894996750) + duration("13882183529ms").toMinutes())) && (A5cZr9000rrrrEErr::"" in A5cZr9000rrrrEErr::"") +}; + +policy1 +forbid( + principal is 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":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"l"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"B":"","r":{"__extn":{"arg":"1120-05-06","fn":"datetime"}}},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R1","resource":{"id":"","type":"l"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"A5cZr9000rrrrEErr"},"request":"R2","resource":{"id":"","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"l"},"request":"R3","resource":{"id":"","type":"l"}} +{"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-09c2d942f5eb39859a30/solution/reference.json b/tasks/cedar_authorization-09c2d942f5eb39859a30/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/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-09c2d942f5eb39859a30/solution/solve.sh b/tasks/cedar_authorization-09c2d942f5eb39859a30/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-09c2d942f5eb39859a30/task.toml b/tasks/cedar_authorization-09c2d942f5eb39859a30/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dc0176a633d697822a2b70432462e27da4fb8ce5 --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-09c2d942f5eb39859a30" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "7a8d7c07b769ff955b2b6b7c983f36f0fcf6f4d1aa983b37ee714a4922dd7edd" + +[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-09c2d942f5eb39859a30/tests/expected.json b/tasks/cedar_authorization-09c2d942f5eb39859a30/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/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-09c2d942f5eb39859a30/tests/grading.py b/tasks/cedar_authorization-09c2d942f5eb39859a30/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/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-09c2d942f5eb39859a30/tests/test.sh b/tasks/cedar_authorization-09c2d942f5eb39859a30/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/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-09c2d942f5eb39859a30/tests/verify.py b/tasks/cedar_authorization-09c2d942f5eb39859a30/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/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-09c2d942f5eb39859a30/validation/openenv.json b/tasks/cedar_authorization-09c2d942f5eb39859a30/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-09c2d942f5eb39859a30/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-0b361de3cfc8ea0db800/environment/Dockerfile b/tasks/cedar_authorization-0b361de3cfc8ea0db800/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0b361de3cfc8ea0db800/instruction.md b/tasks/cedar_authorization-0b361de3cfc8ea0db800/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..acb100761cbb77c2c8c0d9fa4d2471db5f07a74a --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/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 && (((-1736164148113840153) <= (-1736164148113840153)) || ((-1736164148113840153) <= (-1736164148113840153)) || ((-1736164148113840153) <= (-1736164148113840153))) && ((-1099511627545) <= 127972845551615) +}; + +policy1 +forbid( + principal == a::"", + action == Action::"action", + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::i::WMMMMM::_qqqqqqqqqqp::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"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":"Action"},"context":{},"principal":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"},"request":"R2","resource":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"}} +{"action":{"id":"action","type":"A::i::WMMMMM::_qqqqqqqqqqp::Action"},"context":{},"principal":{"id":"","type":"A::i::WMMMMM::_qqqqqqqqqqp::a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"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-0b361de3cfc8ea0db800/solution/reference.json b/tasks/cedar_authorization-0b361de3cfc8ea0db800/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/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-0b361de3cfc8ea0db800/solution/solve.sh b/tasks/cedar_authorization-0b361de3cfc8ea0db800/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0b361de3cfc8ea0db800/task.toml b/tasks/cedar_authorization-0b361de3cfc8ea0db800/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e003e84b54ba6ea51ac1283502822b495f5258ee --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0b361de3cfc8ea0db800" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "995be29b0f0d16be268426b83496373d43b26ad3c97c087e572473a7e1991342" + +[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-0b361de3cfc8ea0db800/tests/expected.json b/tasks/cedar_authorization-0b361de3cfc8ea0db800/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/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-0b361de3cfc8ea0db800/tests/grading.py b/tasks/cedar_authorization-0b361de3cfc8ea0db800/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/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-0b361de3cfc8ea0db800/tests/test.sh b/tasks/cedar_authorization-0b361de3cfc8ea0db800/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/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-0b361de3cfc8ea0db800/tests/verify.py b/tasks/cedar_authorization-0b361de3cfc8ea0db800/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/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-0b361de3cfc8ea0db800/validation/openenv.json b/tasks/cedar_authorization-0b361de3cfc8ea0db800/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0b361de3cfc8ea0db800/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-0b8a1955d41ff0c5993e/environment/Dockerfile b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0b8a1955d41ff0c5993e/instruction.md b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ff2fa5ac0eb26abb3a9dc57fda15f37f09d9158c --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/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 is g::p::pfffffff::g::pfffffff in g::p::pfffffff::g::pfffffff::"", + action in [g::p::pfffffff::g::Action::"action"], + resource == g::p::pfffffff::g::pfffffff::"" +) when { + true && [].containsAll([]) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{"pfffffff":{}},"parents":[],"uid":{"id":"","type":"g::p::pfffffff::g::pfffffff"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"g::p::pfffffff::g::Action"}}] + +Requests +{"action":{"id":"action","type":"g::p::pfffffff::g::Action"},"context":{},"principal":{"id":"","type":"g::p::pfffffff::g::pfffffff"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"g::p::pfffffff::g::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"g::p::pfffffff::g::Action"},"context":{},"principal":{"id":"","type":"g::p::pfffffff::g::pfffffff"},"request":"R3","resource":{"id":"TL","type":"g::p::pfffffff::g::pfffffff"}} +{"action":{"id":"action","type":"g::p::pfffffff::g::Action"},"context":{},"principal":{"id":"","type":"g::p::pfffffff::g::pfffffff"},"request":"R4","resource":{"id":"","type":"g::p::pfffffff::g::pfffffff"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-0b8a1955d41ff0c5993e/solution/reference.json b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4641d1db584c9d6c16920bace3830201b8a946be --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/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-0b8a1955d41ff0c5993e/solution/solve.sh b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0b8a1955d41ff0c5993e/task.toml b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..081e558a16828e515b659624a7a46f988f7a41dc --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0b8a1955d41ff0c5993e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "5f9daf4eeb07f7aaaecb0dd39dd99bcf2753f4f9beb360131c66b9f9432b79b7" + +[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-0b8a1955d41ff0c5993e/tests/expected.json b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4641d1db584c9d6c16920bace3830201b8a946be --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/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-0b8a1955d41ff0c5993e/tests/grading.py b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/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-0b8a1955d41ff0c5993e/tests/test.sh b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/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-0b8a1955d41ff0c5993e/tests/verify.py b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/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-0b8a1955d41ff0c5993e/validation/openenv.json b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0b8a1955d41ff0c5993e/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-0bd02ed7cf35762d179c/environment/Dockerfile b/tasks/cedar_authorization-0bd02ed7cf35762d179c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0bd02ed7cf35762d179c/instruction.md b/tasks/cedar_authorization-0bd02ed7cf35762d179c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ca63ea1cea662e6594e79c0bd13e134e5eaf034e --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/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 == r::r::r::r::Roooooo::"", + action in [r::r::r::r::Action::"action"], + resource == r::r::r::r::A0::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::A0000000009::A::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::A0"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::Roooooo"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::A0000000009::A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"r":{"__extn":{"arg":"255.176.176.176/24","fn":"ip"}}},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r::r::A0"}} +{"action":{"id":"action","type":"A::A0000000009::A::Action"},"context":{"r":{"__extn":{"arg":"176.176.176.176","fn":"ip"}}},"principal":{"id":"","type":"A::A0000000009::A::a"},"request":"R2","resource":{"id":"","type":"A::A0000000009::A::a"}} +{"action":{"id":"action","type":"A::A0000000009::A::Action"},"context":{"r":{"__extn":{"arg":"176.176.176.176","fn":"ip"}}},"principal":{"id":"","type":"r::r::r::r::Roooooo"},"request":"R3","resource":{"id":"","type":"r::r::r::r::A0"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::Roooooo"},"request":"R4","resource":{"id":"","type":"r::r::r::r::A0"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-0bd02ed7cf35762d179c/solution/reference.json b/tasks/cedar_authorization-0bd02ed7cf35762d179c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/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-0bd02ed7cf35762d179c/solution/solve.sh b/tasks/cedar_authorization-0bd02ed7cf35762d179c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0bd02ed7cf35762d179c/task.toml b/tasks/cedar_authorization-0bd02ed7cf35762d179c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c9d696006ff56ef2ce4095c28b3c86b652c2bbfc --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0bd02ed7cf35762d179c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "e80328e39c8d9324e5007a6d5be9c4d9e9d45773d9c6963aa77c05de5b44844c" + +[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-0bd02ed7cf35762d179c/tests/expected.json b/tasks/cedar_authorization-0bd02ed7cf35762d179c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/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-0bd02ed7cf35762d179c/tests/grading.py b/tasks/cedar_authorization-0bd02ed7cf35762d179c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/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-0bd02ed7cf35762d179c/tests/test.sh b/tasks/cedar_authorization-0bd02ed7cf35762d179c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/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-0bd02ed7cf35762d179c/tests/verify.py b/tasks/cedar_authorization-0bd02ed7cf35762d179c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/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-0bd02ed7cf35762d179c/validation/openenv.json b/tasks/cedar_authorization-0bd02ed7cf35762d179c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0bd02ed7cf35762d179c/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-0c362b813a15421f0373/environment/Dockerfile b/tasks/cedar_authorization-0c362b813a15421f0373/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0c362b813a15421f0373/instruction.md b/tasks/cedar_authorization-0c362b813a15421f0373/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ef218b02e8094ae6eb394fb27fe82b4ebd5116c5 --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/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 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":"LYe"}},{"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":[{"id":"","type":"LYY"},{"id":"","type":"LYe"}],"uid":{"id":"(","type":"LYe"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"mmmm3333w*","type":"qgg"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"r":false},"principal":{"id":"(","type":"LYe"},"request":"R1","resource":{"id":"(","type":"LYe"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"(","type":"LYe"},"request":"R2","resource":{"id":"(","type":"LYe"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"(","type":"LYe"},"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-0c362b813a15421f0373/solution/reference.json b/tasks/cedar_authorization-0c362b813a15421f0373/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/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-0c362b813a15421f0373/solution/solve.sh b/tasks/cedar_authorization-0c362b813a15421f0373/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0c362b813a15421f0373/task.toml b/tasks/cedar_authorization-0c362b813a15421f0373/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..75ca28380c0e1fdbfa2d80d0ee1f1c2424f790aa --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0c362b813a15421f0373" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b4f7d4c84a902b2ab371096ea458c13d9065197c89ca595c5612cd694ff99f5f" + +[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-0c362b813a15421f0373/tests/expected.json b/tasks/cedar_authorization-0c362b813a15421f0373/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/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-0c362b813a15421f0373/tests/grading.py b/tasks/cedar_authorization-0c362b813a15421f0373/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/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-0c362b813a15421f0373/tests/test.sh b/tasks/cedar_authorization-0c362b813a15421f0373/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/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-0c362b813a15421f0373/tests/verify.py b/tasks/cedar_authorization-0c362b813a15421f0373/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/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-0c362b813a15421f0373/validation/openenv.json b/tasks/cedar_authorization-0c362b813a15421f0373/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0c362b813a15421f0373/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-0c97fbf623de8d43c8c3/environment/Dockerfile b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0c97fbf623de8d43c8c3/instruction.md b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..234d34985632fc822bd9d4565dc48fa89a882775 --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/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 a::"", + action in [Action::"action",Action::"action"], + resource in a::"" +) when { + true && (if if if false then false else false then if false then false else false else if false then false else true then a::"" in a::"" else if if false then false else false then if false then false else false else if false then false else false) && (if (if true then "2233" else "2233") like "**33*" then true else true) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"A::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"A::Action"},"context":{},"principal":{"id":"","type":"A::a"},"request":"R2","resource":{"id":"","type":"A::a"}} +{"action":{"id":"action","type":"A::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"A::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-0c97fbf623de8d43c8c3/solution/reference.json b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/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-0c97fbf623de8d43c8c3/solution/solve.sh b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0c97fbf623de8d43c8c3/task.toml b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d1a081599b903a0c3ecb01d7f624bdd49988327c --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0c97fbf623de8d43c8c3" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "36fb1ad36f8df20a395abbbf09a580ad330cdd39d530ae12de550a668d976182" + +[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-0c97fbf623de8d43c8c3/tests/expected.json b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/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-0c97fbf623de8d43c8c3/tests/grading.py b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/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-0c97fbf623de8d43c8c3/tests/test.sh b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/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-0c97fbf623de8d43c8c3/tests/verify.py b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/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-0c97fbf623de8d43c8c3/validation/openenv.json b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0c97fbf623de8d43c8c3/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-0d3a456a04fdf5bf42eb/environment/Dockerfile b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/instruction.md b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb1c7fd81e9c63660acd27c5b4100867f14cc97e --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/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 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":"Action"}},{"attrs":{},"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":"iYYYYYY4Z44444444"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"iYYYYYY4Z44444444"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"iYYYYYY4Z44444444"},"request":"R3","resource":{"id":"","type":"iYYYYYY4Z44444444"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"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-0d3a456a04fdf5bf42eb/solution/reference.json b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/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-0d3a456a04fdf5bf42eb/solution/solve.sh b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/task.toml b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..005ac62fdf23b5ee4ea4a7ee68263cc6245f6a0e --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0d3a456a04fdf5bf42eb" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "26ba7c113254b2f5a4775ee875b68da7f35114a16c3cef56f56219b072defe1c" + +[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-0d3a456a04fdf5bf42eb/tests/expected.json b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/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-0d3a456a04fdf5bf42eb/tests/grading.py b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/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-0d3a456a04fdf5bf42eb/tests/test.sh b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/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-0d3a456a04fdf5bf42eb/tests/verify.py b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/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-0d3a456a04fdf5bf42eb/validation/openenv.json b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0d3a456a04fdf5bf42eb/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-0d671931a999ea507163/environment/Dockerfile b/tasks/cedar_authorization-0d671931a999ea507163/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0d671931a999ea507163/instruction.md b/tasks/cedar_authorization-0d671931a999ea507163/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0a9913b2bd3bf24ca67cce41647b77fa21a4b5b9 --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/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 == r::r::r::r::Roooooo::"", + action in [r::r::r::r::Action::"action"], + resource == r::r::r::r::A0::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::A0"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::Roooooo"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"r":{"__extn":{"arg":"255.176.176.176/24","fn":"ip"}}},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r::r::A0"}} +{"action":{"id":"action","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::Action"},"context":{"r":{"__extn":{"arg":"176.176.176.176","fn":"ip"}}},"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":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::Roooooo"},"request":"R3","resource":{"id":"","type":"r::r::r::r::A0"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"r":{"__extn":{"arg":"176.176.176.176","fn":"ip"}}},"principal":{"id":"","type":"r::r::r::r::Roooooo"},"request":"R4","resource":{"id":"","type":"PcZgcecccccccc0::meccc::mcc60::k6afm::mh0005c31VOnnnh::lEEEEEEE::YEEEEEEEEE::r::dEEEEEEEEE"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-0d671931a999ea507163/solution/reference.json b/tasks/cedar_authorization-0d671931a999ea507163/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/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-0d671931a999ea507163/solution/solve.sh b/tasks/cedar_authorization-0d671931a999ea507163/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0d671931a999ea507163/task.toml b/tasks/cedar_authorization-0d671931a999ea507163/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9197612c902b99c0025a6f3f9a08793841464d5e --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0d671931a999ea507163" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ec9efcaac348bd263aff2c1223139c85fb56cfa2ee95395e3b663293cb39ef45" + +[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-0d671931a999ea507163/tests/expected.json b/tasks/cedar_authorization-0d671931a999ea507163/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/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-0d671931a999ea507163/tests/grading.py b/tasks/cedar_authorization-0d671931a999ea507163/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/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-0d671931a999ea507163/tests/test.sh b/tasks/cedar_authorization-0d671931a999ea507163/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/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-0d671931a999ea507163/tests/verify.py b/tasks/cedar_authorization-0d671931a999ea507163/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/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-0d671931a999ea507163/validation/openenv.json b/tasks/cedar_authorization-0d671931a999ea507163/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0d671931a999ea507163/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-0e612d3e8b6df5397c5e/environment/Dockerfile b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0e612d3e8b6df5397c5e/instruction.md b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a7e2d99ca87084641beb05ab5d595d0af821467d --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/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 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":"QxxO0xxxxxxxxxx::a"}},{"attrs":{},"parents":[],"tags":{"":[[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"8>>","type":"r"}}]]],"an >>>":[[[{"__entity":{"id":"","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]]],"~~":[[[{"__entity":{"id":"","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]]]},"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"tags":{"":[[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"8>>","type":"r"}}]]],"~~~":[[[{"__entity":{"id":"","type":"r"}}],[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"","type":"r"}},{"__entity":{"id":"8>>","type":"r"}}],[{"__entity":{"id":"8>>","type":"r"}}]],[[{"__entity":{"id":"8>>","type":"r"}}]]]},"uid":{"id":"8>>","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"QxxO0xxxxxxxxxx::Action"},"context":{},"principal":{"id":"","type":"QxxO0xxxxxxxxxx::a"},"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-0e612d3e8b6df5397c5e/solution/reference.json b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/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-0e612d3e8b6df5397c5e/solution/solve.sh b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0e612d3e8b6df5397c5e/task.toml b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ce5b2fdc75b876a7ce9b87d5d986083774ecbf9b --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0e612d3e8b6df5397c5e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "4f8b6e10ce24dc0cbdc11857651fef85ddcb1c5af71f2c24395d7b9c11611b04" + +[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-0e612d3e8b6df5397c5e/tests/expected.json b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..66eb4d422888607b6a5e02432b46f930aaa99498 --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/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-0e612d3e8b6df5397c5e/tests/grading.py b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/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-0e612d3e8b6df5397c5e/tests/test.sh b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/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-0e612d3e8b6df5397c5e/tests/verify.py b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/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-0e612d3e8b6df5397c5e/validation/openenv.json b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0e612d3e8b6df5397c5e/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-0e9ce02cf2a246e82768/environment/Dockerfile b/tasks/cedar_authorization-0e9ce02cf2a246e82768/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0e9ce02cf2a246e82768/instruction.md b/tasks/cedar_authorization-0e9ce02cf2a246e82768/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..50417fea881169492f05976b64c92d31c7a5b6f7 --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r::r::r::"", + action in [r::r::r::r::Action::"action"], + resource in r::r::r::r::r::"" +) when { + true +}; + +policy1 +forbid( + principal, + action in [Action::"action"], + resource +) when { + true && (resource in [resource, resource, resource]) && (resource in [resource, resource, resource]) && (resource in [l::"", l::"", l::""]) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"l"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::A"}},{"attrs":{},"parents":[],"tags":{"":""},"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"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":"r::r::r::r::r"},"request":"R2","resource":{"id":"","type":"l"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"l"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"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-0e9ce02cf2a246e82768/solution/reference.json b/tasks/cedar_authorization-0e9ce02cf2a246e82768/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/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-0e9ce02cf2a246e82768/solution/solve.sh b/tasks/cedar_authorization-0e9ce02cf2a246e82768/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0e9ce02cf2a246e82768/task.toml b/tasks/cedar_authorization-0e9ce02cf2a246e82768/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d7ff7fe95b701781cbe74c7a31eb2c515eebde91 --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0e9ce02cf2a246e82768" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "cdd94df1dbc6f50c686bbe81e8daaf614757a47fd39e700e973eeb20339a412b" + +[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-0e9ce02cf2a246e82768/tests/expected.json b/tasks/cedar_authorization-0e9ce02cf2a246e82768/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/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-0e9ce02cf2a246e82768/tests/grading.py b/tasks/cedar_authorization-0e9ce02cf2a246e82768/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/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-0e9ce02cf2a246e82768/tests/test.sh b/tasks/cedar_authorization-0e9ce02cf2a246e82768/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/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-0e9ce02cf2a246e82768/tests/verify.py b/tasks/cedar_authorization-0e9ce02cf2a246e82768/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/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-0e9ce02cf2a246e82768/validation/openenv.json b/tasks/cedar_authorization-0e9ce02cf2a246e82768/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0e9ce02cf2a246e82768/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-0ee682c4caefc5453ea0/environment/Dockerfile b/tasks/cedar_authorization-0ee682c4caefc5453ea0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-0ee682c4caefc5453ea0/instruction.md b/tasks/cedar_authorization-0ee682c4caefc5453ea0/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9c2d35f6ba0cf51b853267e04072bc250502abbf --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/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 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":"G::u::A::_qqqqqqqqqqp::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":"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":"G::u::A::_qqqqqqqqqqp::a"},"request":"R2","resource":{"id":"","type":"G::u::A::_qqqqqqqqqqp::a"}} +{"action":{"id":"action","type":"G::u::A::_qqqqqqqqqqp::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::m"},"request":"R3","resource":{"id":"","type":"r::r::r::r::m"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::m"},"request":"R4","resource":{"id":"","type":"r::r::r::r::m"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-0ee682c4caefc5453ea0/solution/reference.json b/tasks/cedar_authorization-0ee682c4caefc5453ea0/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..c1cba6f003dba7ecbcf408f823fd72ec90251bdb --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-0ee682c4caefc5453ea0/solution/solve.sh b/tasks/cedar_authorization-0ee682c4caefc5453ea0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-0ee682c4caefc5453ea0/task.toml b/tasks/cedar_authorization-0ee682c4caefc5453ea0/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fa26ac7e2affce3a5a43fb2b8be2b1155f6ca0d4 --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-0ee682c4caefc5453ea0" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "740ec20e7bbc57b4c606b45c4769d8943cf48d66c3d9502afdd2f3a727e1cc23" + +[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-0ee682c4caefc5453ea0/tests/expected.json b/tasks/cedar_authorization-0ee682c4caefc5453ea0/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..c1cba6f003dba7ecbcf408f823fd72ec90251bdb --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-0ee682c4caefc5453ea0/tests/grading.py b/tasks/cedar_authorization-0ee682c4caefc5453ea0/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/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-0ee682c4caefc5453ea0/tests/test.sh b/tasks/cedar_authorization-0ee682c4caefc5453ea0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/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-0ee682c4caefc5453ea0/tests/verify.py b/tasks/cedar_authorization-0ee682c4caefc5453ea0/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/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-0ee682c4caefc5453ea0/validation/openenv.json b/tasks/cedar_authorization-0ee682c4caefc5453ea0/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-0ee682c4caefc5453ea0/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"]}}