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

[Fleet] Only escape single '*' characters in YAML strings. #93257

Closed

Conversation

skh
Copy link
Contributor

@skh skh commented Mar 2, 2021

Summary

Fixes a problem with the kafka integration described in #93253

(Thanks @mtojek for the analysis!)

This revisits the changes made in #91418 , which lead to the bug above.
Now the behavior is changed so that only the exact string "*" will be forced to be quoted, and everything else left as it was before.

The test cases verify the new behavior:

How to test this

In the Fleet UI, verify that you can add both the apm and the kafka packages to a policy. For APM, be sure to enable RUM.

Then verify that you find the following snippets in the policy, and that the wildcards in the policy are correct. For Kafka:

    data_stream:
          dataset: kafka.log
          type: logs
        paths:
          - /opt/kafka*/logs/controller.log*
          - /opt/kafka*/logs/server.log*
          - /opt/kafka*/logs/state-change.log*
          - /opt/kafka*/logs/kafka-*.log*

For APM:

    data_stream:
      namespace: default
    apm-server:
      host: 'localhost:8200'
      secret_token: null
      max_event_size: 307200
      capture_personal_data: true
      kibana:
        api_key: null
      rum:
        enabled: true
        source_mapping.elasticsearch.api_key: null
        allow_origins: '*'
        allow_headers: null
        library_pattern: null
        exclude_from_grouping: null
        response_headers: null
        event_rate.limit: 300
        event_rate.lru_size: 1000

@skh skh requested a review from a team as a code owner March 2, 2021 16:26
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Mar 2, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@skh skh self-assigned this Mar 2, 2021
@skh skh added release_note:skip Skip the PR/issue when compiling release notes v7.12.0 v7.13.0 v8.0.0 labels Mar 2, 2021
@skh
Copy link
Contributor Author

skh commented Mar 2, 2021

@mtojek @ycombinator if you have opinions about this I'd love to hear them.

@nchaulet
Copy link
Member

nchaulet commented Mar 2, 2021

@skh it is still going to escape something like test: *id I think we should it was the initial issue

@skh
Copy link
Contributor Author

skh commented Mar 2, 2021

it was the initial issue

The initial issue was '*'.

Do we have *id in a package somewhere?

I believe now *id should be treated as a valid YAML alias, and stay unchanged.

@nchaulet
Copy link
Member

nchaulet commented Mar 2, 2021

Do we have *id in a package somewhere?

This will be coming from a text variable populated by the user, so I guess we should not treat as an alias.

@skh
Copy link
Contributor Author

skh commented Mar 2, 2021

This will be coming from a text variable populated by the user, so I guess we should not treat as an alias.

Do you have an issue for that, or can you describe in more detail what breaks in this case? I am only aware of #91401 which was a default variable in a package file.

Please also have a look at how the kafka package uses wildcards and concatenated strings. If we put all strings containing * in double quotes, that package will no longer work.

@skh
Copy link
Contributor Author

skh commented Mar 3, 2021

@nchaulet I have tested this with this branch. If a user wants to enter a string starting with a * manually, they can enclose it in double quotes in the UI, and it will be added with double quotes to the policy.

Let me summarize. The issue is how to treat strings starting with * which we use as wildcard, but which in YAML syntax specifies that the value is not a string, but a YAML alias.

The current behavior after the changes in this PR is:

  • the literal string * is being escaped when it comes in from either a package or the UI.
  • strings containing a * in the middle or at the end go through unchanged and without problems. (This was needed so that the kafka package works again, see this test case: https://github.com/elastic/kibana/pull/93257/files#diff-765deefdff232a5eefcd5f7c04cd49754e383497853d3a77a5f62bfdcc4d3cd8R187 )
  • strings starting with * are assumed to be YAML aliases and rejected when no corresponding anchor is present. The error message is a bit arcane, it only says unidentified alias.
  • strings starting with a * can be enclosed in double quotes in the UI by the user and then go through unchanged and without causing problems.
  • I did not find a way how to specify a string value in a manifest.yml file starting with a * in a way that the quotes survive our parsing and processing. This is the actual bug, which we maybe want to revisit later. It will appear in the UI as prefilled value without any quotes, and cause an error. edited: solved in [Fleet] Don't add extra quotes to YAML strings from manifest files #93585
  • We currently assume that in packages, strings that start with * are valid aliases, and otherwise do not occur, not even in quotes. This can be changed, see below.

For this PR I would suggest:

  • as packages currently don't seem to use YAML aliases, we can extend the special handling to strings starting with a *, but this would mean that we can't use YAML aliases and anchors later, so would only be a band aid.
  • merge so that the kafka package works again

In addition I would suggest opening separate issues for:

  • a discussion on the support of YAML aliases and anchors in packages
  • better handling of any errors during YAML parsing, so that users have a chance to add quotes or make any other necessary changes to the values they enter in the UI, based on the parser errors and additional information we may be able to give
  • dig into the code to find out if we can stop the overeager stripping of double quotes from strings in the first place

@skh skh force-pushed the integrations-752-handle-wildcards-correctly branch from e5c9fed to c15b582 Compare March 3, 2021 11:56
@skh
Copy link
Contributor Author

skh commented Mar 3, 2021

cc @exekias @ruflin @ph

@exekias
Copy link
Contributor

exekias commented Mar 3, 2021

Thanks for the detailed explanation! I see how template variables expanding to unexpected chars could lead to issues. I'm wondering if in the given * example we should do the quoting in the template itself, instead of guessing from Kibnaa.

Would this work?

Switching from:

allow_origins: {{rum_allow_origins}}

to:

allow_origins: "{{rum_allow_origins}}"

@skh
Copy link
Contributor Author

skh commented Mar 3, 2021

@exekias Thank you, this indeed works.

  • Would this be an acceptable fix for packages? @mtojek @simitt @ruflin It would bring Kibana behavior back to what it was before February 16, and the apm package would need to be changed.

  • This still leaves the problem what happens when a user enters a value starting with a * in the UI, but we could amend that with documentation and better error messages.

@ruflin
Copy link
Contributor

ruflin commented Mar 3, 2021

++ on the simplest solution for now and "enforcing" it on the package side. I don't see any reasons at the moment we should add support for yaml aliases / references, I think it would only complicate things.

@mtojek
Copy link
Contributor

mtojek commented Mar 3, 2021

Keep in mind that such change modifies the standard behavior of Kibana, which may mean that we'll have to adjust all templates for all packages. It's also not backwards compatible, so we'd have to add a constraint for specific Kibana version.

@skh
Copy link
Contributor Author

skh commented Mar 3, 2021

@mtojek @ruflin thanks for your comments. Did I understand correctly that you prefer the solution @exekias suggested?

This would mean I could revert the changes made in #91418 .

@ph
Copy link
Contributor

ph commented Mar 3, 2021

I don't see any reasons at the moment we should add support for yaml aliases / references, I think it would only complicate things.

+1 on this, this really overcomplicate things, if we want to support aliases and references I think it should be handled by the tooling, where you can control the "include" path or reference. In an integration managed by fleet we should try to be flat.

Looking at what @exekias propose I think this is indeed the simplest solution and I think this an acceptable way of handling.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

  • 💚 Build #110392 succeeded e5c9fedb7b8675fa5b6aafba18351ec07ef395a9

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @skh

@skh
Copy link
Contributor Author

skh commented Mar 4, 2021

Closed in favor of #93585

@skh skh closed this Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.12.0 v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants