s3tables: improve principal extraction using identity context
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -141,14 +142,18 @@ func (h *S3TablesHandler) HandleRequest(w http.ResponseWriter, r *http.Request,
|
|||||||
// Principal/authorization helpers
|
// Principal/authorization helpers
|
||||||
|
|
||||||
func (h *S3TablesHandler) getPrincipalFromRequest(r *http.Request) string {
|
func (h *S3TablesHandler) getPrincipalFromRequest(r *http.Request) string {
|
||||||
// Extract principal from request headers
|
// Prioritize identity from context (set by IAM middleware)
|
||||||
// This can be extended to parse AWS credentials, client certificates, etc.
|
if identityName := s3_constants.GetIdentityNameFromContext(r); identityName != "" {
|
||||||
|
return identityName
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to request header (e.g., for testing or legacy clients)
|
||||||
principal := r.Header.Get("X-Amz-Principal")
|
principal := r.Header.Get("X-Amz-Principal")
|
||||||
if principal != "" {
|
if principal != "" {
|
||||||
return principal
|
return principal
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to account ID
|
// Default to account ID (owner)
|
||||||
return h.accountID
|
return h.accountID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user