Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit 59fb5db

Browse files
stevenjmpingles
authored andcommitted
Metadata server: Use 301 rather than 308 redirects (#173)
In 20b1c39, requests for the security-credentials URL were changed to redirect to security-credentials/ with a trailing slash. However, this uses http.StatusPermanentRedirect, which corresponds to a 308, whereas the real metadata API issues a 301 redirect (http.StatusMovedPermanently). Some clients do not handle the 308 correctly and fail to retrieve credentials. We've noticed broken behaviour in the Go sdk version 1.4.10, which is used by docker-machine.
1 parent e3ce9c8 commit 59fb5db

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pkg/aws/metadata/handler_role_name.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func trailingSlashSuffixRedirectHandler(rw http.ResponseWriter, req *http.Reques
4141
}
4242

4343
u.Path = fmt.Sprintf("%s/", u.Path)
44-
http.Redirect(rw, req, u.String(), http.StatusPermanentRedirect)
44+
http.Redirect(rw, req, u.String(), http.StatusMovedPermanently)
4545
}
4646

4747
func (h *roleHandler) Install(router *mux.Router) {

pkg/aws/metadata/handler_role_name_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestRedirectsToCanonicalPath(t *testing.T) {
2323

2424
router.ServeHTTP(rr, r)
2525

26-
if rr.Code != http.StatusPermanentRedirect {
26+
if rr.Code != http.StatusMovedPermanently {
2727
t.Error("expected redirect, was", rr.Code)
2828
}
2929
}

0 commit comments

Comments
 (0)