Handling Files
Starlark scripts move files through Remediation Orchestrator as small File references, not as
bytes. Modules stream contents only inside Temporal activities; never put file
contents into workflow history.
The File reference
A File is metadata (name, file_source, size) pointing at a registered
source. Do not construct, alter, or serialize a File yourself. Obtain it from
a module such as objectstore.get_file, http.file, or another file-producing
module, then pass it directly to a module that accepts a File.
File lifecycle guide for script authors
Treat a File as a lazy handle, not as bytes. Creating or receiving a
File in Starlark does not download, copy, or materialize content into the
workflow. The handle only names a source that a Temporal activity can open
later. Bytes cross process boundaries when an activity opens the source and
streams them — never when the Starlark workflow holds the reference.
Because of that, Starlark cannot modify file contents. Transforming,
filtering, appending, or rewriting a file must happen in Go inside a Temporal
activity (or a module API that already runs as one). From the script, obtain a
File, pass it to a consumer module, and keep only small metadata in the
workflow (object keys, sizes, status). Do not read content into strings, lists,
or dicts and do not try to edit a File in place.
Typical lifecycle:
- Produce a
Filefrom a module (http.file,objectstore.get_file, ticket attachments,archive, and similar). - Pass that reference through the workflow to another module. Temporal workflow history records the handle, not the payload.
- Consume it in an activity-backed API (
objectstore.upload_file,ssh.write_file, attach/upload helpers, parsers). The activity opens the source and streams bytes. - Return keys, sizes, and status summaries from the workflow — not file contents.
If you need a new transformation (for example, rewrite a log or convert a
format), implement it as a Go activity or module method that accepts and/or
returns File references. Do not attempt the rewrite in Starlark.
Ways to handle files
1. Object storage (objectstore)
Use the objectstore module to keep files in the Remediation Orchestrator deployment’s
configured object-storage bucket while passing a small File reference through
a Remediation Orchestrator workflow. This is the right boundary for command output, validation
artifacts, large logs, and binaries.
The Remediation Orchestrator operator enables and configures objectstore. A script can call it
only when that module is enabled for its deployment.
Detailed usage is covered below:
- Upload a file
- Download a file as a
Filereference - Share read access with a presigned URL
- Let an external client upload with a presigned POST
2. HTTP (http)
Use http when the bytes live at a URL or must be posted as multipart form
data. Prefer http.file / http.upload over http.get response bodies for
anything that may be large.
auth is the name of an OAuth2 client-credentials profile under
[modules.http.auth.<name>] in TOML (not a {secret:NAME} placeholder). See
Managing Secrets
for the profile configuration.
http.get / post / put / patch return a response body as a string. That
is fine for small JSON or status payloads; do not use it for logs, archives, or
binaries.
3. Host I/O (ssh)
Use ssh.write_file to place a File on a remote host over SFTP. Parent
directories are created as needed. The activity streams bytes from the File
source to the destination path.
Command helpers such as ssh.bash / ssh.execute return stdout and stderr as
strings. Keep those outputs small; persist large command output through
objectstore instead of returning it from the workflow.
4. Ticketing attachments
Ticket modules produce and consume File references so attachments never enter
workflow history as raw bytes.
Jira / Jira Service Management
5. Archives (archive)
Use archive to pack or unpack File references without loading archive bytes
into Starlark. Creation and extraction stream inside activities / file sources.
Upload a file
objectstore.upload_file(file, prefix) streams a File from its existing
source into object storage. It appends the file’s name to prefix and returns
the resulting object key.
For a File named results.json, this stores the object at
<objectstore_default_bucket>/validation/results/results.json. To select a
different allowed bucket, pass an s3:// path as the prefix:
The returned value is the object key, not a durable local path. Retain the
File reference when a downstream Remediation Orchestrator module needs to consume the file; it
lets that module stream the contents without loading them into workflow history.
To get a File again later, use objectstore.get_file(object_key).
Download a file as a File reference
objectstore.get_file(path) verifies that the object exists and returns a
File. It does not copy file bytes into the Starlark workflow. Pass the
returned reference to a module that accepts files.
objectstore.list(prefix) returns object keys under a prefix when a workflow
needs to find stored artifacts. It returns metadata only, not their contents.
Share read access with a presigned URL
objectstore.create_read_only_presigned_request(path, duration="1h") creates a
temporary GET request for one object. duration is a Go-style duration such as
"15m" or "2h"; it must be greater than zero and no longer than seven days.
register_workflow exposes this as a script entrypoint. An authorized client
starts it with POST /api/v1/script/<script>/share_report (or a
schedule); the workflow returns the
short-lived request details in its result. See Registering
entrypoints and Choose a
trigger.
The download client must use the returned HTTP method and include every value in
signed_header. Treat the URL and headers as short-lived bearer credentials;
return them only to an authorized caller and use the shortest practical
duration.
Let an external client upload with a presigned POST
objectstore.create_write_presigned_post(path, duration="1h") creates a
temporary multipart-form upload request. The supplied path determines the
object-key scope the storage provider allows. The returned fields are
provider-generated form fields and must be sent unchanged with the file.
register_workflow exposes this as a script entrypoint (POST /api/v1/script/<script>/request_artifact_upload, or a schedule). The workflow
returns the form URL and fields; an authorized upload client then posts the file
to object storage.
For example, that client sends a multipart/form-data POST to url, adds every
returned field as a form field, and adds the binary as the file form part.
Preserve the returned key field unless the provider’s returned policy
explicitly allows the client to change it; the signature is valid only for the
policy returned by Remediation Orchestrator.
ScreenTest dispatch contract
A ScreenTest validator declares its dispatch input and result-document handoff
with contract="dispatch".
The declaration is metadata on the validator; the dispatch message itself is
supplied separately through launch arguments:
- Input:
launch_args["dispatch_contract"]contains the dispatch JSON string. For schema 3.0.0, this is aTEST_INVOCATIONmessage containing the requested invocations, their targets, and criteria. - Output: the validator returns its usual verdict fields and a
result_recordFile referencing the framework’s result document. This is the result document to publish, rather than a new document built from the verdict summary.
For example, a 3.0.0 dispatch message requesting one test on one node is:
run_framework above represents the validator’s own framework adapter, which
executes the supplied dispatch message. Its document must be an existing
File, such as one returned by
objectstore.get_file(). Return the File object itself so its internal source
identifier survives the workflow result conversion. Keep the document’s bytes
out of workflow return values.
The declaration is stored with the validator entrypoint and is available on a
resolved validator as contract. Unknown contract values are rejected, and a
dispatch declaration requires the default all-or-nothing node locking.
Omitting the declaration preserves existing validator behavior; omitting the
optional result_record field preserves the existing result shape.
Declaring the dispatch_contract launch argument allows the validator to receive
the message; contract="dispatch" declares the input/output protocol it follows.
Spec-driven callers supply the message from their configured invocations.
The dispatch execution integration is responsible for checking that those
callers and validator declarations agree, validating the message, and enforcing
the result-document requirement. The shared-store configuration controls
publication; declaring a contract does not enable uploads.
The orchestration publishes result documents after recording the phase’s test verdicts. Publication failures preserve those verdicts. Canceling the run during result publication cancels the orchestration without changing the completed phase or its test results.
Rules for file handling
Do
- Use
Filereferences and object storage for logs, command output, archives, and binaries that may be large. - Keep workflow return values, activity arguments, and activity results to small metadata such as object keys, sizes, and status summaries.
- Use specific, workflow-scoped prefixes and the shortest practical presigned URL or POST lifetime.
- Pass a
Filedirectly between compatible modules when possible; it streams the contents at activity execution time. - When using
objectstore, record the object key returned byupload_file(and a concise summary) so operators can find the artifact without storing its contents in history.
Do not
- Do not return a log, binary, archive, or other file content from a workflow, or pass it as a string, list, or dict between module calls.
- Do not read a large file into a workflow merely to re-upload it. Use
upload_fileor pass the existingFilereference. - Do not put sensitive data in object keys, workflow arguments, return values, logs, or error messages.
- Do not expose presigned URLs, signed headers, or POST fields to unauthorized users, and do not use a longer lifetime than the handoff requires.
- Do not assume temporary workflow history can hold large artifacts. History has payload and event-size limits; large logs or binaries can exceed them and make a workflow fail or become difficult to replay.