Based on Pull Request #71
- Logger Changes: Replaces
zap
logging withzerolog
. - Router Change: Now using gorilla/mux to distinguish between Prometheus/Loki URLs
- File:
.github/workflows/release.yml
- Name Change:
Publish new release
toCI
- Job Renames:
golangci
tolint
,scan-code
toscan
,build-and-test
split intotest
andbuild
- Go Version: Updated from
1.20
to1.21
- Action Versions:
actions/checkout
andactions/setup-go
upgraded - Scheduling: Removed cron scheduling
- Tagging: switched
autotag
toanothrNick/github-tag-action
- Docker meta: Tagging rules updated
- Release Process: Changes in how releases are created
- Name Change:
- File:
auth.go
- OAuth Token: Changed from
KeycloakToken
toOAuthToken
- Token Retrieval: Functions
getToken
andtrimBearerToken
for token parsing - JWT Parsing: Function
parseJwtToken
to handle JWT tokens - Label Validation:
validateLabels
validates user labels - Admin Check:
isAdmin
checks if user is an admin
- OAuth Token: Changed from
- File:
build/Containerfile
- Base Image: Switch from
ubi9/ubi-minimal
toscratch
. - CA Image:
alpine:latest
for CA certificates.
- Base Image: Switch from
- File:
config.go
- Struct: Updated names and added fields: logging, web, admin, dev, DB, Thanos, Loki.
- WithConfig Method: Reads YAML, sets logging, watches config changes
- WithSAT Method: K8s service account token, dev mode option
- WithTLSConfig Method: TLS setup for HTTP client, CA and mTLS
- WithJWKS Method: JWKS for JWT auth, refresh options
- File:
configs/config.yaml
- log.level:
DEBUG
->1
- tenant_provider: Removed
- web:
insecure_skip_verify
->tls_verify_skip
- Added
label_store_kind
,service_account_token
,oauth_group_name
- Updated
jwks_cert_url
- admin: No change
- db: Added
token_key
- thanos: Added
Header
- loki: Added
Header
- Purpose: Tweaks in logging, web, dev, db, loki settings; Adds/removes keys
- log.level:
- File:
configs/labels.yaml
- Removed:
groups
users
- Added:
group1
:#cluster-wide
flaguser1
:hogarama
namespaceuser3
:grafana
,opernshift-logging
,opernshift-monitoring
namespaces
- Purpose: Redefined user and group label configs, added new settings for cluster-wide and specific namespaces.
- Removed:
- File:
enforce.go
- EnforceQL Interface: Method
Enforce
for query enforcement - enforceRequest Function: Delegates HTTP request based on method
- enforceGet Function: Enforces GET request, modifies URL query
- enforcePost Function: Enforces POST request, modifies form data
- Purpose: HTTP request enforcement based on tenant labels, query matching. Handles both GET and POST methods.
- EnforceQL Interface: Method
- File:
enforcer_logql.go
- LogQLEnforcer Struct: New struct for EnforceQL interface.
- Enforce Method: Modified, returns tenant-isolated query
- matchNamespaceMatchers Function: Ensures query matchers adhere to tenant labels.
- File:
enforcer_promql.go
- Struct Added:
PromQLEnforcer
for enforcing PromQL queries via EnforceQL interface. - Method Changes:
promqlEnforcer
->PromQLEnforcer.Enforce
enforceLabels
,checkLabels
andcreateEnforcer
take an additionallabelMatch
parameter.
- Purpose: Improves structure, logging, and modularity. Adds flexibility for label matching.
- Struct Added:
- File:
go.mod
- Dependencies Added:
github.com/gorilla/mux v1.8.0
github.com/rs/zerolog v1.30.0
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-isatty v0.0.19
- Dependencies Updated:
- Multiple
github.com/go-openapi/*
packages github.com/prometheus/alertmanager
tov0.26.0
go.mongodb.org/mongo-driver
tov1.12.0
- Multiple
- Dependencies Removed:
go.uber.org/zap v1.24.0
- Replace Directive:
github.com/prometheus/prometheus
tov0.46.0
- Purpose: Adds new libraries, updates existing ones for feature enhancements or bug fixes.
- Dependencies Added:
- File:
init.go
- Note: File deleted
- File:
labeler.go
- Note: File deleted
- File:
labelstore.go
- New File: Manages label storage
- Interfaces:
Labelstore
: DefinesConnect
,GetLabels
- Functions:
WithLabelStore()
: Connects LabelStore to AppConfigMapHandler.Connect()
: Reads labels from YAMLConfigMapHandler.GetLabels()
: Merges labelsMySQLHandler.Connect()
: Connects to MySQLMySQLHandler.Close()
: Closes DB connectionMySQLHandler.GetLabels()
: Queries DB for labels
- Error Handling: Logs fatal errors
- Note: Supports multiple label store kinds (ConfigMap, MySQL)
- File:
labelstore_test.go
(Renamed from labeler_test.go)- Test Updates: Tests for
ConfigMapHandler.GetLabels
- Config Changes:
- Removed
setupTestLabeler()
andteardown()
- Moved hard-coded labels into
ConfigMapHandler
instance
- Removed
- Test Cases:
- Tests for different user-group combinations
- Introduced "admin_group" test with skip flag
- Assertions:
- Checks expected labels and skip flag
- Tests:
- User and groups,
- User only,
- User with one group,
- User with non-matching group,
- Admin group with skip flag.
- Test Updates: Tests for
- File:
log.go
- New File: Introduces logging functionalities.
- Data Struct:
requestData
for HTTP request details. - Middleware:
loggingMiddleware
for HTTP request logging.- LogTokens: Configurable to log/redact request body.
- Helper Functions:
readBody
: Reads HTTP request body.logRequestData
: Logs HTTP request details.cleanSensitiveHeaders
: Removes sensitive headers.logAndWriteError
: Logs and writes errors.
- Logging Libraries: Uses
github.com/rs/zerolog/log
. - Security: Conditional redaction of sensitive info.
- Error Handling: In readBody and logRequestData.
- File:
main.go
- Structural Change: Introduced
App
struct, removed globalLogger
- Logging: Switched from
zap
tozerolog
- Initialization: New approach using
App
methods (WithConfig
,WithSAT
, etc.) - Server: Removed old
main()
,healthz
,reverseProxy
. IntroducedStartServer
inApp
struct. - Metrics: Re-configured using
slok/go-http-metrics
- Structural Change: Introduced
- File:
main_test.go
- Changes:
setupTestMain()
returnsApp
and tokensApp
andConfigMapHandler
introduced- Token-related test cases updated
- Additional test cases for Loki
- Tests:
- Headers, tokens, authorization
- Tenant access
- Loki query support
- Cleanup:
- Removed commented-out
defer
- Formatting and naming consistency
- Removed commented-out
- Changes:
- File:
routes.go
- Plugin header: Removed
x-pluging-id
routing. - Struct:
Route
struct withUrl
andMatchWord
. - WithHealthz: Adds health check and metrics routes (
/healthz
,/metrics
,/debug/pprof/
). - WithRoutes: Initializes new router, uses logging middleware, adds Loki and Thanos routes.
- WithLoki: Adds Loki API routes, warns if Loki URL not set (skips).
- WithThanos: Adds Thanos API routes, warns if Thanos URL not set (skips).
- handler: Orchestrates proxy behavior, performs OAuth token validation, conditional enforcement, and forwards requests.
- streamUp: Forwards request to upstream server using a reverse proxy.
- setHeader: Sets HTTP headers, optionally includes authorization.
- Logging: Uses
zerolog
for logging activities and errors. - Configurations: Reads settings like URLs, headers, and TLS flags from
a.Cfg
. - Error Handling: Various functions handle errors by logging and responding with appropriate HTTP statuses.
- Plugin header: Removed
- File:
structs.go
- Deleted: File removed
- File:
util.go
- Removed Functions:
ContainsIgnoreCase
,MapKeysToArray
,teardown
- Functionality: String comparison, map key extraction, teardown initConfig removed
- Changes: Code simplification, possibly moved functions
- Removed Functions:
- File:
README.md
- Updated: Updated with new instructions for building and running the proxy.