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

vtgate : Disable Automatically setting immediateCallerID to user from static authentication context #12961

Merged
merged 5 commits into from
Apr 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <phani@planetscale.com>
  • Loading branch information
Phani Raj committed Apr 26, 2023
commit 73c9ac234598c66e14c630403814ba4b7693defe
24 changes: 17 additions & 7 deletions go/vt/vtgate/grpcvtgateservice/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,35 @@ func immediateCallerIDFromCert(ctx context.Context) (string, []string) {
return cert.Subject.CommonName, cert.DNSNames
}

func immediateCallerID(ctx context.Context) (string, []string) {
if useStaticAuthenticationIdentity {
if immediate := servenv.StaticAuthUsernameFromContext(ctx); immediate != "" {
return immediate, nil
}
// immediateCallerIdFromStaticAuthentication extracts the username of the current
// static authentication context and returns that to the caller.
func immediateCallerIdFromStaticAuthentication(ctx context.Context) (string, []string) {
if immediate := servenv.StaticAuthUsernameFromContext(ctx); immediate != "" {
return immediate, nil
}
return immediateCallerIDFromCert(ctx)

return "", nil
}

// 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)
// The client cert common name (if using mTLS)
immediate, securityGroups := immediateCallerIDFromCert(ctx)

// The effective caller id (if --grpc_use_effective_callerid=true)
if immediate == "" && useEffective && effectiveCallerID != nil {
immediate = effectiveCallerID.Principal
if useEffectiveGroups && len(effectiveCallerID.Groups) > 0 {
securityGroups = effectiveCallerID.Groups
}
}

// The static auth username (if --grpc-use-static-authentication-callerid=true)
if immediate == "" && useStaticAuthenticationIdentity {
immediate, securityGroups = immediateCallerIdFromStaticAuthentication(ctx)
}

if immediate == "" {
immediate = unsecureClient
}
Expand Down