MCPcopy Index your code
hub / github.com/bitsbeats/prometheus-acls

github.com/bitsbeats/prometheus-acls @v0.1.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.2 ↗ · + Follow
46 symbols 126 edges 10 files 35 documented · 76% updated 4y agov0.1.2 · 2020-07-30★ 37
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

prometheus-acls

Build Status Docker Pulls Go Report Card

A reverse proxy for prometheus that provides label based acls via oidc.

Prequisites

  • Running prometheus server
  • OpenID Connect server (i.e. Keycloak) with option to set custom fields in the Access Token
  • Grafana instance that authentificates with OpenID Connect

Configuration

Environment

Via environment you can configure all settings.

  • LISTEN: IP and port to to listen on (default :8080)
  • URL: URL for prometheus-acls, used to generate redirects, login and callback routes (e.g. https://promacl.example.com)
  • COOKIE_SECRET: Cookie Secret (should be 32 or 64 chars), autogenerated if empty
  • PROMETHEUS_URL: URL to the upstream Prometheus (default http://localhost:9090)
  • OIDC_ISSUER: URL to the OpenID Connect Sever (e.g. https://auth.example.com/auth/realms/users)
  • OIDC_CLIENT_ID: Oauth Client ID (e.g. grafana)
  • OIDC_CLIENT_SECRET: Oauth Client Secret (e.g. 12345678-1234-1234-1234-123456789abc)
  • OIDC_ROLES_CLAIM: Field in Acces Token to load the users role (default roles)
  • ACL_FILE: Full or relative path to acl configuration file (default prometheus-acls.yml)

prometheus-acls.yml:

The prometheus-acls.yml file is used to map roles to access rights.

# syntax:
#
# <rolename>:
#   <metricname>: <prometheus label matches>
#   # or
#   re!<regex>: <prometheus label matches>

developer:                # The keys match the OIDC_ROLES_CLAIM field of the access token.

  re!^awesome_app_:       # regex match for all metrics that stat with awesome_app_
    env=dev               # prometheus label match for dev env

  re!^node_:              # regex match for node exporter
    instance=~'.*\.lan$'  # prometheus label match for instances that end with .lan

  up: env!=dev,app=hal    # prometheus labels are handled by prometheus, so their complete
                          # syntax is supported

admin:                    # The keys match the OIDC_ROLES_CLAIM field of the access token.

  secret_app_:            # exact metric name
    ~                     # yaml null value will bock access to a metric

  '*':                    # wildchard match for all metrics
    ''                    # emty prometheus label match for NO RESTRICTIONS

Order of metric name matching:

  • Exact metric name
  • Regex metric name
  • Wildcard metric name
  • Default deny access

Best Practices:

  • Metric regex matches should be started with ^
  • Regex label matches are slower than exact matches

OIDC Provider

Example for keycloak:

  • Create a new client with Access Type confidential
  • Go to the clients mappers and add a new one
  • Most mappers should work e.g User Client Role
  • Set Token Claim Name to roles (if you change this you also need to supply $OIDC_ROLES_CLAIM to prometheus-acls)
  • Claim JSON Type is String
  • Add to access token must be on
  • Configure both Grafana and prometheus-acls with the same settings OIDC settings

Note: When you have multiple roles, the first one that is mentioned in prometheus-acls will be used. We currently use per client roles to avoid any conflics.

Extension points exported contracts — how you extend this code

ACL (Interface)
ACL provides the Prometheus LabelMatchers [3 implementers]
internal/core/config.go
Auth (Interface)
Auth provides all methods neded for an auth provider [1 implementers]
internal/auth/auth.go
NotPromHandlerFunc (FuncType)
NotPromHandlerFunc is a function that is called if the error message is not displayed in Prometheus
internal/prom/prom.go

Core symbols most depended-on inside this repo

SendError
called by 7
internal/prom/prom.go
ParseLabels
called by 3
internal/labeler/labeler.go
AddLabels
called by 3
internal/labeler/labeler.go
GetLabelMatchers
called by 2
internal/core/config.go
labelize
called by 2
internal/labeler/middleware.go
NewLabeler
called by 2
internal/labeler/labeler.go
DedupeMatchers
called by 2
internal/labeler/labeler.go
NewOauthAuth
called by 1
internal/auth/oidc.go

Shape

Method 21
Function 10
Struct 8
TypeAlias 4
Interface 2
FuncType 1

Languages

Go100%

Modules by API surface

internal/config/acl.go11 symbols
internal/auth/oidc.go8 symbols
internal/labeler/labeler_test.go6 symbols
internal/labeler/labeler.go6 symbols
internal/auth/auth.go5 symbols
internal/prom/prom.go3 symbols
internal/labeler/middleware.go2 symbols
internal/core/config.go2 symbols
internal/config/config.go2 symbols
main.go1 symbols

For agents

$ claude mcp add prometheus-acls \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact