diff --git a/tasks/cedar_authorization-1ae7eef38d8727ee80fb/environment/Dockerfile b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1ae7eef38d8727ee80fb/instruction.md b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ceb49bfc60c59882c2df97469be27068b2bd8b09 --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal is r::r33::r::r::r333333311 in r::r33::r::r::r333333311::"|||||||", + action in [r::r33::r::r::Action::"action"], + resource == r::r33::r::r::r333333311::"|||||||" +) when { + true +}; + +policy1 +forbid( + principal == r::"", + action == Action::"action", + resource in r::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"tags":{"":{"__extn":{"arg":"5934-03-01T14:52:52Z","fn":"datetime"}}},"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[{"id":"|","type":"r::r33::r::r::r333333311"},{"id":"|||||~|||||x","type":"r::r33::r::r::slW33zzzzzzzzz"}],"uid":{"id":"","type":"r::r33::r::r::slW33zzzzzzzzz"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r33::r::r::Action"}},{"attrs":{},"parents":[{"id":"|||||~|||||x","type":"r::r33::r::r::slW33zzzzzzzzz"}],"uid":{"id":"|","type":"r::r33::r::r::r333333311"}},{"attrs":{},"parents":[{"id":"|","type":"r::r33::r::r::r333333311"},{"id":"|||||~|||||x","type":"r::r33::r::r::slW33zzzzzzzzz"}],"uid":{"id":"|||||||","type":"r::r33::r::r::r333333311"}},{"attrs":{},"parents":[],"uid":{"id":"|||||~|||||x","type":"r::r33::r::r::slW33zzzzzzzzz"}}] + +Requests +{"action":{"id":"action","type":"r::r33::r::r::Action"},"context":{"AYY":true},"principal":{"id":"|||||||","type":"r::r33::r::r::r333333311"},"request":"R1","resource":{"id":"|||||||","type":"r::r33::r::r::r333333311"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"|||||||","type":"r::r33::r::r::r333333311"},"request":"R3","resource":{"id":"|||||||","type":"r::r33::r::r::r333333311"}} +{"action":{"id":"action","type":"r::r33::r::r::Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R4","resource":{"id":"|||||||","type":"r::r33::r::r::r333333311"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1ae7eef38d8727ee80fb/solution/reference.json b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/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-1ae7eef38d8727ee80fb/solution/solve.sh b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1ae7eef38d8727ee80fb/task.toml b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..731ac6a534f87463820b61231084c6abe2647337 --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1ae7eef38d8727ee80fb" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "5e158d25a2d867c0296939d53c74cd26cea655e7c1eccc642a65d8c51b320686" + +[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-1ae7eef38d8727ee80fb/tests/expected.json b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..45268072ec2b99a2f7a2810c4702675d4fe8a5d3 --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/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-1ae7eef38d8727ee80fb/tests/grading.py b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/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-1ae7eef38d8727ee80fb/tests/test.sh b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/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-1ae7eef38d8727ee80fb/tests/verify.py b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/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-1ae7eef38d8727ee80fb/validation/openenv.json b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1ae7eef38d8727ee80fb/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-1b36808d1ebe0ff9ca92/environment/Dockerfile b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/instruction.md b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4c35a1d429a6d3ee64de2766538aad77b58b279c --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r::r::A::"", + action == r::r::r::r::Action::"action", + resource == r::r::r::r::A::"" +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::wZ1g::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::wZ1g::"" +) when { + true && ((if "||||||||||||~|" like "|*|*|*|*|*|*" then if false then "||||||||||||~|" else "||||||||||||~|" else if false then "||||||||||||~|" else "||||||||||||~|") like "|*|*|*|*|*|*") && ((if "||||||||||||~|" like "*||**|*|*|*|" then "||||||||||||~|" else "||||||||||||~|") like "*|*|*|*|*|*|") +}; + +Entities +[{"attrs":{"_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::g31000000"}},{"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":"","type":"r::r::r::r::wZ1g"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"|","type":"r::r::r::r::r"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::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::wZ1g"},"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::wZ1g"},"request":"R3","resource":{"id":"","type":"r::r::r::r::wZ1g"}} +{"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::wZ1g"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/solution/reference.json b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/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-1b36808d1ebe0ff9ca92/solution/solve.sh b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/task.toml b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e59e179f4d8736b9f35b11c51a6a9efb7aaacf8b --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1b36808d1ebe0ff9ca92" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "5b4dc8cc3d08e41d254405043f86f413153751c43e0367d302aff50a2fcd1d40" + +[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-1b36808d1ebe0ff9ca92/tests/expected.json b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/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-1b36808d1ebe0ff9ca92/tests/grading.py b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/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-1b36808d1ebe0ff9ca92/tests/test.sh b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/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-1b36808d1ebe0ff9ca92/tests/verify.py b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/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-1b36808d1ebe0ff9ca92/validation/openenv.json b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1b36808d1ebe0ff9ca92/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-1bf71d6c09a99ba232ca/environment/Dockerfile b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1bf71d6c09a99ba232ca/instruction.md b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..7db5d49f86089f391a0d16c2ad0689fac2babfd2 --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/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 is TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::a, + action in [TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::Action::"action"], + resource == TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::a::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::Action"}}] + +Requests +{"action":{"id":"action","type":"A::Action"},"context":{},"principal":{"id":"","type":"TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::a"},"request":"R1","resource":{"id":"","type":"TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::a"}} +{"action":{"id":"action","type":"TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::Action"},"context":{},"principal":{"id":"","type":"TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::a"},"request":"R2","resource":{"id":"","type":"TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::a"}} +{"action":{"id":"action","type":"A::Action"},"context":{},"principal":{"id":"","type":"A::a"},"request":"R3","resource":{"id":"","type":"TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::a"}} +{"action":{"id":"action","type":"A::Action"},"context":{},"principal":{"id":"","type":"TOOOO::YOOOOOOO::YOOOO999::T9999::T9999::T9999::T99H9::_qqqqqqq9999::a"},"request":"R4","resource":{"id":"","type":"A::a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1bf71d6c09a99ba232ca/solution/reference.json b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-1bf71d6c09a99ba232ca/solution/solve.sh b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1bf71d6c09a99ba232ca/task.toml b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6df4ae902bb6eae8947832fefc94c8a61040b089 --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1bf71d6c09a99ba232ca" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "e05231d31c75c7f2dd6c9dafa6355fdd01b1ba5b28f2035a4765fdb4d38a65c3" + +[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-1bf71d6c09a99ba232ca/tests/expected.json b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..4a6e384ddd8be30957adaba9705331dd39ff612f --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-1bf71d6c09a99ba232ca/tests/grading.py b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/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-1bf71d6c09a99ba232ca/tests/test.sh b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/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-1bf71d6c09a99ba232ca/tests/verify.py b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/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-1bf71d6c09a99ba232ca/validation/openenv.json b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1bf71d6c09a99ba232ca/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-1c0a0177988dfd23f6dc/environment/Dockerfile b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1c0a0177988dfd23f6dc/instruction.md b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5bb63afbed3088c3a8d05711fa27e19db83a6a4a --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r::"NNN", + action in [r::r::Action::"action",r::r::Action::"action"], + resource is r::r::r +) when { + true && (r::r::r::"NNN" in r::r::r::"NNN") +}; + +policy1 +forbid( + principal in a::"", + action in [Action::"action",Action::"action"], + resource == a::"" +) when { + true && ((if (-4123389851770370362) < 198 then principal else principal) in principal) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"tags":{"":{}},"uid":{"id":"NNN","type":"r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::Action"},"context":{},"principal":{"id":"NNN","type":"r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r"}} +{"action":{"id":"action","type":"r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r"},"request":"R2","resource":{"id":"","type":"r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1c0a0177988dfd23f6dc/solution/reference.json b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/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-1c0a0177988dfd23f6dc/solution/solve.sh b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1c0a0177988dfd23f6dc/task.toml b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6898f674c8b25b1008151d7f6aab275cb454710b --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1c0a0177988dfd23f6dc" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0127aa156e9a0ca93090e3a9f52f0b60cbb7a2fea785d4b80f223567eb18189b" + +[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-1c0a0177988dfd23f6dc/tests/expected.json b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/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-1c0a0177988dfd23f6dc/tests/grading.py b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/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-1c0a0177988dfd23f6dc/tests/test.sh b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/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-1c0a0177988dfd23f6dc/tests/verify.py b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/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-1c0a0177988dfd23f6dc/validation/openenv.json b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1c0a0177988dfd23f6dc/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-1cbf33f4f4fb5cea462c/environment/Dockerfile b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/instruction.md b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d6d2ed0c9d23e66f166b9760de1d8eacd44ab780 --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == G::u::A::_qqqqqqqqqqp::a::"", + action in [G::u::A::_qqqqqqqqqqp::Action::"action"], + resource is G::u::A::_qqqqqqqqqqp::a in G::u::A::_qqqqqqqqqqp::a::"" +) when { + true && ((-1736164148113840153) <= (-1736164148113840153)) && ((-1736164148113840153) <= (-1736164148113840153)) && ((-1736164148113840153) <= 2522015791327471591) +}; + +policy1 +forbid( + principal is r::r::sLW00000z3333333 in r::r::sLW00000z3333333::"", + action in [r::r::Action::"action"], + resource == r::r::sLW00000z3333333::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"G::u::A::_qqqqqqqqqqp::a"}},{"attrs":{},"parents":[{"id":"******","type":"r::r::r"}],"uid":{"id":"","type":"r::r::sLW00000z3333333"}},{"attrs":{},"parents":[],"uid":{"id":"******","type":"r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"G::u::A::_qqqqqqqqqqp::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"G::u::A::_qqqqqqqqqqp::Action"},"context":{"WMMM0M":{},"g":false,"r":[[[[]]]]},"principal":{"id":"","type":"G::u::A::_qqqqqqqqqqp::a"},"request":"R1","resource":{"id":"","type":"G::u::A::_qqqqqqqqqqp::a"}} +{"action":{"id":"action","type":"r::r::Action"},"context":{"WMMM0M":{},"g":false,"r":[[[],[[]]],[[[]]]]},"principal":{"id":"******","type":"r::r::r"},"request":"R2","resource":{"id":"******","type":"r::r::r"}} +{"action":{"id":"action","type":"r::r::Action"},"context":{"WMMM0M":{},"g":false,"r":[[[[]]]]},"principal":{"id":"","type":"r::r::sLW00000z3333333"},"request":"R3","resource":{"id":"","type":"r::r::sLW00000z3333333"}} +{"action":{"id":"action","type":"r::r::Action"},"context":{"WMMM0M":{},"g":false,"r":[[],[[[]]]]},"principal":{"id":"******","type":"r::r::r"},"request":"R4","resource":{"id":"","type":"r::r::sLW00000z3333333"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/solution/reference.json b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/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-1cbf33f4f4fb5cea462c/solution/solve.sh b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/task.toml b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d79ae369846b40d01e27e7aef4defe7eb17e1986 --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1cbf33f4f4fb5cea462c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "5043ab3b12e0d957c5fbe2c6ba0eb61a3f0e0033667636634258fda3b21ee566" + +[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-1cbf33f4f4fb5cea462c/tests/expected.json b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d7e17a23885cf0d93d59ed344832110f3ed681f7 --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/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-1cbf33f4f4fb5cea462c/tests/grading.py b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/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-1cbf33f4f4fb5cea462c/tests/test.sh b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/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-1cbf33f4f4fb5cea462c/tests/verify.py b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/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-1cbf33f4f4fb5cea462c/validation/openenv.json b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1cbf33f4f4fb5cea462c/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-1cd7726030e89497eb93/environment/Dockerfile b/tasks/cedar_authorization-1cd7726030e89497eb93/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1cd7726030e89497eb93/instruction.md b/tasks/cedar_authorization-1cd7726030e89497eb93/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..39c7e441fe81b0d6ebaffadadc1bd76fcca3698e --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/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, + action in [Action::"action"], + resource +) when { + true && (r::"yyyyyyyyyyyyyyyye" has r) && (r::"yyyyyyyyyyyyyyyye" has r) && (r::"yyyyyyyyyyyyyyyye".r has r) +}; + +Entities +[{"attrs":{"r":{"__entity":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::W"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::u"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{"r":{"__entity":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}},"parents":[],"uid":{"id":"yyyyyyyyyyyyyyyye","type":"r"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"r":false},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R1","resource":{"id":"","type":"r::r::r::r::q"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"r":false},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R3","resource":{"id":"","type":"r"}} +{"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-1cd7726030e89497eb93/solution/reference.json b/tasks/cedar_authorization-1cd7726030e89497eb93/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..71c6642e43a201e0274d8a8eec52b73ac1282893 --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-1cd7726030e89497eb93/solution/solve.sh b/tasks/cedar_authorization-1cd7726030e89497eb93/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1cd7726030e89497eb93/task.toml b/tasks/cedar_authorization-1cd7726030e89497eb93/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..939dffee051d6ebe5b43e409152a6ffb1608c940 --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1cd7726030e89497eb93" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "77b0e415cf0372323254b5af7d64fd536087660605e795a89c31e2d07fc59d08" + +[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-1cd7726030e89497eb93/tests/expected.json b/tasks/cedar_authorization-1cd7726030e89497eb93/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..71c6642e43a201e0274d8a8eec52b73ac1282893 --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-1cd7726030e89497eb93/tests/grading.py b/tasks/cedar_authorization-1cd7726030e89497eb93/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/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-1cd7726030e89497eb93/tests/test.sh b/tasks/cedar_authorization-1cd7726030e89497eb93/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/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-1cd7726030e89497eb93/tests/verify.py b/tasks/cedar_authorization-1cd7726030e89497eb93/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/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-1cd7726030e89497eb93/validation/openenv.json b/tasks/cedar_authorization-1cd7726030e89497eb93/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1cd7726030e89497eb93/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-1d4eca8034b80bd94108/environment/Dockerfile b/tasks/cedar_authorization-1d4eca8034b80bd94108/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1d4eca8034b80bd94108/instruction.md b/tasks/cedar_authorization-1d4eca8034b80bd94108/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..794a514a7c2c23e2102ad59bdcecefc1e375f8a5 --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in a::"", + action in [Action::"action",Action::"action"], + resource is a +) when { + true && ((if true then {"": a::""} else {"": a::""})[""] in (if true then {"": [principal]} else context)[""]) && ({"": action}[""] in {"": [action]}[""]) && true +}; + +policy1 +forbid( + principal in iYYYYYY4Z44444444::"", + action in [Action::"action",Action::"action"], + resource in iYYYYYY4Z44444444::"" +) when { + true && [[[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]], [[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]]].contains(if [[resource, resource], [resource, resource]].contains([resource, resource]) then if false then [[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]] else [[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]] else [[[resource, resource], [resource, resource]], [[resource, resource], [resource, resource]]]) && (if false then {"": decimal("-441275054312267.7054")} else {"": decimal("-557019330853190.3822")})[""].lessThan(decimal("0.0")) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"O4444124"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Tqqqqqqqq"}},{"attrs":{},"parents":[],"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":"action","type":"Action"},"context":{},"principal":{"id":"","type":"iYYYYYY4Z44444444"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"iYYYYYY4Z44444444"},"request":"R3","resource":{"id":"","type":"iYYYYYY4Z44444444"}} +{"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-1d4eca8034b80bd94108/solution/reference.json b/tasks/cedar_authorization-1d4eca8034b80bd94108/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/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-1d4eca8034b80bd94108/solution/solve.sh b/tasks/cedar_authorization-1d4eca8034b80bd94108/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1d4eca8034b80bd94108/task.toml b/tasks/cedar_authorization-1d4eca8034b80bd94108/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..956481798c8d38e8476dcc633c8015d7ebf7f03e --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1d4eca8034b80bd94108" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "4522750b54bdc926954504eeafb5e2add6ca5e2b2ecf2f85dea70568c992d7ac" + +[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-1d4eca8034b80bd94108/tests/expected.json b/tasks/cedar_authorization-1d4eca8034b80bd94108/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/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-1d4eca8034b80bd94108/tests/grading.py b/tasks/cedar_authorization-1d4eca8034b80bd94108/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/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-1d4eca8034b80bd94108/tests/test.sh b/tasks/cedar_authorization-1d4eca8034b80bd94108/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/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-1d4eca8034b80bd94108/tests/verify.py b/tasks/cedar_authorization-1d4eca8034b80bd94108/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/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-1d4eca8034b80bd94108/validation/openenv.json b/tasks/cedar_authorization-1d4eca8034b80bd94108/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1d4eca8034b80bd94108/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-1d6c872a4193b24ee72c/environment/Dockerfile b/tasks/cedar_authorization-1d6c872a4193b24ee72c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1d6c872a4193b24ee72c/instruction.md b/tasks/cedar_authorization-1d6c872a4193b24ee72c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3edec3b46f2cf238389a5b56cbcd36692ad49458 --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in a::"", + action, + resource +) when { + true && ((if true then resource is a else false == false) == ((false == false) == (false == false))) && ((([true] == []) == true) == false) +}; + +policy1 +forbid( + principal == r::r::r::r::q::"", + action == r::r::r::r::Action::"action", + resource == r::r::r::r::q::"" +) when { + true && (if false then {"": ip("0.0.194.194")} else {"": ip("238.238.32.1")})[""].isMulticast() +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::h"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::n"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::h"}],"tags":{"":[[[[]]]]},"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"r::r::r::r::q"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R3","resource":{"id":"","type":"r::r::r::r::q"}} +{"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-1d6c872a4193b24ee72c/solution/reference.json b/tasks/cedar_authorization-1d6c872a4193b24ee72c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/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-1d6c872a4193b24ee72c/solution/solve.sh b/tasks/cedar_authorization-1d6c872a4193b24ee72c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1d6c872a4193b24ee72c/task.toml b/tasks/cedar_authorization-1d6c872a4193b24ee72c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..00d7c161a52a27be3f8e7bb822d45ab076e3e5b0 --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1d6c872a4193b24ee72c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "bf32c0e28315bc28de223473d24ef3fba2b2791513798275766a87855e2ae568" + +[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-1d6c872a4193b24ee72c/tests/expected.json b/tasks/cedar_authorization-1d6c872a4193b24ee72c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/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-1d6c872a4193b24ee72c/tests/grading.py b/tasks/cedar_authorization-1d6c872a4193b24ee72c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/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-1d6c872a4193b24ee72c/tests/test.sh b/tasks/cedar_authorization-1d6c872a4193b24ee72c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/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-1d6c872a4193b24ee72c/tests/verify.py b/tasks/cedar_authorization-1d6c872a4193b24ee72c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/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-1d6c872a4193b24ee72c/validation/openenv.json b/tasks/cedar_authorization-1d6c872a4193b24ee72c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1d6c872a4193b24ee72c/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-1d8f9d75b31b48899d33/environment/Dockerfile b/tasks/cedar_authorization-1d8f9d75b31b48899d33/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1d8f9d75b31b48899d33/instruction.md b/tasks/cedar_authorization-1d8f9d75b31b48899d33/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1d37a5cd92baed5097f2a10a6d0d04ea3e2309d2 --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A100120000000040::A::B::a::"", + action == A100120000000040::A::B::Action::"action", + resource in A100120000000040::A::B::a::"" +) when { + true && (A100120000000040::A::B::a::"" in A100120000000040::A::B::a::"") && (A100120000000040::A::B::a::"" in A100120000000040::A::B::a::"") +}; + +policy1 +forbid( + principal is l, + action == Action::"action", + resource is l +) when { + true && ([ip("ffff:a20:6e61:693b:dfdf:dfdf:dfdf:dfdf"), ip("ffff:ffff:ffff:fff:ffff:ffff:2dff:feff/126"), ip("160.160.160.160/25")].containsAny([]) || (principal in principal) || (resource in resource)) && (resource in resource) && (resource in resource) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A100120000000040::A::B::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"l"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A100120000000040::A::B::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{"B":"","r":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"r3":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"A100120000000040::A::B::Action"},"context":{"B":"","r":{"__extn":{"arg":"0000-01-01","fn":"datetime"}},"r3":{"__extn":{"arg":"0000-01-01","fn":"datetime"}}},"principal":{"id":"","type":"A100120000000040::A::B::a"},"request":"R2","resource":{"id":"","type":"A100120000000040::A::B::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"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-1d8f9d75b31b48899d33/solution/reference.json b/tasks/cedar_authorization-1d8f9d75b31b48899d33/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/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-1d8f9d75b31b48899d33/solution/solve.sh b/tasks/cedar_authorization-1d8f9d75b31b48899d33/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1d8f9d75b31b48899d33/task.toml b/tasks/cedar_authorization-1d8f9d75b31b48899d33/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ac64d399e92895d52d4beb6e7c8a4d183859b6a2 --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1d8f9d75b31b48899d33" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "e334d156236f14e51f33807b257086f4cce7f30f15cb785bf31a1108d249cb91" + +[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-1d8f9d75b31b48899d33/tests/expected.json b/tasks/cedar_authorization-1d8f9d75b31b48899d33/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/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-1d8f9d75b31b48899d33/tests/grading.py b/tasks/cedar_authorization-1d8f9d75b31b48899d33/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/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-1d8f9d75b31b48899d33/tests/test.sh b/tasks/cedar_authorization-1d8f9d75b31b48899d33/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/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-1d8f9d75b31b48899d33/tests/verify.py b/tasks/cedar_authorization-1d8f9d75b31b48899d33/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/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-1d8f9d75b31b48899d33/validation/openenv.json b/tasks/cedar_authorization-1d8f9d75b31b48899d33/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1d8f9d75b31b48899d33/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-1dc670f4177239fc4efe/environment/Dockerfile b/tasks/cedar_authorization-1dc670f4177239fc4efe/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1dc670f4177239fc4efe/instruction.md b/tasks/cedar_authorization-1dc670f4177239fc4efe/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a793a8d73ffd50cf6fb76375742317fb56da2bcc --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/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, + action in [Action::"action"], + resource +) when { + true && (r::"" has r) && (r::"".r has r) && (r::"" has r) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}},{"attrs":{"r":{"__entity":{"id":"","type":"r"}}},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}} +{"action":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"},"context":{},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R2","resource":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"B::G::GTTTTTTTTTTTTTT::r::Action"},"context":{},"principal":{"id":"","type":"B::G::GTTTTTTTTTTTTTT::r::a"},"request":"R4","resource":{"id":"","type":"r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1dc670f4177239fc4efe/solution/reference.json b/tasks/cedar_authorization-1dc670f4177239fc4efe/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..057b206a9b7582ca95356992a884c0dcc9d5fcd2 --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"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-1dc670f4177239fc4efe/solution/solve.sh b/tasks/cedar_authorization-1dc670f4177239fc4efe/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1dc670f4177239fc4efe/task.toml b/tasks/cedar_authorization-1dc670f4177239fc4efe/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3396b6fbcac1d1ea77c469dd9d13dd346c85193e --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1dc670f4177239fc4efe" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "ecb3b4816bde2417dbcbc7946cc13aeb62715f17d1c0b63395a10c119f24b11d" + +[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-1dc670f4177239fc4efe/tests/expected.json b/tasks/cedar_authorization-1dc670f4177239fc4efe/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..057b206a9b7582ca95356992a884c0dcc9d5fcd2 --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"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-1dc670f4177239fc4efe/tests/grading.py b/tasks/cedar_authorization-1dc670f4177239fc4efe/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/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-1dc670f4177239fc4efe/tests/test.sh b/tasks/cedar_authorization-1dc670f4177239fc4efe/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/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-1dc670f4177239fc4efe/tests/verify.py b/tasks/cedar_authorization-1dc670f4177239fc4efe/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/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-1dc670f4177239fc4efe/validation/openenv.json b/tasks/cedar_authorization-1dc670f4177239fc4efe/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1dc670f4177239fc4efe/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-1e254e9d89fedf68570b/environment/Dockerfile b/tasks/cedar_authorization-1e254e9d89fedf68570b/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1e254e9d89fedf68570b/instruction.md b/tasks/cedar_authorization-1e254e9d89fedf68570b/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..59012d6ed609ab42f50d87217e0c857bfa258ee3 --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in a::"F", + action in [Action::"action"], + resource == a::"F" +) when { + true && (a::"F" has Evv2999) && (a::"F" has Evv2999) && (if if if false then false else false then a::"F" has Evv2999 else a::"F" has Evv2999 then a::"F" has Evv2999 else false) +}; + +policy1 +forbid( + principal, + 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":[],"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":{"Evv2999":{"__extn":{"arg":"0737-07-13T06:18:18Z","fn":"datetime"}}},"parents":[],"uid":{"id":"F","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R1","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"F","type":"a"},"request":"R2","resource":{"id":"F","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"F","type":"a"},"request":"R3","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R4","resource":{"id":"F","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1e254e9d89fedf68570b/solution/reference.json b/tasks/cedar_authorization-1e254e9d89fedf68570b/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..057b206a9b7582ca95356992a884c0dcc9d5fcd2 --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"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-1e254e9d89fedf68570b/solution/solve.sh b/tasks/cedar_authorization-1e254e9d89fedf68570b/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1e254e9d89fedf68570b/task.toml b/tasks/cedar_authorization-1e254e9d89fedf68570b/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c2f05a8ec6011035f9283c0c40db4a029a3b092c --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1e254e9d89fedf68570b" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "516b294839cffa865bf01644d2be443bf63c6b9ac434154188e7875b322fd314" + +[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-1e254e9d89fedf68570b/tests/expected.json b/tasks/cedar_authorization-1e254e9d89fedf68570b/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..057b206a9b7582ca95356992a884c0dcc9d5fcd2 --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"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-1e254e9d89fedf68570b/tests/grading.py b/tasks/cedar_authorization-1e254e9d89fedf68570b/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/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-1e254e9d89fedf68570b/tests/test.sh b/tasks/cedar_authorization-1e254e9d89fedf68570b/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/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-1e254e9d89fedf68570b/tests/verify.py b/tasks/cedar_authorization-1e254e9d89fedf68570b/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/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-1e254e9d89fedf68570b/validation/openenv.json b/tasks/cedar_authorization-1e254e9d89fedf68570b/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1e254e9d89fedf68570b/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-1ecc00a26f36bfa4a2a5/environment/Dockerfile b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/instruction.md b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d8182939c8b81ac1a5d7e98cbe2dcefdc8b1aa76 --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == r::"", + action == Action::"action", + resource +) when { + true +}; + +policy1 +forbid( + principal in a::"", + action in [Action::"action"], + resource in a::"" +) when { + true && resource.getTag("").getTag("").hasTag("") +}; + +Entities +[{"attrs":{},"parents":[],"tags":{"":{"__entity":{"id":"","type":"a"}}},"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R2","resource":{"id":"","type":"r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/solution/reference.json b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..3ffa2505a6a1f29cfec26eac33da1d6fd8f03189 --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/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-1ecc00a26f36bfa4a2a5/solution/solve.sh b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/task.toml b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..eefce3cd37d0cb3e674e0c767b5c0987f44153bb --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1ecc00a26f36bfa4a2a5" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "957d78cf160a28919e06b93906750cdae958d37e1975dd4014977a1515f8088f" + +[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-1ecc00a26f36bfa4a2a5/tests/expected.json b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..3ffa2505a6a1f29cfec26eac33da1d6fd8f03189 --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/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-1ecc00a26f36bfa4a2a5/tests/grading.py b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/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-1ecc00a26f36bfa4a2a5/tests/test.sh b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/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-1ecc00a26f36bfa4a2a5/tests/verify.py b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/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-1ecc00a26f36bfa4a2a5/validation/openenv.json b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1ecc00a26f36bfa4a2a5/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-1efe4064c569511d5299/environment/Dockerfile b/tasks/cedar_authorization-1efe4064c569511d5299/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1efe4064c569511d5299/instruction.md b/tasks/cedar_authorization-1efe4064c569511d5299/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd56383f683d462adce8706a27441ca3b1189473 --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r::"NNN", + action in [r::r::Action::"action",r::r::Action::"action"], + resource is r::r::r +) when { + true && (r::r::r::"NNN" in r::r::r::"NNN") +}; + +policy1 +forbid( + principal in r::r::r::r::wZ1g::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::wZ1g::"" +) when { + true && ((if "||||||||||||~|" like "|*|*|*|*|*|*" then if false then "||||||||||||~|" else "||||||||||||~|" else if false then "||||||||||||~|" else "||||||||||||~|") like "|*|*|*|*|*|*") && ((if "||||||||||||~|" like "*||**|*|*|*|" then "||||||||||||~|" else "||||||||||||~|") like "*|*|*|*|*|*|") +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::g31000000"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::wZ1g"}},{"attrs":{},"parents":[],"tags":{"":{}},"uid":{"id":"NNN","type":"r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"|","type":"r::r::r::r::r"}}] + +Requests +{"action":{"id":"action","type":"r::r::Action"},"context":{},"principal":{"id":"NNN","type":"r::r::r"},"request":"R1","resource":{"id":"","type":"r::r::r"}} +{"action":{"id":"action","type":"r::r::Action"},"context":{},"principal":{"id":"NNN","type":"r::r::r"},"request":"R2","resource":{"id":"","type":"r::r::r::r::wZ1g"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"NNN","type":"r::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::wZ1g"},"request":"R4","resource":{"id":"","type":"r::r::r::r::wZ1g"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1efe4064c569511d5299/solution/reference.json b/tasks/cedar_authorization-1efe4064c569511d5299/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/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-1efe4064c569511d5299/solution/solve.sh b/tasks/cedar_authorization-1efe4064c569511d5299/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1efe4064c569511d5299/task.toml b/tasks/cedar_authorization-1efe4064c569511d5299/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9e72bba944c8905cb3dbf94d55f89b0b0cafe8d3 --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1efe4064c569511d5299" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "99b57b4a48e967ce78e704db562db1e5333c9b7c61207978905b14313899a64e" + +[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-1efe4064c569511d5299/tests/expected.json b/tasks/cedar_authorization-1efe4064c569511d5299/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/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-1efe4064c569511d5299/tests/grading.py b/tasks/cedar_authorization-1efe4064c569511d5299/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/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-1efe4064c569511d5299/tests/test.sh b/tasks/cedar_authorization-1efe4064c569511d5299/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/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-1efe4064c569511d5299/tests/verify.py b/tasks/cedar_authorization-1efe4064c569511d5299/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/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-1efe4064c569511d5299/validation/openenv.json b/tasks/cedar_authorization-1efe4064c569511d5299/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1efe4064c569511d5299/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-1f13f633aef95755065a/environment/Dockerfile b/tasks/cedar_authorization-1f13f633aef95755065a/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-1f13f633aef95755065a/instruction.md b/tasks/cedar_authorization-1f13f633aef95755065a/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d62a49a5b667abd5e20a60a35f32a0f8b82b9ae --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == r::r::r::r::r::"***((((((((", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal in a::"", + action in [Action::"action",Action::"action"], + resource == a::"" +) when { + true && ((if (-4123389851770370362) < 198 then principal else principal) in principal) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"***((((((((","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"***((((((((","type":"r::r::r::r::r"},"request":"R1","resource":{"id":"***((((((((","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"***((((((((","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"L5c":true,"LYY":true,"PcY":{"__entity":{"id":"***((((((((","type":"r::r::r::r::r"}}},"principal":{"id":"***((((((((","type":"r::r::r::r::r"},"request":"R4","resource":{"id":"***((((((((","type":"r::r::r::r::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-1f13f633aef95755065a/solution/reference.json b/tasks/cedar_authorization-1f13f633aef95755065a/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..086b845858573703b01390817ea414e77e201181 --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-1f13f633aef95755065a/solution/solve.sh b/tasks/cedar_authorization-1f13f633aef95755065a/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-1f13f633aef95755065a/task.toml b/tasks/cedar_authorization-1f13f633aef95755065a/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d4a5b5041fb20d5bd22cf73e90efa8df6d846a97 --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-1f13f633aef95755065a" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "aeb3802a2664989b652ff23e3a3a7d5427a27c041a2cd771219dd65eba185320" + +[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-1f13f633aef95755065a/tests/expected.json b/tasks/cedar_authorization-1f13f633aef95755065a/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..086b845858573703b01390817ea414e77e201181 --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"deny","determining":[],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-1f13f633aef95755065a/tests/grading.py b/tasks/cedar_authorization-1f13f633aef95755065a/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/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-1f13f633aef95755065a/tests/test.sh b/tasks/cedar_authorization-1f13f633aef95755065a/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/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-1f13f633aef95755065a/tests/verify.py b/tasks/cedar_authorization-1f13f633aef95755065a/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/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-1f13f633aef95755065a/validation/openenv.json b/tasks/cedar_authorization-1f13f633aef95755065a/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-1f13f633aef95755065a/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-204a16a2ad9735a14163/environment/Dockerfile b/tasks/cedar_authorization-204a16a2ad9735a14163/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-204a16a2ad9735a14163/instruction.md b/tasks/cedar_authorization-204a16a2ad9735a14163/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45ff0ddfdf94fbd8f633af0a708aaf8858dfc63c --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal is a, + action == Action::"action", + resource is a +) when { + true && (true || (principal in principal) || (a::"((((((((((((((((" is a)) && (a::"((((((((((((((((" is a) && (a::"((((((((((((((((" is a) +}; + +policy1 +forbid( + principal, + action in [j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action::"action"], + resource +) when { + true && (j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a::"" has r) && true && (j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a::"" in resource.j5530000000.j5530000000) +}; + +Entities +[{"attrs":{"j5530000000":{"__entity":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}},"r":""},"parents":[],"uid":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}},{"attrs":{},"parents":[],"uid":{"id":"((((((((((((((((","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action"}}] + +Requests +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action"},"context":{},"principal":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"},"request":"R1","resource":{"id":"((((((((((((((((","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"((((((((((((((((","type":"a"},"request":"R2","resource":{"id":"((((((((((((((((","type":"a"}} +{"action":{"id":"action","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::Action"},"context":{},"principal":{"id":"((((((((((((((((","type":"a"},"request":"R3","resource":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"j5555555::Hzzzpppp::z::j5555555::j55400::j55yzzz5::a"},"request":"R4","resource":{"id":"((((((((((((((((","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-204a16a2ad9735a14163/solution/reference.json b/tasks/cedar_authorization-204a16a2ad9735a14163/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..df0c8b18fd3d27e6249f3b21e5d70ff4c255064e --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":["policy1"],"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-204a16a2ad9735a14163/solution/solve.sh b/tasks/cedar_authorization-204a16a2ad9735a14163/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-204a16a2ad9735a14163/task.toml b/tasks/cedar_authorization-204a16a2ad9735a14163/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cb64498c9715163317fdf1a3a2e7ddf304684225 --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-204a16a2ad9735a14163" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "04fdb20f62847e36349ef1fcd12fc83e2f858a296ea7177fdeba00e23446067b" + +[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-204a16a2ad9735a14163/tests/expected.json b/tasks/cedar_authorization-204a16a2ad9735a14163/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..df0c8b18fd3d27e6249f3b21e5d70ff4c255064e --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":[],"errors":["policy1"],"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-204a16a2ad9735a14163/tests/grading.py b/tasks/cedar_authorization-204a16a2ad9735a14163/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/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-204a16a2ad9735a14163/tests/test.sh b/tasks/cedar_authorization-204a16a2ad9735a14163/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/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-204a16a2ad9735a14163/tests/verify.py b/tasks/cedar_authorization-204a16a2ad9735a14163/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/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-204a16a2ad9735a14163/validation/openenv.json b/tasks/cedar_authorization-204a16a2ad9735a14163/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-204a16a2ad9735a14163/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-20556eb9f99993381c1e/environment/Dockerfile b/tasks/cedar_authorization-20556eb9f99993381c1e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-20556eb9f99993381c1e/instruction.md b/tasks/cedar_authorization-20556eb9f99993381c1e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..085aa2f9ba190a85c2d4bbab640e4ea4aad0cb88 --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/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 in [r::r::r::r::Action::"action"], + resource in r::r::r::r::P::"" +) when { + true && (principal in principal) && (principal in principal) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::P"},{"id":"","type":"r::r::r::r::_Y333333333333"}],"tags":{"":{"__entity":{"id":"","type":"r::r::r::r::A"}},"*********":{"__entity":{"id":"","type":"r::r::r::r::A"}}},"uid":{"id":"","type":"r::r::r::r::A"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::_Y333333333333"}],"uid":{"id":"","type":"r::r::r::r::P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::_Y333333333333"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r::r::A"},{"id":"","type":"r::r::r::r::_Y333333333333"},{"id":"","type":"r::r::r::r::P"}],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::w"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::A"},"request":"R1","resource":{"id":"","type":"r::r::r::r::_Y333333333333"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"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::P"}} +{"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-20556eb9f99993381c1e/solution/reference.json b/tasks/cedar_authorization-20556eb9f99993381c1e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/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-20556eb9f99993381c1e/solution/solve.sh b/tasks/cedar_authorization-20556eb9f99993381c1e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-20556eb9f99993381c1e/task.toml b/tasks/cedar_authorization-20556eb9f99993381c1e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a3d9196a3045895360420f06442e8495e7821aa9 --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-20556eb9f99993381c1e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "8ed72da36366b07f09e86777e67f34f2364d87aa57108da8eb2006eaa7fdcd35" + +[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-20556eb9f99993381c1e/tests/expected.json b/tasks/cedar_authorization-20556eb9f99993381c1e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..7ef4ac08555e695e52f523f8a35610a867a88da0 --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/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-20556eb9f99993381c1e/tests/grading.py b/tasks/cedar_authorization-20556eb9f99993381c1e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/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-20556eb9f99993381c1e/tests/test.sh b/tasks/cedar_authorization-20556eb9f99993381c1e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/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-20556eb9f99993381c1e/tests/verify.py b/tasks/cedar_authorization-20556eb9f99993381c1e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/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-20556eb9f99993381c1e/validation/openenv.json b/tasks/cedar_authorization-20556eb9f99993381c1e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-20556eb9f99993381c1e/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-20939271904288beafd6/environment/Dockerfile b/tasks/cedar_authorization-20939271904288beafd6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-20939271904288beafd6/instruction.md b/tasks/cedar_authorization-20939271904288beafd6/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f0590241caa2aa794cd456edd29f33bab9b56076 --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action, + resource +) when { + true +}; + +policy1 +forbid( + principal in r::r::r::r::wZ1g::"", + action == r::r::r::r::Action::"action", + resource in r::r::r::r::wZ1g::"" +) when { + true && ((if "||||||||||||~|" like "|*|*|*|*|*|*" then if false then "||||||||||||~|" else "||||||||||||~|" else if false then "||||||||||||~|" else "||||||||||||~|") like "|*|*|*|*|*|*") && ((if "||||||||||||~|" like "*||**|*|*|*|" then "||||||||||||~|" else "||||||||||||~|") like "*|*|*|*|*|*|") +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::g31000000"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::wZ1g"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"|","type":"r::r::r::r::r"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"LYY"},"request":"R1","resource":{"id":"","type":"LYY"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"(((((((((","type":"LYY"},"request":"R2","resource":{"id":"(((((((((","type":"LYY"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::wZ1g"},"request":"R3","resource":{"id":"","type":"r::r::r::r::wZ1g"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::wZ1g"},"request":"R4","resource":{"id":"","type":"r::r::r::r::wZ1g"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-20939271904288beafd6/solution/reference.json b/tasks/cedar_authorization-20939271904288beafd6/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/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-20939271904288beafd6/solution/solve.sh b/tasks/cedar_authorization-20939271904288beafd6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-20939271904288beafd6/task.toml b/tasks/cedar_authorization-20939271904288beafd6/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9d56a0d4164af41ef0c18233406cef7ff4f2d554 --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-20939271904288beafd6" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "6a70e9b8183a643bf84cc4dc487d31d4d66409d258cfd141fa565bbc311a2613" + +[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-20939271904288beafd6/tests/expected.json b/tasks/cedar_authorization-20939271904288beafd6/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..31ad2d3b721e54e96b98e715e7f651b4c9335ea3 --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/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-20939271904288beafd6/tests/grading.py b/tasks/cedar_authorization-20939271904288beafd6/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/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-20939271904288beafd6/tests/test.sh b/tasks/cedar_authorization-20939271904288beafd6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/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-20939271904288beafd6/tests/verify.py b/tasks/cedar_authorization-20939271904288beafd6/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/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-20939271904288beafd6/validation/openenv.json b/tasks/cedar_authorization-20939271904288beafd6/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-20939271904288beafd6/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-215434b593f130114c11/environment/Dockerfile b/tasks/cedar_authorization-215434b593f130114c11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-215434b593f130114c11/instruction.md b/tasks/cedar_authorization-215434b593f130114c11/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ddc7c5bc3078fa634bcdd43ac7f90fb4d2e6dca9 --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/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 r::r::r::r::j55555555::"", + action in [r::r::r::r::Action::"action"], + resource == r::r::r::r::j55555555::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cjr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::j55555555"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"tags":{"":{"__entity":{"id":"","type":"r::r::r::r::r"}}},"uid":{"id":"","type":"r::r::r::r::r333"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cjr9000rrrrEErr"}},{"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":"A5cjr9000rrrrEErr"},"request":"R1","resource":{"id":"`","type":"A5cjr9000rrrrEErr"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"`","type":"A5cjr9000rrrrEErr"},"request":"R2","resource":{"id":"","type":"r::r::r::r::j55555555"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","type":"A5cjr9000rrrrEErr"},"request":"R3","resource":{"id":"`","type":"A5cjr9000rrrrEErr"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::j55555555"},"request":"R4","resource":{"id":"","type":"r::r::r::r::j55555555"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-215434b593f130114c11/solution/reference.json b/tasks/cedar_authorization-215434b593f130114c11/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..93a7415544211bc62c788bff4057a9aa5ccc1ae3 --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/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-215434b593f130114c11/solution/solve.sh b/tasks/cedar_authorization-215434b593f130114c11/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-215434b593f130114c11/task.toml b/tasks/cedar_authorization-215434b593f130114c11/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..91f56e9cd1c33cd8285033436d0da15e39793890 --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-215434b593f130114c11" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "118c1e7a5eef622a5cb8f3d691c4320f85ef29890776a52569af7db0c2357e0d" + +[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-215434b593f130114c11/tests/expected.json b/tasks/cedar_authorization-215434b593f130114c11/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..93a7415544211bc62c788bff4057a9aa5ccc1ae3 --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/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-215434b593f130114c11/tests/grading.py b/tasks/cedar_authorization-215434b593f130114c11/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/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-215434b593f130114c11/tests/test.sh b/tasks/cedar_authorization-215434b593f130114c11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/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-215434b593f130114c11/tests/verify.py b/tasks/cedar_authorization-215434b593f130114c11/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/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-215434b593f130114c11/validation/openenv.json b/tasks/cedar_authorization-215434b593f130114c11/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-215434b593f130114c11/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-21785f67ed3b4fb10140/environment/Dockerfile b/tasks/cedar_authorization-21785f67ed3b4fb10140/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-21785f67ed3b4fb10140/instruction.md b/tasks/cedar_authorization-21785f67ed3b4fb10140/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2377fe9f88a57a0e57c54632ffcb6a78f09037b0 --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal == r::r::ERRRRRRRRRRRR::r::a::"", + action, + resource +) when { + true +}; + +policy1 +forbid( + principal in 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":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}}] + +Requests +{"action":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"}} +{"action":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::Action"},"context":{"r":"g"},"principal":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"},"request":"R2","resource":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R3","resource":{"id":"","type":"r::r::ERRRRRRRRRRRR::r::a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R4","resource":{"id":"","type":"a"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-21785f67ed3b4fb10140/solution/reference.json b/tasks/cedar_authorization-21785f67ed3b4fb10140/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/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-21785f67ed3b4fb10140/solution/solve.sh b/tasks/cedar_authorization-21785f67ed3b4fb10140/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-21785f67ed3b4fb10140/task.toml b/tasks/cedar_authorization-21785f67ed3b4fb10140/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4883b6d8a6c58ee7dcd1dccd1fbcfabf84e8642b --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-21785f67ed3b4fb10140" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "7e919996c888a22809985ad35224150ecf4102e744a82c1491f389fc5e42167b" + +[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-21785f67ed3b4fb10140/tests/expected.json b/tasks/cedar_authorization-21785f67ed3b4fb10140/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/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-21785f67ed3b4fb10140/tests/grading.py b/tasks/cedar_authorization-21785f67ed3b4fb10140/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/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-21785f67ed3b4fb10140/tests/test.sh b/tasks/cedar_authorization-21785f67ed3b4fb10140/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/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-21785f67ed3b4fb10140/tests/verify.py b/tasks/cedar_authorization-21785f67ed3b4fb10140/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/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-21785f67ed3b4fb10140/validation/openenv.json b/tasks/cedar_authorization-21785f67ed3b4fb10140/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-21785f67ed3b4fb10140/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-2235d73feac5d4e761ed/environment/Dockerfile b/tasks/cedar_authorization-2235d73feac5d4e761ed/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-2235d73feac5d4e761ed/instruction.md b/tasks/cedar_authorization-2235d73feac5d4e761ed/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..85fbae8676d8256e1a087305ac20e172a01e4d8d --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action in [Action::"",Action::""], + resource is a +) when { + true && (!(!(!false))) && (!(!(!false))) +}; + +policy1 +forbid( + principal == A::a::"", + action == A::Action::"action", + resource == A::a::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A::Action"}}] + +Requests +{"action":{"id":"","type":"Action"},"context":{"vi7Iwwww333333333":""},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"A::Action"},"context":{},"principal":{"id":"","type":"A::a"},"request":"R3","resource":{"id":"","type":"A::a"}} +{"action":{"id":"action","type":"A::Action"},"context":{"vi7Iwwww333333333":""},"principal":{"id":"","type":"A::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-2235d73feac5d4e761ed/solution/reference.json b/tasks/cedar_authorization-2235d73feac5d4e761ed/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..ffb2f051a7f9bd165f222e264638c800ced39987 --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2235d73feac5d4e761ed/solution/solve.sh b/tasks/cedar_authorization-2235d73feac5d4e761ed/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-2235d73feac5d4e761ed/task.toml b/tasks/cedar_authorization-2235d73feac5d4e761ed/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ebb4a04417814a17bb08a9b4304d0617bd86a6a0 --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-2235d73feac5d4e761ed" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0756abd83bb5776472f74201cf6dd3c98aa2aa7d32a30486e5c67d3a54c01fb2" + +[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-2235d73feac5d4e761ed/tests/expected.json b/tasks/cedar_authorization-2235d73feac5d4e761ed/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..ffb2f051a7f9bd165f222e264638c800ced39987 --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-2235d73feac5d4e761ed/tests/grading.py b/tasks/cedar_authorization-2235d73feac5d4e761ed/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/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-2235d73feac5d4e761ed/tests/test.sh b/tasks/cedar_authorization-2235d73feac5d4e761ed/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/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-2235d73feac5d4e761ed/tests/verify.py b/tasks/cedar_authorization-2235d73feac5d4e761ed/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/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-2235d73feac5d4e761ed/validation/openenv.json b/tasks/cedar_authorization-2235d73feac5d4e761ed/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-2235d73feac5d4e761ed/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-223648752314c32f9f2b/environment/Dockerfile b/tasks/cedar_authorization-223648752314c32f9f2b/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-223648752314c32f9f2b/instruction.md b/tasks/cedar_authorization-223648752314c32f9f2b/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b4f8f5881686009f6b68d4479cb78c5870e11d6d --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A100120000000040::A::B::a::"", + action == A100120000000040::A::B::Action::"action", + resource in A100120000000040::A::B::a::"" +) when { + true && (A100120000000040::A::B::a::"" in A100120000000040::A::B::a::"") && (A100120000000040::A::B::a::"" in A100120000000040::A::B::a::"") +}; + +policy1 +forbid( + principal == q::r::r::A333333333333z3::r::"", + action == q::r::r::A333333333333z3::Action::"", + resource == q::r::r::A333333333333z3::r::"" +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A100120000000040::A::B::a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A333333333333z3::A"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A333333333333z3::A00_______3333063"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A333333333333z3::Action"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"q::r::r::A333333333333z3::r"}},{"attrs":{},"parents":[{"id":"","type":"q::r::r::A333333333333z3::A"},{"id":"","type":"q::r::r::A333333333333z3::r"},{"id":"","type":"q::r::r::A333333333333z3::A00_______3333063"},{"id":">","type":"q::r::r::A333333333333z3::r33"},{"id":">>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>","type":"q::r::r::A333333333333z3::r33"}],"uid":{"id":"","type":"q::r::r::A333333333333z3::r33"}},{"attrs":{},"parents":[{"id":"","type":"q::r::r::A333333333333z3::r"},{"id":"","type":"q::r::r::A333333333333z3::A"},{"id":">>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>","type":"q::r::r::A333333333333z3::r33"},{"id":"","type":"q::r::r::A333333333333z3::A00_______3333063"}],"uid":{"id":">","type":"q::r::r::A333333333333z3::r33"}},{"attrs":{},"parents":[{"id":"","type":"q::r::r::A333333333333z3::r"},{"id":"","type":"q::r::r::A333333333333z3::A00_______3333063"}],"uid":{"id":">>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>","type":"q::r::r::A333333333333z3::r33"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"A100120000000040::A::B::Action"}},{"attrs":{},"parents":[],"uid":{"id":"~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::Action"}}] + +Requests +{"action":{"id":"action","type":"A100120000000040::A::B::Action"},"context":{},"principal":{"id":"","type":"A100120000000040::A::B::a"},"request":"R1","resource":{"id":"","type":"A100120000000040::A::B::a"}} +{"action":{"id":"~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>>>>>>>>>>>>>>>>>>>>~~~~~~~~~~~~~~~~~~~~~~~~~","type":"q::r::r::A333333333333z3::Action"},"context":{},"principal":{"id":"","type":"q::r::r::A333333333333z3::A"},"request":"R2","resource":{"id":"","type":"q::r::r::A333333333333z3::r"}} +{"action":{"id":"action","type":"A100120000000040::A::B::Action"},"context":{},"principal":{"id":"","type":"q::r::r::A333333333333z3::r"},"request":"R3","resource":{"id":"","type":"A100120000000040::A::B::a"}} +{"action":{"id":"","type":"q::r::r::A333333333333z3::Action"},"context":{},"principal":{"id":"","type":"q::r::r::A333333333333z3::r"},"request":"R4","resource":{"id":"","type":"q::r::r::A333333333333z3::r"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-223648752314c32f9f2b/solution/reference.json b/tasks/cedar_authorization-223648752314c32f9f2b/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/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-223648752314c32f9f2b/solution/solve.sh b/tasks/cedar_authorization-223648752314c32f9f2b/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-223648752314c32f9f2b/task.toml b/tasks/cedar_authorization-223648752314c32f9f2b/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a6eb5256b4c6b1a2ac7fa13d0b1365881e73ee49 --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-223648752314c32f9f2b" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "54a7b3f0b2568c3eaf4c419f4e850e5eb7731a7ba060b7086daf9d9f30601750" + +[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-223648752314c32f9f2b/tests/expected.json b/tasks/cedar_authorization-223648752314c32f9f2b/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7967ea3d94ac12d315d2a20577655af7504415 --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/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-223648752314c32f9f2b/tests/grading.py b/tasks/cedar_authorization-223648752314c32f9f2b/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/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-223648752314c32f9f2b/tests/test.sh b/tasks/cedar_authorization-223648752314c32f9f2b/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/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-223648752314c32f9f2b/tests/verify.py b/tasks/cedar_authorization-223648752314c32f9f2b/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/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-223648752314c32f9f2b/validation/openenv.json b/tasks/cedar_authorization-223648752314c32f9f2b/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-223648752314c32f9f2b/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-22979f9072f3bffda49e/environment/Dockerfile b/tasks/cedar_authorization-22979f9072f3bffda49e/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-22979f9072f3bffda49e/instruction.md b/tasks/cedar_authorization-22979f9072f3bffda49e/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..70d7b69d9b22cebae684bc79e7520b4536035b6f --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal, + action in [Action::"",Action::""], + resource is a +) when { + true && (!(!(!false))) && (!(!(!false))) +}; + +policy1 +forbid( + principal in 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":"","type":"Action"},"context":{},"principal":{"id":"","type":"iYYYYYY4Z44444444"},"request":"R1","resource":{"id":"","type":"a"}} +{"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":"a"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"iYYYYYY4Z44444444"},"request":"R4","resource":{"id":"","type":"iYYYYYY4Z44444444"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-22979f9072f3bffda49e/solution/reference.json b/tasks/cedar_authorization-22979f9072f3bffda49e/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..d3d473e0a7deae2956a2473d224ea927c3732496 --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-22979f9072f3bffda49e/solution/solve.sh b/tasks/cedar_authorization-22979f9072f3bffda49e/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-22979f9072f3bffda49e/task.toml b/tasks/cedar_authorization-22979f9072f3bffda49e/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ce04d60b0776250a5900fb9ee569bffbf9723a57 --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-22979f9072f3bffda49e" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "0ea535fbe8b6810f0e0c5119f8a64097e03276977fee0658dae4356d5ac7b773" + +[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-22979f9072f3bffda49e/tests/expected.json b/tasks/cedar_authorization-22979f9072f3bffda49e/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..d3d473e0a7deae2956a2473d224ea927c3732496 --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"allow","determining":["policy0"],"errors":[],"request":"R1"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R2"},{"decision":"deny","determining":[],"errors":[],"request":"R3"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-22979f9072f3bffda49e/tests/grading.py b/tasks/cedar_authorization-22979f9072f3bffda49e/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/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-22979f9072f3bffda49e/tests/test.sh b/tasks/cedar_authorization-22979f9072f3bffda49e/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/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-22979f9072f3bffda49e/tests/verify.py b/tasks/cedar_authorization-22979f9072f3bffda49e/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/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-22979f9072f3bffda49e/validation/openenv.json b/tasks/cedar_authorization-22979f9072f3bffda49e/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-22979f9072f3bffda49e/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-22ce1e490cd2fc2176db/environment/Dockerfile b/tasks/cedar_authorization-22ce1e490cd2fc2176db/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-22ce1e490cd2fc2176db/instruction.md b/tasks/cedar_authorization-22ce1e490cd2fc2176db/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9645c5bcbfe035dfbc667ed09b2ce4aee79807f8 --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in r::r::r3::r::WMMMMM::"", + action in [r::r::r3::r::Action::"action",r::r::r3::r::Action::"action"], + resource in r::r::r3::r::WMMMMM::"" +) when { + true && (if if "1" like "*3*1*3*10*" then {"": action} has n99999qqqqqq.dqQ0.dqqq else action in r::r::r3::r::jwwwwwwwwwwwwwwww::"" then {"": action}[""] in {"": action}[""] else {"": action}[""] in {"": action}[""]) && ({"": action}[""] in {"": action}[""]) +}; + +policy1 +forbid( + principal in a::"", + action, + resource +) when { + true +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[{"id":"","type":"r::r::r3::r::j3333j3335"}],"uid":{"id":"","type":"r::r::r3::r::WMMMMM"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::_YlW3333333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::j3333j3335"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::jwwwwwwwww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::jwwwwwwwwwwwwwwww"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r3::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r3::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3::r::_YlW3333333333"},"request":"R1","resource":{"id":"","type":"r::r::r3::r::jwwwwwwwww"}} +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3::r::WMMMMM"},"request":"R2","resource":{"id":"","type":"r::r::r3::r::WMMMMM"}} +{"action":{"id":"action","type":"r::r::r3::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r3::r::_YlW3333333333"},"request":"R3","resource":{"id":"","type":"r::r::r3::r::_YlW3333333333"}} +{"action":{"id":"action","type":"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-22ce1e490cd2fc2176db/solution/reference.json b/tasks/cedar_authorization-22ce1e490cd2fc2176db/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/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-22ce1e490cd2fc2176db/solution/solve.sh b/tasks/cedar_authorization-22ce1e490cd2fc2176db/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-22ce1e490cd2fc2176db/task.toml b/tasks/cedar_authorization-22ce1e490cd2fc2176db/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f10f1773fc6e2ea546fc7af6b983e19fffa3b7ed --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-22ce1e490cd2fc2176db" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "4e7080754dec1d27747feb037e5b8ebce56ac1e7726fb216ffb1c635808c40af" + +[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-22ce1e490cd2fc2176db/tests/expected.json b/tasks/cedar_authorization-22ce1e490cd2fc2176db/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2ec5d8a1b2ba9a3f43820e3175a8ebdc4210f5 --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/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-22ce1e490cd2fc2176db/tests/grading.py b/tasks/cedar_authorization-22ce1e490cd2fc2176db/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/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-22ce1e490cd2fc2176db/tests/test.sh b/tasks/cedar_authorization-22ce1e490cd2fc2176db/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/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-22ce1e490cd2fc2176db/tests/verify.py b/tasks/cedar_authorization-22ce1e490cd2fc2176db/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/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-22ce1e490cd2fc2176db/validation/openenv.json b/tasks/cedar_authorization-22ce1e490cd2fc2176db/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-22ce1e490cd2fc2176db/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-22dfe6329c68c3b9e4c5/environment/Dockerfile b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/instruction.md b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9357487fa8bbe4c2c353b605a965f0eb4ae58a27 --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/instruction.md @@ -0,0 +1,31 @@ +Review these authorization requests using Cedar semantics. Evaluate each independently against the same policies and entity snapshot. A matching forbid overrides all permits. With no matching permit the decision is deny. A policy whose evaluation errors is skipped. For an allow list all matching permits as determining; for an explicit deny list all matching forbids; for default deny use an empty list. Include all policy IDs that errored separately. The entity "in" operation includes the entity itself and transitive parents. No authorization schema is applied. +Return one JSON object with key "results". Its value is an array in request order. Each entry has "request" (the displayed ID), "decision" ("allow" or "deny"), "determining" (array of IDs), and "errors" (array of IDs). Sort each ID array lexicographically. + +policy0 +permit( + principal in A5cZr9000rrrrEErr::"`", + action == Action::"action", + resource in A5cZr9000rrrrEErr::"`" +) when { + true && ((-2712756478873001310) < (6510615555426900570 + (-940422246894996750) + duration("4971692651079231812ms").toMinutes())) && (A5cZr9000rrrrEErr::"`" in (if false then {"": action} else {"": principal})[""]) +}; + +policy1 +forbid( + principal in r::r::r::r::r::"", + action in [r::r::r::r::Action::"action",r::r::r::r::Action::"action"], + resource in r::r::r::r::r::"" +) when { + true && (if if if false then false else false then if false then false else false else if false then false else false then if if false then false else false then if false then false else false else if false then false else false else if if false then true else true then action in action else action in action) && ({"": action}[""] in {"": action}[""]) +}; + +Entities +[{"attrs":{},"parents":[],"uid":{"id":"","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::P"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::WMMMMM"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::_YlW3333333333"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"`","type":"A5cZr9000rrrrEErr"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R1","resource":{"id":"`","type":"A5cZr9000rrrrEErr"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"`","type":"A5cZr9000rrrrEErr"},"request":"R2","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::r"},"request":"R3","resource":{"id":"","type":"r::r::r::r::r"}} +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"`","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-22dfe6329c68c3b9e4c5/solution/reference.json b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/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-22dfe6329c68c3b9e4c5/solution/solve.sh b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/task.toml b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..64c76880c9519b11eec2404f3d8799f3933c17c3 --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-22dfe6329c68c3b9e4c5" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "84d0303608798c24759520232ec1891305201dd699b613eaf0f4ecde1902b4bb" + +[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-22dfe6329c68c3b9e4c5/tests/expected.json b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..a62d3d5114e6819c2f72e893876c63d74b8ff96f --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/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-22dfe6329c68c3b9e4c5/tests/grading.py b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/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-22dfe6329c68c3b9e4c5/tests/test.sh b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/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-22dfe6329c68c3b9e4c5/tests/verify.py b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/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-22dfe6329c68c3b9e4c5/validation/openenv.json b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-22dfe6329c68c3b9e4c5/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-248812b2e0090be4215c/environment/Dockerfile b/tasks/cedar_authorization-248812b2e0090be4215c/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46b074426c0d73363042c674c4f2fdd43708badd --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/environment/Dockerfile @@ -0,0 +1 @@ +FROM docker.io/library/python@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b diff --git a/tasks/cedar_authorization-248812b2e0090be4215c/instruction.md b/tasks/cedar_authorization-248812b2e0090be4215c/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1395e7f8538ffb80b3d8e63eabf8d76638fb236c --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/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 a::"", + action in [Action::"action",Action::"action"], + resource +) when { + true +}; + +Entities +[{"attrs":{"A0":"*******"},"parents":[],"tags":{"":[[[[]]]],"****":[[[]],[[],[[]]],[[[]]]]},"uid":{"id":"","type":"a"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::W"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::q"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::r"}},{"attrs":{},"parents":[],"uid":{"id":"","type":"r::r::r::r::u"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"Action"}},{"attrs":{},"parents":[],"uid":{"id":"action","type":"r::r::r::r::Action"}}] + +Requests +{"action":{"id":"action","type":"Action"},"context":{},"principal":{"id":"","type":"a"},"request":"R1","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"Action"},"context":{"r":false},"principal":{"id":"","type":"a"},"request":"R2","resource":{"id":"","type":"a"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{"r":false},"principal":{"id":"","type":"r::r::r::r::q"},"request":"R3","resource":{"id":"","type":"r::r::r::r::q"}} +{"action":{"id":"action","type":"r::r::r::r::Action"},"context":{},"principal":{"id":"","type":"r::r::r::r::u"},"request":"R4","resource":{"id":"","type":"r::r::r::r::u"}} + +Save your final JSON response to /tmp/answer.json. Harbor grades the contents of this file. diff --git a/tasks/cedar_authorization-248812b2e0090be4215c/solution/reference.json b/tasks/cedar_authorization-248812b2e0090be4215c/solution/reference.json new file mode 100644 index 0000000000000000000000000000000000000000..aa62584ade49d5763b142d30b1244f873a0bf8f3 --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/solution/reference.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-248812b2e0090be4215c/solution/solve.sh b/tasks/cedar_authorization-248812b2e0090be4215c/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ee8125cef44d657117e619e6be53dde779d8536 --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/solution/solve.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +cp /solution/reference.json /tmp/answer.json diff --git a/tasks/cedar_authorization-248812b2e0090be4215c/task.toml b/tasks/cedar_authorization-248812b2e0090be4215c/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1494061a3cbb552e1f844aa5d9c88a84242eec5d --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/task.toml @@ -0,0 +1,26 @@ +schema_version = "1.3" +artifacts = ["/tmp/answer.json"] + +[task] +name = "cyber-defense/cedar_authorization-248812b2e0090be4215c" + +[metadata.cyber_defense] +family = "cedar_authorization" +sealed_task_sha256 = "b22a4e3bf4109effce29151902fc41fa61f38a1d8e1eb8756a56389f17ef09d9" + +[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-248812b2e0090be4215c/tests/expected.json b/tasks/cedar_authorization-248812b2e0090be4215c/tests/expected.json new file mode 100644 index 0000000000000000000000000000000000000000..aa62584ade49d5763b142d30b1244f873a0bf8f3 --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/tests/expected.json @@ -0,0 +1 @@ +{"results":[{"decision":"deny","determining":["policy1"],"errors":[],"request":"R1"},{"decision":"deny","determining":["policy1"],"errors":[],"request":"R2"},{"decision":"allow","determining":["policy0"],"errors":[],"request":"R3"},{"decision":"deny","determining":[],"errors":[],"request":"R4"}]} diff --git a/tasks/cedar_authorization-248812b2e0090be4215c/tests/grading.py b/tasks/cedar_authorization-248812b2e0090be4215c/tests/grading.py new file mode 100644 index 0000000000000000000000000000000000000000..6136a1556176e69ea87283fd54b69d4efa2726d9 --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/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-248812b2e0090be4215c/tests/test.sh b/tasks/cedar_authorization-248812b2e0090be4215c/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..add2235bb37efb1dc59cd10564013e617b575563 --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/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-248812b2e0090be4215c/tests/verify.py b/tasks/cedar_authorization-248812b2e0090be4215c/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..05ee24bf3ef2f535fa535ea9b4e0989025098366 --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/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-248812b2e0090be4215c/validation/openenv.json b/tasks/cedar_authorization-248812b2e0090be4215c/validation/openenv.json new file mode 100644 index 0000000000000000000000000000000000000000..584762453550ce8ef3be3645957f3dc9c5181070 --- /dev/null +++ b/tasks/cedar_authorization-248812b2e0090be4215c/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"]}}