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 -cors.origin flag to "zed serve" #4334

Merged
merged 3 commits into from
Jan 26, 2023
Merged

add -cors.origin flag to "zed serve" #4334

merged 3 commits into from
Jan 26, 2023

Conversation

nwt
Copy link
Member

@nwt nwt commented Jan 25, 2023

The -cors.origin flag specifies a CORS allowed origin. The flag may be repeated.

This change removes the two baked-in allowed origins, *.observableusercontent.com and localhost, and replaces them with a default allowed origin of *. As a consequence, "zed serve" with no -cors.origin flag behaves like "zed serve -cors.origin '*'".

Closes #4297.

The -cors.origins flag accepts a comma-separated list of CORS allowed
origins.

Closes #4297.
@nwt nwt requested a review from a team January 25, 2023 19:42
@philrz
Copy link
Contributor

philrz commented Jan 25, 2023

I've tested out this branch at commit 990520e and confirmed that it does the trick for allowing connections from the Grafana data source proxy at origin http://localhost:3000. Therefore it's a functional 👍 from me!

@@ -53,6 +53,8 @@ func New(parent charm.Command, f *flag.FlagSet) (charm.Command, error) {
c.conf.Version = cli.Version
c.logflags.SetFlags(f)
f.IntVar(&c.brimfd, "brimfd", -1, "pipe read fd passed by brim to signal brim closure")
c.conf.CORSAllowedOrigins = []string{"*.observableusercontent.com", "localhost"}
f.Var((*cli.CommaStringsFlag)(&c.conf.CORSAllowedOrigins), "cors.origins", "comma-separated list of CORS allowed origins")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really like doing comma strings, can we rather just have the ability for the user to specify the flag multiple times? I know we did this somewhere...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, happy to make this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, this one:

    -I source file containing Zed query text (may be used multiple times)

Copy link
Member Author

Choose a reason for hiding this comment

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

@mattnibs: Done in 0ecdef6.

@nwt nwt changed the title add -cors.origins flag to "zed serve" add -cors.origin flag to "zed serve" Jan 26, 2023
@@ -30,9 +30,7 @@ func requestIDMiddleware() mux.MiddlewareFunc {
}
}

var allowedOrigins = []string{"*.observableusercontent.com", "localhost"}
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that I've removed these baked-in values!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, we need to make sure brim uses this new command argument to add these origins.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it'll work fine without them.

We will however need to add https://*.observableusercontent.com on cloud deployments to keep the Observable integration working.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh ok, good point.

@nwt nwt requested review from mattnibs and philrz January 26, 2023 14:33
@philrz
Copy link
Contributor

philrz commented Jan 26, 2023

I've re-tested this in the branch at commit 1452539 and it's still a functional 👍 for me. The removal of the baked-in values actually works great for my use case since it means that my target user won't even need to invoke the new option, though it's nice to have it there in case someone wants to lock down the service more tightly.

@nwt nwt merged commit 58606a0 into main Jan 26, 2023
@nwt nwt deleted the cors branch January 26, 2023 21:31
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.

"zed serve" flag to specify additional AllowedOrigins
3 participants