-
Notifications
You must be signed in to change notification settings - Fork 948
feat: allow bypassing current CORS magic based on template config #18706
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
coderd/workspaceapps/proxy.go
Outdated
// If passthru behavior is set, disable our CORS header stripping. | ||
if cors.HasBehavior(r.Request.Context(), codersdk.CORSBehaviorPassthru) { | ||
fmt.Println("not modifying headers!!!") | ||
return nil | ||
} |
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.
Was this the main change to fix things?
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 on slack but for record keeping:
Yes, that and the owner client in apptest.go.
Without changing the owner client from sdk client to app client the template id was different in the test setup where we try to set the templates cors behaviour vs in the actual code path where we check the cors behaviour on a template. For tests that were using that owner client.
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
🚀 Deploying PR 18706 ... |
@@ -323,6 +324,37 @@ func (s *Server) workspaceAppsProxyPath(rw http.ResponseWriter, r *http.Request) | |||
s.proxyWorkspaceApp(rw, r, *token, chiPath, appurl.ApplicationURL{}) | |||
} | |||
|
|||
// determineCORSBehavior examines the given token and conditionally applies | |||
// CORS middleware if the token specifies that behavior. | |||
func (s *Server) determineCORSBehavior(token *SignedToken, app appurl.ApplicationURL) func(http.Handler) http.Handler { |
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 don't know all the details behind when a token is issued. For example, if user 1 has an app with a share level of authenticated (or same but shared port), how can user 2 access the app? We need the signed token to grab the CORS behaviour, but if the user just goes to the apps externally accessible URL, will the correct token be issued?
Solves #15096
This is a slight rework/refactor of the earlier PRs from @dannykopping and @Emyrk:
Rather than having a per-app CORS behaviour setting and additionally a template level setting for ports, this PR adds a single template level CORS behaviour setting that is then used by all apps/ports for workspaces created from that template.
The main changes are in
proxy.go
andrequest.go
to:a) get the CORS behaviour setting from the template
b) have
HandleSubdomain
bypass the CORS middleware handler if the selected behaviour ispassthru
c) in
proxyWorkspaceApp
, do not modify the response if the selected behaviour ispassthru