Documentation
¶
Index ¶
- Constants
- func ClientLBACInterceptor(ctx context.Context, method string, req, reply interface{}, ...) error
- func InjectLabelMatchersContext(ctx context.Context, matchers LabelPolicySet) context.Context
- func InjectLabelMatchersHTTP(r *http.Request, instancePolicyMap LabelPolicySet) error
- func ModifyAggregatedMetricsQuery(r *http.Request, matchers LabelPolicySet) error
- func NewLabelAccessMiddleware(logger log.Logger) middleware.Interface
- func NewMiddleware() queryrangebase.Middleware
- func ServerLBACInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, ...) (interface{}, error)
- func StreamClientLBACInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, ...) (grpc.ClientStream, error)
- func StreamServerLBACInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, ...) error
- func UserIDTransformer(ctx context.Context, userID string) string
- func WrapStore(wrapped storage.Store) storage.Store
- func WritePromError(w http.ResponseWriter, errorMessage string, code int)
- type ChunkFilterer
- type Codec
- func (c *Codec) DecodeHTTPGrpcRequest(ctx context.Context, r *httpgrpc.HTTPRequest) (queryrangebase.Request, context.Context, error)
- func (c *Codec) EncodeRequest(ctx context.Context, req queryrangebase.Request) (*http.Request, error)
- func (c *Codec) QueryRequestUnwrap(ctx context.Context, req *queryrange.QueryRequest) (queryrangebase.Request, context.Context, error)
- func (c *Codec) QueryRequestWrap(ctx context.Context, r queryrangebase.Request) (*queryrange.QueryRequest, error)
- type Config
- type ErrorAPI
- type IngesterWrapper
- type LabelPolicySet
- func ExtractLabelMatchersContext(ctx context.Context) (LabelPolicySet, error)
- func ExtractLabelMatchersFromHeaders(headers http.Header) (LabelPolicySet, error)
- func ExtractLabelMatchersGRPC(r *httpgrpc.HTTPRequest) (LabelPolicySet, error)
- func ExtractLabelMatchersHTTP(r *http.Request) (LabelPolicySet, error)
- type RequestChunkFilterer
- type StoreWrapper
- type WrappedIngester
Constants ¶
const (
// HTTPHeaderKey is used as the header to store label matcher values
HTTPHeaderKey = "X-Prom-Label-Policy"
)
Variables ¶
This section is empty.
Functions ¶
func ClientLBACInterceptor ¶
func ClientLBACInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
ClientLBACInterceptor propagates the LBAC headers from the context to gRPC metadata, which eventually ends up as a HTTP2 header.
func InjectLabelMatchersContext ¶
func InjectLabelMatchersContext(ctx context.Context, matchers LabelPolicySet) context.Context
InjectLabelMatchersContext injects label matchers into the context using httpreq.InjectHeader.
func InjectLabelMatchersHTTP ¶
func InjectLabelMatchersHTTP(r *http.Request, instancePolicyMap LabelPolicySet) error
InjectLabelMatchersHTTP takes the provided matcher protobufs and stores them as HTTP headers
func ModifyAggregatedMetricsQuery ¶
func ModifyAggregatedMetricsQuery(r *http.Request, matchers LabelPolicySet) error
ModifyAggregatedMetricsQuery modifies Loki queries for aggregated metrics to include label-based access control (LBAC) filters.
For aggregated metrics, labels are stored inside the log content rather than as stream labels, so we need to apply LBAC filters after parsing the log content with the logfmt parser. This function:
- Identifies queries targeting aggregated metrics
- Extracts LBAC policies for the tenant
- Builds filter expressions combining all policies (ORed together)
- Injects a logfmt parser and label filter into the FRONT of query pipeline
- Updates the request URL with the modified query
The resulting query will contain a pipeline that parses log lines with logfmt and filters out lines that don't match the LBAC policies, ensuring that users only see aggregated metrics they have permission to access.
func NewLabelAccessMiddleware ¶
func NewLabelAccessMiddleware(logger log.Logger) middleware.Interface
NewLabelAccessMiddleware returns a HTTP middleware that parses the X-Prom-Label-Policy header and injects the parsed label selectors into the request context.
func NewMiddleware ¶
func NewMiddleware() queryrangebase.Middleware
NewMiddleware wraps the existing middleware to make sure the LBAC headers are propagated
func ServerLBACInterceptor ¶
func ServerLBACInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
ServerLBACInterceptor propagates the LBAC headers from the gRPC metadata back to our context.
func StreamClientLBACInterceptor ¶
func StreamClientLBACInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error)
StreamClientLBACInterceptor propagates the LBAC headers from the context to gRPC metadata, which eventually ends up as a HTTP2 header. For streaming gRPC requests.
func StreamServerLBACInterceptor ¶
func StreamServerLBACInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error
StreamServerLBACInterceptor propagates the LBAC headers from the gRPC metadata back to our context.
func UserIDTransformer ¶
UserIDTransformer returns the changed userID if there is a LabelPolicy set in the context. This is used in Loki in GenerateCacheKey so the cached results have the labelpolicy as part of the cache key.
func WritePromError ¶
func WritePromError(w http.ResponseWriter, errorMessage string, code int)
Types ¶
type ChunkFilterer ¶
type ChunkFilterer struct {
// contains filtered or unexported fields
}
func (*ChunkFilterer) RequiredLabelNames ¶
func (c *ChunkFilterer) RequiredLabelNames() []string
func (*ChunkFilterer) ShouldFilter ¶
func (c *ChunkFilterer) ShouldFilter(metric labels.Labels) bool
type Codec ¶
func (*Codec) DecodeHTTPGrpcRequest ¶
func (c *Codec) DecodeHTTPGrpcRequest(ctx context.Context, r *httpgrpc.HTTPRequest) (queryrangebase.Request, context.Context, error)
func (*Codec) EncodeRequest ¶
func (*Codec) QueryRequestUnwrap ¶
func (c *Codec) QueryRequestUnwrap(ctx context.Context, req *queryrange.QueryRequest) (queryrangebase.Request, context.Context, error)
func (*Codec) QueryRequestWrap ¶
func (c *Codec) QueryRequestWrap(ctx context.Context, r queryrangebase.Request) (*queryrange.QueryRequest, error)
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled"`
}
Config holds the configuration for label-based access control.
func (*Config) RegisterFlags ¶
RegisterFlags adds the flags for LBAC to the given FlagSet.
type IngesterWrapper ¶
type IngesterWrapper struct{}
type LabelPolicySet ¶
type LabelPolicySet map[string][]*types.LabelPolicy
LabelPolicySet is used
func ExtractLabelMatchersContext ¶
func ExtractLabelMatchersContext(ctx context.Context) (LabelPolicySet, error)
ExtractLabelMatchersContext gets the embedded label matchers from the context. It extracts headers stored by PropagateAllHeadersMiddleware or httpreq.InjectHeader.
func ExtractLabelMatchersFromHeaders ¶
func ExtractLabelMatchersFromHeaders(headers http.Header) (LabelPolicySet, error)
ExtractLabelMatchersFromHeaders parses label matcher protobufs from the provided headers
func ExtractLabelMatchersGRPC ¶
func ExtractLabelMatchersGRPC(r *httpgrpc.HTTPRequest) (LabelPolicySet, error)
func ExtractLabelMatchersHTTP ¶
func ExtractLabelMatchersHTTP(r *http.Request) (LabelPolicySet, error)
ExtractLabelMatchersHTTP takes the provided HTTP request and parses out label matcher protobufs
func (LabelPolicySet) String ¶
func (l LabelPolicySet) String() string
type RequestChunkFilterer ¶
type RequestChunkFilterer struct{}
func (*RequestChunkFilterer) ForRequest ¶
func (r *RequestChunkFilterer) ForRequest(ctx context.Context) chunk.Filterer
type StoreWrapper ¶
type WrappedIngester ¶
func (*WrappedIngester) Label ¶
func (i *WrappedIngester) Label(ctx context.Context, req *logproto.LabelRequest) (*logproto.LabelResponse, error)
Label overrides the existing Label method. Label matchers in the context are applied to labels stored for the instance/org ID.