Skip to content

API Reference parrot.storage.artifact_signing

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.storage.artifact_signing

View source

Shared signing helpers for public infographic artifact URLs (FEAT-197).

The public HTML serving route GET /api/v1/artifacts/public/{signature}/{artifact_id}.html authorises requests with an HMAC signature instead of a session, so the frontend can embed a frozen infographic in an <iframe> without an auth round-trip.

This module is the single source of truth for that signature scheme so that both producers (the core InfographicToolkit that mints the URL when it persists an artifact) and consumers (the server-side ArtifactPublicHTMLView that verifies it) agree byte-for-byte.

Signature format::

{expiry}.{hmac_sha256_base64url}

where hmac_sha256_base64url = HMAC-SHA256(key=INFOGRAPHIC_SIGNING_KEY, msg='{artifact_id}|{expiry}') base64url-encoded without padding and expiry is an absolute UNIX timestamp (seconds).

Function build_public_html_url

Build a signed, relative public-HTML URL for an infographic artifact.

The result targets the server's ArtifactPublicHTMLView which streams rendered HTML from Artifact.definition.html — unlike the S3 presigned URL produced by ArtifactStore.get_public_url (which points at the raw overflow JSON object, not servable HTML).

Scope query params (user_id / agent_id / session_id) are appended when provided so that scope-partitioned backends (e.g. the local filesystem store, whose objects live under USER#…/AGENT#…/THREAD#…) can locate the artifact without session context. They are NOT covered by the signature; on backends that support global lookup by artifact_id they can be omitted to avoid leaking scope into the URL.

build_public_html_url(artifact_id: str, *, user_id: str | None = None, agent_id: str | None = None, session_id: str | None = None, expiry_seconds: int | None = None, key: bytes | None = None) -> str

Parameter Type Default Description
artifact_id str Artifact identifier.
user_id str | None None Owning user (storage scope).
agent_id str | None None Producing agent (storage scope).
session_id str | None None Owning session/thread (storage scope).
expiry_seconds int | None None URL validity window; defaults to INFOGRAPHIC_URL_EXPIRY_SECONDS (7 days).
key bytes | None None Override signing key (defaults to get_signing_key()).

Returns: str — A relative URL string, e.g. /api/v1/artifacts/public/1717100000.AbCd/infographic-x.html?....

Function get_signing_key

Read INFOGRAPHIC_SIGNING_KEY from the environment.

get_signing_key() -> bytes

Returns: bytes — The configured key as bytes, or a deterministic insecure fallback when the variable is unset (development only).

Function sign_artifact

Compute the base64url HMAC digest over '{artifact_id}|{expiry}'.

sign_artifact(artifact_id: str, expiry: int, key: bytes) -> str

Parameter Type Default Description
artifact_id str Artifact identifier being signed.
expiry int Absolute UNIX expiry timestamp (seconds).
key bytes HMAC secret key.

Returns: str — base64url-encoded digest without = padding.

Function verify_signature

Verify a {expiry}.{sig} signature segment.

verify_signature(artifact_id: str, signature_segment: str, key: bytes) -> bool

Parameter Type Default Description
artifact_id str Artifact identifier the signature should authorise.
signature_segment str The {expiry}.{hmac} path segment.
key bytes HMAC secret key.

Returns: bool — True when the signature is valid AND the expiry is in the future.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally