mirror of https://github.com/grafana/grafana
AuthZ: GRPC client init and config options (#89161)
parent
3776c44c33
commit
5f83fdef2c
@ -1,3 +1,51 @@ |
||||
# Authorization |
||||
|
||||
This package contains the authorization server implementation. |
||||
|
||||
## Feature toggles |
||||
|
||||
The following feature toggles need to be activated: |
||||
|
||||
```ini |
||||
[feature_toggles] |
||||
authZGRPCServer = true |
||||
grpcServer = true |
||||
``` |
||||
|
||||
## Configuration |
||||
|
||||
To configure the authorization server and client, use the "authorization" section of the configuration ini file. |
||||
|
||||
The `remote_address` setting, specifies the address where the authorization server is located (ex: `server.example.org:10000`). |
||||
|
||||
The `mode` setting can be set to either `grpc` or `inproc`. When set to `grpc`, the client will connect to the specified address. When set to `inproc` the client will use inprocgrpc (relying on go channels) to wrap a local instantiation of the server. |
||||
|
||||
The `listen` setting determines whether the authorization server should listen for incoming requests. When set to `true`, the authorization service will be registered to the Grafana GRPC server. |
||||
|
||||
The default configuration does not register the authorization service on the Grafana GRPC server and binds the client to it `inproc`: |
||||
|
||||
```ini |
||||
[authorization] |
||||
remote_address = "" |
||||
listen = false |
||||
mode = "inproc" |
||||
``` |
||||
|
||||
### Example |
||||
|
||||
Here is an example to connect the authorization client to a remote grpc server. |
||||
|
||||
```ini |
||||
[authorization] |
||||
remote_address = "server.example.org:10000" |
||||
mode = "grpc" |
||||
``` |
||||
|
||||
Here is an example to register the authorization service on the Grafana GRPC server and connect the client to it through grpc |
||||
|
||||
```ini |
||||
[authorization] |
||||
remote_address = "localhost:10000" |
||||
listen = true |
||||
mode = "grpc" |
||||
``` |
||||
|
||||
@ -0,0 +1,43 @@ |
||||
package authz |
||||
|
||||
import ( |
||||
"fmt" |
||||
|
||||
"github.com/grafana/grafana/pkg/setting" |
||||
) |
||||
|
||||
type Mode string |
||||
|
||||
func (s Mode) IsValid() bool { |
||||
switch s { |
||||
case ModeGRPC, ModeInProc: |
||||
return true |
||||
} |
||||
return false |
||||
} |
||||
|
||||
const ( |
||||
ModeGRPC Mode = "grpc" |
||||
ModeInProc Mode = "inproc" |
||||
) |
||||
|
||||
type Cfg struct { |
||||
remoteAddress string |
||||
listen bool |
||||
mode Mode |
||||
} |
||||
|
||||
func ReadCfg(cfg *setting.Cfg) (*Cfg, error) { |
||||
section := cfg.SectionWithEnvOverrides("authorization") |
||||
|
||||
mode := Mode(section.Key("mode").MustString(string(ModeInProc))) |
||||
if !mode.IsValid() { |
||||
return nil, fmt.Errorf("authorization: invalid mode %q", mode) |
||||
} |
||||
|
||||
return &Cfg{ |
||||
remoteAddress: section.Key("remote_address").MustString(""), |
||||
listen: section.Key("listen").MustBool(false), |
||||
mode: mode, |
||||
}, nil |
||||
} |
||||
Loading…
Reference in new issue