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

configmap: option to not trust incoming tracing spans #7045

Merged
merged 2 commits into from
Oct 24, 2021

Conversation

timmysilv
Copy link
Contributor

@timmysilv timmysilv commented Apr 13, 2021

What this PR does / why we need it:

nginx-opentracing allows a static configuration to not propagate incoming span headers. This gives the user the opportunity to choose whether to propagate the trace/span headers via configmap.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Which issue/s this PR fixes

How Has This Been Tested?

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 13, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @timmysilv. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 13, 2021
@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 28, 2021
@timmysilv timmysilv changed the title validate the sender of tracing spans configmap: option to not trust incoming tracing spans Apr 28, 2021
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 28, 2021
@@ -1092,6 +1092,9 @@ stream {
set $global_rate_limit_exceeding n;

{{ buildOpentracingForLocation $all.Cfg.EnableOpentracing $location }}
{{ if not $all.Cfg.OpentracingTrustIncomingSpan }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for this configuration to be global instead of location specific / per annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. It could be added to buildOpentracingForLocation() and use the same logic as isOTSetInLoc && isOTEnabledInLoc if that's preferred, so there can be both global and location-specific settings.

@rikatz
Copy link
Contributor

rikatz commented May 12, 2021

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 12, 2021
@rikatz
Copy link
Contributor

rikatz commented May 12, 2021

/assign
/cc

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 14, 2021
{"globally enabled and enabled in location", true, true, &trueVal, loadOT},
{"globally disabled and not enabled in location", false, false, nil, ""},
{"globally disabled but enabled in location", false, true, &trueVal, loadOT},
{"globally disabled, enabled in location but false", false, true, &trueVal, loadOT},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted this line bc it was the same as the one before. Also added true, false, nil to each line since that results in the same behaviour as before this PR.

@@ -1343,33 +1343,29 @@ func httpsListener(addresses []string, co string, tc config.TemplateConfig) []st
return out
}

func buildOpentracingForLocation(isOTEnabled bool, location *ingress.Location) string {
func buildOpentracingForLocation(isOTEnabled bool, isOTTrustSet bool, location *ingress.Location) string {
isOTEnabledInLoc := location.Opentracing.Enabled
isOTSetInLoc := location.Opentracing.Set

if isOTEnabled {
if isOTSetInLoc && !isOTEnabledInLoc {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still trying to ramp up on this, but maybe... why we check isOTSetnLock and isOTEnabledInLoc, when isOTEnabledInLoc = false will always be false? And the default value is false anyway?

I would remove this and check only !isOTEnabledInLoc {return opentracing off; }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default for isOTEnabledInLoc is false, so this scenario means:

  • OT is enabled globally
  • There is an OT annotation present on the specific Ingress
  • That annotation is set to false

The reason to check both is the (common) case where OT is enabled globally, and there is no annotation present on an Ingress. In that case the values will be: {isOTEnabled: true, isOTSetInLoc: false, isOTEnabledInLoc: false}, BUT it should be enabled in that location.

}

return opc
} else if !isOTSetInLoc || !isOTEnabledInLoc {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, I might be missing something but are we double checking things that might be a legacy behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, in this case we should be able to just check !isOTEnabledInLoc. If it's set and set to false, don't enable. And if it's not set, the default for this bool would be false anyway. Also don't enable.

@@ -1094,7 +1094,7 @@ stream {
set $location_path {{ $ing.Path | escapeLiteralDollar | quote }};
set $global_rate_limit_exceeding n;

{{ buildOpentracingForLocation $all.Cfg.EnableOpentracing $location }}
{{ buildOpentracingForLocation $all.Cfg.EnableOpentracing $all.Cfg.OpentracingTrustIncomingSpan $location }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the main difference here is:
Opentracing can be enabled globally, while we can or cannot enable trusting incoming span locally right?

So my question is: what is the behavior, as the cluster admin we wanna do? Leave this decision to the user? If so, this should be exclusively local (and we don't need to assess this here).

If we want to have precedence, than we need to have a configmap that explicits if we trust incoming span or not, and bypass the verification of the location

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR adds that configmap value. Without this PR (current state), all incoming spans are accepted as default behaviour. The change introduced here is the option to set a global "off" switch for that. The possible scenarios are:

  • Spans are trusted globally, but certain backend/ingress owners decide they don't want to trust any spans
  • Spans are not trusted globally, but certain backend/ingress owners decide that they do want to trust any spans

Seeing as we don't know every user of ingress-nginx, I'd prefer to keep it flexible. However, if you feel that there is a principle to be followed (for example, when trust is globally disabled then no one backend owner should have the right to enable it for just them), I am willing to change this PR to become more opinionated.

@rikatz
Copy link
Contributor

rikatz commented Jun 27, 2021

@timmysilv I'm really ok with this :)

Just wondering what are the user stories: Should we block trusting span globally? Per user? both?

Please just give me some context so we can decide the best approach together.

@rikatz rikatz changed the base branch from master to main July 16, 2021 13:27
@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

@timmysilv friendly ping :)

@timmysilv
Copy link
Contributor Author

hi, sorry for the lack of clarity - I explained how this feature might be used by cluster owners and app owners in tandem in the inline comment responses.

@rikatz
Copy link
Contributor

rikatz commented Oct 24, 2021

/lgtm
/approve
Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 24, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rikatz, timmysilv

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 24, 2021
@k8s-ci-robot k8s-ci-robot merged commit 7d5452d into kubernetes:main Oct 24, 2021
kskalski pushed a commit to kskalski/ingress-nginx that referenced this pull request Nov 28, 2021
* validate the sender of tracing spans

* add location-specific setting
rchshld pushed a commit to joomcode/ingress-nginx that referenced this pull request May 19, 2023
* validate the sender of tracing spans

* add location-specific setting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants