Repository navigation
Reference secrets instead of local files (cont. #2524) - #2716
Conversation
befc90c to
423403d
Compare
lilic
left a comment
There was a problem hiding this comment.
Just had a quick look at this.
| // attack, users can instead use the BearerTokenSecret field. | ||
| type ArbitraryFSAccessThroughSMsConfig struct { | ||
| Deny bool | ||
| // TODO: To be implemented. |
There was a problem hiding this comment.
When do we want to implement this?
There was a problem hiding this comment.
I think the idea was to implement this as a follow up. How about we instead of having this TODO here, we open an issue?
| for namespaceAndName, sm := range res { | ||
| for _, endpoint := range sm.Spec.Endpoints { | ||
| if err := testForArbitraryFSAccess(endpoint); err != nil { | ||
| delete(res, namespaceAndName) |
There was a problem hiding this comment.
Why do we need to delete the entries from res here?
There was a problem hiding this comment.
We want to deny ServiceMonitors which are not allowed to access filesystem
brancz
left a comment
There was a problem hiding this comment.
A few comments, but I think generally we're already pretty close. Nice work!
| // attack, users can instead use the BearerTokenSecret field. | ||
| type ArbitraryFSAccessThroughSMsConfig struct { | ||
| Deny bool | ||
| // TODO: To be implemented. |
There was a problem hiding this comment.
I think the idea was to implement this as a follow up. How about we instead of having this TODO here, we open an issue?
| CAFile string `json:"caFile,omitempty"` | ||
| // The client cert file for the targets. | ||
| // Secret containing the CA cert to use for the targets. | ||
| CASecret *v1.SecretKeySelector `json:"caSecret,omitempty"` |
There was a problem hiding this comment.
At least for our own usage we'll already require this to be a configmap instead. I think we'll need to for everything where we use a secretkeyselector right now, instead do either configmapkeyselector or secretkeyselector.
59d2cc0 to
599b70d
Compare
|
Is this ready for another review? |
|
@lilic sorry for the long wait, it is ready for next review. /cc @s-urbaniak |
| } | ||
|
|
||
| cfg = addTLStoYaml(cfg, am.TLSConfig) | ||
| // TODO: If we want to support secret refs for alertmanager config tls |
There was a problem hiding this comment.
Did we open an issue for this?
There was a problem hiding this comment.
I will open an issue the moment this PR is merged.
b4cad4c to
c0c7917
Compare
|
Is this ready for another review, I vaguely remember getting a ping somewhere to re-review this? :) |
|
@lilic I am trying to figure out what is broken in CI. Fix is on the way. |
|
Rebased and regenerated files to resolve conflicts. |
23bfa32 to
b713f08
Compare
|
Rebased again :) |
| apiserverConfig *v1.APIServerConfig, | ||
| basicAuthSecrets map[string]BasicAuthCredentials, | ||
| bearerTokens map[string]BearerToken, | ||
| ) yaml.MapSlice { |
There was a problem hiding this comment.
nit: this method is getting slowly out of hand, how about adding functional options a la https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis ?
There was a problem hiding this comment.
the above comment still holds, although we can address this (please) as a follow-up.
To configure a bearer token users could only specify a file path in the service monitor, pointing to a bearer token file in the Prometheus container. This enables hostile users, being able to configure a service monitor and controlling the scrape target, to retrieve arbitrary files in the Prometheus container. In cases where users can not be trusted, this patch adds an option to disallow the above file path specification and replaces it by a secret reference. This secret has to be in the same namespace as the service monitor, shrinking the attack vector. pkg/prometheus: Add option to deny file system access through service monitors ArbitraryFSAccessThroughSMsConfig enables users to configure, whether a service monitor selected by the Prometheus instance is allowed to use arbitrary files on the file system of the Prometheus container. This is the case when e.g. a service monitor specifies a BearerTokenFile in an endpoint. A malicious user could create a service monitor selecting arbitrary secret files in the Prometheus container. Those secrets would then be send with a scrape request by Prometheus to a malicious target. Denying the above would prevent the attack, users can instead use the BearerTokenSecret field. test/basic-auth-test-app: Add mTLS endpoint pkg/prometheus: Enable users to configure tls from secret pkg/prometheus/operator: Validate TLS configs before retrieving assets Before retrieving TLS assets from Kubernetes secrets for a given service monitor, make sure the user did not specify both file and secret reference, e.g. both `CAFile` and `CASecret`. test: Rename basic-auth-test-app to instrumented-sample-app Given that the basic-auth-test-app not only supports basic auth, but also bearer token as well as tls authentication, this patch renames the app to a more generic name. test/e2e/prometheus_test: Test ArbitraryFSAccessThroughSM option for tls The Prometheus custom resource has the option to disable arbitrary filesystem access configured through service monitors. This commit adds an end-to-end test for this option in combination with the TLS configuration via files or secret references in service monitors. pkg/prometheus/operator: Move check for arbitrary fs access into func
…gMap in the same way as from Secrets
…ator,pkg/apis/monitoring/v1: regenerate
…Secret and ConfigMap in one entry
…ator,pkg/apis/monitoring/v1: regenerate
|
Rebased and possibly fixed issue discovered in tests. |
|
@brancz @lilic @s-urbaniak this is ready for the review :) |
| // attack, users can instead use the BearerTokenSecret field. | ||
| type ArbitraryFSAccessThroughSMsConfig struct { | ||
| Deny bool | ||
| // ServiceMonitorAllowlist |
There was a problem hiding this comment.
nit: i guess we can remove this comment?
| } | ||
|
|
||
| // If denied by Prometheus spec, filter out all service monitors that access | ||
| // the file system. |
There was a problem hiding this comment.
this will also filter out service monitors which have an invalid tls configuration. can you add that to the comment here?
|
lgtm from my side :-) just two very small nits and a follow-up request. |
|
lgtm |
This was flagged by [golangci-lint](https://staticcheck.io/docs/checks#SA4022). The check was for the address of the pointer, not the value. Add a test (failing on master) to verify this, and fix the validation logic. Follow-up to prometheus-operator#2716. Signed-off-by: Matthias Rampke <[email protected]>
This was flagged by [golangci-lint](https://staticcheck.io/docs/checks#SA4022). The check was for the address of the pointer, not the value. Add a test (failing on master) to verify this, and fix the validation logic. Follow-up to prometheus-operator#2716. Signed-off-by: Matthias Rampke <[email protected]>
Rebased #2524 and continuing work here.