{"record":{"id":"87bf6ca34228b26d","repo":"JuliusBrussee/caveman","slug":"runtime-policy-public-key-must-be-a-base64-encoded","errorCode":null,"errorMessage":"runtime_policy public_key must be a base64-encoded 32-byte Ed25519 key","messagePattern":"runtime_policy public_key must be a base64-encoded 32-byte Ed25519 key","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/sdk/python/caveman_cloud/core.py","lineNumber":2255,"sourceCode":"        kill_env: str = _POLICY_KILL_ENV,\n        workflow: str | None = None,\n    ) -> None:\n        self._cave = cave\n        self._workflow = workflow or cave.default_workflow\n        self._kill_env = kill_env\n        self._lock = threading.Lock()\n        self._bundle: dict[str, Any] | None = None\n        self._signed = False\n        self._killed_locally = False\n        # A pinned key makes a signature mandatory. An unparseable pin is a\n        # caller bug, not a runtime condition: it raises here rather than\n        # returning a client that silently rejects every bundle forever\n        # (mirrors the TypeScript constructor, which throws).\n        self._pinned_key: bytes | None = None\n        if public_key is not None:\n            decoded = self._decode_key(public_key)\n            if decoded is None:\n                raise ValueError(\"runtime_policy public_key must be a base64-encoded 32-byte Ed25519 key\")\n            self._pinned_key = decoded\n        self._stop = threading.Event()\n        self._thread: threading.Thread | None = None\n        interval = _policy_number(auto_refresh_seconds)\n        if interval is not None and interval > 0:\n            self._thread = threading.Thread(\n                target=self._auto_refresh,\n                args=(interval,),\n                name=\"caveman-runtime-policy\",\n                daemon=True,\n            )\n            self._thread.start()\n\n    # ── lifecycle ────────────────────────────────────────────────────────────\n\n    def kill(self) -> None:\n        \"\"\"Latch this client onto the baseline path immediately and locally.\n","sourceCodeStart":2237,"sourceCodeEnd":2273,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/sdk/python/caveman_cloud/core.py#L2237-L2273","documentation":"The runtime-policy bundle loader validates that the pinned public_key is a base64 string decoding to exactly 32 bytes (an Ed25519 public key). Anything else — wrong length, non-base64, empty string, raw bytes — raises ValueError in the constructor. This fails fast rather than constructing a client that would silently reject every signed bundle forever.","triggerScenarios":"Constructing the runtime-policy loader with public_key set to a non-base64 string, a base64 blob that is not 32 bytes after decoding, a key of the wrong algorithm, or bytes instead of a base64 str.","commonSituations":"Pasting an Ed448/X25519 key, truncating a key during copy-paste, base64url-encoding with unpadded variants the decoder rejects, or passing the raw DER/PEM instead of the 32-byte raw key.","solutions":["Supply the raw 32-byte Ed25519 public key, base64-encoded (standard base64)","Verify len(base64.b64decode(key)) == 32 before constructing","Re-export the key from the signing tool in raw format, not PEM/DER/hex","Check for copy-paste truncation or whitespace/newlines in the key string"],"exampleFix":"// before\nloader = RuntimePolicyLoader(public_key=\"MCowBQYDK2VwAyEA...\")  # PEM-ish, decodes to >32 bytes\n// after\nimport base64\nraw = base64.b64encode(ed25519_pub.to_bytes()).decode()  # exactly 32 bytes raw\nassert len(base64.b64decode(raw)) == 32\nloader = RuntimePolicyLoader(public_key=raw)","handlingStrategy":"validation","validationCode":"import base64, re\ndef valid_pinned_key(key: str) -> bool:\n    if not isinstance(key, str) or not re.fullmatch(r'[A-Za-z0-9+/]+={0,2}', key.strip()):\n        return False\n    try:\n        return len(base64.b64decode(key, validate=True)) == 32\n    except Exception:\n        return False","typeGuard":"def is_base64_ed25519_key(value: object) -> bool:\n    import base64\n    if not isinstance(value, str):\n        return False\n    try:\n        return len(base64.b64decode(value, validate=True)) == 32\n    except Exception:\n        return False","tryCatchPattern":"try:\n    loader = RuntimePolicyLoader(public_key=key)\nexcept ValueError as e:\n    raise ConfigError(f'bad runtime_policy public_key: {e}') from e","preventionTips":["Always export Ed25519 keys in raw 32-byte form, then base64-encode","Assert key length after decoding in config loading code","Strip whitespace and reject PEM/DER/hex forms explicitly in config validation","Unit-test the key loader with your production keys at deploy time"],"tags":["python","ed25519","base64","key-validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}