JuliusBrussee/caveman · error · ValueError

runtime_policy public_key must be a base64-encoded 32-byte…

Error message

runtime_policy public_key must be a base64-encoded 32-byte Ed25519 key

What it means

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.

Solutions

  1. Supply the raw 32-byte Ed25519 public key, base64-encoded (standard base64)
  2. Verify len(base64.b64decode(key)) == 32 before constructing
  3. Re-export the key from the signing tool in raw format, not PEM/DER/hex
  4. Check for copy-paste truncation or whitespace/newlines in the key string

Example fix

// before
loader = RuntimePolicyLoader(public_key="MCowBQYDK2VwAyEA...")  # PEM-ish, decodes to >32 bytes
// after
import base64
raw = base64.b64encode(ed25519_pub.to_bytes()).decode()  # exactly 32 bytes raw
assert len(base64.b64decode(raw)) == 32
loader = RuntimePolicyLoader(public_key=raw)
Defensive patterns

Strategy: validation

Validate before calling

import base64, re
def valid_pinned_key(key: str) -> bool:
    if not isinstance(key, str) or not re.fullmatch(r'[A-Za-z0-9+/]+={0,2}', key.strip()):
        return False
    try:
        return len(base64.b64decode(key, validate=True)) == 32
    except Exception:
        return False

Type guard

def is_base64_ed25519_key(value: object) -> bool:
    import base64
    if not isinstance(value, str):
        return False
    try:
        return len(base64.b64decode(value, validate=True)) == 32
    except Exception:
        return False

Try / catch

try:
    loader = RuntimePolicyLoader(public_key=key)
except ValueError as e:
    raise ConfigError(f'bad runtime_policy public_key: {e}') from e

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/87bf6ca34228b26d. Report an issue: GitHub.

Appendix: source

Thrown at packages/sdk/python/caveman_cloud/core.py:2255

        kill_env: str = _POLICY_KILL_ENV,
        workflow: str | None = None,
    ) -> None:
        self._cave = cave
        self._workflow = workflow or cave.default_workflow
        self._kill_env = kill_env
        self._lock = threading.Lock()
        self._bundle: dict[str, Any] | None = None
        self._signed = False
        self._killed_locally = False
        # A pinned key makes a signature mandatory. An unparseable pin is a
        # caller bug, not a runtime condition: it raises here rather than
        # returning a client that silently rejects every bundle forever
        # (mirrors the TypeScript constructor, which throws).
        self._pinned_key: bytes | None = None
        if public_key is not None:
            decoded = self._decode_key(public_key)
            if decoded is None:
                raise ValueError("runtime_policy public_key must be a base64-encoded 32-byte Ed25519 key")
            self._pinned_key = decoded
        self._stop = threading.Event()
        self._thread: threading.Thread | None = None
        interval = _policy_number(auto_refresh_seconds)
        if interval is not None and interval > 0:
            self._thread = threading.Thread(
                target=self._auto_refresh,
                args=(interval,),
                name="caveman-runtime-policy",
                daemon=True,
            )
            self._thread.start()

    # ── lifecycle ────────────────────────────────────────────────────────────

    def kill(self) -> None:
        """Latch this client onto the baseline path immediately and locally.

View on GitHub (pinned to 3ee70a1026)