labelaccess

package
v4.0.0-rc.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
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:

  1. Identifies queries targeting aggregated metrics
  2. Extracts LBAC policies for the tenant
  3. Builds filter expressions combining all policies (ORed together)
  4. Injects a logfmt parser and label filter into the FRONT of query pipeline
  5. 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

func UserIDTransformer(ctx context.Context, userID string) string

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 WrapStore

func WrapStore(wrapped storage.Store) storage.Store

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

type Codec struct {
	codec.Codec
}

func NewCodec

func NewCodec(original codec.Codec) *Codec

func (*Codec) DecodeHTTPGrpcRequest

func (c *Codec) DecodeHTTPGrpcRequest(ctx context.Context, r *httpgrpc.HTTPRequest) (queryrangebase.Request, context.Context, error)

func (*Codec) EncodeRequest

func (c *Codec) EncodeRequest(ctx context.Context, req queryrangebase.Request) (*http.Request, error)

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

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags for LBAC to the given FlagSet.

type ErrorAPI

type ErrorAPI struct {
	Status string `json:"status"`
	Error  string `json:"error"`
}

type IngesterWrapper

type IngesterWrapper struct{}

func (*IngesterWrapper) Wrap

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 StoreWrapper struct {
	storage.Store
}

func (*StoreWrapper) LabelValuesForMetricName

func (w *StoreWrapper) LabelValuesForMetricName(ctx context.Context, orgID string, from, through model.Time, metricName string, labelName string, matchers ...*labels.Matcher) ([]string, error)

type WrappedIngester

type WrappedIngester struct {
	ingester.Interface
}

func (*WrappedIngester) Label

Label overrides the existing Label method. Label matchers in the context are applied to labels stored for the instance/org ID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址