Repository navigation
feat: keep S3 credentials out of task pods - #3
Conversation
Three opt-in extensions for task pods without S3 credentials: - SetBound confines every task to a "<bucket>/<prefix>", e.g. its run's root, on top of what its request names. - SetLister answers a GET of a prefix URL below a DIRECTORY input with the keys there, so the filer can stage directory inputs. - TaskRoot returns a task's capability URL on any base URL, e.g. Conquest's in-cluster address. Without SetBound and SetLister the gateway behaves as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
internal/isolation holds what task pods need to reach their objects without S3 credentials: - Client, an objstore.Client over a task's storage gateway URL: it asks the gateway for a presigned URL per object, then reads or writes there; ListPrefix uses the gateway's listings. - RunBound, a storagegw.Bound that confines tasks to their run root. The integration test (build tag integration) stages a task in and out through the gateway against a real S3 server and checks that another run's objects can be neither read nor written, although the task request names them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Every task pod got the bucket-wide S3 credentials, readable by the user's executor, so any user could read and write every run's data. With CONQUEST_STORAGE_ISOLATION=true (chart: storageIsolation.enabled, default off), task pods get no S3 credentials and no S3 endpoint, only their storage gateway URL on Conquest's in-cluster address (CONQUEST_TASK_STORAGE_URL). Stage-in and stage-out go through it, and the gateway bounds every task to its run's root. The switch needs the gateway secret; the chart reuses or generates it. Runner pods still get the credentials (documented). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
A new job starts SeaweedFS (pinned by digest; MinIO publishes no images any more) with signature checks on and runs the isolation package's integration test against it. The CI gate needs it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
A key segment such as "..%2Fr2" decoded to "../r2", which the traversal check missed: a task whose request named s3://<bucket>/<own prefix>/../<other prefix>/x got that key presigned, and the new run bound, a prefix check, passed it too. Segments that contain "." or ".." after decoding are now refused with 400. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
- Build the task pods' env in named slices instead of nested appends. - Pick the gateway client in the exec wrapper without evaluating the manifest check twice; drop a redundant condition in main. - Test the client's error paths and the exec wrapper's client choice. - CI: time out the integration job and wait for S3 to answer 403. - Docs: the executor sees its task URL; CONQUEST_INTERNAL_BASE_URL must be right; the federation section links to isolation. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Listings are now reachable from task pods, so one task could make the API server collect and send arbitrarily long listings. Longer ones get 413. Docs now say that the run bound trusts the task's run ID, which the unauthenticated runner callback API and the public TES API's conquest_run_id tag take from the caller, and that changing the layout version needs drained runs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
With isolation every object operation of every task goes through the Conquest API pod, and task Jobs don't retry, so a restart or a 503 from S3 failed whole tasks; minio-go, used without isolation, retries. The client now retries connection errors and 429/5xx of either hop with backoff (about a minute), uploads only when the reader can seek back, and its transport times out silent servers after a minute. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Reviewer's GuideAPIExtend the storage gateway with task-root capability URLs, optional run bounds, and bounded directory listings, and enforce those checks before issuing presigned S3 redirects.
Uses of the APIWire the task storage capability into local Kubernetes jobs and select gateway-backed storage in the filer when isolation is enabled.
ImplementationBuild task-pod storage environment variables so isolated jobs receive only their per-task capability URL, while default jobs retain the existing S3 settings and credentials.
Implement the credential-free object-store client, its transient-failure retries, and the run-root bound used by the gateway.
Add Kubernetes job-spec tests for default credential injection and isolated jobs’ capability-only environment.
Add filer coverage showing stage-out uses the task gateway URL without S3 configuration.
Add unit coverage for capability access, run-bound enforcement, listings, traversal rejection, and client retries and errors.
Add gateway tests for task roots, bounds, directory listings, traversal handling, and listing caps.
Add real-S3 integration coverage for isolated stage-in and stage-out, cross-run denial, and capability expiry.
Add the SeaweedFS S3 configuration used by the storage integration test.
ConfigurationAdd the storage-isolation setting and validate that enabling it has a sufficiently long gateway secret and an S3 endpoint.
Configure the chart to enable isolation and provide or reuse the gateway signing secret without requiring the remote-endpoint gateway URL.
Require the real-S3 storage integration job in the CI completion gate.
Test isolation’s disabled default and its required configuration validation.
DocumentationDocument isolation behavior, its trust boundary and operational limits, and link it from the federation gateway guidance and configuration table.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Keep both integration jobs (PostgreSQL from #2, storage) and both README paragraphs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
There was a problem hiding this comment.
Hey - I've found 9 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="internal/storagegw/gateway.go" line_range="262" />
<code_context>
+ return nil, statusError("list", bucket, dir, resp)
+ }
+ var body struct {
+ Keys []string `json:"keys"`
+ }
+ if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
</code_context>
<issue_to_address>
**Listed keys escape staging directory**
When a listed S3 object key beneath a DIRECTORY input contains `..` path components that escape the input directory, `Gateway.list` returns S3 keys without checking their path components, and `StageIn` joins each key’s relative path to the input directory without confirming the result stays inside it. A key containing enough `..` components therefore writes outside the staging directory, potentially overwriting shared pod files such as `/tools/conquest` and breaking task staging or execution.
Reject keys with traversal components in the listing or verify each resolved staging path remains beneath the input directory before writing it.
</issue_to_address>
### Comment 2
<location path="cmd/conquest/main.go" line_range="494-495" />
<code_context>
+ // pods need; otherwise below, only for remote endpoints.
+ var gateway *storagegw.Gateway
+ var gatewayStore remote.Storage
+ if cfg.StorageIsolation {
+ gateway, gatewayStore, err = newStorageGateway(cfg, layout, taskStore, log)
+ if err != nil {
</code_context>
<issue_to_address>
**Remote tasks access other runs**
When federation exposes the storage gateway while `CONQUEST_STORAGE_ISOLATION` is off and a remote TES task requests another run’s objects, `gw.SetBound` runs only when `StorageIsolation` is true, so the gateway authorizes remote requests by task scope without checking the run prefix, letting the caller read or overwrite another run’s objects.
Apply the run-bound check whenever the gateway is exposed to federation, not only when storage isolation is enabled.
</issue_to_address>
### Comment 3
<location path="internal/backend/k8s/taskstorage.go" line_range="15" />
<code_context>
+// only the task's storage gateway URL and no credentials.
+func taskStorageEnv(task *domain.Task, cfg Config) (settings, credentials []corev1.EnvVar) {
+ if cfg.TaskStorageURL != nil {
+ return []corev1.EnvVar{{Name: isolation.EnvTaskStorageURL, Value: cfg.TaskStorageURL(task.TaskID)}}, nil
+ }
+ return []corev1.EnvVar{
</code_context>
<issue_to_address>
**Presigned writes outlive tasks**
When a task obtains a presigned URL shortly before it ends and uses it afterward, a task can exchange its capability URL for a presigned S3 URL while active, then use that URL after the task ends to overwrite an object in its run. The gateway’s active-task check blocks new redirects but cannot revoke URLs already issued; the default S3 URL expiry is 15 minutes, so completed run data can still change.
Use a substantially shorter presign expiry for task capabilities and account for already-issued URLs when defining when task storage access ends.
</issue_to_address>
### Comment 4
<location path="cmd/conquest/main.go" line_range="287" />
<code_context>
}
- gateway = gw
- tasks, err = routing.New(fedCfg, taskBackend, runStore, cfg.S3Bucket, storage, log)
+ fedStorage := gatewayStore
+ if cfg.StorageGatewayURL == "" {
+ fedStorage = nil // isolation only: no URLs remote endpoints can reach
</code_context>
<issue_to_address>
**Remote listings bypass isolation**
When a remote task uses `s3_url_style: gateway` with a directory input outside its run root or containing more than 100000 keys, `remote.translate` expands gateway-style directory inputs through `gatewayStorage.ListPrefix`, which calls the S3 lister directly without checking the task's run bound or enforcing `MaxListKeys`. It can enumerate keys outside the run and forward them to the remote endpoint, or materialize an oversized listing despite the advertised cap.
Make directory expansion enforce the task's run bound and listing limit before returning keys to the remote translation.
</issue_to_address>
### Comment 5
<location path="internal/storagegw/gateway.go" line_range="244" />
<code_context>
+ http.Error(w, "prefix not below the task's directory inputs", http.StatusForbidden)
+ return
+ }
+ keys, err := g.lister.ListPrefix(r.Context(), bucket, prefix)
+ if err != nil {
+ g.log.Error("storage gateway: listing failed", "task_id", taskID, "err", err)
</code_context>
<issue_to_address>
**Large listings exhaust gateway memory**
When a task lists a DIRECTORY input whose prefix contains a very large number of objects, `g.list` receives the entire result from `Lister.ListPrefix` before checking `MaxListKeys`; `S3Client.ListPrefix` accumulates every matching key in memory. A large directory therefore consumes unbounded listing time and memory before returning 413, potentially exhausting the API process.
Add a bounded listing operation that stops after the limit plus one key and use it in the gateway.
</issue_to_address>
### Comment 6
<location path="internal/isolation/client.go" line_range="41" />
<code_context>
+func NewClient(root string, hc *http.Client) *Client {
+ if hc == nil {
+ transport := http.DefaultTransport.(*http.Transport).Clone()
+ transport.ResponseHeaderTimeout = time.Minute
+ hc = &http.Client{Transport: transport}
+ }
</code_context>
<issue_to_address>
**Stalled transfers leave tasks stuck**
When the gateway or S3 endpoint stalls while transferring a request or response body, `ResponseHeaderTimeout` only limits waiting for response headers, and the client has no overall or transfer deadline; stalled stage-in or stage-out therefore remains blocked indefinitely and leaves the task stuck.
Give the client’s full request and response transfers an overall deadline or cancellation timeout.
</issue_to_address>
### Comment 7
<location path="internal/isolation/client.go" line_range="71" />
<code_context>
+ defer resp.Body.Close()
+ return nil, statusError("get", bucket, key, resp)
+ }
+ return resp.Body, nil
+}
+
</code_context>
<issue_to_address>
**Mid-download errors fail staging**
When a gateway or S3 connection drops after successful GET headers arrive but before the full object body is read, `Client.Get` returns the raw body after `Client.retry` finishes, so a later read error is not retried and stage-in fails on the transient disconnect.
Include reading the object body in the retry operation, reopening the GET when a body read fails.
</issue_to_address>
### Comment 8
<location path="cmd/conquest/main.go" line_range="238" />
<code_context>
HelperResources: helperResources,
}
+ if cfg.StorageIsolation {
+ backendCfg.TaskStorageURL = func(taskID string) string {
+ return gateway.TaskRoot(cfg.InternalBaseURL, taskID)
+ }
</code_context>
<issue_to_address>
**Tasks fail during rolling upgrades**
When an isolated task stages data while old and new API replicas are both serving the internal Service, the task URL points at the shared Conquest Service, but an older replica may not have the isolation gateway route. The client treats that replica’s 404 as final, so staging fails and the task exits instead of retrying.
Make rollout behavior keep the gateway route available on every serving replica before scheduling isolated tasks, or otherwise prevent isolated tasks from starting during incompatible version skew.
</issue_to_address>
### Comment 9
<location path="internal/backend/k8s/taskstorage_test.go" line_range="31" />
<code_context>
+ pod := job.Spec.Template.Spec
+ for _, c := range []corev1.Container{pod.InitContainers[1], pod.Containers[0]} {
+ env := storageEnvOf(c)
+ if env["AWS_SECRET_ACCESS_KEY"].ValueFrom == nil || env["CONQUEST_S3_ENDPOINT"].Value != "http://minio:9000" {
+ t.Errorf("%s: storage env = %v", c.Name, env)
+ }
</code_context>
<issue_to_address>
**Test misses access key ID**
When the default job spec omits `AWS_ACCESS_KEY_ID` but retains the secret-key reference, `TestBuildJobSpec_TaskPodsGetS3CredentialsByDefault` checks only the secret-key reference and endpoint, so the test passes without usable default S3 credentials.
Assert that the default job spec also provides `AWS_ACCESS_KEY_ID`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 9 findings to address first, and if the gateway’s scope or run-prefix checks are wrong, a task could read another run’s objects or write into them; exposed data and overwritten objects remain affected even after reverting. The documented caller-controlled run ID also means this boundary depends on callers of the task APIs being trusted.
Blocking findings: internal/storagegw/gateway.go:262, cmd/conquest/main.go:495, internal/backend/k8s/taskstorage.go:15, cmd/conquest/main.go:287, internal/storagegw/gateway.go:244, and 4 more
- Listings leave out keys with "." or ".." segments: they can't be served, and a filer joining them to a local path would write outside the input directory. - The client also retries the gateway's 404, which a replica without isolation answers during a rollout. - The default job spec test checks AWS_ACCESS_KEY_ID too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Summary
Keeps the bucket-wide S3 credentials out of task pods, so users can't read or write each other's run data (gi#18 design finding F4; D-405, D-414).
With
CONQUEST_STORAGE_ISOLATION=true(chart:storageIsolation.enabled, off by default, upstream behaviour unchanged):CONQUEST_TASK_STORAGE_URL=<internal base URL>/storage/v1/t/<task ID>/<HMAC>.internal/isolation.Client). The gateway answers with307to S3 URLs presigned per object and method, and lists keys belowDIRECTORYinputs (capped at 100000).s3://<bucket>/v1/workflow-runs/<run ID>/, even when its TES request names other objects...via%2F(e.g...%2Fother-run) were presigned. They now get400.Design (D-406: loosely coupled, upstream style)
internal/isolation: the client,RunBound, and the env name.internal/storagegw:SetBound,SetLister,TaskRoot.TaskStorageURLhook in the k8s job spec, a few lines of client choice in the filer, a config switch, and the main wiring.Limits (documented in README "Storage Isolation")
/internal/runs/<run ID>/...(design slice S1) and theconquest_run_idtag on the public TES API (slice S5). Isolation is therefore complete only once those are authenticated and owner-checked.s3://inputs outside the run root (e.g. shared reference data) are refused.CONQUEST_LAYOUT_VERSION.Closes elixir-cloud-aai/generic-issues#148
Verification
gofmt -s -l cmd internal: onlyinternal/backend/k8s/workspace.go, which is unformatted on master as well (local Go 1.25.5; CI usesstable).go vet ./...,go vet -tags integration ./...andgo build ./...pass.go test -race -count=1 ./...passes.internal/isolation/s3_integration_test.go:go test -tags integration -race ./internal/isolation/against SeaweedFS 4.52 with signature checks on. MinIO publishes no images any more: pulls from Docker Hub and quay.io are denied.storage-integrationruns the same test, and theCI passedgate needs it.helm template(alpine/helm 3.16.4) in three cases: isolation only (Secret andCONQUEST_STORAGE_ISOLATIONplusCONQUEST_STORAGE_GATEWAY_SECRET, no gateway URL), gateway only (unchanged), and isolation withexistingSecret(no Secret generated). The repo has no chart test in CI.Storage integration test,Integration tests,CI passed, image builds); push/publish/scan jobs skipped as on every PR. Branch merged with master after feat: record run owners #2 (run owners).Declined review findings
CONQUEST_TASK_STORAGE_URLwith isolation off (low): this affects only the user's own task, the same as settingCONQUEST_S3_ENDPOINTin executor env today. Stripping reserved env names is a separate change.objstore.Client.ListPrefix, an upstream interface change, and a task's run would first have to write millions of keys. Left as a follow-up.run(). The exec wrapper's client choice is now tested (internal/filer/isolation_test.go).Automated review
Sourcery raised 9 findings. I fixed 3 in 12fc28e: listings leave out keys with dot segments, the client retries the gateway's 404 during a rollout, and the default job spec test checks
AWS_ACCESS_KEY_ID. For the other 6 I answered with reasons in their threads and resolved them: remote bound with isolation off, presign expiry, remote listing expansion, listing memory, transfer deadline, and mid-download resume.Open questions
None for this PR. Follow-ups (runner credentials, callback and tag authentication) are listed in the issue.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5