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

Conversation

Phanatic
Copy link

@Phanatic Phanatic commented Apr 24, 2023

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

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on the CI
  • Documentation was added or is not required

@vitess-bot vitess-bot bot added NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says labels Apr 24, 2023
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Apr 24, 2023

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • If this is a change that users need to know about, please apply the release notes (needs details) label so that merging is blocked unless the summary release notes document is included.
  • If a test is added or modified, there should be a documentation on top of the test to explain what the expected behavior is what the test does.

If a new flag is being introduced:

  • Is it really necessary to add this flag?
  • Flag names should be clear and intuitive (as far as possible)
  • Help text should be descriptive.
  • Flag names should use dashes (-) as word separators rather than underscores (_).

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow should be required, the maintainer team should be notified.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should include a link to an issue that describes the bug.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from VTop, if used there.

@Phanatic Phanatic changed the title Disables automatically setting immediateCallerID to User from Static authentication Context Disable automatically setting immediateCallerID to User from Static authentication Context Apr 24, 2023
@github-actions github-actions bot added this to the v17.0.0 milestone Apr 24, 2023
Copy link
Member

@deepthi deepthi left a 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

@frouioui when this is backported to release-16.0 do we need to add a summary release note for 16.0.2?

@harshit-gangal
Copy link
Member

harshit-gangal commented Apr 25, 2023

Changes looks fine.

I need to understand a little bit more about how it is used.

  1. My understanding is that the static auth user is always set. So, when the new flag is enabled how it will start working like what changes so that it does not fail?
  2. My assumption is that immediate Caller ID is not set in the cert for PS. Is that correct?

@@ -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 {
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Author

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

Copy link
Contributor

@brendar brendar Apr 25, 2023

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.

Copy link
Member

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?

Copy link
Contributor

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)

Copy link
Member

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

Copy link
Member

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

@harshit-gangal
Copy link
Member

harshit-gangal commented Apr 25, 2023

After reading the old PR #12050 and its description.
We can basically use the effective caller id and enable grpc_use_effective_callerid. The reason you were seeing unsecure_grpc_client was that the connection created between your service and vtgate is non-ssl connection.

This also means the previous change can be reverted.

@Phanatic Phanatic added Component: ACL Type: Bug and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work labels Apr 25, 2023
Copy link
Member

@harshit-gangal harshit-gangal left a 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.

@Phanatic Phanatic changed the title Disable automatically setting immediateCallerID to User from Static authentication Context Revert https://github.com/vitessio/vitess/pull/12050 Apr 25, 2023
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]>
@Phanatic Phanatic changed the title Revert https://github.com/vitessio/vitess/pull/12050 vtgate : Disable Automatically setting immediateCallerID to user from static authentication context Apr 26, 2023
@Phanatic
Copy link
Author

website PR is at vitessio/website#1454

@Phanatic Phanatic removed the NeedsWebsiteDocsUpdate What it says label Apr 26, 2023
Copy link
Contributor

@brendar brendar left a 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.

@frouioui
Copy link
Member

@frouioui when this is backported to release-16.0 do we need to add a summary release note for 16.0.2?

@deepthi @Phanatic, yes I think. It changes the behavior significantly enough that it should be mentioned in the 16.0.2 release notes, but I think also in the 17.0.0 release notes.

GuptaManan100 added a commit that referenced this pull request May 9, 2023
…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]>
frouioui pushed a commit to planetscale/vitess that referenced this pull request Nov 21, 2023
…mediateCallerID to user from static authentication context (vitessio#2027)

* cherry pick of 12961

* fix merge conflicts

---------

Co-authored-by: Phani Raj <[email protected]>
@hmaurer hmaurer mentioned this pull request Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EffectiveCallerId is overriden for all vtgate grpc calls if vtgate uses static authentication.
7 participants