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

Beats configuration "dotted" keys issue #27079

Open
aleksmaus opened this issue Jul 27, 2021 · 15 comments
Open

Beats configuration "dotted" keys issue #27079

aleksmaus opened this issue Jul 27, 2021 · 15 comments
Labels
Stalled Team:Elastic-Agent Label for the Agent team Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@aleksmaus
Copy link
Member

aleksmaus commented Jul 27, 2021

It looks like the "dotted" keys are not supported in the configuration as of July 27th, 2021.

Trying to introduce the ecs_mapping for osquery_manager integration.

The data stream template (stream.yml.hbs) looks like this:

query: {{query}}
{{#if interval}}
interval: {{interval}}
{{/if}}
id: {{id}}
{{#if platform}}
platform: {{platform}}
{{/if}}
{{#if version}}
version: {{version}}
{{/if}}
{{#if ecs_mapping}}
ecs_mapping:
{{#each ecs_mapping}}
   '{{@key}}':
      {{#each this}}
         '{{@key}}': {{this}} 
      {{/each}}
{{/each}}
{{/if}}

Submitting the integration configuration payload with ecs_mapping that looks like the following:

....
                        "ecs_mapping": {
                            "value": {
                                "user.custom.shoeSize": {
                                    "value": 45
                                },
                                "user.id": {
                                    "field": "uid"
                                },
                                "user.name": {
                                    "field": "username"
                                }
                            }
                        }
....

Kibana renders the stream configuration with ecs_mapping like the following

    streams:
      - id: users
        data_stream:
          dataset: osquery_manager.result
          type: logs
        query: select * from users limit 2
        interval: 60
        ecs_mapping:
          user.custom.shoeSize:
            value: 45
          user.id:
            field: uid
          user.name:
            field: username

The agent receives the ecs_mapping blob correctly as JSON

{
    "ecs_mapping": {
        "user.custom.shoeSize": {
            "value": 45
        },
        "user.id": {
            "field": "uid"
        },
        "user.name": {
            "field": "username"
        }
    }
} 

The beats configuration YAML update is "broken", the beat received the configuration where the keys with dots are unwrapped into the nested YAML tree:

    ecs_mapping:
      user:
        custom:
          shoeSize:
            value: 45
        id:
          field: uid
        name:
          field: username      

Expecting the keys with dots to be preserved as is and the original structure of the document to be unchanged (flat mapping document with the dotted keys".

@aleksmaus aleksmaus added the Team:Elastic-Agent Label for the Agent team label Jul 27, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/agent (Team:Agent)

@ruflin
Copy link
Member

ruflin commented Jul 27, 2021

@michalpristas @blakerouse @urso I assume this building of the tree somewhere happens between Elastic Agent when the config is shipped down to the process. Maybe go-ucfg is applying some magic here? Is there a reason we "dedot" configs?

@aleksmaus
Copy link
Member Author

go-ucfg

looks like default options use ucfg.PathSep(".") which will split the key

@ruflin
Copy link
Member

ruflin commented Jul 28, 2021

I wonder if we should disable this in general. Maybe worth trying to remove it and see what happens? Otherwise we could just disabled it for osquerybeat?

@blakerouse
Copy link
Contributor

blakerouse commented Jul 28, 2021

I don't think we can just remove it. It would break parsing other parts of the elastic-agent.yml.

@aleksmaus
Copy link
Member Author

aleksmaus commented Jul 28, 2021

{
        "foo.bar": {
            "value": 45
        }
        "foo": {
            "bar": {
                "value": 23
            }
        }
}

so with the JSON like this for example we will loose some values after converting to YAML? the last one wins?
I understand the compatibility issues with existing yaml configuration. but does it have to be yaml a year from now for example? maybe a config format can be a part of the spec? this possibly would allow to skip yaml conversion for the beats/apps that can consume JSON configuration as is. just thinking out loud.

@ruflin
Copy link
Member

ruflin commented Sep 6, 2021

@aleksmaus Did we ever make progress on this issue? How did you solve it?

@ruflin ruflin removed their assignment Sep 6, 2021
@aleksmaus
Copy link
Member Author

@aleksmaus Did we ever make progress on this issue? How did you solve it?

as far as I understood from the replies that this can't be easily fixing without breaking backwards compatibility. we just adopted what we get in osquerybeat in this particular case, and flattened the tree in osquerybeat code.

@javabrett
Copy link

I wonder if I've hit a variant of this issue - my case is different in that I'm just starting with a Beats metricbeat module prometheus configuration, as module configuration in YAML only, so no JSON. I guess the config file is still processed by ucfg with ucfg.PathSep("."), and this is preventing me from expressing config keys which contain a .:

- module: prometheus
  period: 60s
  hosts: ["https://endpoint.with.https:443"]
  metricsets: ["query"]
  queries:
  - name: export
    path: /path/to/export
    params:
      foo.bar: baz
  username: "someuser"
  password: "somesecretpassword"

... results in a bad interpretation of key foo.bar resulting in a query https://endpoint.with.https:443/path/to/export?foo=map%5Bbar%3Abaz%5D or decoded, foo=map[bar:baz].

Are there any known escaping or quoting workarounds for this?

Also posted to https://discuss.elastic.co/t/how-can-i-represent-a-config-key-containing-a-dot-period-full-stop/301907

@ruflin ruflin added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Apr 11, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic
Copy link

botelastic bot commented Apr 11, 2023

Hi!
We just realized that we haven't looked into this issue in a while. We're sorry!

We're labeling this issue as Stale to make it hit our filters and make sure we get back to it as soon as possible. In the meantime, it'd be extremely helpful if you could take a look at it as well and confirm its relevance. A simple comment with a nice emoji will be enough :+1.
Thank you for your contribution!

@botelastic botelastic bot added the Stalled label Apr 11, 2023
@aleksmaus
Copy link
Member Author

My memories are vague about this issue, it's been awhile. I think for osquerybeat we "worked around" this limitation. Could potentially be closed.

@botelastic botelastic bot removed the Stalled label Apr 11, 2023
@ruflin
Copy link
Member

ruflin commented Apr 11, 2023

I think the problem that how the configs are treated is not always the same still persists. @joshdover Reminds me of the standalone elastic agent experience where dots sometimes work and sometimes don't.

@bartoszcisek
Copy link

This issuer might be related to escaping URLs in query argument elastic/elastic-agent#3421

@botelastic
Copy link

botelastic bot commented Sep 14, 2024

Hi!
We just realized that we haven't looked into this issue in a while. We're sorry!

We're labeling this issue as Stale to make it hit our filters and make sure we get back to it as soon as possible. In the meantime, it'd be extremely helpful if you could take a look at it as well and confirm its relevance. A simple comment with a nice emoji will be enough :+1.
Thank you for your contribution!

@botelastic botelastic bot added the Stalled label Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stalled Team:Elastic-Agent Label for the Agent team Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

No branches or pull requests

6 participants