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] add escapeMultilineString Handlebar helper #195159

Merged

Conversation

opauloh
Copy link
Contributor

@opauloh opauloh commented Oct 5, 2024

Summary

Adding a handlebar helper to escape multiline strings. It has the same function as escapeStringHelper, but does not wrap strings in single quotes, allowing concatenation of escaped variables in the hbs template such as this example:

audit_rules: "{{escape_multiline_string audit_rules}}
  {{escape_multiline_string "
  # Session data audit rules
  -a always,exit -F arch=b64 -S execve,execveat -k exec
  -a always,exit -F arch=b64 -S exit_group
  -a always,exit -F arch=b64 -S setsid"}}"
{{else}}
  {{#if audit_rules}}
audit_rules: {{escape_string audit_rules}}
  {{/if}}
{{/if}}

The above would not be possible using only escape_string as audit_rules would be wrapped in single quotes.

Screenshots

The example above illustrates how this option allows the Auditd manager integration to append Session data audit rules to the audit_rules field when Session data is enabled in the integration (PR).

image image

@opauloh opauloh requested a review from a team as a code owner October 5, 2024 01:50
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Oct 5, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@opauloh opauloh added v8.16.0 backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes labels Oct 5, 2024
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add test coverage on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call @juliaElastic, I added it!

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #84 / Controls Dashboard control group apply button range slider selections making selection enables apply button

Metrics [docs]

✅ unchanged

History

@opauloh opauloh merged commit 407137a into elastic:main Oct 8, 2024
25 checks passed
@opauloh opauloh deleted the auditdmanager/add_escape_multiline_string branch October 8, 2024 18:56
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11241898487

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.x An unhandled error occurred. Please see the logs for details

Manual backport

To create the backport manually run:

node scripts/backport --pr 195159

Questions ?

Please refer to the Backport tool documentation

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 8, 2024
## Summary

Adding a handlebar helper to escape multiline strings. It has the same
function as `escapeStringHelper`, but does not wrap strings in single
quotes, allowing concatenation of escaped variables in the `hbs`
template such as this example:

```hbs
audit_rules: "{{escape_multiline_string audit_rules}}
  {{escape_multiline_string "
  # Session data audit rules
  -a always,exit -F arch=b64 -S execve,execveat -k exec
  -a always,exit -F arch=b64 -S exit_group
  -a always,exit -F arch=b64 -S setsid"}}"
{{else}}
  {{#if audit_rules}}
audit_rules: {{escape_string audit_rules}}
  {{/if}}
{{/if}}
```

The above would not be possible using only `escape_string` as
`audit_rules` would be wrapped in single quotes.

## Screenshots

The example above illustrates how this option allows the Auditd manager
integration to append Session data audit rules to the `audit_rules`
field when Session data is enabled in the integration
([PR](elastic/integrations#11336)).

<img width="872" alt="image"
src="https://github.com/user-attachments/assets/325d784d-26a4-4dfe-9d0e-54d51c3ed060">

<img width="801" alt="image"
src="https://github.com/user-attachments/assets/ebd521c0-4471-48f9-ba8d-94630ea0efd2">

(cherry picked from commit 407137a)
@opauloh
Copy link
Contributor Author

opauloh commented Oct 8, 2024

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

opauloh added a commit to opauloh/kibana that referenced this pull request Oct 8, 2024
## Summary

Adding a handlebar helper to escape multiline strings. It has the same
function as `escapeStringHelper`, but does not wrap strings in single
quotes, allowing concatenation of escaped variables in the `hbs`
template such as this example:

```hbs
audit_rules: "{{escape_multiline_string audit_rules}}
  {{escape_multiline_string "
  # Session data audit rules
  -a always,exit -F arch=b64 -S execve,execveat -k exec
  -a always,exit -F arch=b64 -S exit_group
  -a always,exit -F arch=b64 -S setsid"}}"
{{else}}
  {{#if audit_rules}}
audit_rules: {{escape_string audit_rules}}
  {{/if}}
{{/if}}
```

The above would not be possible using only `escape_string` as
`audit_rules` would be wrapped in single quotes.

## Screenshots

The example above illustrates how this option allows the Auditd manager
integration to append Session data audit rules to the `audit_rules`
field when Session data is enabled in the integration
([PR](elastic/integrations#11336)).

<img width="872" alt="image"
src="https://github.com/user-attachments/assets/325d784d-26a4-4dfe-9d0e-54d51c3ed060">

<img width="801" alt="image"
src="https://github.com/user-attachments/assets/ebd521c0-4471-48f9-ba8d-94630ea0efd2">

(cherry picked from commit 407137a)
opauloh added a commit that referenced this pull request Oct 9, 2024
…195497)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] add escapeMultilineString Handlebar helper
(#195159)](#195159)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Paulo
Silva","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-08T18:56:08Z","message":"[Fleet]
add escapeMultilineString Handlebar helper (#195159)\n\n##
Summary\r\n\r\nAdding a handlebar helper to escape multiline strings. It
has the same\r\nfunction as `escapeStringHelper`, but does not wrap
strings in single\r\nquotes, allowing concatenation of escaped variables
in the `hbs`\r\ntemplate such as this
example:\r\n\r\n```hbs\r\naudit_rules: \"{{escape_multiline_string
audit_rules}}\r\n {{escape_multiline_string \"\r\n # Session data audit
rules\r\n -a always,exit -F arch=b64 -S execve,execveat -k exec\r\n -a
always,exit -F arch=b64 -S exit_group\r\n -a always,exit -F arch=b64 -S
setsid\"}}\"\r\n{{else}}\r\n {{#if audit_rules}}\r\naudit_rules:
{{escape_string audit_rules}}\r\n {{/if}}\r\n{{/if}}\r\n```\r\n\r\nThe
above would not be possible using only `escape_string`
as\r\n`audit_rules` would be wrapped in single quotes.\r\n\r\n##
Screenshots\r\n\r\nThe example above illustrates how this option allows
the Auditd manager\r\nintegration to append Session data audit rules to
the `audit_rules`\r\nfield when Session data is enabled in the
integration\r\n([PR](https://github.com/elastic/integrations/pull/11336)).\r\n\r\n<img
width=\"872\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/325d784d-26a4-4dfe-9d0e-54d51c3ed060\">\r\n\r\n<img
width=\"801\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/ebd521c0-4471-48f9-ba8d-94630ea0efd2\">","sha":"407137a6befb38f34cb11f6a3b6a741a27977031","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","v8.16.0","backport:version"],"number":195159,"url":"https://github.com/elastic/kibana/pull/195159","mergeCommit":{"message":"[Fleet]
add escapeMultilineString Handlebar helper (#195159)\n\n##
Summary\r\n\r\nAdding a handlebar helper to escape multiline strings. It
has the same\r\nfunction as `escapeStringHelper`, but does not wrap
strings in single\r\nquotes, allowing concatenation of escaped variables
in the `hbs`\r\ntemplate such as this
example:\r\n\r\n```hbs\r\naudit_rules: \"{{escape_multiline_string
audit_rules}}\r\n {{escape_multiline_string \"\r\n # Session data audit
rules\r\n -a always,exit -F arch=b64 -S execve,execveat -k exec\r\n -a
always,exit -F arch=b64 -S exit_group\r\n -a always,exit -F arch=b64 -S
setsid\"}}\"\r\n{{else}}\r\n {{#if audit_rules}}\r\naudit_rules:
{{escape_string audit_rules}}\r\n {{/if}}\r\n{{/if}}\r\n```\r\n\r\nThe
above would not be possible using only `escape_string`
as\r\n`audit_rules` would be wrapped in single quotes.\r\n\r\n##
Screenshots\r\n\r\nThe example above illustrates how this option allows
the Auditd manager\r\nintegration to append Session data audit rules to
the `audit_rules`\r\nfield when Session data is enabled in the
integration\r\n([PR](https://github.com/elastic/integrations/pull/11336)).\r\n\r\n<img
width=\"872\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/325d784d-26a4-4dfe-9d0e-54d51c3ed060\">\r\n\r\n<img
width=\"801\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/ebd521c0-4471-48f9-ba8d-94630ea0efd2\">","sha":"407137a6befb38f34cb11f6a3b6a741a27977031"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195159","number":195159,"mergeCommit":{"message":"[Fleet]
add escapeMultilineString Handlebar helper (#195159)\n\n##
Summary\r\n\r\nAdding a handlebar helper to escape multiline strings. It
has the same\r\nfunction as `escapeStringHelper`, but does not wrap
strings in single\r\nquotes, allowing concatenation of escaped variables
in the `hbs`\r\ntemplate such as this
example:\r\n\r\n```hbs\r\naudit_rules: \"{{escape_multiline_string
audit_rules}}\r\n {{escape_multiline_string \"\r\n # Session data audit
rules\r\n -a always,exit -F arch=b64 -S execve,execveat -k exec\r\n -a
always,exit -F arch=b64 -S exit_group\r\n -a always,exit -F arch=b64 -S
setsid\"}}\"\r\n{{else}}\r\n {{#if audit_rules}}\r\naudit_rules:
{{escape_string audit_rules}}\r\n {{/if}}\r\n{{/if}}\r\n```\r\n\r\nThe
above would not be possible using only `escape_string`
as\r\n`audit_rules` would be wrapped in single quotes.\r\n\r\n##
Screenshots\r\n\r\nThe example above illustrates how this option allows
the Auditd manager\r\nintegration to append Session data audit rules to
the `audit_rules`\r\nfield when Session data is enabled in the
integration\r\n([PR](https://github.com/elastic/integrations/pull/11336)).\r\n\r\n<img
width=\"872\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/325d784d-26a4-4dfe-9d0e-54d51c3ed060\">\r\n\r\n<img
width=\"801\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/ebd521c0-4471-48f9-ba8d-94630ea0efd2\">","sha":"407137a6befb38f34cb11f6a3b6a741a27977031"}},{"branch":"8.x","label":"v8.16.0","labelRegex":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.16.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants