-
Notifications
You must be signed in to change notification settings - Fork 57
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
first steps towards data-plane-gateway deprecation #1628
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8ebbe32
agent: add additional `data_planes` columns
jgraettinger ddb002b
agent: refator out Snapshot into a separate module
jgraettinger 2974df6
tables: add UserGrants and refine transitive role search
jgraettinger 244345a
agent: add `/authorize/user/task` and `/authorize/user/collection` ro…
jgraettinger 030133f
gazette: refactor Router to make clients cheap to clone
jgraettinger e912244
flowctl: refactor config and support new collection & task authorizat…
jgraettinger 7b659c6
go/network: refactored and updated connector networking feature
jgraettinger b1bbdde
go.mod/Tiltfile: update for grpc-web and connector networking
jgraettinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package network | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
|
||
pb "go.gazette.dev/core/broker/protocol" | ||
"google.golang.org/grpc/metadata" | ||
) | ||
|
||
// verifyAuthorization ensures the request has an authorization which | ||
// is valid for capability NETWORK_PROXY to `taskName`. | ||
func verifyAuthorization(req *http.Request, verifier pb.Verifier, taskName string) error { | ||
var bearer = req.Header.Get("authorization") | ||
if bearer != "" { | ||
// Pass. | ||
} else if cookie, err := req.Cookie(AuthCookieName); err == nil { | ||
bearer = fmt.Sprintf("Bearer %s", cookie.Value) | ||
} else { | ||
return errors.New("missing authorization") | ||
} | ||
|
||
var _, cancel, claims, err = verifier.Verify( | ||
metadata.NewIncomingContext( | ||
req.Context(), | ||
metadata.Pairs("authorization", bearer), | ||
), | ||
0, // TODO(johnny): Should be pf.Capability_NETWORK_PROXY. | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
cancel() // We don't use the returned context. | ||
|
||
/* TODO(johnny): Inspect claims once UI is updated to use /authorize/user/task API. | ||
if !claims.Selector.Matches(pb.MustLabelSet( | ||
labels.TaskName, taskName, | ||
)) { | ||
return fmt.Errorf("invalid authorization for task %s (%s)", taskName, bearer) | ||
} | ||
*/ | ||
_ = claims | ||
|
||
return nil | ||
} | ||
|
||
// startAuthRedirect redirect an interactive user to the dashboard, which will | ||
// obtain a user task authorization and redirect back to us with it. | ||
func startAuthRedirect(w http.ResponseWriter, req *http.Request, err error, dashboard *url.URL, taskName string) { | ||
var query = make(url.Values) | ||
query.Add("orig_url", "https://"+req.Host+req.URL.Path) | ||
query.Add("task", taskName) | ||
query.Add("prefix", taskName) | ||
query.Add("err", err.Error()) // Informational. | ||
|
||
var target = dashboard.JoinPath("/data-plane-auth-req") | ||
target.RawQuery = query.Encode() | ||
|
||
http.Redirect(w, req, target.String(), http.StatusTemporaryRedirect) | ||
} | ||
|
||
// completeAuthRedirect handles path "/auth-redirect" as part of a redirect chain | ||
// back from the dashboard. It expects a token parameter, which is set as a cookie, | ||
// and an original URL which it in-turn redirects to. | ||
func completeAuthRedirect(w http.ResponseWriter, req *http.Request) { | ||
var params = req.URL.Query() | ||
|
||
var token = params.Get("token") | ||
if token == "" { | ||
http.Error(w, "URL is missing required `token` parameter", http.StatusBadRequest) | ||
return | ||
} | ||
var origUrl = params.Get("orig_url") | ||
if origUrl == "" { | ||
http.Error(w, "URL is missing required `orig_url` parameter", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
var cookie = &http.Cookie{ | ||
Name: AuthCookieName, | ||
Value: token, | ||
Secure: true, | ||
HttpOnly: true, | ||
Path: "/", | ||
} | ||
http.SetCookie(w, cookie) | ||
|
||
http.Redirect(w, req, origUrl, http.StatusTemporaryRedirect) | ||
} | ||
|
||
func scrubProxyRequest(req *http.Request, public bool) { | ||
if _, ok := req.Header["User-Agent"]; !ok { | ||
req.Header.Set("User-Agent", "") // Omit auto-added User-Agent. | ||
} | ||
|
||
if public { | ||
return // All done. | ||
} | ||
|
||
// Scrub authentication token(s) from the request. | ||
req.Header.Del("Authorization") | ||
|
||
// There's no `DeleteCookie` function, so we parse them, delete them all, and | ||
// add them back in while filtering out the flow_auth cookie. | ||
var cookies = req.Cookies() | ||
req.Header.Del("Cookie") | ||
|
||
for _, cookie := range cookies { | ||
if cookie.Name != AuthCookieName { | ||
req.AddCookie(cookie) | ||
} | ||
} | ||
} | ||
|
||
// AuthCookieName is the name of the cookie that we use for passing the JWT for interactive logins. | ||
// It's name begins with '__Host-' in order to opt in to some additional security restrictions. | ||
// See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#cookie_prefixes | ||
const AuthCookieName = "__Host-flow_auth" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just to confirm my uderstanding is that we won't actually verify authZ at this stage, but it won't actually allow unauthorized access because this endpoint can't be reached in our current public data plane. So we'll need to update the UI to use the new authorize api, and then enforce authZ here before setting up any of the new private data planes. That sound right?
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.
Yep that's right