Skip to content
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

Hubble: improve security by adding an option to redact API key in Kafka requests (L7) #25844

Merged
merged 2 commits into from
Jun 30, 2023

Conversation

ioandr
Copy link
Contributor

@ioandr ioandr commented Jun 1, 2023

Add option to redact API key in Kafka requests.

TODOS

  • Accept option to redact Kafka API key
  • Add business logic to L7 parser
  • Add unit tests
  • Update Helm charts
  • Update docs

Refs: #23887

Depends on: #25746

@ioandr ioandr requested a review from a team as a code owner June 1, 2023 22:42
@ioandr ioandr requested a review from kaworu June 1, 2023 22:42
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jun 1, 2023
@github-actions github-actions bot added the kind/community-contribution This was a contribution made by a community member. label Jun 1, 2023
@ioandr ioandr closed this Jun 1, 2023
@ioandr ioandr reopened this Jun 1, 2023
@ioandr ioandr marked this pull request as draft June 1, 2023 22:46
Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @ioandr, patch LGTM.

I would like to see a new test ensuring that KafkaRedactAPIKey is honored. Also although a breaking change I think it should be true by default cc @rolinh.

@kaworu kaworu added kind/feature This introduces new functionality. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. sig/hubble Impacts hubble server or relay labels Jun 5, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Jun 5, 2023
Copy link
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

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

Thanks for the patch! Unfortunately, we can't mutate LogRecord structures so the patch needs to be updated (see comment below).

Also although a breaking change I think it should be true by default cc @rolinh.

Mmh, I'm not sure about that. If L7 visibility was an opt-out feature, then I'd clearly say yes, Hubble should redact Kafka's API keys by default. However, L7 visibility is opt-in and its (security) implications should be well understood when enabling it (note: we should probably update the documentation to make that clear). My point is that even if we try our best to redact sensitive data, there's no guarantee that Hubble will always correctly redact all sensitive data from L7 payloads. Therefore, L7 flows should be treated as sensitive data overall. I also think that if we redact (known) sensitive data by default, then that means we should do it overall which would imply that we also redact all HTTP headers by default and I'm not sure we would want that.

pkg/hubble/parser/seven/kafka.go Outdated Show resolved Hide resolved
@ioandr ioandr force-pushed the feature-hubble-kafka-redact branch from 00e1df7 to f18bf51 Compare June 5, 2023 22:01
@ioandr
Copy link
Contributor Author

ioandr commented Jun 5, 2023

I would like to see a new test ensuring that KafkaRedactAPIKey is honored.

Hi @kaworu, thanks for taking a look at this!

I pushed a commit that updates the Kafka unit tests to cover the Kafka API key redact option. LMK if this is what you had in mind.

@ioandr ioandr force-pushed the feature-hubble-kafka-redact branch from f18bf51 to edcadad Compare June 5, 2023 22:29
@kaworu
Copy link
Member

kaworu commented Jun 6, 2023

@rolinh generally agree with all that you wrote

I also think that if we redact (known) sensitive data by default, then that means we should do it overall which would imply that we also redact all HTTP headers by default and I'm not sure we would want that.

HTTP headers may or may not be sensitive data, while I think we can agree basic auth password and Kafka API key always are. We're already redacting the former unconditionally, so in my opinion doing it by default for the latter would be consistent. Not feeling too strongly about this though.

Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

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

Thanks @ioandr for the quick update! The patch LGTM besides the missing doc update 🚀

@ioandr
Copy link
Contributor Author

ioandr commented Jun 6, 2023

Thanks @ioandr for the quick update! The patch LGTM besides the missing doc

Sure, I can prepare a short doc as discussed above.

However the following is not 100% clear to me:

How are we planning to expose this option to end-users? Do we want end-users to control this option via the cilium CLI? i.e.,

$ cilium config set hubble-l7-parser-kafka-redact-api-key true/false

IIUC the above command directly updates the kube-system/cilium-config ConfigMap.

We can also add a new argument in the cilium-agent CLI. Looking at the codebase, this requires the following:

  1. Extend Cilium https://github.com/cilium/cilium/blob/main/pkg/option/config.go with an option to control whether Hubble's L7 parser redacts Kafka API keys - we already declare Hubble* options there
  2. Set a sane default value for the newly added Hubble L7 option under https://github.com/cilium/cilium/blob/main/pkg/defaults/defaults.go
  3. Pass context to the L7 payload parser upon creation: https://github.com/cilium/cilium/blob/main/daemon/cmd/hubble.go#L141
  4. Initialize flag in https://github.com/cilium/cilium/blob/main/daemon/cmd/daemon_main.go
  5. Possibly update Cilium's Helm chart, so that Cilium's ConfigMap contains this option
  6. Update user-facing files as neededHubbleMetrics (e.g., README, Helm Reference, etc.)

This is what @ChrsMark has done in his PR that tackles the redaction of HTTP query params, so maybe we want a uniform approach in both. PTAL: https://github.com/cilium/cilium/pull/25746/files

CC @kaworu @rolinh

@ioandr ioandr force-pushed the feature-hubble-kafka-redact branch 2 times, most recently from 68ea860 to 086d452 Compare June 9, 2023 08:58
@ioandr ioandr marked this pull request as ready for review June 9, 2023 08:58
@ioandr ioandr requested review from a team as code owners June 9, 2023 08:58
@ChrsMark
Copy link
Contributor

Hey @pippolo84 @nathanjsweet @asauber @aditighag any chances having a look into this one? It should be a simple one 🙏🏽. Despite being labeled with dont-merge/wait-until-release it would be great if can have it reviewed and ready for merge :).

Copy link
Contributor

@zacharysarah zacharysarah left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@pippolo84 pippolo84 left a comment

Choose a reason for hiding this comment

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

Thanks! 💯

Copy link
Member

@jrajahalme jrajahalme left a comment

Choose a reason for hiding this comment

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

LGTM

@jrajahalme
Copy link
Member

@kaworu Looks like your concern was addressed?

Copy link
Member

@kaworu kaworu left a comment

Choose a reason for hiding this comment

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

Thanks for the update @ioandr patch LGMT!

@kaworu Looks like your concern was addressed?

Yes, although I still find it inconsistent to redact the HTTP password unconditionally while the Kafka API key redaction is opt-in, but that's arguably out of the scope of this PR.

@ioandr
Copy link
Contributor Author

ioandr commented Jun 21, 2023

Yes, although I still find it inconsistent to redact the HTTP password unconditionally while the Kafka API key redaction is opt-in, but that's arguably out of the scope of this PR.

Indeed, we can address this with a small, dedicated issue/PR that will make HTTP password redaction in L7 flows configurable, similar to what we did for URL query parameters and Kafka API key.

Redaction of HTTP password was already implemented and non-configurable. As such, we avoided this refactoring to keep our PRs small and concise.

Thanks for the review @kaworu

@kaworu
Copy link
Member

kaworu commented Jun 21, 2023

/test

@ChrsMark
Copy link
Contributor

+1 on providing a follow-up for --hubble-redact=http-basic-auth-password which will be true by default :).

@ldelossa
Copy link
Contributor

@ioandr, Can you please rebase this PR on main and push? Should fix some issues with the tests.

@ioandr ioandr force-pushed the feature-hubble-kafka-redact branch from 51cb34f to 91929a2 Compare June 27, 2023 13:16
@ioandr
Copy link
Contributor Author

ioandr commented Jun 27, 2023

@ldelossa the only test that is failing is the mergeability one - I suppose due to the dont-merge/wait-until-release label that prevents merge.

LMK if you need any further action from my side.

@kaworu
Copy link
Member

kaworu commented Jun 27, 2023

/test

Copy link
Member

@asauber asauber left a comment

Choose a reason for hiding this comment

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

LGTM, my main feedback here would be that we should list the "allowed" redacted values more clearly in the docs; make it clear that right now there are exactly two options and what they are.

@ioandr
Copy link
Contributor Author

ioandr commented Jun 28, 2023

LGTM, my main feedback here would be that we should list the "allowed" redacted values more clearly in the docs; make it clear that right now there are exactly two options and what they are.

Hi @asauber, thank you for your feedback on this. How about we rephrase the doc as follows:

To harden security, Cilium provides the ``--hubble-redact`` option which
accepts a comma-separated list of values that control how Hubble handles
sensitive information present in Layer 7 flows. More specifically, it offers
the following features and values for supported Layer 7 protocols:

* For HTTP: redacting URL query (GET) parameters (``--hubble-redact=http-url-query``)
* For Kafka: redacting API key (``--hubble-redact=kafka-api-key``)

@asauber
Copy link
Member

asauber commented Jun 28, 2023

@ioandr That phrasing looks good to me

ioandr and others added 2 commits June 29, 2023 02:05
Co-authored-by: ChrsMark <chrismarkou92@gmail.com>
Signed-off-by: Ioannis Androulidakis <androulidakis.ioannis@gmail.com>
* Extend accepted values for the `--hubble-redact` CLI option
* Add unit tests for Kafka in L7 parser
* Update the `visibility.rst` document
* Update Helm chart templates and values

Co-authored-by: ChrsMark <chrismarkou92@gmail.com>
Signed-off-by: Ioannis Androulidakis <androulidakis.ioannis@gmail.com>
@ioandr ioandr force-pushed the feature-hubble-kafka-redact branch from 91929a2 to 675f79e Compare June 28, 2023 23:05
@ldelossa ldelossa removed the dont-merge/wait-until-release Freeze window for current release is blocking non-bugfix PRs label Jun 29, 2023
@ldelossa
Copy link
Contributor

/test

@ioandr
Copy link
Contributor Author

ioandr commented Jun 30, 2023

@ldelossa I see that you removed the dont-merge/wait-until-release label so I suppose there is no blocker towards merging this.

I see that one test is failing with:

connectivity test failed: timeout reached waiting lookup for localhost from pod cilium-test/client-6965d549d5-mjxk9 to server on pod cilium-test/echo-other-node-545c9b778b-m6d6t to succeed (last error: context deadline exceeded)
Error: Process completed with exit code 1.

I believe this is something temporary/flaky, that is, the test failure is not caused by the changes of this PR. Maybe we can re-trigger tests?

@kaworu
Copy link
Member

kaworu commented Jun 30, 2023

/ci-multicluster
EDIT: previous CI run hit #26513

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 30, 2023
@ldelossa ldelossa merged commit 386b17a into cilium:main Jun 30, 2023
65 checks passed
@ioandr ioandr deleted the feature-hubble-kafka-redact branch June 30, 2023 14:03
@ioandr ioandr restored the feature-hubble-kafka-redact branch June 30, 2023 14:03
@ioandr ioandr deleted the feature-hubble-kafka-redact branch June 30, 2023 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/community-contribution This was a contribution made by a community member. kind/feature This introduces new functionality. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. sig/hubble Impacts hubble server or relay
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet