Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add compatibility with CEPH S3 #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

enguerr
Copy link

@enguerr enguerr commented Mar 9, 2025

permit alternative region
remove white space on authorization header compare

remove white space on authorization header compare
handler.go Outdated
@@ -225,9 +225,12 @@ func (h *Handler) buildUpstreamRequest(req *http.Request) (*http.Request, error)
return nil, err
}

//Sanitize fakeReq to remove some white spaces
fakeAuthorizationStr := strings.Replace(strings.Replace(fakeReq.Header["Authorization"][0],", Signature",",Signature",1),", SignedHeaders",",SignedHeaders",1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for improved readability: please split this into one replace operation per line of code

Also: please add tests to validate the new and old behaviour.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it 's a dirty workaround because s3cmd send the authorization header without this white spaces... s3cmd work's well with amazon s3. So, do you have any advice about the way to validate it in a test ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could compute a valid signature and then simply add/remove whitespace as you need to make s3cmd happy.

See https://github.com/Kriechi/aws-s3-reverse-proxy/blob/master/handler_test.go#L47 and https://github.com/Kriechi/aws-s3-reverse-proxy/blob/master/handler_test.go#L136 for reference.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay i will add some tests to validate this

@@ -17,7 +17,7 @@ import (
log "github.com/sirupsen/logrus"
)

var awsAuthorizationCredentialRegexp = regexp.MustCompile("Credential=([a-zA-Z0-9]+)/[0-9]+/([a-z]+-?[a-z]+-?[0-9]+)/s3/aws4_request")
var awsAuthorizationCredentialRegexp = regexp.MustCompile("Credential=([a-zA-Z0-9]+)/[0-9]+/([a-zA-Z-0-9]+)/s3/aws4_request")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a code comment with sample values for the new less-strict regex.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i will refactor this and add comments

add comments on less restrictive region regexp
add /health path on metrics httpserve
@enguerr
Copy link
Author

enguerr commented Mar 9, 2025

go test passed with s3cmd compatibility

handler_test.go Outdated
authorizationReq := req.Header.Get("Authorization");
authorizationReq = strings.Replace(authorizationReq,", Signature",",Signature",1)
authorizationReq = strings.Replace(authorizationReq,", SignedHeaders",",SignedHeaders",1)
req.Header.Set("Authorization",authorizationReq);
Copy link
Owner

@Kriechi Kriechi Mar 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run go fmt or similar. The whitespace around the commas inside a string and as function argument is confusing to read + also fix indentation.

main.go Outdated
@@ -136,6 +139,8 @@ func main() {
var wrappedHandler http.Handler = handler
if len(opts.MetricsListenAddr) > 0 && len(strings.Split(opts.MetricsListenAddr, ":")) == 2 {
metricsHandler := http.NewServeMux()
//add health on metrics http to serve k8s liveness
metricsHandler.HandleFunc("/health",health)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated changes - please send as separate PR - and address indentation + formatting.

refactor indentations
handler.go Outdated
fakeAuthorizationStr := fakeReq.Header.Get("Authorization")
// Sanitize fakeReq to remove white spaces before the comma signature
authorizationStr := strings.Replace(req.Header["Authorization"][0], ",Signature", ", Signature", 1)
// Sanitize fakeReq to remove white spaces before the comma signheaders
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment in the correct direction?
the strings.Replace function call is "adding" a space if it is missing. Or am I reading this wrong?

@enguerr
Copy link
Author

enguerr commented Mar 9, 2025 via email

@enguerr
Copy link
Author

enguerr commented Mar 17, 2025

@Kriechi Hi, if you have few minutes, can you review this PR ? i have some more feature depending on this one to propose ... in the next draft PR i 've rewrote this part to only check the signature part in order to allow presign url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants