Skip to content

Reference secrets instead of local files (cont. #2524) - #2716

Merged
s-urbaniak merged 12 commits into
prometheus-operator:masterfrom
paulfantom:bearer
Oct 9, 2019
Merged

s-urbaniak merged 12 commits into
prometheus-operator:masterfrom
paulfantom:bearer

Conversation

@paulfantom

Copy link
Copy Markdown
Member

Rebased #2524 and continuing work here.

@paulfantom
paulfantom force-pushed the bearer branch 2 times, most recently from befc90c to 423403d Compare August 13, 2019 15:37
@paulfantom paulfantom changed the title [WIP] Reference secrets instead of local files (cont. #2524) Reference secrets instead of local files (cont. #2524) Aug 20, 2019

@lilic lilic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just had a quick look at this.

Comment thread pkg/apis/monitoring/v1/types.go Resolved
Comment thread pkg/apis/monitoring/v1/types.go Outdated
// attack, users can instead use the BearerTokenSecret field.
type ArbitraryFSAccessThroughSMsConfig struct {
Deny bool
// TODO: To be implemented.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When do we want to implement this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Comment thread pkg/apis/monitoring/v1/types.go Resolved
Comment thread pkg/prometheus/operator.go Resolved
Comment thread pkg/prometheus/operator.go Resolved
for namespaceAndName, sm := range res {
for _, endpoint := range sm.Spec.Endpoints {
if err := testForArbitraryFSAccess(endpoint); err != nil {
delete(res, namespaceAndName)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need to delete the entries from res here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We want to deny ServiceMonitors which are not allowed to access filesystem

Comment thread pkg/prometheus/statefulset.go Resolved
Comment thread test/instrumented-sample-app/Makefile Resolved
Comment thread test/instrumented-sample-app/main.go Resolved

@brancz brancz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few comments, but I think generally we're already pretty close. Nice work!

Comment thread Documentation/api.md Resolved
Comment thread pkg/apis/monitoring/v1/types.go Outdated
// attack, users can instead use the BearerTokenSecret field.
type ArbitraryFSAccessThroughSMsConfig struct {
Deny bool
// TODO: To be implemented.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Comment thread pkg/apis/monitoring/v1/types.go Outdated
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"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

@paulfantom
paulfantom force-pushed the bearer branch 3 times, most recently from 59d2cc0 to 599b70d Compare September 6, 2019 14:55
@lilic

lilic commented Sep 18, 2019

Copy link
Copy Markdown
Contributor

Is this ready for another review?

@paulfantom

Copy link
Copy Markdown
Member Author

@lilic sorry for the long wait, it is ready for next review.

/cc @s-urbaniak

Comment thread Documentation/api.md Resolved

@lilic lilic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looking good! 🎉 Few questions and agree with @brancz we should allow option of ConfigMap and Secret KeySelectors.

Comment thread pkg/prometheus/promcfg.go
}

cfg = addTLStoYaml(cfg, am.TLSConfig)
// TODO: If we want to support secret refs for alertmanager config tls

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did we open an issue for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will open an issue the moment this PR is merged.

Comment thread pkg/prometheus/statefulset.go Resolved
@lilic

lilic commented Sep 26, 2019

Copy link
Copy Markdown
Contributor

Is this ready for another review, I vaguely remember getting a ping somewhere to re-review this? :)

@paulfantom

Copy link
Copy Markdown
Member Author

@lilic I am trying to figure out what is broken in CI. Fix is on the way.

@paulfantom

Copy link
Copy Markdown
Member Author

Rebased and regenerated files to resolve conflicts.

@paulfantom
paulfantom force-pushed the bearer branch 7 times, most recently from 23bfa32 to b713f08 Compare October 1, 2019 12:28
@paulfantom

Copy link
Copy Markdown
Member Author

Rebased again :)

Comment thread pkg/prometheus/promcfg.go
apiserverConfig *v1.APIServerConfig,
basicAuthSecrets map[string]BasicAuthCredentials,
bearerTokens map[string]BearerToken,
) yaml.MapSlice {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
@paulfantom

Copy link
Copy Markdown
Member Author

Rebased and possibly fixed issue discovered in tests.

@paulfantom

Copy link
Copy Markdown
Member Author

@brancz @lilic @s-urbaniak this is ready for the review :)

// attack, users can instead use the BearerTokenSecret field.
type ArbitraryFSAccessThroughSMsConfig struct {
Deny bool
// ServiceMonitorAllowlist

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: i guess we can remove this comment?

}

// If denied by Prometheus spec, filter out all service monitors that access
// the file system.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this will also filter out service monitors which have an invalid tls configuration. can you add that to the comment here?

@s-urbaniak

Copy link
Copy Markdown
Contributor

lgtm from my side :-) just two very small nits and a follow-up request.

@brancz

brancz commented Oct 8, 2019

Copy link
Copy Markdown
Contributor

lgtm

@s-urbaniak
s-urbaniak merged commit 62af025 into prometheus-operator:master Oct 9, 2019
@paulfantom
paulfantom deleted the bearer branch October 9, 2019 12:23
matthiasr added a commit to matthiasr/prometheus-operator that referenced this pull request Aug 17, 2020
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]>
simonpasquier pushed a commit to simonpasquier/prometheus-operator that referenced this pull request Aug 18, 2020
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants