vmauth
is an HTTP proxy, which can authorize, route
and load balance requests across VictoriaMetrics components
or any other HTTP backends.
Quick start #
Just download vmutils-*
archive from releases page, unpack it
and pass the following flag to vmauth
binary in order to start authorizing and proxying requests:
|
|
The -auth.config
command-line flag must point to valid config. See use cases with typical -auth.config
examples.
vmauth
accepts HTTP requests on port 8427
and proxies them according to the provided -auth.config.
The port can be modified via -httpListenAddr
command-line flag.
See how to reload config without restart.
Docker images for vmauth
are available at Docker Hub and Quay.
See how vmauth
used in docker-compose env.
Pass -help
to vmauth
in order to see all the supported command-line flags with their descriptions.
Feel free contacting us if you need customized auth proxy for VictoriaMetrics with the support of LDAP, SSO, RBAC, SAML, accounting and rate limiting such as vmgateway.
Use cases #
- Simple HTTP proxy
- Generic HTTP proxy for different backends
- Generic HTTP load balancer
- Load balancer for vmagent
- Load balancer for VictoriaMetrics cluster
- High availability
- TLS termination proxy
- Basic Auth proxy
- Bearer Token auth proxy
- Per-tenant authorization
- mTLS-based request routing
- Enforcing query args
Simple HTTP proxy #
The following -auth.config
instructs vmauth
to proxy all the incoming requests to the given backend.
For example, requests to http://vmauth:8427/foo/bar
are proxied to http://backend/foo/bar
:
|
|
vmauth
can balance load among multiple backends - see these docs for details.
See also authorization and routing docs.
Generic HTTP proxy for different backends #
vmauth
can proxy requests to different backends depending on the requested path, query args and any HTTP request header.
For example, the following -auth.config
instructs vmauth
to make the following:
- Requests starting with
/app1/
are proxied tohttp://app1-backend/
, while the/app1/
path prefix is dropped according todrop_src_path_prefix_parts
. For example, the request tohttp://vmauth:8427/app1/foo/bar?baz=qwe
is proxied tohttp://app1-backend/foo/bar?baz=qwe
. - Requests starting with
/app2/
are proxied tohttp://app2-backend/
, while the/app2/
path prefix is dropped according todrop_src_path_prefix_parts
. For example, the request tohttp://vmauth:8427/app2/index.html
is proxied tohttp://app2-backend/index.html
. - Other requests are proxied to
http://default-backed/
.
|
|
Sometimes it is needed to proxy all the requests, which do not match url_map
, to a special 404
page, which could count invalid requests.
Use default_url
for this case. For example, the following -auth.config
instructs vmauth
sending all the requests,
which do not match url_map
, to the http://some-backend/404-page.html
page. The requested path is passed via request_path
query arg.
For example, the request to http://vmauth:8427/foo/bar?baz=qwe
is proxied to http://some-backend/404-page.html?request_path=%2Ffoo%2Fbar%3Fbaz%3Dqwe
.
|
|
See routing docs for details.
See also authorization and load balancing docs.
Generic HTTP load balancer #
vmauth
can balance load among multiple HTTP backends in least-loaded round-robin mode.
For example, the following -auth.config
instructs vmauth
to spread load among multiple application instances:
|
|
See load balancing docs for more details.
See also authorization and routing docs.
Load balancer for vmagent #
If vmagent is used for processing data push requests,
then it is possible to scale the performance of data processing at vmagent
by spreading load among multiple identically configured vmagent
instances.
This can be done with the following config for vmauth
:
|
|
See load balancing docs for more details.
See also authorization and routing docs.
Load balancer for VictoriaMetrics cluster #
VictoriaMetrics cluster accepts incoming data via vminsert
nodes
and processes incoming requests via vmselect
nodes according to these docs.
vmauth
can be used for balancing both insert
and select
requests among vminsert
and vmselect
nodes, when the following -auth.config
is used:
|
|
See load balancing docs for more details.
See also authorization and routing docs.
High availability #
vmauth
automatically switches from temporarily unavailable backend to other hot standby backends listed in url_prefix
if it runs with -loadBalancingPolicy=first_available
command-line flag. The load balancing policy can be overridden at user
and url_map
sections
of -auth.config
via load_balancing_policy
option. For example, the following config instructs vmauth
to proxy requests to http://victoria-metrics-main:8428/
backend.
If this backend becomes unavailable, then vmauth
starts proxying requests to http://victoria-metrics-standby1:8428/
.
If this backend becomes also unavailable, then requests are proxied to the last specified backend - http://victoria-metrics-standby2:8428/
:
|
|
See load-balancing docs for more details.
See also authorization and routing docs.
TLS termination proxy #
vmauth
can terminate HTTPS requests to backend services when it runs with the following command-line flags:
|
|
-httpListenAddr
sets the address to listen for incoming HTTPS requests-tls
enables accepting TLS connections at-httpListenAddr
-tlsKeyFile
sets the path to TLS certificate key file-tlsCertFile
sets the path to TLS certificate file
See also automatic issuing of TLS certificates.
See also authorization, routing and load balancing docs.
Basic Auth proxy #
vmauth
can authorize access to backends depending on the provided Basic Auth request headers.
For example, the following config proxies requests to single-node VictoriaMetrics
if they contain Basic Auth header with the given username
and password
:
|
|
See also authorization, routing and load balancing docs.
Bearer Token auth proxy #
vmauth
can authorize access to backends depending on the provided Bearer Token
request headers.
For example, the following config proxies requests to single-node VictoriaMetrics
if they contain the given bearer_token
:
|
|
See also authorization, routing and load balancing docs.
Per-tenant authorization #
The following -auth.config
instructs proxying insert
and select
requests from the Basic Auth
user tenant1
to the tenant 1
,
while requests from the user tenant2
are sent to tenant 2
:
|
|
See also authorization, routing and load balancing docs.
mTLS-based request routing #
Enterprise version of vmauth
can be configured for routing requests
to different backends depending on the following subject fields in the TLS certificate provided by client:
organizational_unit
akaOU
organization
akaO
common_name
akaCN
For example, the following -auth.config
routes requests from clients with organizational_unit: finance
TLS certificates
to http://victoriametrics-finance:8428
backend, while requests from clients with organizational_unit: devops
TLS certificates
are routed to http://victoriametrics-devops:8428
backend:
|
|
mTLS protection must be enabled for mTLS-based routing.
See also authorization, routing and load balancing docs.
Enforcing query args #
vmauth
can be configured for adding some mandatory query args before proxying requests to backends.
For example, the following config adds extra_label
to all the requests, which are proxied to single-node VictoriaMetrics:
|
|
See also authorization, routing and load balancing docs.
Dropping request path prefix #
By default vmauth
doesn’t drop the path prefix from the original request when proxying the request to the matching backend.
Sometimes it is needed to drop path prefix before proxying the request to the backend. This can be done by specifying the number of /
-delimited
prefix parts to drop from the request path via drop_src_path_prefix_parts
option at url_map
level or at user
level or -auth.config
.
For example, if you need serving requests to vmalert at /vmalert/
path prefix,
while serving requests to vmagent at /vmagent/
path prefix,
then the following -auth.config can be used:
|
|
Authorization #
vmauth
supports the following authorization mechanisms:
- No authorization
- Basic Auth
- Bearer token
- Client TLS certificate verification aka mTLS
- Auth tokens via Arbitrary HTTP request headers
See also security docs, routing docs and load balancing docs.
Routing #
vmauth
can proxy requests to different backends depending on the following parts of HTTP request:
See also authorization and load balancing.
For debug purposes, extra logging for failed requests can be enabled by setting dump_request_on_errors: true
Available from v1.107.0
on user level. Please note, such logging may expose sensitive info and is recommended to use only for debugging.
Routing by path #
src_paths
option can be specified inside url_map
in order to route requests by path.
The following -auth.config
routes requests to paths starting with /app1/
to http://app1-backend
,
while requests with paths starting with /app2
are routed to http://app2-backend
, and the rest of requests
are routed to http://some-backend/404-page.html
:
|
|
src_paths
accepts a list of regular expressions. The incoming request is routed to the given url_prefix
if the whole requested path matches at least one src_paths
entry.
See also how to drop request path prefix.
Routing by host #
src_hosts
option can be specified inside url_map
in order to route requests by host header.
The following -auth.config
routes requests to app1.my-host.com
host to http://app1-backend
, while routing requests to app2.my-host.com
host to http://app2-backend
,
and the rest of requests are routed to http://some-backend/404-page.html
:
|
|
src_hosts
accepts a list of regular expressions. The incoming request is routed to the given url_prefix
if the whole request host matches at least one src_hosts
entry.
Routing by query arg #
src_query_args
option can be specified inside url_map
in order to route requests by the given query arg.
For example, the following -auth.config
routes requests to http://app1-backend/
if db=foo
query arg is present in the request,
while routing requests with db
query arg starting with bar
to http://app2-backend
, and the rest of requests are routed to http://some-backend/404-page.html
:
|
|
src_query_args
accepts a list of strings in the format arg=value
or arg=~regex
. The arg=value
format means exact matching of the whole arg
query arg value to the given value
.
The arg=~regex
format means regex matching of the whole arg
query arg value to the given regex
.
If at least a single query arg in the request matches at least one src_query_args
entry, then the request is routed to the given url_prefix
.
Routing by header #
src_headers
option can be specified inside url_map
in order to route requests by the given HTTP request header.
For example, the following -auth.config
routes requests to http://app1-backend
if TenantID
request header equals to 42
, while routing requests to http://app2-backend
if TenantID
request header equals to 123:456
, and the rest of requests are routed to http://some-backend/404-page.html
:
|
|
If src_headers
contains multiple entries, then it is enough to match only a single entry in order to route the request to the given url_prefix
.
Routing by multiple parts #
Any subset of src_paths
, src_hosts
, src_query_args
and src_headers
options can be specified simultaneously in a single url_map
entry. In this case the request is routed to the given url_prefix
if the request matches
all the provided configs simultaneously.
For example, the following -auth.config
routes requests to http://app1-backend
if all the conditions mentioned below are simultaneously met:
- the request path starts with
/app/
- the requested hostname ends with
.bar.baz
- the request contains
db=abc
query arg - the
TenantID
request header equals to42
|
|
Load balancing #
Each url_prefix
in the -auth.config can be specified in the following forms:
A single url. For example:
1 2
unauthorized_user: url_prefix: 'http://vminsert:8480/insert/0/prometheus/`
In this case
vmauth
proxies requests to the specified url.A list of urls. For example:
1 2 3 4 5
unauthorized_user: url_prefix: - 'http://vminsert-1:8480/insert/0/prometheus/' - 'http://vminsert-2:8480/insert/0/prometheus/' - 'http://vminsert-3:8480/insert/0/prometheus/'
In this case
vmauth
spreads requests among the specified urls using least-loaded round-robin policy. This guarantees that incoming load is shared uniformly among the specified backends. See also discovering backend IPs.vmauth
automatically detects temporarily unavailable backends and spreads incoming queries among the remaining available backends. This allows restarting the backends and performing maintenance tasks on the backends without the need to remove them from theurl_prefix
list.By default
vmauth
returns backend responses with all the http status codes to the client. It is possible to configure automatic retry of requests at other backends if the backend responds with status code specified in the-retryStatusCodes
command-line flag. It is possible to customize the list of http response status codes to retry viaretry_status_codes
list atuser
andurl_map
level of-auth.config
. For example, the following config re-tries requests on other backends if the current backend returns response with500
or502
HTTP status code:1 2 3 4 5 6
unauthorized_user: url_prefix: - http://vmselect1:8481/ - http://vmselect2:8481/ - http://vmselect3:8481/ retry_status_codes: [500, 502]
By default
vmauth
usesleast_loaded
policy for spreading incoming requests among available backends. The policy can be changed tofirst_available
via-loadBalancingPolicy
command-line flag. In this casevmauth
sends all the requests to the first specified backend while it is available.vmauth
starts sending requests to the next specified backend when the first backend is temporarily unavailable. It is possible to customize the load balancing policy at theuser
andurl_map
level. For example, the following config specifiesfirst_available
load balancing policy for unauthorized requests:1 2 3 4 5
unauthorized_user: url_prefix: - http://victoria-metrics-main:8428/ - http://victoria-metrics-standby:8428/ load_balancing_policy: first_available
Load balancing feature can be used in the following cases:
Balancing the load among multiple
vmselect
and/orvminsert
nodes in VictoriaMetrics cluster. The following-auth.config
can be used for spreading incoming requests among 3 vmselect nodes and re-trying failed requests or requests with 500 and 502 response status codes:1 2 3 4 5 6
unauthorized_user: url_prefix: - http://vmselect1:8481/ - http://vmselect2:8481/ - http://vmselect3:8481/ retry_status_codes: [500, 502]
Sending select queries to the closest availability zone (AZ), while falling back to other AZs with identical data if the closest AZ is unavailable. For example, the following
-auth.config
sends select queries tohttps://vmselect-az1/
and uses thehttps://vmselect-az2/
as a fallback whenhttps://vmselect-az1/
is temporarily unavailable or cannot return full responses. See these docs for details aboutdeny_partial_response
query arg, which is added to requests before they are proxied to backends.1 2 3 4 5 6
unauthorized_user: url_prefix: - https://vmselect-az1/?deny_partial_response=1 - https://vmselect-az2/?deny_partial_response=1 retry_status_codes: [500, 502, 503] load_balancing_policy: first_available
Load balancing can be configured independently per each user
entry and per each url_map
entry. See auth config docs for more details.
See also discovering backend IPs, authorization and routing.
Discovering backend IPs #
By default vmauth
spreads load among the listed backends at url_prefix
as described in load balancing docs.
Sometimes multiple backend instances can be hidden behind a single hostname. For example, vmselect-service
hostname
may point to a cluster of vmselect
instances in VictoriaMetrics cluster setup.
So the following config may fail spreading load among available vmselect
instances, since vmauth
will send all the requests to the same url, which may end up
to a single backend instance:
|
|
There are the following solutions for this issue:
To enumerate every
vmselect
hosname or IP in theurl_prefix
list:1 2 3 4 5
unauthorized_user: url_prefix: - http://vmselect-1:8481/select/0/prometheus/ - http://vmselect-2:8481/select/0/prometheus/ - http://vmselect-3:8481/select/0/prometheus/
This scheme works great, but it needs manual updating of the
-auth.config
every timevmselect
services are restarted, downscaled or upscaled.To set
discover_backend_ips: true
option, sovmauth
automatically discovers IPs behind the given hostname and then spreads load among the discovered IPs:1 2 3
unauthorized_user: url_prefix: http://vmselect-service:8481/select/0/prometheus/ discover_backend_ips: true
If the
url_prefix
contains hostname withsrv+
prefix, then the hostname withoutsrv+
prefix is automatically resolved via DNS SRV to the list of hostnames with TCP ports, andvmauth
balances load among the discovered TCP addresses:1 2 3
unauthorized_user: url_prefix: "http://srv+vmselect/select/0/prometheus" discover_backend_ips: true
This functionality is useful for balancing load among backend instances, which run on different TCP ports, since DNS SRV records contain TCP ports.
The
discover_backend_ips
option can be specified atuser
andurl_map
level in the-auth.config
. It can also be enabled globally via-discoverBackendIPs
command-line flag.
See also load balancing docs.
SRV urls #
If url_prefix
contains url with the hostname starting with srv+
prefix, then vmauth
uses DNS SRV lookup
for the hostname without the srv+
prefix and selects random TCP address (e.g. hostname plus TCP port) form the resolved results.
For example, if some-addr
DNS SRV record contains some-host:12345
TCP address,
then url_prefix: http://srv+some-addr/some/path
is automatically resolved into url_prefix: http://some-host:12345/some/path
.
The DNS SRV resolution is performed every time new connection to the url_prefix
backend is established.
See also discovering backend addresses.
Modifying HTTP headers #
vmauth
supports the ability to set and remove HTTP request headers before sending the requests to backends.
This is done via headers
option. For example, the following -auth.config
sets TenantID: foobar
header
to requests proxied to http://backend:1234/
. It also overrides X-Forwarded-For
request header with an empty value. This effectively
removes the X-Forwarded-For
header from requests proxied to http://backend:1234/
:
|
|
vmauth
also supports the ability to set and remove HTTP response headers before returning the response from the backend to client.
This is done via response_headers
option. For example, the following -auth.config
sets Foo: bar
response header
and removes Server
response header before returning the response to client:
|
|
See also Host
header docs.
Host HTTP header #
By default vmauth
sets the Host
HTTP header to the backend hostname when proxying requests to the corresponding backend.
Sometimes it is needed to keep the original Host
header from the client request sent to vmauth
. For example, if backends use host-based routing.
In this case set keep_original_host: true
. For example, the following config instructs to use the original Host
header from client requests
when proxying requests to the backend:1234
:
|
|
It is also possible to set the Host
header to arbitrary value when proxying the request to the configured backend, via headers
option:
|
|
Config reload #
vmauth
supports dynamic reload of -auth.config
via the following ways:
- By sending
SIGHUP
signal tovmauth
process:1
kill -HUP `pidof vmauth`
- By querying
/-/reload
endpoint. It is recommended protecting it with-reloadAuthKey
. See security docs for details. - By passing the interval for config check to
-configCheckInterval
command-line flag.
Concurrency limiting #
vmauth
may limit the number of concurrent requests according to the following command-line flags:
-maxConcurrentRequests
limits the global number of concurrent requestsvmauth
can serve across all the configured users.-maxConcurrentPerUserRequests
limits the number of concurrent requestsvmauth
can serve per each configured user.
It is also possible to set individual limits on the number of concurrent requests per each user
with the max_concurrent_requests
option. For example, the following -auth.config
limits the number of concurrent requests from the user foo
to 10:
|
|
vmauth
responds with 429 Too Many Requests
HTTP error when the number of concurrent requests exceeds the configured limits.
The following metrics related to concurrency limits are exposed by vmauth
:
vmauth_concurrent_requests_capacity
- the global limit on the number of concurrent requestsvmauth
can serve. It is set via-maxConcurrentRequests
command-line flag.vmauth_concurrent_requests_current
- the current number of concurrent requestsvmauth
processes.vmauth_concurrent_requests_limit_reached_total
- the number of requests rejected with429 Too Many Requests
error because of the global concurrency limit has been reached.vmauth_user_concurrent_requests_capacity{username="..."}
- the limit on the number of concurrent requests for the givenusername
.vmauth_user_concurrent_requests_current{username="..."}
- the current number of concurrent requests for the givenusername
.vmauth_user_concurrent_requests_limit_reached_total{username="..."}
- the number of requests rejected with429 Too Many Requests
error because of the concurrency limit has been reached for the givenusername
.vmauth_unauthorized_user_concurrent_requests_capacity
- the limit on the number of concurrent requests for unauthorized users (ifunauthorized_user
section is used).vmauth_unauthorized_user_concurrent_requests_current
- the current number of concurrent requests for unauthorized users (ifunauthorized_user
section is used).vmauth_unauthorized_user_concurrent_requests_limit_reached_total
- the number of requests rejected with429 Too Many Requests
error because of the concurrency limit has been reached for unauthorized users (ifunauthorized_user
section is used).
Backend TLS setup #
By default vmauth
uses system settings when performing requests to HTTPS backends specified via url_prefix
option
in the -auth.config
. These settings can be overridden with the following command-line flags:
-backend.tlsInsecureSkipVerify
allows skipping TLS verification when connecting to HTTPS backends. This global setting can be overridden at per-user level inside-auth.config
viatls_insecure_skip_verify
option. For example:1 2 3
- username: "foo" url_prefix: "https://localhost" tls_insecure_skip_verify: true
-backend.tlsCAFile
allows specifying the path to TLS Root CA for verifying backend TLS certificates. This global setting can be overridden at per-user level inside-auth.config
viatls_ca_file
option. For example:1 2 3
- username: "foo" url_prefix: "https://localhost" tls_ca_file: "/path/to/tls/root/ca"
-backend.tlsCertFile
and-backend.tlsKeyFile
allows specifying client TLS certificate for passing in requests to HTTPS backends, so these certificate could be verified at the backend side (aka mTLS). This global setting can be overridden at per-user level inside-auth.config
viatls_cert_file
andtls_key_file
options. For example:1 2 3 4
- username: "foo" url_prefix: "https://localhost" tls_cert_file: "/path/to/tls/cert" tls_key_file: "/path/to/tls/key"
-backend.tlsServerName
allows specifying optional TLS ServerName for passing in requests to HTTPS backends. This global setting can be overridden at per-user level inside-auth.config
viatls_server_name
option. For example:1 2 3
- username: "foo" url_prefix: "https://localhost" tls_server_name: "foo.bar.com"
The -backend.tlsCAFile
, -backend.tlsCertFile
, -backend.tlsKeyFile
, tls_ca_file
, tls_cert_file
and tls_key_file
may point either to local file or to http
/ https
url.
The file is checked for modifications every second and is automatically re-read when it is updated.
IP filters #
Enterprise version of vmauth
can be configured to allow / deny incoming requests via global and per-user IP filters.
For example, the following config allows requests to vmauth
from 10.0.0.0/24
network and from 1.2.3.4
IP address, while denying requests from 10.0.0.42
IP address:
|
|
The following config allows requests for the user foobar
only from the IP 127.0.0.1
:
|
|
By default, the client’s TCP address is utilized for IP filtering. In scenarios where vmauth
operates behind a reverse proxy, it is advisable to configure vmauth
to retrieve the client IP address from an HTTP header (e.g., X-Forwarded-For
)
Available from v1.107.0
or via the Proxy Protocol for TCP load balancers. This can be achieved using the global configuration flags:
-httpRealIPHeader=X-Forwarded-For
Available from v1.107.0-httpListenAddr.useProxyProtocol=true
Security Considerations #
HTTP headers are inherently untrustworthy. It is strongly recommended to implement additional security measures, such as:
- Dropping
X-Forwarded-For
headers at the internet-facing reverse proxy (e.g., before traffic reachesvmauth
). - Do not use
-httpRealIPHeader
at internet-facingvmauth
. - Add
removeXFFHTTPHeaderValue
for the internet-facingvmauth
. It instructsvmauth
to replace value ofX-Forwarded-For
HTTP header withremoteAddr
of the client.
See additional recommendations at link
Per-User Configuration #
The values of httpRealIPHeader
Available from v1.107.0
can be changed on a per-user basis within the user-specific configuration.
|
|
See config example of using IP filters here.
Reading auth tokens from other HTTP headers #
vmauth
reads username
, password
and bearer_token
config values from Authorization
request header.
It is possible to read these auth tokens from any other request header by specifying it via -httpAuthHeader
command-line flag.
For example, the following command instructs vmauth
to read auth token from X-Amz-Firehose-Access-Key
header:
|
|
It is possible to read auth tokens from multiple headers. For example, the following command instructs vmauth
to read auth token
from both Authorization
and X-Amz-Firehose-Access-Key
headers:
|
|
See also authorization docs and security docs.
Auth config #
-auth.config
is represented in the following yml
format:
|
|
The config may contain %{ENV_VAR}
placeholders, which are substituted by the corresponding ENV_VAR
environment variable values.
This may be useful for passing secrets to the config.
mTLS protection #
By default vmauth
accepts http requests at 8427
port (this port can be changed via -httpListenAddr
command-line flags).
Enterprise version of vmauth supports the ability to accept mTLS
requests at this port, by specifying -tls
and -mtls
command-line flags. For example, the following command runs vmauth
, which accepts only mTLS requests at port 8427
:
|
|
By default system-wide TLS Root CA is used for verifying client certificates if -mtls
command-line flag is specified.
It is possible to specify custom TLS Root CA via -mtlsCAFile
command-line flag.
See also automatic issuing of TLS certificates and mTLS-based request routing.
Security #
It is expected that all the backend services protected by vmauth
are located in an isolated private network, so they can be accessed by external users only via vmauth
.
Do not transfer auth headers in plaintext over untrusted networks. Enable https at -httpListenAddr
. This can be done by passing the following -tls*
command-line flags to vmauth
:
|
|
See also automatic issuing of TLS certificates.
See these docs on how to enable mTLS protection at vmauth
.
Alternatively, TLS termination proxy may be put in front of vmauth
.
It is recommended protecting the following endpoints with authKeys:
/-/reload
with-reloadAuthKey
command-line flag, so external users couldn’t trigger config reload./flags
with-flagsAuthKey
command-line flag, so unauthorized users couldn’t get command-line flag values./metrics
with-metricsAuthKey
command-line flag, so unauthorized users couldn’t access vmauth metrics./debug/pprof
with-pprofAuthKey
command-line flag, so unauthorized users couldn’t access profiling information.
As an alternative, it’s possible to serve internal API routes at the different listen address with command-line flag -httpInternalListenAddr=127.0.0.1:8426
.
Available from v1.111.0
vmauth
also supports the ability to restrict access by IP - see these docs. See also concurrency limiting docs.
Automatic issuing of TLS certificates #
vmauth
Enterprise supports automatic issuing of TLS certificates via Let’s Encrypt service.
The following command-line flags must be set in order to enable automatic issuing of TLS certificates:
-httpListenAddr
must be set for listening TCP port443
. For example,-httpListenAddr=:443
. This port must be accessible by the Let’s Encrypt service.-tls
must be set in order to accept HTTPS requests at-httpListenAddr
. Note that-tlcCertFile
and-tlsKeyFile
aren’t needed when automatic TLS certificate issuing is enabled.-tlsAutocertHosts
must be set to comma-separated list of hosts, which can be reached via-httpListenAddr
. TLS certificates are automatically issued for these hosts.-tlsAutocertEmail
must be set to contact email for the issued TLS certificates.-tlsAutocertCacheDir
may be set to the directory path for persisting the issued TLS certificates betweenvmauth
restarts. If this flag isn’t set, then TLS certificates are re-issued on every restart.
This functionality can be evaluated for free according to these docs.
See also security recommendations.
Monitoring #
vmauth
exports various metrics in Prometheus exposition format at http://vmauth-host:8427/metrics
page. It is recommended setting up regular scraping of this page
either via vmagent or via Prometheus-compatible scraper, so the exported metrics could be analyzed later.
Use the official Grafana dashboard and alerting rules
for vmauth
monitoring.
If you use Google Cloud Managed Prometheus for scraping metrics from VictoriaMetrics components, then pass -metrics.exposeMetadata
command-line to them, so they add TYPE
and HELP
comments per each exposed metric at /metrics
page.
See these docs for details.
vmauth
exports the following metrics per each defined user in -auth.config
:
vmauth_user_requests_total
counter - the number of requests served for the givenusername
vmauth_user_request_backend_errors_total
counter - the number of request errors for the givenusername
vmauth_user_request_duration_seconds
summary - the duration of requests for the givenusername
vmauth_user_concurrent_requests_limit_reached_total
counter - the number of failed requests for the givenusername
because of exceeded concurrency limitsvmauth_user_concurrent_requests_capacity
gauge - the maximum number of concurrent requests for the givenusername
vmauth_user_concurrent_requests_current
gauge - the current number of concurrent requests for the givenusername
By default, per-user metrics contain only username
label. This label is set to username
field value at the corresponding user section in the -auth.config
file.
It is possible to override the username
label value by specifying name
field additionally to username
field.
For example, the following config will result in vmauth_user_requests_total{username="foobar"}
instead of vmauth_user_requests_total{username="secret_user"}
:
|
|
Additional labels for per-user metrics can be specified via metric_labels
section. For example, the following config
defines {dc="eu",team="dev"}
labels additionally to username="foobar"
label:
|
|
vmauth
exports the following metrics if unauthorized_user
section is defined in -auth.config
:
vmauth_unauthorized_user_requests_total
counter - the number of unauthorized requests servedvmauth_unauthorized_user_request_backend_errors_total
counter - the number of unauthorized request errorsvmauth_unauthorized_user_request_duration_seconds
summary - the duration of unauthorized requestsvmauth_unauthorized_user_concurrent_requests_limit_reached_total
counter - the number of failed unauthorized requests because of exceeded concurrency limitsvmauth_unauthorized_user_concurrent_requests_capacity
gauge - the maximum number of concurrent unauthorized requestsvmauth_unauthorized_user_concurrent_requests_current
gauge - the current number of concurrent unauthorized requests
How to build from sources #
It is recommended using binary releases - vmauth
is located in vmutils-*
archives there.
Development build #
- Install Go. The minimum supported version is Go 1.22.
- Run
make vmauth
from the root folder of the repository. It buildsvmauth
binary and puts it into thebin
folder.
Production build #
- Install docker.
- Run
make vmauth-prod
from the root folder of the repository. It buildsvmauth-prod
binary and puts it into thebin
folder.
Building docker images #
Run make package-vmauth
. It builds victoriametrics/vmauth:<PKG_TAG>
docker image locally.
<PKG_TAG>
is auto-generated image tag, which depends on source code in the repository.
The <PKG_TAG>
may be manually set via PKG_TAG=foobar make package-vmauth
.
The base docker image is alpine but it is possible to use any other base image
by setting it via <ROOT_IMAGE>
environment variable. For example, the following command builds the image on top of scratch image:
|
|
Profiling #
vmauth
provides handlers for collecting the following Go profiles:
- Memory profile. It can be collected with the following command (replace
0.0.0.0
with hostname if needed):
|
|
- CPU profile. It can be collected with the following command (replace
0.0.0.0
with hostname if needed):
|
|
The command for collecting CPU profile waits for 30 seconds before returning.
The collected profiles may be analyzed with go tool pprof. It is safe sharing the collected profiles from security point of view, since they do not contain sensitive information.
Advanced usage #
Pass -help
command-line arg to vmauth
in order to see all the configuration options:
|
|