diff --git a/api/auth/center.go b/api/auth/center.go index 72fb7fea..dafa9c14 100644 --- a/api/auth/center.go +++ b/api/auth/center.go @@ -270,7 +270,9 @@ func (c *Center) checkFormData(r *http.Request) (*middleware.Box, error) { return nil, fmt.Errorf("failed to parse x-amz-date field: %w", err) } - addr, err := getAddress(submatches["access_key_id"]) + accessKeyID := submatches["access_key_id"] + + addr, err := getAddress(accessKeyID) if err != nil { return nil, err } @@ -290,7 +292,15 @@ func (c *Center) checkFormData(r *http.Request) (*middleware.Box, error) { reqSignature, signature) } - return &middleware.Box{AccessBox: box, Attributes: attrs}, nil + return &middleware.Box{ + AccessBox: box, + AuthHeaders: &middleware.AuthHeader{ + AccessKeyID: accessKeyID, + Region: region, + SignatureV4: signature, + }, + Attributes: attrs, + }, nil } func cloneRequest(r *http.Request, authHeader *AuthHeader) *http.Request { diff --git a/api/auth/center_test.go b/api/auth/center_test.go index e2feb732..d70ad6da 100644 --- a/api/auth/center_test.go +++ b/api/auth/center_test.go @@ -434,7 +434,7 @@ func TestAuthenticate(t *testing.T) { func TestHTTPPostAuthenticate(t *testing.T) { const ( - policyBase64 = "eyAiZXhwaXJhdGlvbiI6ICIyMDA3LTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICJjb25kaXRpb25zIjogWwogICAgeyJhY2wiOiAicHVibGljLXJlYWQiIH0sCiAgICB7ImJ1Y2tldCI6ICJqb2huc21pdGgiIH0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAidXNlci9lcmljLyJdLAogIF0KfQ==" + policyBase64 = "eyJleHBpcmF0aW9uIjogIjIwMjUtMTItMDFUMTI6MDA6MDAuMDAwWiIsImNvbmRpdGlvbnMiOiBbCiBbInN0YXJ0cy13aXRoIiwgIiR4LWFtei1jcmVkZW50aWFsIiwgIiJdLAogWyJzdGFydHMtd2l0aCIsICIkeC1hbXotZGF0ZSIsICIiXQpdfQ==" invalidValue = "invalid-value" defaultFieldName = "file" service = "s3" @@ -602,6 +602,7 @@ func TestHTTPPostAuthenticate(t *testing.T) { } else { require.NoError(t, err) require.Equal(t, secret.SecretKey, box.AccessBox.Gate.SecretKey) + require.Equal(t, accessKeyID, box.AuthHeaders.AccessKeyID) } }) }