Skip to content

Commit a554146

Browse files
author
Jill Grant
authored
Merge pull request #274487 from Sohamdg081992/main
Update mtls doc , rearrange some parts
2 parents a4b8968 + 8aab5d3 commit a554146

File tree

1 file changed

+102
-53
lines changed

1 file changed

+102
-53
lines changed

articles/azure-monitor/containers/prometheus-metrics-scrape-configuration.md

Lines changed: 102 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ The new label also shows up in the cluster parameter dropdown in the Grafana das
118118
119119
> [!NOTE]
120120
> Only alphanumeric characters are allowed. Any other characters are replaced with `_`. This change is to ensure that different components that consume this label adhere to the basic alphanumeric convention.
121+
> If you are enabling recording and alerting rules, please make sure to use the cluster alias name in the cluster name parameter of the rule onboarding template for the rules to work.
121122
122123
### Debug mode
123124
@@ -458,58 +459,14 @@ metric_relabel_configs:
458459
459460
---
460461
461-
### TLS based scraping
462-
463-
If you have a Prometheus instance served with TLS and you want to scrape metrics from it, you need to set scheme to `https` and set the TLS settings in your configmap or respective CRD. You can use the `tls_config` configuration property inside a custom scrape job to configure the TLS settings either using a CRD or a configmap. You need to provide a CA certificate to validate API server certificate with. The CA certificate is used to verify the authenticity of the server's certificate when Prometheus connects to the target over TLS. It helps ensure that the server's certificate is signed by a trusted authority.
464-
465-
The secret should be created in kube-system namespace and then the configmap/CRD should be created in kube-system namespace. The order of secret creation matters. When there's no secret but a valid CRD/config map, you will find errors in collector log -> `no file found for cert....`
466462
467-
Below are the details about how to provide the TLS config settings through a configmap or CRD.
468-
469-
- To provide the TLS config setting in a configmap, please create the self-signed certificate and key inside your mtls enabled app.
470-
An example tlsConfig inside the config map should look like this:
471-
472-
```yaml
473-
tls_config:
474-
ca_file: /etc/prometheus/certs/client-cert.pem
475-
cert_file: /etc/prometheus/certs/client-cert.pem
476-
key_file: /etc/prometheus/certs/client-key.pem
477-
insecure_skip_verify: false
478-
```
479-
480-
- To provide the TLS config setting in a CRD, please create the self-signed certificate and key inside your mtls enabled app.
481-
An example tlsConfig inside a Podmonitor should look like this:
482-
483-
```yaml
484-
tlsConfig:
485-
ca:
486-
secret:
487-
key: "client-cert.pem" # since it is self-signed
488-
name: "ama-metrics-mtls-secret"
489-
cert:
490-
secret:
491-
key: "client-cert.pem"
492-
name: "ama-metrics-mtls-secret"
493-
keySecret:
494-
key: "client-key.pem"
495-
name: "ama-metrics-mtls-secret"
496-
insecureSkipVerify: false
497-
```
498-
> [!NOTE]
499-
> Make sure that the certificate file name and key name inside the mtls app is in the following format in case of a CRD based scraping.
500-
For example: secret_kube-system_ama-metrics-mtls-secret_cert-name.pem and secret_kube-system_ama-metrics-mtls-secret_key-name.pem.
501-
> The CRD needs to be created in kube-system namespace.
502-
> The secret name should exactly be ama-metrics-mtls-secret in kube-system namespace. An example command for creating secret: kubectl create secret generic ama-metrics-mtls-secret --from-file=secret_kube-system_ama-metrics-mtls-secret_client-cert.pem=secret_kube-system_ama-metrics-mtls-secret_client-cert.pem --from-file=secret_kube-system_ama-metrics-mtls-secret_client-key.pem=secret_kube-system_ama-metrics-mtls-secret_client-key.pem -n kube-system
503-
504-
To read more on TLS authentication, the following documents might be helpful.
505-
506-
- Generating TLS certificates -> https://o11y.eu/blog/prometheus-server-tls/
507-
- Configurations -> https://prometheus.io/docs/alerting/latest/configuration/#tls_config
508463
509464
### Basic Authentication
465+
### [Scrape Configs using Config file](#tab/ConfigFileScrapeConfigBasicAuth)
466+
510467
If you are using `basic_auth` setting in your prometheus configuration, please follow the steps -
511-
1. Create a secret in the **kube-system** namespace named **ama-metrics-mtls-secret**
512468

469+
1. Create a secret in the **kube-system** namespace named **ama-metrics-mtls-secret**
513470

514471
The value for password1 is **base64encoded**
515472
The key *password1* can be anything, but just needs to match your scrapeconfig *password_file* filepath.
@@ -524,6 +481,7 @@ type: Opaque
524481
data:
525482
password1: <base64-encoded-string>
526483
```
484+
The **ama-metrics-mtls-secret** secret is mounted on to the ama-metrics containers at path - **/etc/prometheus/certs/** and is made available to the process that is scraping prometheus metrics. The key( ex - password1) in the above example will be the file name and the value is base64 decoded and added to the contents of the file within the container and the prometheus scraper uses the contents of this file to get the value that is used as the password used to scrape the endpoint.
527485

528486
2. In the configmap for the custom scrape configuration use the following setting -
529487
```yaml
@@ -532,17 +490,108 @@ basic_auth:
532490
password_file: /etc/prometheus/certs/password1
533491
534492
```
493+
By providing the path to the password_file above, the prometheus scraper uses the contents of the file named password1 in the path /etc/prometheus/certs as the value of password for basic auth based scraping.
494+
495+
### [Scrape Configs using CRD(Pod/Service Monitor)](#tab/CRDScrapeConfigBasicAuth)
496+
Scraping targets using basic auth is currently not supported using pod/service monitors. Support for this will be added in the upcoming releases.
497+
498+
---
499+
500+
If you are using both basic auth and tls auth, please refer to the [section](#basic-auth-and-tls) below.
501+
For more details, refer to the [note section](#note) below.
502+
503+
504+
### TLS based scraping
505+
506+
If you have a Prometheus instance served with TLS and you want to scrape metrics from it, you need to set scheme to `https` and set the TLS settings in your configmap or respective CRD.
507+
Please follow the below steps.
508+
509+
1. Create a secret in the kube-system namespace named ama-metrics-mtls-secret. Each key-value pair specified in the data section of the secret object will be mounted as a separate file in this /etc/prometheus/certs location with filename(s) same as key(s) specified in the data section. The secret values should be base64 encoded before putting them under the data section, like below.
510+
511+
Below is an example of creating secret through YAML.
512+
513+
```yaml
514+
apiVersion: v1
515+
kind: Secret
516+
metadata:
517+
name: ama-metrics-mtls-secret
518+
namespace: kube-system
519+
type: Opaque
520+
data:
521+
<certfile>: base64_cert_content
522+
<keyfile>: base64_key_content
523+
```
524+
525+
The **ama-metrics-mtls-secret** secret is mounted on to the ama-metrics containers at path - **/etc/prometheus/certs/** and is made available to the process that is scraping prometheus metrics. The key( ex - certfile) in the above example will be the file name and the value is base64 decoded and added to the contents of the file within the container and the prometheus scraper uses the contents of this file to get the value that is used as the password used to scrape the endpoint.
526+
527+
528+
2. Below are the details about how to provide the TLS config settings through a configmap or CRD.
529+
530+
### [Scrape Config using Config File](#tab/ConfigFileScrapeConfigTLSAuth)
531+
532+
- To provide the TLS config setting in a configmap, please follow the below example.
533+
534+
```yaml
535+
tls_config:
536+
ca_file: /etc/prometheus/certs/<certfile> # since it is self-signed
537+
cert_file: /etc/prometheus/certs/<certfile>
538+
key_file: /etc/prometheus/certs/<keyfile>
539+
insecure_skip_verify: false
540+
```
541+
542+
### [Scrape Config using CRD(Pod/Service Monitor)](#tab/CRDScrapeConfigTLSAuth)
543+
544+
- To provide the TLS config setting in a CRD(Pod/Service Monitor), please follow the below example.
545+
546+
```yaml
547+
tlsConfig:
548+
ca:
549+
secret:
550+
key: "<certfile>" # since it is self-signed
551+
name: "ama-metrics-mtls-secret"
552+
cert:
553+
secret:
554+
key: "<certfile>"
555+
name: "ama-metrics-mtls-secret"
556+
keySecret:
557+
key: "<keyfile>"
558+
name: "ama-metrics-mtls-secret"
559+
insecureSkipVerify: false
560+
```
535561

562+
---
563+
564+
565+
### Basic Auth and TLS
566+
567+
If you want to use both basic and Tls authentication settings in your configmap/CRD, just make sure that the secret **ama-metrics-mtls-secret** includes all the files(keys) under the data section with their corresponding base 64 encoded values, as shown below.
568+
569+
```yaml
570+
apiVersion: v1
571+
kind: Secret
572+
metadata:
573+
name: ama-metrics-mtls-secret
574+
namespace: kube-system
575+
type: Opaque
576+
data:
577+
certfile: base64_cert_content # used for Tls
578+
keyfile: base64_key_content # used for Tls
579+
password1: base64-encoded-string # used for basic auth
580+
password2: base64-encoded-string # used for basic auth
581+
```
582+
583+
### Note
536584
> [!NOTE]
537-
>
538-
> Make sure the name is **ama-metrics-mtls-secret** and it is in **kube-system** namespace.
539-
>
540-
> The **/etc/prometheus/certs/** path is mandatory, but *password1* can be any string and needs to match the key for the data in the secret created above.
541-
This is because the secret **ama-metrics-mtls-secret** is mounted in the path **/etc/prometheus/certs/** within the container.
585+
>
586+
> The **/etc/prometheus/certs/** path is mandatory, but *password1* can be any string and needs to match the key for the data in the secret created above. This is because the secret **ama-metrics-mtls-secret** is mounted in the path **/etc/prometheus/certs/** within the container.
542587
>
543588
> The base64 encoded value is automatically decoded by the agent pods when the secret is mounted as file.
544589
>
545-
> Any other configuration setting for authorization that is considered as a secret in the [prometheus configuration](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config) needs to use the file setting alternative instead as described above.
590+
> Make sure the secret name is **ama-metrics-mtls-secret** and it is in **kube-system** namespace.
591+
>
592+
> The secret should be created and then the configmap/CRD should be created in kube-system namespace. The order of secret creation matters. When there's no secret but a valid CRD/config map, you will find errors in collector log -> `no file found for cert....`
593+
>
594+
> To read more on TLS configuration settings, please follow this [Configurations](https://aka.ms/tlsconfigsetting).
546595

547596
## Next steps
548597

0 commit comments

Comments
 (0)