package
0.0.0-20241212110159-5ae10177a923
Repository: https://github.com/grafana/authlib.git
Documentation: pkg.go.dev
# README
Authz: User and Namespace Access Control
This library provides utilities for your Grafana applications or plugins to manage user permissions and control access to resources within namespaces.
Features:
- Single-tenant RBAC client, typically used by plugins to query Grafana for user permissions and control their access.
- [unstable / under development] Multi-tenant client, typically used by multi-tenant applications to enforce service and user access.
- A composable namespace checker to authorize requests based on JWT namespaces
Access-control EnforcementClient
This package exports an RBAC client library that contains a set of utilities to check users permissions from Grafana.
Grafana Configuration
Grafana needs to be configured with the accessControlOnCall
feature toggle set for the search permissions endpoint to be registered.
[feature_toggles]
enable = accessControlOnCall
Example: Check if a user can list users
Here is an example on how to check access on a resouce for a user.
package main
import (
"context"
"log"
"github.com/grafana/authlib/authz"
)
func main() {
client, err := authz.NewEnforcementClient(authz.Config{
APIURL: "http://localhost:3000",
Token: "<service account token>",
JWKsURL: "<jwks url>",
})
if err != nil {
log.Fatal("failed to construct authz client", err)
}
ok, err := client.HasAccess(context.Background(), "<id token>", "users:read", authz.Resource{
Kind: "users",
Attr: "id",
ID: "1",
})
if err != nil {
log.Fatal("failed to perform access check", err)
}
log.Println("has access: ", ok)
}
[unstable / under development ] Multi-tenant authz client
Namespace access
# Packages
No description provided by the author
# Functions
MetadataStackIDExtractor extracts the stack ID from the gRPC metadata.
NamespaceAuthorizationFunc returns a AuthorizeFunc that checks the caller claims access to a given namespace.
No description provided by the author
No description provided by the author
NewNamespaceAuthorizer creates a new namespace authorizer.
StreamAuthorizeInterceptor returns a new stream server interceptor that performs per-request authorization.
UnaryAuthorizeInterceptor returns a new unary server interceptor that performs per-request authorization.
No description provided by the author
No description provided by the author
WithDisableAccessTokenClientOption is an option to disable access token authorization.
WithGrpcConnectionClientOption sets the gRPC client connection directly.
WithGrpcDialOptionsClientOption sets the gRPC dial options for client connection setup.
No description provided by the author
WithSearchByPrefix makes the client search for permissions always using the given prefix.
No description provided by the author
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
CheckRequest describes the requested access.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Resource represents a resource in Grafana.
# Interfaces
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
HTTPRequestDoer performs HTTP requests.
No description provided by the author
ServiceAuthorizeFuncOverride allows a given gRPC service implementation to override the global `AuthorizeFunc`.
# Type aliases
AuthorizeFunc is the pluggable function that performs access control checks.
No description provided by the author
Checker checks whether a user has access to any of the provided resources.
ClientOption allows setting custom parameters during construction.
TODO: Should the namespace be specified in the request instead.
No description provided by the author
No description provided by the author