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

x-pack/filebeat/input/httpjson: add hash template function #31630

Merged
merged 6 commits into from
May 24, 2022

Conversation

efd6
Copy link
Contributor

@efd6 efd6 commented May 16, 2022

What does this PR do?

This adds template helper functions for hashing a set of strings, output as hex or base64.

Why is it important?

This feature is needed for authentication with some APIs.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@efd6 efd6 added enhancement Filebeat Filebeat Team:Security-External Integrations backport-skip Skip notification from the automated backport with mergify 8.3-candidate labels May 16, 2022
@efd6 efd6 requested a review from a team as a code owner May 16, 2022 04:32
@efd6 efd6 self-assigned this May 16, 2022
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label May 16, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label May 16, 2022
CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
@elasticmachine
Copy link
Collaborator

elasticmachine commented May 16, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-05-23T23:34:41.773+0000

  • Duration: 76 min 43 sec

Test stats 🧪

Test Results
Failed 0
Passed 2120
Skipped 166
Total 2286

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@@ -62,13 +62,15 @@ func (t *valueTpl) Unpack(in string) error {
"mul": mul,
"div": div,
"hmac": hmacStringHex,
"hash": hashStringHex,
"base64Encode": base64Encode,
"base64EncodeNoPad": base64EncodeNoPad,
"base64Decode": base64Decode,
"base64DecodeNoPad": base64DecodeNoPad,
"join": join,
"sprintf": fmt.Sprintf,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed this exists; it is already provided by the text/template packages global template functions via printf.

n += len(d)
}
if n == 0 {
return nil
Copy link
Member

@andrewkroh andrewkroh May 16, 2022

Choose a reason for hiding this comment

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

Why is there special handling for empty values? I would have expected that these result in the hash value for 0 length input / empty string (like the same values listed in the test vectors for 0 len values).

Copy link
Contributor Author

@efd6 efd6 May 16, 2022

Choose a reason for hiding this comment

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

The current behaviour for hmac treats "" specially (I think this is wrong, but I was keeping that behaviour). I can drop that if you want.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should remove the special handling for hash.

I just looked at the hmac implementation and don't know why the special handling was added there. @marc-gr would there be a reason to handle empty values with special behavior?

Copy link
Contributor

@marc-gr marc-gr May 23, 2022

Choose a reason for hiding this comment

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

The only reason I can remember of is since this will be used from templates an empty value would come as <no value>, but now that I try to think about anything else I am leaning more towards a bad outcome of trying to be too defensive. I'd rather change the way we deal with it in the other functions.

@mergify
Copy link
Contributor

mergify bot commented May 20, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b httpjson-hash upstream/httpjson-hash
git merge upstream/main
git push upstream httpjson-hash

@efd6 efd6 force-pushed the httpjson-hash branch from a90eca1 to 832c9b7 Compare May 23, 2022 00:06
@efd6
Copy link
Contributor Author

efd6 commented May 23, 2022

Taking the opportunity to remove nolint directives for gosec linting that is in the process of being removed.

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
n += len(d)
}
if n == 0 {
return nil
Copy link
Contributor

@marc-gr marc-gr May 23, 2022

Choose a reason for hiding this comment

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

The only reason I can remember of is since this will be used from templates an empty value would come as <no value>, but now that I try to think about anything else I am leaning more towards a bad outcome of trying to be too defensive. I'd rather change the way we deal with it in the other functions.

@mergify
Copy link
Contributor

mergify bot commented May 23, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b httpjson-hash upstream/httpjson-hash
git merge upstream/main
git push upstream httpjson-hash

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
@efd6 efd6 merged commit 6ae8856 into elastic:main May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.3-candidate backport-skip Skip notification from the automated backport with mergify enhancement Filebeat Filebeat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[filebeat][httpjson] Add support for setting hash in request header.
4 participants