-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
vtgate : Disable Automatically setting immediateCallerID to user from static authentication context #12961
Conversation
…authentication Context Signed-off-by: Phani Raj <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
If a new flag is being introduced:
If a workflow is added or modified:
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
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.
Seems like a reasonable way to handle the issue.
@Phanatic plans to create an issue and link it (as required for all bug reports).
In addition to that, we need
- to have all the CI checks fixed
a PR to update website docs at https://github.com/vitessio/website/blob/prod/content/en/docs/17.0/reference/programs/vtgate.mdNo longer needed since there is no new flag
@frouioui when this is backported to release-16.0 do we need to add a summary release note for 16.0.2?
Changes looks fine. I need to understand a little bit more about how it is used.
|
@@ -95,8 +97,10 @@ func immediateCallerIDFromCert(ctx context.Context) (string, []string) { | |||
} | |||
|
|||
func immediateCallerID(ctx context.Context) (string, []string) { | |||
if immediate := servenv.StaticAuthUsernameFromContext(ctx); immediate != "" { | |||
return immediate, nil | |||
if useStaticAuthenticationIdentity { |
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.
It seems like this check is in the wrong place? Isn't it more a responsibility of the caller of immediateCallerID
?
We already have the useEffective
so shouldn't we make sure that if that value is set, we don't let immediate override it?
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 think if we go with an approach like the following, we can achieve the same result without needing another flag?
diff --git i/go/vt/vtgate/grpcvtgateservice/server.go w/go/vt/vtgate/grpcvtgateservice/server.go
index d012786d6e..a819730cb1 100644
--- i/go/vt/vtgate/grpcvtgateservice/server.go
+++ w/go/vt/vtgate/grpcvtgateservice/server.go
@@ -104,12 +104,15 @@ func immediateCallerID(ctx context.Context) (string, []string) {
// withCallerIDContext creates a context that extracts what we need
// from the incoming call and can be forwarded for use when talking to vttablet.
func withCallerIDContext(ctx context.Context, effectiveCallerID *vtrpcpb.CallerID) context.Context {
- immediate, securityGroups := immediateCallerID(ctx)
- if immediate == "" && useEffective && effectiveCallerID != nil {
+ var immediate string
+ var securityGroups []string
+ if useEffective && effectiveCallerID != nil {
immediate = effectiveCallerID.Principal
if useEffectiveGroups && len(effectiveCallerID.Groups) > 0 {
securityGroups = effectiveCallerID.Groups
}
+ } else {
+ immediate, securityGroups = immediateCallerID(ctx)
}
if immediate == "" {
immediate = unsecureClient
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.
fixed now, I just reverted the changes from the PR that introduced this behavior
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.
The changes @dbussink is suggesting above make sense to me. If the intention is for effective caller id to take precedence over other credentials, then that could be done explicitly. Just reverting the changes in #12050 would mean that a client connecting to vtgate using mTLS would still have their immediate caller id set from the client cert rather than the effective caller id.
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.
@brendar in your use case do you use mTLS and not want to use the client name from the cert?
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.
No, we use TLS (but not mTLS) + static auth to connect to vtgates. The precedence order doesn't matter to us since we're also not using grpc_use_effective_callerid
, but we'd like to be able to use grpc static auth usernames in table ACLs. That allows us to provide clients with a set of username/password credentials, and they can use those to connect to vtgate via mysql protocol or grpc as they choose.
To clarify what I mean by precedence order, before #12050 the immediate caller id would have been set from the first non-empty value from:
- The client cert common name (if using mTLS)
- The effective caller id (if
--grpc_use_effective_callerid=true
)
After #12050 the order would have been:
- The static auth username (if using static auth)
- The client cert common name (if using mTLS)
- The effective caller id (if
--grpc_use_effective_callerid=true
)
If the effective caller id should take precedence over other credentials, then perhaps the order should be something like this?
- The effective caller id (if
--grpc_use_effective_callerid=true
) - The static auth username (if using static auth)
- The client cert common name (if using mTLS)
Looking at the comment for grpc_use_effective_callerid though
"If set, and SSL is not used, will set the immediate caller id from the effective caller id's principal."
If we wanted to preserve that behavior, then perhaps the order should be:
- The client cert common name (if using mTLS)
- The effective caller id (if
--grpc_use_effective_callerid=true
) - The static auth username (if using static auth)
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.
@brendar We should also put static auth username
behind a flag something like mysql_use_static_auth_username
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.
Also, I think the last order makes sense as it is the least disruptive change in the way it works before the change in #12050
After reading the old PR #12050 and its description. This also means the previous change can be reverted. |
02df2f1
to
122ee97
Compare
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.
The changes look good.
This PR would need an updated PR title and description.
The client cert common name (if using mTLS) The effective caller id (if --grpc_use_effective_callerid=true) The static auth username (if --mysql_use_static_auth_username=true) Signed-off-by: Phani Raj <[email protected]>
58f7c23
to
73c9ac2
Compare
Signed-off-by: Phani Raj <[email protected]>
Signed-off-by: Phani Raj <[email protected]>
Signed-off-by: Phani Raj <[email protected]>
website PR is at vitessio/website#1454 |
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.
This solution looks good to me. Thanks for the opportunity to provide feedback, and apologies for the undesirable behavior.
…ID to user from static authentication context (#12961) (#12984) * Disables automatically setting immediateCallerID to User from Static authentication Context Signed-off-by: Phani Raj <[email protected]> * Set effectiveCallerID based on these rules The client cert common name (if using mTLS) The effective caller id (if --grpc_use_effective_callerid=true) The static auth username (if --mysql_use_static_auth_username=true) Signed-off-by: Phani Raj <[email protected]> * update vtgate help text fixture Signed-off-by: Phani Raj <[email protected]> * Add new test to vtgate_shard_heavy test run Signed-off-by: Phani Raj <[email protected]> * Run EffectiveCallerID tests in vtgate_general_heavy Signed-off-by: Phani Raj <[email protected]> * feat: use DialWithOpts in release-16.0 since Dial doesn't exist Signed-off-by: Manan Gupta <[email protected]> --------- Signed-off-by: Phani Raj <[email protected]> Signed-off-by: Manan Gupta <[email protected]> Co-authored-by: Phani Raj <[email protected]> Co-authored-by: Manan Gupta <[email protected]>
…mediateCallerID to user from static authentication context (vitessio#2027) * cherry pick of 12961 * fix merge conflicts --------- Co-authored-by: Phani Raj <[email protected]>
Description
Fixes #12970
This PR adds a new flag grpc-use-static-authentication-callerid to gate the behavior introduced in #12050
While I reviewed this PR, I didn't catch the issue where the username from static authentication context would completely override the immediate callerID for all
Execute
calls to vtgate.PlanetScale's usage of vtgate static auth and ACLs system is a bit unique in that we don't handle authentication for user queries in vtgate. We do that in our own query front-end service.
VTGate static authentication is configured for service-to-service authentication between the query front-end and vtgate, ACL system is configured to pass through user roles from our credential store to vtgate.
We do this by setting the effectiveCallerID on requests made to the vtgate gRPC service and having the same names reflected in the acl config file for a given vttablet.
With the change in the referenced PR, all ACL checks for a database will fail since it will use the static authentication username, and not the effectiveCallerID from the
ExecuteRequest
call.The precedence of assigning the immediate Caller ID is now :
The client cert common name (if using mTLS) The effective caller id (if --grpc_use_effective_callerid=true) The static auth username (if --grpc-use-static-authentication-callerid=true)
Checklist