Conversation
|
The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with |
3f18fbe to
fa8c486
Compare
| // CORS defines the CORS policy for AppSpecV3 | ||
| message CORS { | ||
| // AllowedOrigins specifies which origins are allowed to access the app. | ||
| repeated string AllowedOrigins = 1 [(gogoproto.jsontag) = "allowed_origins,omitempty"]; |
There was a problem hiding this comment.
Can we use the new proto style rules with names using snake case instead of camel?
There was a problem hiding this comment.
You mean like this? I'll make any recommended change to the naming conventions, just want to make sure I know what you mean
repeated string allowed_origins = 1 [(gogoproto.jsontag) = "allowed_origins,omitempty"];| } | ||
|
|
||
| // CORS defines the CORS policy for AppSpecV3 | ||
| message CORS { |
There was a problem hiding this comment.
Should we name it CORSSpec?
|
|
||
| // makeApplicationCORS converts a servicecfg.CORS to a types.CORS. | ||
| func makeApplicationCORS(c *servicecfg.CORS) *types.CORS { | ||
| if c == nil { |
There was a problem hiding this comment.
Does Teleport infers any default rules as of today or it forwards the CORS requests directly into the application?
There was a problem hiding this comment.
Currently any preflight requests are completely thrown out because they are unauthenticated. So no defaults. (technically its not "thrown out", its just redirected to the /web/launch route, but preflights cannot contain a redirect and anything other than a 2XX response counts as a fail anyway)
| foundApp := servers[0].GetApp() | ||
| corsPolicy := foundApp.GetCORS() | ||
| if corsPolicy == nil { | ||
| return |
There was a problem hiding this comment.
Given that we intercept every single cors request, won't this break existing apps without cors specified?
Should we mark it as breaking change?
There was a problem hiding this comment.
The wouldn't be a breaking change.
- Every prelight request is already "broken" so nothing would change
- its opt in, so only users who wanted CORS to work would have to explicitly set it.
|
🤖 Vercel preview here: https://docs-7bjd0wxeg-goteleport.vercel.app/docs/ver/preview |
9f31667 to
7fdc1f6
Compare
|
🤖 Vercel preview here: https://docs-4t2o3ogrr-goteleport.vercel.app/docs/ver/preview |
| // CORSSpec defines the CORS policy for AppSpecV3 | ||
| message CORSSpec { |
There was a problem hiding this comment.
Suggestoin: s/Spec/Policy to more accurately represent this type?
| // CORSSpec defines the CORS policy for AppSpecV3 | |
| message CORSSpec { | |
| // CORSPolicy defines the CORS policy for AppSpecV3 | |
| message CORSPolicy { |
|
|
||
| servers, err := app.Match(r.Context(), h.handler.cfg.AccessPoint, app.MatchPublicAddr(publicAddr)) | ||
| if err != nil { | ||
| h.handler.log.Error("failed to match application with public addr %s", publicAddr) |
There was a problem hiding this comment.
Is this truly an error? Or is this more information? In other words might it be expected that we don't find a match for all preflight requests?
There was a problem hiding this comment.
I suppose it wouldn't be an error error because the app itself would still function (granted, CORS wont work, but thats the same as now). I'll switch to info
| } | ||
|
|
||
| if len(servers) == 0 { | ||
| h.handler.log.Error("failed to match application with public addr %s", publicAddr) |
There was a problem hiding this comment.
Same question as above.
| foundApp := servers[0].GetApp() | ||
| corsPolicy := foundApp.GetCORS() | ||
| if corsPolicy == nil { |
There was a problem hiding this comment.
Is there any chance that we might have multiple matching apps, each with a slightly different CORS policy?
| return nil | ||
| } | ||
|
|
||
| return &types.CORSSpec{ |
There was a problem hiding this comment.
Do we need to sanitize any of this data? Does it matter if it contains a bunch of empty strings? Or a really long string? Is there any possibility that these values could be defined in such a way that it would prevent the preflight request from completing successfully?
There was a problem hiding this comment.
the max length of a custom header is dependent on web server but not defined in the web spec. Apache is 8kb for a single header length.
extra spaces or trailing spaces in the origins would cause the preflight to fail. should that be left to correct configuration or do we normally remove stuff like leading/trailing spaces elsewhere? perhaps note it in the docs? (which are coming after all this is approved). happy either way
|
🤖 Vercel preview here: https://docs-jrpum396p-goteleport.vercel.app/docs/ver/preview |
6dc1fcb to
4698e76
Compare
|
rebased onto master and cleaned up some of the |
|
🤖 Vercel preview here: https://docs-45jy80nki-goteleport.vercel.app/docs/ver/preview |
|
🤖 Vercel preview here: https://docs-o4echbhrf-goteleport.vercel.app/docs/ver/preview |
|
🤖 Vercel preview here: https://docs-6zpweudgt-goteleport.vercel.app/docs/ver/preview |
Requires: #45512 (not a hard requirement, but I'd like for it to go in after)
Part of: #17588
The purpose of this PR is to solve the CORS preflight request issue when an app makes a request to another app. The problem currently manifests because preflight requests sent by the browser do not include credentials, therefore Teleport throws the request out and does not forward to the destination app. The three solutions that came up when brainstorming this idea were
OPTIONSrequests that came in. This would have to be a pretty "open" CORS policy to respond to all preflights for X amount of apps enabled in the app service so it seemed really weak in terms of security and control.This PR implements option number 2. The main benefit here is that, unless a CORS policy is set in the app spec (after this change goes in), then nothing will change.
All of the CORS fields are optional so if a user only wants to set
Access-Control-Allow-Headers, that is possible.Example app spec
I've uploaded my repo that I used during testing to work through the required apps PR as well as this CORS pr. You can use it here if you'd like! https://github.com/avatus/corstest
TODO: add docs when we agree on the contents of the spec
changelog: You can now specify a CORS policy per application in the application config.