-
Notifications
You must be signed in to change notification settings - Fork 146
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
Credentials JSON string is mangled when rendered to YAML #178
Comments
Could you clarify what was verified as correct here? Did we look at the fully compiled policy in the latest revision of the policy in If I'm understanding correctly, there's some breakdown happening in the processing between Simple, isolated repro steps would be quite helpful to debug this, is that easy to produce? |
It is interesting that standalone with the config works but inspect still outputs a non proper result. This indicates the "problem" happens somewhere before the policy is picked up by Elastic Agent but that there is also a post processing "issue" in elastic agent maybe just on the inspect side. As @joshdover , lets try to find a minimal example to reproduce it. My guess is any input with |
There are some examples that don't trigger this issue in elastic/integrations#2712, so I suspect line length is a factor. I'll experiment with different strings to collect more details about this behaviour.
@joshdover I used tcpdump to inspect the network traffic and from it's analysis the JSON sent from Fleet to the Agent is correct (but my understanding of the policy update process is limited, so I may have misinterpreted the results). I have the dump file for further inspection if interested. |
I have a feeling that this is related to escaping quotes and new lines while configuring policy using Fleet UI. Agent picks it up from the Fleet Server and it's already mangled. |
I performed some tests and these are the result: behaviour is observed when a string contains a space and is longer than 101 characters (not exact length, not sure if it make sense to pinpoint exactly at which length this happens). This string:
is dumped (by - credentials_json: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
This string (in
is dumped (by - credentials_json: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb Note the hard newline in this case. This is consistent with it happening with a string representing a private key, very long and containing spaces. |
Looking at the above I see that you are using an embedded certificate, @lykkin since you are working on the LS output, have you seen this issue when working with certificates? |
I was trying to determine what is wrong with the example given. The example appears to be valid YAML and its contents appear to be valid JSON. It passes when I paste it into https://yamllint.com. And when I check it with
So where does this newline get lost at? |
@andrewkroh I fear that may be a copy paste error on my side, as the newline is missing in my local configuration. I amended the test string. |
I went the other way round and tried to remove the escaping problem from the equation.
Now you can see that elastic-package starts the terraform container to create GCP compute machine. It proves that credentials are working correctly. Then, elastic-package runs system test runner (which fails):
(no metrics found) When I jump into Metricbeat's logs, I can see:
Short: @endorama Does it mean that I misconfigured something? BTW when I look into Kibana's UI, I can see this: @endorama QQ: is the credentials_json correctly rendered? or is it a different issue we found here? |
I guess that we found the root cause. The elastic-package used 8.0.1-SNAPSHOT in this branch, but this feature ( |
As written by @mtojek the Still: When using stack 8.1.0-SNAPSHOT and Kibana UI I encountered issues. We were able to run tests by fixing the escaping (thank you @andrewkroh), but those pass credentials through YAML files. To conclude:
|
I confirmed using Stack version 8.1.0 everything works, even if the string is mangled as mentioned in this issue. I confirm the findings from @andrewkroh: both YAML and JSON are correct so even if it looks weird it actually works when passed to the Agent and Metricbeat. I'm going to close this as not a bug. I'm also going to investigate @mtojek finding about the empty Kibana UI, but separately. Thank you all for the help with this issue, your help has been very precious 🙇 |
ping @ph |
Followup issue #185 |
Context: adding system tests for gcp integration package (elastic/elastic-package#701)
Observed behaviour: gcp metrics collector does not initialise with correct credentials (and report various errors related to permission errors)
Worth mentioning:
we pass a JSON string containing credentials to the integration (via Fleet UI/YAML); this allow to provide a JSON string instead of a file path and helps with testing (as credentials can be pulled from the environment)
after debugging I noticed that the JSON string is broken down in 3 pieces (newlines are added) so is not a single string but a multiline. This breaks credential parsing from GCP library client within metricbeat. Example of relevant YAML config (this private key is not the real one) with the strange newlines:
newlines added are consistent (I tried with different keys and newlines have been added always in the same places)
we found a similar issue, we thought it was fixed, in Add single quotes around the credentials_json var integrations#2712
Steps taken so far:
metricbeat
standalone withcredentials_json
configuration: workscredentials_json
from Fleet UI: correctconfirmed by the agent logs (excerpt):
{"log.level":"info","message":"Non-zero metrics in the last 30s","monitoring":{"metrics":{"metricbeat":{"gcp":{"compute":{"events":8,"success":8}}}},"ecs.version":"1.6.0"}}
but I then printed diagnostics info with
elastic-agent diagnostics collect
and inspected theconfig/elastic-agent-policy.yaml
file: the newlines were presentI can provide further debug files but given they contain sensitive credentials will not upload them here.
/cc @joshdover @ruflin @mtojek
The text was updated successfully, but these errors were encountered: