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

[8.x](backport #40997) x-pack/filebeat/input/internal/private: add field redaction package #41210

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Oct 13, 2024

Proposed commit message

Initial donation of code from github.com/kortschak/dex/internal/private.

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.

Disruptive User Impact

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

diff --git a/x-pack/filebeat/input/httpjson/input.go b/x-pack/filebeat/input/httpjson/input.go
index 67daa7ef84..41b46c1878 100644
--- a/x-pack/filebeat/input/httpjson/input.go
+++ b/x-pack/filebeat/input/httpjson/input.go
@@ -33,6 +33,7 @@ import (
        "github.com/elastic/beats/v7/libbeat/version"
        "github.com/elastic/beats/v7/x-pack/filebeat/input/internal/httplog"
        "github.com/elastic/beats/v7/x-pack/filebeat/input/internal/httpmon"
+       "github.com/elastic/beats/v7/x-pack/filebeat/input/internal/private"
        "github.com/elastic/elastic-agent-libs/logp"
        "github.com/elastic/elastic-agent-libs/mapstr"
        "github.com/elastic/elastic-agent-libs/monitoring"
@@ -82,6 +83,19 @@ func (log *retryLogger) Warn(msg string, keysAndValues ...interface{}) {
        log.log.Warnw(msg, keysAndValues...)
 }
 
+type redact struct {
+       value  mapstr.M
+       fields []string
+}
+
+func (r redact) MarshalLogObject(enc zapcore.ObjectEncoder) error {
+       v, err := private.Redact(r.value, "", r.fields)
+       if err != nil {
+               return fmt.Errorf("could not redact value: %v", err)
+       }
+       return v.MarshalLogObject(enc)
+}
+
 func Plugin(log *logp.Logger, store inputcursor.StateStore) v2.Plugin {
        return v2.Plugin{
                Name:       inputName,
diff --git a/x-pack/filebeat/input/httpjson/request.go b/x-pack/filebeat/input/httpjson/request.go
index 6cc46b27f2..5dfb91dbdb 100644
--- a/x-pack/filebeat/input/httpjson/request.go
+++ b/x-pack/filebeat/input/httpjson/request.go
@@ -465,7 +465,7 @@ func (rf *requestFactory) newRequest(ctx *transformContext) (transformable, erro
                }
        }
 
-       rf.log.Debugf("new request: %#v", req)
+       rf.log.Debugw("new request", "req", redact{value: mapstr.M(req), fields: []string{"header.Authorization"}})
 
        return req, nil
 }

Could also be used in place of the current redactor in CEL, though that has a non-deletion redaction that this does not have. Adding that requires thought since this will redact non-string values.

Screenshots

Logs


This is an automatic backport of pull request #40997 done by [Mergify](https://mergify.com).

…40997)

This package supports zeroing arbitrary fields based on a set of redaction
paths or field sibling marks.

(cherry picked from commit 9fde7b0)
@mergify mergify bot requested a review from a team as a code owner October 13, 2024 20:12
@mergify mergify bot added the backport label Oct 13, 2024
@mergify mergify bot requested a review from a team as a code owner October 13, 2024 20:12
@mergify mergify bot assigned efd6 Oct 13, 2024
@mergify mergify bot requested review from AndersonQ and belimawr and removed request for a team October 13, 2024 20:12
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Oct 13, 2024
@botelastic
Copy link

botelastic bot commented Oct 13, 2024

This pull request doesn't have a Team:<team> label.

Copy link
Contributor Author

mergify bot commented Oct 14, 2024

This pull request has not been merged yet. Could you please review and merge it @efd6? 🙏

@efd6 efd6 merged commit e885a50 into 8.x Oct 14, 2024
19 of 22 checks passed
@efd6 efd6 deleted the mergify/bp/8.x/pr-40997 branch October 14, 2024 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport needs_team Indicates that the issue/PR needs a Team:* label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant