-
Notifications
You must be signed in to change notification settings - Fork 23
add compatibility with CEPH S3 #10
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,12 @@ func verifySignature(w http.ResponseWriter, r *http.Request) { | |
signer.Sign(r, body, "s3", "eu-test-1", signTime) | ||
expectedAuthorization := r.Header["Authorization"][0] | ||
|
||
// WORKAROUND S3CMD who dont use white space before the comma in the authorization header | ||
// Sanitize fakeReq to remove white spaces before the comma signature | ||
receivedAuthorization = strings.Replace(receivedAuthorization,",Signature",", Signature",1) | ||
// Sanitize fakeReq to remove white spaces before the comma signheaders | ||
receivedAuthorization = strings.Replace(receivedAuthorization,",SignedHeaders",", SignedHeaders",1) | ||
|
||
// verify signature | ||
fmt.Fprintln(w, receivedAuthorization, expectedAuthorization) | ||
if receivedAuthorization == expectedAuthorization { | ||
|
@@ -143,6 +149,20 @@ func TestHandlerValidSignature(t *testing.T) { | |
assert.Equal(t, 200, resp.Code) | ||
assert.Contains(t, resp.Body.String(), "Hello, client") | ||
} | ||
func TestHandlerValidSignatureS3cmd(t *testing.T) { | ||
h := newTestProxy(t) | ||
|
||
req := httptest.NewRequest(http.MethodGet, "http://foobar.example.com", nil) | ||
signRequest(req) | ||
authorizationReq := req.Header.Get("Authorization"); | ||
authorizationReq = strings.Replace(authorizationReq,", Signature",",Signature",1) | ||
authorizationReq = strings.Replace(authorizationReq,", SignedHeaders",",SignedHeaders",1) | ||
req.Header.Set("Authorization",authorizationReq); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please run |
||
resp := httptest.NewRecorder() | ||
h.ServeHTTP(resp, req) | ||
assert.Equal(t, 200, resp.Code) | ||
assert.Contains(t, resp.Body.String(), "Hello, client") | ||
} | ||
|
||
func TestHandlerInvalidCredential(t *testing.T) { | ||
h := newTestProxy(t) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,10 @@ func NewAwsS3ReverseProxy(opts Options) (*Handler, error) { | |
} | ||
return handler, nil | ||
} | ||
|
||
//handle /health path | ||
func health(w http.ResponseWriter, req *http.Request){ | ||
fmt.Fprintf(w,"ok") | ||
} | ||
func main() { | ||
opts := NewOptions() | ||
handler, err := NewAwsS3ReverseProxy(opts) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated changes - please send as separate PR - and address indentation + formatting. |
||
metricsHandler.Handle("/metrics", promhttp.Handler()) | ||
|
||
log.Infof("Listening for secure Prometheus metrics on %s", opts.MetricsListenAddr) | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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