-
Notifications
You must be signed in to change notification settings - Fork 613
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
Set router skip clean to false #1844
Changes from all 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"family": "task-server-endpoint-validator", | ||
"taskRoleArn": "$$$TASK_ROLE$$$", | ||
"networkMode": "host", | ||
"containerDefinitions": [{ | ||
"image": "amazonlinux:2", | ||
"name": "task_server_endpoint_validator_container", | ||
"memory": 256, | ||
"command": ["sh", "-c", "curl -L -o /dev/null -s -w \"%{http_code}\n\" http://169.254.170.2/$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI | grep \"200\" && exit 42 || exit 1"] | ||
}] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,9 +56,9 @@ func taskServerSetup(credentialsManager credentials.Manager, | |
containerInstanceArn string) *http.Server { | ||
muxRouter := mux.NewRouter() | ||
|
||
// Set this so that for request like "/v3//metadata/task", the Agent will pass | ||
// it to task metadata handler instead of returning a 301 error. | ||
muxRouter.SkipClean(true) | ||
// Set this to false so that for request like "//v3//metadata/task" | ||
// to permanently redirect(301) to "/v3/metadata/task" handler | ||
muxRouter.SkipClean(false) | ||
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. Since this defaults to 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. I think a 301 redirect is more clear as it is not "becoming" the new url. it is a specific 301 redirect to the new url. let me know how you think 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. I see |
||
|
||
muxRouter.HandleFunc(v1.CredentialsPath, | ||
v1.CredentialsHandler(credentialsManager, auditLogger)) | ||
|
@@ -79,7 +79,7 @@ func taskServerSetup(credentialsManager credentials.Manager, | |
loggingMuxRouter.Handle(rootPath, tollbooth.LimitHandler( | ||
limiter, NewLoggingHandler(muxRouter))) | ||
|
||
loggingMuxRouter.SkipClean(true) | ||
loggingMuxRouter.SkipClean(false) | ||
|
||
server := http.Server{ | ||
Addr: ":" + strconv.Itoa(config.AgentCredentialsPort), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1052,6 +1052,34 @@ func TestV3ContainerAssociation(t *testing.T) { | |
assert.Equal(t, expectedAssociationResponse, string(res)) | ||
} | ||
|
||
func TestTaskHTTPEndpoint301Redirect(t *testing.T) { | ||
testPathsMap := map[string]string{ | ||
"http://127.0.0.1/v3///task/": "http://127.0.0.1/v3/task/", | ||
"http://127.0.0.1//v2/credentials/test": "http://127.0.0.1/v2/credentials/test", | ||
} | ||
|
||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
state := mock_dockerstate.NewMockTaskEngineState(ctrl) | ||
auditLog := mock_audit.NewMockAuditLogger(ctrl) | ||
statsEngine := mock_stats.NewMockEngine(ctrl) | ||
ecsClient := mock_api.NewMockECSClient(ctrl) | ||
|
||
server := taskServerSetup(credentials.NewManager(), auditLog, state, ecsClient, clusterName, statsEngine, | ||
config.DefaultTaskMetadataSteadyStateRate, config.DefaultTaskMetadataBurstRate, "", containerInstanceArn) | ||
|
||
for testPath, expectedPath := range testPathsMap { | ||
t.Run(fmt.Sprintf("Test path: %s", testPath), func(t *testing.T) { | ||
recorder := httptest.NewRecorder() | ||
req, _ := http.NewRequest("GET", testPath, nil) | ||
server.Handler.ServeHTTP(recorder, req) | ||
assert.Equal(t, http.StatusMovedPermanently, recorder.Code) | ||
assert.Equal(t, expectedPath, recorder.Header().Get("Location")) | ||
}) | ||
} | ||
} | ||
|
||
func TestTaskHTTPEndpointErrorCode404(t *testing.T) { | ||
testPaths := []string{ | ||
"/", | ||
|
@@ -1061,7 +1089,6 @@ func TestTaskHTTPEndpointErrorCode404(t *testing.T) { | |
"/v3/v3-endpoint-id/", | ||
"/v3/v3-endpoint-id/wrong-path", | ||
"/v3/v3-endpoint-id/task/", | ||
"/v3///task/", | ||
"/v3/v3-endpoint-id/task/stats/", | ||
"/v3/v3-endpoint-id/task/stats/wrong-path", | ||
"/v3/v3-endpoint-id/associtions-with-typo/elastic-inference/dev1", | ||
|
@@ -1101,11 +1128,11 @@ func TestTaskHTTPEndpointErrorCode400(t *testing.T) { | |
"/v3/wrong-v3-endpoint-id", | ||
"/v3/", | ||
"/v3/wrong-v3-endpoint-id/stats", | ||
"/v3//stats", | ||
"/v3/stats", | ||
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. Why was this changed? Shouldn't 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. we handle double/muti slash with a redirect prior to 1.20.3 release. at 1.21.0 release we changed the router and added the behavior to not clean double/multi slash. This is the root cause of this issue #1839. |
||
"/v3/wrong-v3-endpoint-id/task", | ||
"/v3//task", | ||
"/v3/task", | ||
"/v3/wrong-v3-endpoint-id/task/stats", | ||
"/v3//task/stats", | ||
"/v3/task/stats", | ||
"/v3/wrong-v3-endpoint-id/associations/elastic-inference", | ||
"/v3/wrong-v3-endpoint-id/associations/elastic-inference/dev1", | ||
} | ||
|
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.
Is there a particular reason you hand-wrote this code instead of using the simpletests package? I would recommend using that instead.
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.
I believe it is for setting the task iam roles configuration.
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.
Discussed with Sam offline, we might not need network mode setup for it to work.
But I'm thinking for now, let's keep test file as hand-written to release it today to solve our customers' issue. I will keep troubleshooting to see if I can make functional test work with simpletests file
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.
Task IAM roles are supported with "host", "bridge", and "awsvpc" network modes, and we have existing functional tests that validate this. There should not be a dependency on using the "host" network mode.
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.
Read some document, agree on this should not depend on host mode. I will dive deep to see if my host needs some config to make it functional test on other modes, and I will follow up with another pr to address it once i get it figured out.