iceberg: answer vended credentials with Cache-Control: no-store (#13137)

A table or view load (and create) answered with `X-Iceberg-Access-Delegation: vended-credentials` carries live S3 session credentials in `config` and `storage-credentials`. The response sends `Vary: X-Iceberg-Access-Delegation` but no `Cache-Control`, so a shared HTTP cache in front of the catalog may store it and hand one caller's table-scoped session to another caller of the same URL that sends the same delegation header. The OAuth token endpoint already answers `Cache-Control: no-store` for the same reason (RFC 6749 §5.1).

`writeLoadResult` sets `Cache-Control: no-store` when the response holds credentials: a non-empty `storage-credentials`, or `s3.access-key-id` / `s3.secret-access-key` / `s3.session-token` in `config` (tables and views, values or pointers). Responses without credentials are unchanged.

`TestVendedLoadAnswerIsNoStore` (vended and not vended, table and view responses): red with the header removed. `go vet ./weed/s3api/iceberg/` and `go test -race ./weed/s3api/iceberg/` pass, and `weed` builds.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Javier de la TorreandClaude Opus 5.5 authored and GitHub committed 2026-11-30 11:36:25 -08:00
1 parent 3da9c41404
commit aa006fa228
2 files changed
+88 -1

No files matched your search

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/http/httptest"
"strings"
"testing"
"time"
)
@@ -176,3 +177,50 @@ func TestCredentialDurationHeaderReachesTheVendor(t *testing.T) {
}
}
}
// A load or view answer that carries vended credentials is never stored by a
// cache; one without them keeps its usual caching.
func TestVendedLoadAnswerIsNoStore(t *testing.T) {
for _, tc := range []struct {
name string
delegate bool
wantNoStore bool
}{
{"vended", true, true},
{"not vended", false, false},
} {
t.Run(tc.name, func(t *testing.T) {
vendor := &stubVendor{credentials: &VendedCredentials{
AccessKeyID: "ASIAEXAMPLE", SecretAccessKey: "secret", SessionToken: "token",
}}
s := vendingServer(vendor)
r := httptest.NewRequest("GET", "/v1/namespaces/ns/tables/t", nil)
if tc.delegate {
r.Header.Set(accessDelegationHeader, "vended-credentials")
}
config, storageCredentials := s.buildFileIOConfig(r, "s3://warehouse/ns/t", nil)
if tc.delegate && config["s3.session-token"] != "token" {
t.Fatalf("nothing vended: %v", config)
}
if !tc.delegate && config["s3.endpoint"] == "" {
t.Fatalf("no FileIO config built: %v", config)
}
table := LoadTableResult{Config: config, StorageCredentials: storageCredentials}
for _, result := range []interface{}{
table,
&table,
LoadTableResult{StorageCredentials: storageCredentials},
ViewResponse{Config: config},
} {
w := httptest.NewRecorder()
writeLoadResult(w, 200, result)
if got := w.Header().Get("Cache-Control") == "no-store"; got != tc.wantNoStore {
t.Errorf("%T: Cache-Control = %q, want no-store=%v", result, w.Header().Get("Cache-Control"), tc.wantNoStore)
}
if got := w.Header().Get("Vary"); !strings.Contains(got, accessDelegationHeader) {
t.Errorf("%T: Vary = %q, want it to name %q", result, got, accessDelegationHeader)
}
}
})
}
}
+40 -1
View File
@@ -145,12 +145,51 @@ func requestedCredentialDuration(r *http.Request) int64 {
// writeLoadResult writes a table or view load response. The FileIO config it
// carries depends on the delegation and the session lifetime the client asked
// for, so a cache between us and the client must key on those headers and not
// on the URL alone.
// on the URL alone. A response that carries vended credentials must not be
// stored by any cache at all (Cache-Control: no-store, as for the OAuth token
// response).
func writeLoadResult(w http.ResponseWriter, status int, v interface{}) {
w.Header().Set("Vary", accessDelegationHeader+", "+credentialDurationHeader)
if carriesCredentials(v) {
w.Header().Set("Cache-Control", "no-store")
}
writeJSON(w, status, v)
}
// carriesCredentials reports whether a load response holds vended
// credentials, in storage-credentials or in its FileIO config.
func carriesCredentials(v interface{}) bool {
var config iceberg.Properties
switch result := v.(type) {
case LoadTableResult:
if len(result.StorageCredentials) > 0 {
return true
}
config = result.Config
case *LoadTableResult:
if result == nil {
return false
}
if len(result.StorageCredentials) > 0 {
return true
}
config = result.Config
case ViewResponse:
config = result.Config
case *ViewResponse:
if result == nil {
return false
}
config = result.Config
}
for _, key := range []string{"s3.access-key-id", "s3.secret-access-key", "s3.session-token"} {
if config[key] != "" {
return true
}
}
return false
}
// writeJSON writes a JSON response.
func writeJSON(w http.ResponseWriter, status int, v interface{}) {
w.Header().Set("Content-Type", "application/json")