Skip to content

Commit

Permalink
Load --grpc_auth_static_client_creds file once
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
  • Loading branch information
timvaillancourt committed Jan 24, 2024
1 parent bbbf3c2 commit 33a252a
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions go/vt/grpcclient/client_auth_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"flag"
"os"
"sync"

"context"

Expand All @@ -31,6 +32,9 @@ var (
credsFile = flag.String("grpc_auth_static_client_creds", "", "when using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server")
// StaticAuthClientCreds implements client interface to be able to WithPerRPCCredentials
_ credentials.PerRPCCredentials = (*StaticAuthClientCreds)(nil)

credsFileOnce sync.Once
clientCreds *StaticAuthClientCreds
)

// StaticAuthClientCreds holder for client credentials
Expand All @@ -54,21 +58,30 @@ func (c *StaticAuthClientCreds) RequireTransportSecurity() bool {
return false
}

// AppendStaticAuth optionally appends static auth credentials if provided.
func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) {
if *credsFile == "" {
return opts, nil
}
data, err := os.ReadFile(*credsFile)
// loadStaticAuthCredsFromFile loads static auth credentials from a file.
func loadStaticAuthCredsFromFile(credsFile string) (*StaticAuthClientCreds, error) {
data, err := os.ReadFile(credsFile)
if err != nil {
return nil, err
}
clientCreds := &StaticAuthClientCreds{}
err = json.Unmarshal(data, clientCreds)
return clientCreds, err
}

// AppendStaticAuth optionally appends static auth credentials if provided.
func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) {
if credsFile == "" {

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_scheduler) mysql80

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / End-to-End Test

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Local example using etcd on ubuntu-latest

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / End-to-End Test (Race)

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Local example using k8s on ubuntu-latest

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Region Sharding example using etcd on ubuntu-latest

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Local example using consul on ubuntu-latest

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

invalid operation: cannot compare credsFile == "" (mismatched types *string and untyped string) (typecheck)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Queries)

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old VTTablet

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Schema)

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old Vtctl

invalid operation: credsFile == "" (mismatched types *string and untyped string)

Check failure on line 74 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Backups - Manual

invalid operation: credsFile == "" (mismatched types *string and untyped string)
return opts, nil
}
var err error
credsFileOnce.Do(func() {
clientCreds, err = loadStaticAuthCredsFromFile(credsFile)

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_scheduler) mysql80

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / End-to-End Test

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Local example using etcd on ubuntu-latest

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / End-to-End Test (Race)

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Local example using k8s on ubuntu-latest

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Region Sharding example using etcd on ubuntu-latest

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Local example using consul on ubuntu-latest

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile (typecheck)

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

cannot use credsFile (variable of type *string) as type string in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

cannot use credsFile (variable of type *string) as type string in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

cannot use credsFile (variable of type *string) as type string in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

cannot use credsFile (variable of type *string) as type string in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

cannot use credsFile (variable of type *string) as type string in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

cannot use credsFile (variable of type *string) as type string in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Queries)

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old VTTablet

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Schema)

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old Vtctl

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile

Check failure on line 79 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Backups - Manual

cannot use credsFile (variable of type *string) as string value in argument to loadStaticAuthCredsFromFile
})
if err != nil {
return nil, err
}
creds := grpc.WithPerRPCCredentials(clientCreds)
creds := grpc.WithPerRPCCredentials(*clientCreds)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_scheduler) mysql80

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / End-to-End Test

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Local example using etcd on ubuntu-latest

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / End-to-End Test (Race)

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Local example using k8s on ubuntu-latest

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Region Sharding example using etcd on ubuntu-latest

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Local example using consul on ubuntu-latest

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver) (typecheck)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

cannot use *clientCreds (variable of type StaticAuthClientCreds) as type "google.golang.org/grpc/credentials".PerRPCCredentials in argument to grpc.WithPerRPCCredentials:

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

cannot use *clientCreds (variable of type StaticAuthClientCreds) as type "google.golang.org/grpc/credentials".PerRPCCredentials in argument to grpc.WithPerRPCCredentials:

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

cannot use *clientCreds (variable of type StaticAuthClientCreds) as type "google.golang.org/grpc/credentials".PerRPCCredentials in argument to grpc.WithPerRPCCredentials:

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

cannot use *clientCreds (variable of type StaticAuthClientCreds) as type "google.golang.org/grpc/credentials".PerRPCCredentials in argument to grpc.WithPerRPCCredentials:

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

cannot use *clientCreds (variable of type StaticAuthClientCreds) as type "google.golang.org/grpc/credentials".PerRPCCredentials in argument to grpc.WithPerRPCCredentials:

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

cannot use *clientCreds (variable of type StaticAuthClientCreds) as type "google.golang.org/grpc/credentials".PerRPCCredentials in argument to grpc.WithPerRPCCredentials:

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Queries)

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old VTTablet

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Schema)

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old Vtctl

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)

Check failure on line 84 in go/vt/grpcclient/client_auth_static.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Backups - Manual

cannot use *clientCreds (variable of type StaticAuthClientCreds) as "google.golang.org/grpc/credentials".PerRPCCredentials value in argument to grpc.WithPerRPCCredentials: StaticAuthClientCreds does not implement "google.golang.org/grpc/credentials".PerRPCCredentials (method GetRequestMetadata has pointer receiver)
opts = append(opts, creds)
return opts, nil
}
Expand Down

0 comments on commit 33a252a

Please sign in to comment.