|
|
|
@ -55,14 +55,16 @@ func ProvideAuthZClient( |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
case ModeGRPC: |
|
|
|
|
client, err = newGrpcLegacyClient(authCfg.remoteAddress) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
case ModeCloud: |
|
|
|
|
client, err = newCloudLegacyClient(authCfg) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
if cfg.StackID == "" { |
|
|
|
|
client, err = newGrpcLegacyClient(authCfg) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
client, err = newCloudLegacyClient(authCfg) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -83,7 +85,7 @@ func ProvideStandaloneAuthZClient( |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return newGrpcLegacyClient(authCfg.remoteAddress) |
|
|
|
|
return newGrpcLegacyClient(authCfg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newInProcLegacyClient(server *legacyServer) (authzlib.AccessChecker, error) { |
|
|
|
@ -108,25 +110,20 @@ func newInProcLegacyClient(server *legacyServer) (authzlib.AccessChecker, error) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newGrpcLegacyClient(address string) (authzlib.AccessChecker, error) { |
|
|
|
|
func newGrpcLegacyClient(authCfg *Cfg) (authzlib.AccessChecker, error) { |
|
|
|
|
// This client interceptor is a noop, as we don't send an access token
|
|
|
|
|
grpcClientConfig := authnlib.GrpcClientConfig{} |
|
|
|
|
clientInterceptor, err := authnlib.NewGrpcClientInterceptor(&grpcClientConfig, |
|
|
|
|
authnlib.WithDisableAccessTokenOption(), |
|
|
|
|
) |
|
|
|
|
clientConfig := authnlib.GrpcClientConfig{} |
|
|
|
|
clientInterceptor, err := authnlib.NewGrpcClientInterceptor(&clientConfig, authnlib.WithDisableAccessTokenOption()) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cfg := authzlib.ClientConfig{RemoteAddress: address} |
|
|
|
|
cfg := authzlib.ClientConfig{RemoteAddress: authCfg.remoteAddress} |
|
|
|
|
client, err := authzlib.NewClient(&cfg, |
|
|
|
|
// TODO(drclau): make this configurable (e.g. allow to use insecure connections)
|
|
|
|
|
authzlib.WithGrpcDialOptionsClientOption( |
|
|
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()), |
|
|
|
|
grpc.WithUnaryInterceptor(clientInterceptor.UnaryClientInterceptor), |
|
|
|
|
grpc.WithStreamInterceptor(clientInterceptor.StreamClientInterceptor), |
|
|
|
|
getDialOpts(clientInterceptor, authCfg.allowInsecure)..., |
|
|
|
|
), |
|
|
|
|
// TODO(drclau): remove this once we have access token support on-prem
|
|
|
|
|
// TODO: remove this once access tokens are supported on-prem
|
|
|
|
|
authzlib.WithDisableAccessTokenClientOption(), |
|
|
|
|
) |
|
|
|
|
if err != nil { |
|
|
|
@ -155,11 +152,8 @@ func newCloudLegacyClient(authCfg *Cfg) (authzlib.AccessChecker, error) { |
|
|
|
|
|
|
|
|
|
clientCfg := authzlib.ClientConfig{RemoteAddress: authCfg.remoteAddress} |
|
|
|
|
client, err := authzlib.NewClient(&clientCfg, |
|
|
|
|
// TODO(drclau): make this configurable (e.g. allow to use insecure connections)
|
|
|
|
|
authzlib.WithGrpcDialOptionsClientOption( |
|
|
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()), |
|
|
|
|
grpc.WithUnaryInterceptor(clientInterceptor.UnaryClientInterceptor), |
|
|
|
|
grpc.WithStreamInterceptor(clientInterceptor.StreamClientInterceptor), |
|
|
|
|
getDialOpts(clientInterceptor, authCfg.allowInsecure)..., |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
if err != nil { |
|
|
|
@ -168,3 +162,16 @@ func newCloudLegacyClient(authCfg *Cfg) (authzlib.AccessChecker, error) { |
|
|
|
|
|
|
|
|
|
return client, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getDialOpts(interceptor *authnlib.GrpcClientInterceptor, allowInsecure bool) []grpc.DialOption { |
|
|
|
|
dialOpts := []grpc.DialOption{ |
|
|
|
|
grpc.WithUnaryInterceptor(interceptor.UnaryClientInterceptor), |
|
|
|
|
grpc.WithStreamInterceptor(interceptor.StreamClientInterceptor), |
|
|
|
|
} |
|
|
|
|
if allowInsecure { |
|
|
|
|
// allow insecure connections in development mode to facilitate testing
|
|
|
|
|
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return dialOpts |
|
|
|
|
} |
|
|
|
|