Compare commits

...
Author SHA1 Message Date
Chris Lu 84ba1840d8 s3tables: let resource-policy denies veto the learn-absence answer
Review feedback: a caller whose only grant was an identity-level action could still learn absence under a resource-policy Deny, and authorizeAbsentResource evaluated the policy against the caller-supplied ARN, which accepts any account. Denies are now checked before the learn-absence fallback and the policy is evaluated against the canonical ARN.
2026-10-21 13:11:32 -07:00
Chris Lu 7ceaeea654 s3tables: cover the absent-target authorization answers 2026-10-21 13:00:18 -07:00
Chris Lu 559e29ec81 s3tables: judge absent tag targets at the bucket or identity level
TagResource, ListTagsForResource and UntagResource answered 404 for a missing table or bucket before the permission check, while a denied resource got 403. An absent target is now authorized against the bucket that owns the name; the caller hears not-found only with a grant.
2026-10-21 13:00:18 -07:00
Chris Lu 1937182b15 s3tables: check ListViews permission before revealing a missing namespace
Same read-before-authorize as ListTables: a missing namespace answered an empty 200 while a denied one got 403. loadAuthContext now tolerates an absent bucket or resource too.
2026-10-21 13:00:18 -07:00
Chris Lu 1bc823d74d s3tables: check ListTables permission before revealing a missing namespace or bucket
ListTables read the namespace and bucket first and answered an empty 200 for a missing name, while a denied existing one got 403. The reads are now tolerant of absent entries and the unchanged check decides; a caller that may learn absence still gets the empty list.
2026-10-21 13:00:18 -07:00
Chris Lu 6ed29f8c04 s3tables: authorize CreateNamespace before revealing a missing bucket
A bucket that is absent or not a table bucket used to answer 404 before the permission check ran, while a denied existing bucket answered 403. An unauthorized caller now gets the same denial unless it may learn the name is absent (admin, trusted handler, identity grant).
2026-10-21 13:00:18 -07:00
Chris Lu 295303fc1a s3tables: answer a bucket entry without metadata like a missing one
GetTableBucket and ListNamespaces returned 500 for a name held by a plain S3 bucket while a missing name returned 404, letting an unauthorized caller tell taken names apart from free ones. Both now take the same not-found path a denied bucket already takes.
2026-10-21 13:00:04 -07:00
8 changed files with 447 additions and 53 deletions

No files matched your search

+8
View File
@@ -262,6 +262,14 @@ func (h *S3TablesHandler) getExtendedAttribute(ctx context.Context, client filer
return data, nil
}
// absentEntry reports whether err means there is no usable catalog entry at
// the path: nothing is there, or what is there carries none of the attributes
// the operation keys on (a plain S3 bucket holding the name, a directory left
// without metadata).
func absentEntry(err error) bool {
return errors.Is(err, filer_pb.ErrNotFound) || errors.Is(err, ErrAttributeNotFound)
}
// loadNamespaceMetadata resolves a namespace to its metadata. A directory that
// carries no namespace metadata is not a namespace, so a missing attribute
// reports the same absence as a missing entry and every caller tests one
+14
View File
@@ -459,6 +459,20 @@ func isAuthError(err error) bool {
return errors.As(err, &authErr) || errors.Is(err, ErrAccessDenied)
}
// mayLearnAbsence reports whether the caller may be shown that an operation's
// target is absent rather than the operation's denial: the admin, a trusted
// handler, or a grant the request itself carries (an identity-level action
// grant, or the open default-allow context).
func (h *S3TablesHandler) mayLearnAbsence(r *http.Request, operation, bucketName string) bool {
if h.getAccountID(r) == s3_constants.AccountAdminId || h.defaultAllowFor(r) {
return true
}
return hasIdentityPermission(operation, &PolicyContext{
TableBucketName: bucketName,
IdentityActions: getIdentityActions(r),
})
}
func (h *S3TablesHandler) readTags(ctx context.Context, client filer_pb.SeaweedFilerClient, path string) (map[string]string, error) {
data, err := h.getExtendedAttribute(ctx, client, path, ExtendedKeyTags)
if err != nil {
@@ -0,0 +1,246 @@
package s3tables
import (
"context"
"encoding/json"
"fmt"
"net/http/httptest"
"testing"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables/s3tablestest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func runAbsentOp(t *testing.T, m *Manager, fs *s3tablestest.MemFiler, operation string, input interface{}, name string, actions []string) s3TablesHTTPError {
t.Helper()
body, err := json.Marshal(input)
require.NoError(t, err)
identity := &testIdentity{Name: name, Account: &testIdentityAccount{Id: name}, Actions: actions}
req, err := newManagerRequest(s3_constants.SetIdentityInContext(context.Background(), identity), operation, body, name)
require.NoError(t, err)
recorder := httptest.NewRecorder()
m.handler.HandleRequest(recorder, req, NewManagerClient(fs.Client))
result := recorder.Result()
defer result.Body.Close()
var response S3TablesError
if result.StatusCode >= 400 {
require.NoError(t, json.NewDecoder(result.Body).Decode(&response))
}
return s3TablesHTTPError{status: result.StatusCode, body: response}
}
func absentBucketARN(t *testing.T, name string) string {
t.Helper()
arn, err := BuildBucketARN(DefaultRegion, DefaultAccountID, name)
require.NoError(t, err)
return arn
}
func absentTableARN(t *testing.T, bucket, namespace, table string) string {
t.Helper()
arn, err := BuildTableARN(DefaultRegion, DefaultAccountID, bucket, namespace, table)
require.NoError(t, err)
return arn
}
// An outsider gets the operation's own denial for an absent name, a name a
// plain S3 bucket holds, and a name it is denied on, so none of them can be
// told apart.
func TestAbsentTargetsAnswerLikeDenials(t *testing.T) {
fs, m := startRenameManager(t)
m.SetTrusted(false)
m.SetDefaultAllow(false)
ghostARN := absentBucketARN(t, "ghostbkt")
plainARN := absentBucketARN(t, "plainbkt")
fs.Put(TablesPath, "plainbkt", nil) // a plain S3 bucket holds the name
outsider := []string{"Read"}
t.Run("ListTables", func(t *testing.T) {
for _, tc := range []struct {
name string
req *ListTablesRequest
}{
{"denied namespace", &ListTablesRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}}},
{"missing namespace", &ListTablesRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ghost"}}},
{"namespace in missing bucket", &ListTablesRequest{TableBucketARN: ghostARN, Namespace: []string{"ns"}}},
{"namespace in plain bucket", &ListTablesRequest{TableBucketARN: plainARN, Namespace: []string{"ns"}}},
{"denied bucket", &ListTablesRequest{TableBucketARN: mustBucketARN(t)}},
{"missing bucket", &ListTablesRequest{TableBucketARN: ghostARN}},
{"plain bucket", &ListTablesRequest{TableBucketARN: plainARN}},
} {
got := runAbsentOp(t, m, fs, "ListTables", tc.req, "attacker", outsider)
assert.Equal(t, 403, got.status, "%s: %s", tc.name, got.body.Message)
assert.Equal(t, ErrCodeAccessDenied, got.body.Type, tc.name)
}
})
t.Run("ListViews", func(t *testing.T) {
for _, tc := range []struct {
name string
req *ListViewsRequest
}{
{"denied namespace", &ListViewsRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}}},
{"missing namespace", &ListViewsRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ghost"}}},
{"missing bucket", &ListViewsRequest{TableBucketARN: ghostARN, Namespace: []string{"ns"}}},
{"plain bucket", &ListViewsRequest{TableBucketARN: plainARN, Namespace: []string{"ns"}}},
} {
got := runAbsentOp(t, m, fs, "ListViews", tc.req, "attacker", outsider)
assert.Equal(t, 403, got.status, "%s: %s", tc.name, got.body.Message)
assert.Equal(t, ErrCodeAccessDenied, got.body.Type, tc.name)
}
})
t.Run("CreateNamespace", func(t *testing.T) {
for _, tc := range []struct {
name string
arn string
}{
{"denied bucket", mustBucketARN(t)},
{"missing bucket", ghostARN},
{"plain bucket", plainARN},
} {
got := runAbsentOp(t, m, fs, "CreateNamespace", &CreateNamespaceRequest{TableBucketARN: tc.arn, Namespace: []string{"ns"}}, "attacker", outsider)
assert.Equal(t, 403, got.status, "%s: %s", tc.name, got.body.Message)
assert.Equal(t, ErrCodeAccessDenied, got.body.Type, tc.name)
}
})
t.Run("GetTableBucket and ListNamespaces", func(t *testing.T) {
for _, tc := range []struct {
name string
arn string
}{
{"denied bucket", mustBucketARN(t)},
{"missing bucket", ghostARN},
{"plain bucket", plainARN},
} {
for _, op := range []string{"GetTableBucket", "ListNamespaces"} {
var req interface{} = &GetTableBucketRequest{TableBucketARN: tc.arn}
if op == "ListNamespaces" {
req = &ListNamespacesRequest{TableBucketARN: tc.arn}
}
got := runAbsentOp(t, m, fs, op, req, "attacker", outsider)
assert.Equal(t, 404, got.status, "%s %s: %s", op, tc.name, got.body.Message)
assert.Equal(t, ErrCodeNoSuchBucket, got.body.Type, "%s %s", op, tc.name)
}
}
})
t.Run("tag operations", func(t *testing.T) {
missingTableARN := absentTableARN(t, renameTestBucket, "ns", "ghost")
deniedTableARN := absentTableARN(t, renameTestBucket, "ns", "t")
for _, tc := range []struct {
name string
op string
req interface{}
}{
{"TagResource denied table", "TagResource", &TagResourceRequest{ResourceARN: deniedTableARN, Tags: map[string]string{"k": "v"}}},
{"TagResource missing table", "TagResource", &TagResourceRequest{ResourceARN: missingTableARN, Tags: map[string]string{"k": "v"}}},
{"TagResource missing bucket", "TagResource", &TagResourceRequest{ResourceARN: ghostARN, Tags: map[string]string{"k": "v"}}},
{"ListTagsForResource denied table", "ListTagsForResource", &ListTagsForResourceRequest{ResourceARN: deniedTableARN}},
{"ListTagsForResource missing table", "ListTagsForResource", &ListTagsForResourceRequest{ResourceARN: missingTableARN}},
{"ListTagsForResource missing bucket", "ListTagsForResource", &ListTagsForResourceRequest{ResourceARN: ghostARN}},
{"UntagResource denied table", "UntagResource", &UntagResourceRequest{ResourceARN: deniedTableARN, TagKeys: []string{"k"}}},
{"UntagResource missing table", "UntagResource", &UntagResourceRequest{ResourceARN: missingTableARN, TagKeys: []string{"k"}}},
{"UntagResource missing bucket", "UntagResource", &UntagResourceRequest{ResourceARN: ghostARN, TagKeys: []string{"k"}}},
} {
got := runAbsentOp(t, m, fs, tc.op, tc.req, "attacker", outsider)
assert.Equal(t, 403, got.status, "%s: %s", tc.name, got.body.Message)
assert.Equal(t, ErrCodeAccessDenied, got.body.Type, tc.name)
}
})
}
// A caller the operation would have authorized — the bucket owner, a bucket-
// policy grantee, an identity-level grant, the admin or a trusted handler —
// may still be told the name is absent: the empty list or the not-found stays.
func TestGrantedCallersLearnAbsence(t *testing.T) {
fs, m := startRenameManager(t)
m.SetTrusted(false)
m.SetDefaultAllow(false)
ghostARN := absentBucketARN(t, "ghostbkt")
missingTableARN := absentTableARN(t, renameTestBucket, "ns", "ghost")
adminActions := []string{s3_constants.ACTION_ADMIN}
// The bucket owner, and a grantee the bucket policy names, learn absence.
bucketGrant := fmt.Sprintf(`{"Statement":[{"Effect":"Allow","Principal":"%s","Action":"s3tables:*","Resource":"*"}]}`, "grantee")
fs.Get(TablesPath, renameTestBucket).Extended[ExtendedKeyPolicy] = []byte(bucketGrant)
t.Run("bucket grant learns an absent namespace", func(t *testing.T) {
req := &ListTablesRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ghost"}}
for _, name := range []string{DefaultAccountID, "grantee"} {
got := runAbsentOp(t, m, fs, "ListTables", req, name, nil)
assert.Equal(t, 200, got.status, "%s", name)
}
// And on a namespace that exists they still see the table.
got := runAbsentOp(t, m, fs, "ListTables", &ListTablesRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}}, "grantee", nil)
assert.Equal(t, 200, got.status)
})
t.Run("identity grant learns an absent bucket", func(t *testing.T) {
got := runAbsentOp(t, m, fs, "ListTables", &ListTablesRequest{TableBucketARN: ghostARN}, "lister", []string{"s3tables:ListTables"})
assert.Equal(t, 200, got.status)
got = runAbsentOp(t, m, fs, "ListViews", &ListViewsRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ghost"}}, "lister", []string{"s3tables:ListViews"})
assert.Equal(t, 200, got.status)
})
t.Run("admin learns an absent bucket", func(t *testing.T) {
got := runAbsentOp(t, m, fs, "ListTables", &ListTablesRequest{TableBucketARN: ghostARN}, s3_constants.AccountAdminId, adminActions)
assert.Equal(t, 200, got.status)
got = runAbsentOp(t, m, fs, "CreateNamespace", &CreateNamespaceRequest{TableBucketARN: ghostARN, Namespace: []string{"ns"}}, s3_constants.AccountAdminId, adminActions)
assert.Equal(t, 404, got.status)
assert.Equal(t, ErrCodeNoSuchBucket, got.body.Type)
})
t.Run("tag operations answer 404 to granted callers", func(t *testing.T) {
got := runAbsentOp(t, m, fs, "TagResource", &TagResourceRequest{ResourceARN: missingTableARN, Tags: map[string]string{"k": "v"}}, "grantee", nil)
assert.Equal(t, 404, got.status, got.body.Message)
assert.Equal(t, ErrCodeNoSuchTable, got.body.Type)
got = runAbsentOp(t, m, fs, "ListTagsForResource", &ListTagsForResourceRequest{ResourceARN: missingTableARN}, DefaultAccountID, nil)
assert.Equal(t, 404, got.status)
got = runAbsentOp(t, m, fs, "UntagResource", &UntagResourceRequest{ResourceARN: missingTableARN, TagKeys: []string{"k"}}, s3_constants.AccountAdminId, adminActions)
assert.Equal(t, 404, got.status)
})
t.Run("a trusted handler still lists an absent namespace", func(t *testing.T) {
m.SetTrusted(true)
got := runAbsentOp(t, m, fs, "ListTables", &ListTablesRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ghost"}}, "svc", nil)
assert.Equal(t, 200, got.status)
})
}
// A bucket-policy Deny still vetoes the operation on an absent name: a denied
// caller must not trade the denial for a not-found or an empty list.
func TestAbsentResourceBucketDenyStillDenies(t *testing.T) {
fs, m := startRenameManager(t)
m.SetTrusted(false)
m.SetDefaultAllow(false)
deny := `{"Statement":[{"Effect":"Deny","Principal":"lister","Action":"s3tables:*","Resource":"*"}]}`
fs.Get(TablesPath, renameTestBucket).Extended[ExtendedKeyPolicy] = []byte(deny)
got := runAbsentOp(t, m, fs, "TagResource",
&TagResourceRequest{ResourceARN: absentTableARN(t, renameTestBucket, "ns", "ghost"), Tags: map[string]string{"k": "v"}},
"lister", []string{"s3tables:TagResource"})
assert.Equal(t, 403, got.status, got.body.Message)
assert.Equal(t, ErrCodeAccessDenied, got.body.Type)
for _, tc := range []struct {
op string
req interface{}
}{
{"ListTables", &ListTablesRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ghost"}}},
{"ListTables", &ListTablesRequest{TableBucketARN: mustBucketARN(t)}},
{"ListViews", &ListViewsRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ghost"}}},
} {
got := runAbsentOp(t, m, fs, tc.op, tc.req, "lister", []string{"s3tables:ListTables", "s3tables:ListViews"})
assert.Equal(t, 403, got.status, "%s: %s", tc.op, got.body.Message)
}
}
@@ -58,7 +58,7 @@ func (h *S3TablesHandler) handleGetTableBucket(w http.ResponseWriter, r *http.Re
})
if err != nil {
if errors.Is(err, filer_pb.ErrNotFound) {
if absentEntry(err) {
h.writeError(w, http.StatusNotFound, ErrCodeNoSuchBucket, fmt.Sprintf("table bucket %s not found", bucketName))
} else {
h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to get table bucket: %v", err))
+7 -1
View File
@@ -140,6 +140,12 @@ func (h *S3TablesHandler) handleCreateNamespace(w http.ResponseWriter, r *http.R
return ErrAccessDenied
}
if errors.Is(err, filer_pb.ErrNotFound) {
// An absent name and a denied one must read alike; the caller is
// told the bucket is missing only when it may learn that.
if !h.mayLearnAbsence(r, "CreateNamespace", bucketName) {
h.writeError(w, http.StatusForbidden, ErrCodeAccessDenied, "not authorized to create namespace in this bucket")
return ErrAccessDenied
}
h.writeError(w, http.StatusNotFound, ErrCodeNoSuchBucket, fmt.Sprintf("table bucket %s not found", bucketName))
} else {
h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to check table bucket: %v", err))
@@ -481,7 +487,7 @@ func (h *S3TablesHandler) handleListNamespaces(w http.ResponseWriter, r *http.Re
})
if err != nil {
if errors.Is(err, filer_pb.ErrNotFound) {
if absentEntry(err) {
h.writeError(w, http.StatusNotFound, ErrCodeNoSuchBucket, fmt.Sprintf("table bucket %s not found", bucketName))
} else {
h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to list namespaces: %v", err))
+86 -3
View File
@@ -659,7 +659,16 @@ func (h *S3TablesHandler) handleTagResource(w http.ResponseWriter, r *http.Reque
// Read metadata for ownership check
data, err := h.getExtendedAttribute(r.Context(), client, resourcePath, ExtendedKeyMetadata)
if err != nil {
return err
if !absentEntry(err) {
return err
}
ctx := &PolicyContext{RequestTags: req.Tags, TagKeys: requestTagKeys}
if rType == ResourceTypeTable {
if _, ctx.Namespace, ctx.TableName, err = parseTableFromARN(req.ResourceARN); err != nil {
return err
}
}
return h.authorizeAbsentResource(r, client, "TagResource", req.ResourceARN, resourcePath, "not authorized to tag resource", ctx)
}
ownerAccountID, bucketName, err := h.extractResourceOwnerAndBucket(data, resourcePath, rType)
@@ -793,7 +802,16 @@ func (h *S3TablesHandler) handleListTagsForResource(w http.ResponseWriter, r *ht
// Read metadata for ownership check
data, err := h.getExtendedAttribute(r.Context(), client, resourcePath, ExtendedKeyMetadata)
if err != nil {
return err
if !absentEntry(err) {
return err
}
ctx := &PolicyContext{}
if rType == ResourceTypeTable {
if _, ctx.Namespace, ctx.TableName, err = parseTableFromARN(req.ResourceARN); err != nil {
return err
}
}
return h.authorizeAbsentResource(r, client, "ListTagsForResource", req.ResourceARN, resourcePath, "not authorized to list tags for resource", ctx)
}
ownerAccountID, bucketName, err := h.extractResourceOwnerAndBucket(data, resourcePath, rType)
@@ -913,7 +931,16 @@ func (h *S3TablesHandler) handleUntagResource(w http.ResponseWriter, r *http.Req
// Read metadata for ownership check
data, err := h.getExtendedAttribute(r.Context(), client, resourcePath, ExtendedKeyMetadata)
if err != nil {
return err
if !absentEntry(err) {
return err
}
ctx := &PolicyContext{TagKeys: req.TagKeys}
if rType == ResourceTypeTable {
if _, ctx.Namespace, ctx.TableName, err = parseTableFromARN(req.ResourceARN); err != nil {
return err
}
}
return h.authorizeAbsentResource(r, client, "UntagResource", req.ResourceARN, resourcePath, "not authorized to untag resource", ctx)
}
ownerAccountID, bucketName, err := h.extractResourceOwnerAndBucket(data, resourcePath, rType)
@@ -1017,6 +1044,62 @@ func (h *S3TablesHandler) handleUntagResource(w http.ResponseWriter, r *http.Req
return nil
}
// authorizeAbsentResource answers a tag operation whose target carries no
// readable metadata. A caller holding a grant on the bucket that owns the
// name, or an identity-level or admin grant, is told the resource is absent;
// anyone else is refused with the operation's denial.
func (h *S3TablesHandler) authorizeAbsentResource(r *http.Request, client filer_pb.SeaweedFilerClient, operation, resourceARN, resourcePath, message string, ctx *PolicyContext) error {
parts := strings.Split(strings.Trim(resourcePath, "/"), "/")
if len(parts) < 2 {
return filer_pb.ErrNotFound
}
bucketName := parts[1]
bucketPath := GetTableBucketPath(bucketName)
ctx.TableBucketName = bucketName
var bucketMeta tableBucketMetadata
var bucketPolicy string
if data, err := h.getExtendedAttribute(r.Context(), client, bucketPath, ExtendedKeyMetadata); err == nil {
if err := json.Unmarshal(data, &bucketMeta); err != nil {
return fmt.Errorf("failed to unmarshal bucket metadata: %w", err)
}
} else if !absentEntry(err) {
return err
}
if policy, err := h.readPolicy(r, client, bucketPath); err == nil {
bucketPolicy = policy
} else if !absentEntry(err) {
return err
}
if tags, err := h.readTags(r.Context(), client, bucketPath); err == nil {
if tags != nil {
ctx.TableBucketTags = tags
}
} else if !absentEntry(err) {
return err
}
principal := h.getAccountID(r)
ctx.TrustedIssuers = h.trustedIssuers(r)
ctx.IsLocalAccountID = h.localAccountIDs
ctx.IdentityActions = getIdentityActions(r)
ctx.DefaultAllow = h.defaultAllowFor(r)
// Evaluate against the canonical ARN, not the request's: the ARN parser
// accepts any account, so a crafted ARN could otherwise dodge a Deny's
// resource match.
if ctx.TableName != "" {
resourceARN = h.generateTableARN(bucketMeta.OwnerAccountID, bucketName, ctx.Namespace+"/"+ctx.TableName)
} else {
resourceARN = h.generateTableBucketARN(bucketMeta.OwnerAccountID, bucketName)
}
if deniedByPolicy(operation, principal, bucketPolicy, resourceARN, ctx) ||
(!CheckPermissionWithContext(operation, principal, bucketMeta.OwnerAccountID, bucketPolicy, resourceARN, ctx) &&
!h.mayLearnAbsence(r, operation, bucketName)) {
return NewAuthError(operation, principal, message)
}
return filer_pb.ErrNotFound
}
// resolveResourcePath determines the resource path and extended attribute key from a resource ARN
func (h *S3TablesHandler) resolveResourcePath(resourceARN string) (path string, key string, rType ResourceType, err error) {
// Try parsing as table ARN first
+56 -38
View File
@@ -514,59 +514,69 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques
var namespacePolicy, bucketPolicy string
bucketTags := map[string]string{}
// Fetch namespace metadata and policy
// Fetch namespace metadata and policy; a missing or foreign entry
// leaves them empty and lets the check below answer.
data, err := h.getExtendedAttribute(r.Context(), client, namespacePath, ExtendedKeyMetadata)
if err != nil {
return err // Not Found handled by caller
}
if err := json.Unmarshal(data, &nsMeta); err != nil {
nsFound := err == nil
if nsFound {
if err := json.Unmarshal(data, &nsMeta); err != nil {
return err
}
policyData, err := h.getExtendedAttribute(r.Context(), client, namespacePath, ExtendedKeyPolicy)
if err == nil {
namespacePolicy = string(policyData)
} else if !errors.Is(err, ErrAttributeNotFound) {
return fmt.Errorf("failed to fetch namespace policy: %w", err)
}
} else if !absentEntry(err) {
return err
}
// Fetch namespace policy if it exists
policyData, err := h.getExtendedAttribute(r.Context(), client, namespacePath, ExtendedKeyPolicy)
if err == nil {
namespacePolicy = string(policyData)
} else if !errors.Is(err, ErrAttributeNotFound) {
return fmt.Errorf("failed to fetch namespace policy: %w", err)
}
// Fetch bucket metadata and policy
data, err = h.getExtendedAttribute(r.Context(), client, bucketPath, ExtendedKeyMetadata)
if err == nil {
if err := json.Unmarshal(data, &bucketMeta); err != nil {
return fmt.Errorf("failed to unmarshal bucket metadata: %w", err)
}
} else if !errors.Is(err, ErrAttributeNotFound) {
} else if !absentEntry(err) {
return fmt.Errorf("failed to fetch bucket metadata: %w", err)
}
policyData, err = h.getExtendedAttribute(r.Context(), client, bucketPath, ExtendedKeyPolicy)
policyData, err := h.getExtendedAttribute(r.Context(), client, bucketPath, ExtendedKeyPolicy)
if err == nil {
bucketPolicy = string(policyData)
} else if !errors.Is(err, ErrAttributeNotFound) {
} else if !absentEntry(err) {
return fmt.Errorf("failed to fetch bucket policy: %w", err)
}
if tags, err := h.readTags(r.Context(), client, bucketPath); err != nil {
return fmt.Errorf("failed to read bucket tags: %w", err)
if !absentEntry(err) {
return fmt.Errorf("failed to read bucket tags: %w", err)
}
} else if tags != nil {
bucketTags = tags
}
bucketARN := h.generateTableBucketARN(bucketMeta.OwnerAccountID, bucketName)
identityActions := getIdentityActions(r)
policyCtx := &PolicyContext{
TrustedIssuers: h.trustedIssuers(r),
IsLocalAccountID: h.localAccountIDs,
TableBucketName: bucketName,
Namespace: namespaceName,
TableBucketTags: bucketTags,
IdentityActions: identityActions,
DefaultAllow: h.defaultAllowFor(r),
}
if !CheckTableOrBucketPermission("ListTables", accountID,
nsMeta.OwnerAccountID, namespacePolicy, bucketARN,
bucketMeta.OwnerAccountID, bucketPolicy, bucketARN, &PolicyContext{
TrustedIssuers: h.trustedIssuers(r),
IsLocalAccountID: h.localAccountIDs,
TableBucketName: bucketName,
Namespace: namespaceName,
TableBucketTags: bucketTags,
IdentityActions: identityActions,
DefaultAllow: h.defaultAllowFor(r),
}) {
return ErrAccessDenied
bucketMeta.OwnerAccountID, bucketPolicy, bucketARN, policyCtx) {
// The target is absent: an empty list would reveal that, so
// only a caller that may learn absence proceeds to it, and a
// resource-policy Deny vetoes even that.
if nsFound || !h.mayLearnAbsence(r, "ListTables", bucketName) ||
deniedByPolicy("ListTables", accountID, bucketPolicy, bucketARN, policyCtx) {
return ErrAccessDenied
}
}
tables, paginationToken, err = h.listTablesInNamespaceWithClient(r, client, bucketName, namespaceName, req.Prefix, req.ContinuationToken, maxTables)
@@ -580,39 +590,47 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques
var bucketPolicy string
bucketTags := map[string]string{}
// Fetch bucket metadata and policy
// Fetch bucket metadata and policy; a missing or foreign entry
// leaves them empty and lets the check below answer.
data, err := h.getExtendedAttribute(r.Context(), client, bucketPath, ExtendedKeyMetadata)
if err != nil {
bucketFound := err == nil
if bucketFound {
if err := json.Unmarshal(data, &bucketMeta); err != nil {
return fmt.Errorf("failed to unmarshal bucket metadata: %w", err)
}
} else if !absentEntry(err) {
return fmt.Errorf("failed to fetch bucket metadata: %w", err)
}
if err := json.Unmarshal(data, &bucketMeta); err != nil {
return fmt.Errorf("failed to unmarshal bucket metadata: %w", err)
}
// Fetch bucket policy if it exists
policyData, err := h.getExtendedAttribute(r.Context(), client, bucketPath, ExtendedKeyPolicy)
if err == nil {
bucketPolicy = string(policyData)
} else if !errors.Is(err, ErrAttributeNotFound) {
} else if !absentEntry(err) {
return fmt.Errorf("failed to fetch bucket policy: %w", err)
}
if tags, err := h.readTags(r.Context(), client, bucketPath); err != nil {
return fmt.Errorf("failed to read bucket tags: %w", err)
if !absentEntry(err) {
return fmt.Errorf("failed to read bucket tags: %w", err)
}
} else if tags != nil {
bucketTags = tags
}
bucketARN := h.generateTableBucketARN(bucketMeta.OwnerAccountID, bucketName)
identityActions := getIdentityActions(r)
if !CheckPermissionWithContext("ListTables", accountID, bucketMeta.OwnerAccountID, bucketPolicy, bucketARN, &PolicyContext{
policyCtx := &PolicyContext{
TrustedIssuers: h.trustedIssuers(r),
IsLocalAccountID: h.localAccountIDs,
TableBucketName: bucketName,
TableBucketTags: bucketTags,
IdentityActions: identityActions,
DefaultAllow: h.defaultAllowFor(r),
}) {
return ErrAccessDenied
}
if !CheckPermissionWithContext("ListTables", accountID, bucketMeta.OwnerAccountID, bucketPolicy, bucketARN, policyCtx) {
if bucketFound || !h.mayLearnAbsence(r, "ListTables", bucketName) ||
deniedByPolicy("ListTables", accountID, bucketPolicy, bucketARN, policyCtx) {
return ErrAccessDenied
}
}
tables, paginationToken, err = h.listTablesInAllNamespaces(r, client, bucketName, req.Prefix, req.ContinuationToken, maxTables)
+29 -10
View File
@@ -278,10 +278,12 @@ func (h *S3TablesHandler) handleListViews(w http.ResponseWriter, r *http.Request
bucketPath := GetTableBucketPath(bucketName)
var nsMeta namespaceMetadata
data, err := h.getExtendedAttribute(r.Context(), client, namespacePath, ExtendedKeyMetadata)
if err != nil {
return err
}
if err := json.Unmarshal(data, &nsMeta); err != nil {
nsFound := err == nil
if nsFound {
if err := json.Unmarshal(data, &nsMeta); err != nil {
return err
}
} else if !absentEntry(err) {
return err
}
@@ -290,8 +292,23 @@ func (h *S3TablesHandler) handleListViews(w http.ResponseWriter, r *http.Request
return err
}
bucketARN := h.generateTableBucketARN(bucketMeta.OwnerAccountID, bucketName)
if !h.authorizeViewOp(r, "ListViews", h.getAccountID(r), nsMeta.OwnerAccountID, bucketMeta.OwnerAccountID, namespacePolicy, bucketPolicy, bucketARN, bucketName, namespaceName, "", bucketTags) {
return ErrAccessDenied
accountID := h.getAccountID(r)
if !h.authorizeViewOp(r, "ListViews", accountID, nsMeta.OwnerAccountID, bucketMeta.OwnerAccountID, namespacePolicy, bucketPolicy, bucketARN, bucketName, namespaceName, "", bucketTags) {
// An empty list would reveal the namespace is absent; only a
// caller that may learn absence proceeds to it, and a
// resource-policy Deny vetoes even that.
if nsFound || !h.mayLearnAbsence(r, "ListViews", bucketName) ||
deniedByPolicy("ListViews", accountID, bucketPolicy, bucketARN, &PolicyContext{
TrustedIssuers: h.trustedIssuers(r),
IsLocalAccountID: h.localAccountIDs,
TableBucketName: bucketName,
Namespace: namespaceName,
TableBucketTags: bucketTags,
IdentityActions: getIdentityActions(r),
DefaultAllow: h.defaultAllowFor(r),
}) {
return ErrAccessDenied
}
}
views, paginationToken, err = h.listViewsInNamespace(r, client, bucketName, namespaceName, req.Prefix, req.ContinuationToken, maxViews)
@@ -637,25 +654,27 @@ func (h *S3TablesHandler) loadAuthContext(r *http.Request, filerClient FilerClie
if e := json.Unmarshal(data, &bucketMetadata); e != nil {
return fmt.Errorf("failed to unmarshal bucket metadata: %w", e)
}
} else if !errors.Is(e, ErrAttributeNotFound) {
} else if !absentEntry(e) {
return fmt.Errorf("failed to fetch bucket metadata: %w", e)
}
policyData, e := h.getExtendedAttribute(r.Context(), client, resourcePath, ExtendedKeyPolicy)
if e == nil {
resourcePolicy = string(policyData)
} else if !errors.Is(e, ErrAttributeNotFound) {
} else if !absentEntry(e) {
return fmt.Errorf("failed to fetch resource policy: %w", e)
}
policyData, e = h.getExtendedAttribute(r.Context(), client, bucketPath, ExtendedKeyPolicy)
if e == nil {
bucketPolicy = string(policyData)
} else if !errors.Is(e, ErrAttributeNotFound) {
} else if !absentEntry(e) {
return fmt.Errorf("failed to fetch bucket policy: %w", e)
}
if tags, e := h.readTags(r.Context(), client, bucketPath); e != nil {
return e
if !absentEntry(e) {
return e
}
} else if tags != nil {
bucketTags = tags
}