SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
s3tables: add table name validation and 404 propagation to policy handlers
Chris Luf83cef12598a
diff --git a/weed/s3api/s3tables/handler_policy.go b/weed/s3api/s3tables/handler_policy.goindex 516c979e60..254b9b4be3 100644--- a/weed/s3api/s3tables/handler_policy.go+++ b/weed/s3api/s3tables/handler_policy.go@@ -199,7 +199,12 @@ func (h *S3TablesHandler) handlePutTablePolicy(w http.ResponseWriter, r *http.Re}// Check if table exists- tablePath := getTablePath(bucketName, namespaceName, req.Name)+ tableName, err := validateTableName(req.Name)+ if err != nil {+ h.writeError(w, http.StatusBadRequest, ErrCodeInvalidRequest, err.Error())+ return err+ }+ tablePath := getTablePath(bucketName, namespaceName, tableName)err = filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {_, err := h.getExtendedAttribute(r.Context(), client, tablePath, ExtendedKeyMetadata)return err@@ -207,7 +212,7 @@ func (h *S3TablesHandler) handlePutTablePolicy(w http.ResponseWriter, r *http.Reif err != nil {if errors.Is(err, filer_pb.ErrNotFound) {- h.writeError(w, http.StatusNotFound, ErrCodeNoSuchTable, fmt.Sprintf("table %s not found", req.Name))+ h.writeError(w, http.StatusNotFound, ErrCodeNoSuchTable, fmt.Sprintf("table %s not found", tableName))} else {h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to check table: %v", err))}@@ -260,7 +265,12 @@ func (h *S3TablesHandler) handleGetTablePolicy(w http.ResponseWriter, r *http.Rereturn err}- tablePath := getTablePath(bucketName, namespaceName, req.Name)+ tableName, err := validateTableName(req.Name)+ if err != nil {+ h.writeError(w, http.StatusBadRequest, ErrCodeInvalidRequest, err.Error())+ return err+ }+ tablePath := getTablePath(bucketName, namespaceName, tableName)var policy []byteerr = filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {var readErr error@@ -317,7 +327,12 @@ func (h *S3TablesHandler) handleDeleteTablePolicy(w http.ResponseWriter, r *httpreturn err}- tablePath := getTablePath(bucketName, namespaceName, req.Name)+ tableName, err := validateTableName(req.Name)+ if err != nil {+ h.writeError(w, http.StatusBadRequest, ErrCodeInvalidRequest, err.Error())+ return err+ }+ tablePath := getTablePath(bucketName, namespaceName, tableName)err = filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {return h.deleteExtendedAttribute(r.Context(), client, tablePath, ExtendedKeyPolicy)})@@ -373,7 +388,11 @@ func (h *S3TablesHandler) handleTagResource(w http.ResponseWriter, r *http.Requereturn nil})if err != nil {- h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to read existing tags: %v", err))+ if errors.Is(err, filer_pb.ErrNotFound) {+ h.writeError(w, http.StatusNotFound, ErrCodeNoSuchBucket, "resource not found")+ } else {+ h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to read existing tags: %v", err))+ }return err}@@ -437,7 +456,11 @@ func (h *S3TablesHandler) handleListTagsForResource(w http.ResponseWriter, r *ht})if err != nil {- h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to list tags: %v", err))+ if errors.Is(err, filer_pb.ErrNotFound) {+ h.writeError(w, http.StatusNotFound, ErrCodeNoSuchBucket, "resource not found")+ } else {+ h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to list tags: %v", err))+ }return err}@@ -485,11 +508,23 @@ func (h *S3TablesHandler) handleUntagResource(w http.ResponseWriter, r *http.Reqerr = filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {data, err := h.getExtendedAttribute(r.Context(), client, resourcePath, extendedKey)if err != nil {- return nil+ if errors.Is(err, ErrAttributeNotFound) {+ return nil+ }+ return err}return json.Unmarshal(data, &tags)})+ if err != nil {+ if errors.Is(err, filer_pb.ErrNotFound) {+ h.writeError(w, http.StatusNotFound, ErrCodeNoSuchBucket, "resource not found")+ } else {+ h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, "failed to read existing tags")+ }+ return err+ }+// Remove specified tagsfor _, key := range req.TagKeys {delete(tags, key)