Skip to content

Add HTTPS option to prometheus endpoint #1652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2021

Conversation

soneillf5
Copy link
Contributor

Proposed changes

This change adds https as an option of the prometheus endpoint.

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto master
  • I will ensure my PR is targeting the master branch and pulling from my branch from my own fork

@github-actions github-actions bot added the enhancement Pull requests for new features/feature enhancements label Jun 8, 2021
@soneillf5 soneillf5 requested review from ciarams87 and pleshakov June 8, 2021 16:17
@pleshakov
Copy link
Contributor

Hi @soneillf5

The implementation looks good.

However, I think we can make it more integrated with Kubernetes and add some usability. The issue I see is how the admin will propagate the cert and key to the file system of the pod? Also consider our three installation methods: manifests, helm chart and the operator.

A good approach that would work well for all installation methods is for the admin to create a Secret with a TLS cert and key and pass its name as an Ingress Controller parameter. This would be similar to the -default-server-tls-secret or -wildcard-tls-secret command-line flags.

Could we have a similar -prometheus-tls-secret flag?

If it is set, the TLS will be enabled for Prometheus metrics and the IC will use the TLS cert and key from the referenced Secret. If the secret doesn't exist or it is invalid, the IC will fail to start with an error.

An extra feature here - supporting updating that secret - if the Secret is updated, the IC will start using the new version. This is something that we support for the default and the wildcard secrets. However, supporting updating will be more involved, and we can start with a simple implementation without it.

Regarding different installation methods:

  • For the manifests installation, the admin will need to create a TLS Secret and update the Ingress Controller deployment/daemonset to use it (the cli args). There are also annotations that are needed to be added as described here https://docs.nginx.com/nginx-ingress-controller/logging-and-monitoring/prometheus/#enabling-metrics
  • For Helm chart, we can add parameters similar to the parameters for the default server secret and the wildcard secret ( see controller.wildcardTLS.*). There is no need to provide the default value of the cert and key. Note that we already have prometheus.* parameter, so it makes sense to extend them. For example, prometheus.tls.cert, prometheus.tls.key and prometheus.tls.secret. If the prometheus.tls.secret, helm will configure the IC args to use the referenced secret. If ``prometheus.tls.certandprometheus.tls.key` are set, helm will create a Secret with those values and configure the IC args to use it.
  • For the Operator, we can add a field:
   prometheus:
     enable: true
     port: 9114
     tlsSecret: ns/name

Regarding documentation - we will need to document all new cli args, helm parameters, etc. It makes sense to mention that you can secure the Prometheus endpoint with TLS here https://docs.nginx.com/nginx-ingress-controller/logging-and-monitoring/prometheus/

Not tested, but we might need to add prometheus.io/scheme: https annotation to the pod template if TLS is enabled. For manifests installation, we can simply add and comment it out. For helm and operator, we will need to add it if the TLS is enabled for Prometheus.

While the operator lives in a separate repo and requires a separate PR, I mentioned it here for completeness.

@soneillf5 soneillf5 force-pushed the feature/prometheus-ssl-support branch from d706f25 to d7616e2 Compare June 9, 2021 15:12
@soneillf5
Copy link
Contributor Author

@pleshakov I've updated to use a Kubernetes Secret resource for the TLS cert data, I still need to add an automated test for it, but I've confirmed it works locally. I'll update the operator/helm/docs in the next few days too.

@soneillf5 soneillf5 force-pushed the feature/prometheus-ssl-support branch from d7616e2 to ddd22fe Compare June 9, 2021 15:15
@soneillf5 soneillf5 force-pushed the feature/prometheus-ssl-support branch from f642202 to a25151c Compare June 15, 2021 16:21
@github-actions github-actions bot added the documentation Pull requests/issues for documentation label Jun 15, 2021
@soneillf5 soneillf5 requested a review from pleshakov June 15, 2021 16:21
Copy link
Contributor

@pleshakov pleshakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @soneillf5

Could we also update this part https://docs.nginx.com/nginx-ingress-controller/logging-and-monitoring/prometheus/#enabling-metrics ? For example, you can make the second step there like this:
2. To enable TLS for the Prometheus endpoint, configure the -prometheus-tls-secret cli argument with the namespace and name of a TLS Secret.

Also, the prometheus.io/scheme: https annotation is required by the Prometheus to use TLS, we need to mention it the step 3 there.

@@ -310,3 +310,6 @@ prometheus:

## Configures the port to scrape the metrics.
port: 9113

## Specifies the namespace/name of a Kubernetes TLS Secret which will be used to protect the Prometheus endpoint.
secret: ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add the ability to configure the secret values? this is handy, as it allows the admins to define every part of the Ingress Controller installation through a helm chart.

For Helm chart, we can add parameters similar to the parameters for the default server secret and the wildcard secret ( see controller.wildcardTLS.*). There is no need to provide the default value of the cert and key. Note that we already have prometheus.* parameter, so it makes sense to extend them. For example, prometheus.tls.cert, prometheus.tls.key and prometheus.tls.secret. If the prometheus.tls.secret, helm will configure the IC args to use the referenced secret. If prometheus.tls.cert and prometheus.tls.key are set, helm will create a Secret with those values and configure the IC args to use it.
From #1652 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about helm, but putting the value of secrets into values.yaml doesn't seem like a good idea.

I only had a quick look around online a few blogs on the topic, so I'm not very knowledgable about it. it did seem like values.yaml is committed to version control, so that's one reason why it's not a good idea.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a few ways I see to keep those values protected:

  • a plugin to encrypt secret values https://itnext.io/helm-3-secrets-management-4f23041f05c3
  • have a separate values files only for secrets (helm install can take multiple values , for examle, helm install .. -f a.yaml -f b.yaml -f c.yaml) and not store it in the source control, but generate it during deployment
  • you can also configure all or some helm parameters via cli args, so helm can take the values for those parameters from env variables.

Allowing configuring secret values in the helm chart allows the admin to use the chart as a single source of truth -- so to install the Ingress Controller, you only need to run helm install ... and nothing else.

I think it is important to provide an alternative, so that secrets could be managed separately. That's why the secret parameter makes sense.

Copy link
Contributor Author

@soneillf5 soneillf5 Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand there are mitigations, such as additional values files and encryption and cli-args.

I still think it's not a good idea and I won't be adding secret values to this PR. If you'd like to block this PR based on this, let me know so we can do something to resolve it. @pleshakov

@soneillf5 soneillf5 requested a review from pleshakov June 16, 2021 14:11
@pleshakov
Copy link
Contributor

Hi @soneillf5 the changes look good

There are few remaining comments:
#1652 (comment)
#1652 (comment)
#1652 (comment)

@soneillf5 soneillf5 force-pushed the feature/prometheus-ssl-support branch from 79c98c3 to dc847c6 Compare June 17, 2021 13:22
Copy link
Contributor

@pleshakov pleshakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@soneillf5 soneillf5 force-pushed the feature/prometheus-ssl-support branch from dc847c6 to ea183ef Compare June 22, 2021 09:31
@soneillf5 soneillf5 merged commit cda6424 into master Jun 22, 2021
@soneillf5 soneillf5 deleted the feature/prometheus-ssl-support branch June 22, 2021 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Pull requests/issues for documentation enhancement Pull requests for new features/feature enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants