Skip to content

Commit 5f1e656

Browse files
zmoogAndrea Spacca
andauthored
[AWS] [S3] Remove url.QueryUnescape() from aws-s3 input in polling mode (#38125)
* Remove url.QueryUnescape() We introduced [^1] the `url.QueryUnescape()` function to unescape object keys from S3 notification in SQS messages. However, the object keys in the S3 list object responses do not require [^2] unescape. We must remove the unescape to avoid unintended changes to the S3 object key. [^1]: #18370 [^2]: #38012 (comment) --------- Co-authored-by: Andrea Spacca <andrea.spacca@elastic.co>
1 parent 27cde87 commit 5f1e656

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fields added to events containing the Beats version. {pull}37553[37553]
9797
- [threatintel] MISP pagination fixes {pull}37898[37898]
9898
- Fix file handle leak when handling errors in filestream {pull}37973[37973]
9999
- Prevent HTTPJSON holding response bodies between executions. {issue}35219[35219] {pull}38116[38116]
100+
- Fix "failed processing S3 event for object key" error on aws-s3 input when key contains the "+" character {issue}38012[38012] {pull}38125[38125]
100101

101102
*Heartbeat*
102103

x-pack/filebeat/input/awss3/s3.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"errors"
1010
"fmt"
11-
"net/url"
1211
"sync"
1312
"time"
1413

@@ -208,14 +207,7 @@ func (p *s3Poller) GetS3Objects(ctx context.Context, s3ObjectPayloadChan chan<-
208207
// Metrics
209208
p.metrics.s3ObjectsListedTotal.Add(uint64(totListedObjects))
210209
for _, object := range page.Contents {
211-
// Unescape s3 key name. For example, convert "%3D" back to "=".
212-
filename, err := url.QueryUnescape(*object.Key)
213-
if err != nil {
214-
p.log.Errorw("Error when unescaping object key, skipping.", "error", err, "s3_object", *object.Key)
215-
continue
216-
}
217-
218-
state := newState(bucketName, filename, *object.ETag, p.listPrefix, *object.LastModified)
210+
state := newState(bucketName, *object.Key, *object.ETag, p.listPrefix, *object.LastModified)
219211
if p.states.MustSkip(state, p.store) {
220212
p.log.Debugw("skipping state.", "state", state)
221213
continue
@@ -240,7 +232,7 @@ func (p *s3Poller) GetS3Objects(ctx context.Context, s3ObjectPayloadChan chan<-
240232
s3ObjectHandler: s3Processor,
241233
s3ObjectInfo: s3ObjectInfo{
242234
name: bucketName,
243-
key: filename,
235+
key: *object.Key,
244236
etag: *object.ETag,
245237
lastModified: *object.LastModified,
246238
listingID: listingID.String(),

x-pack/filebeat/input/awss3/s3_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func TestS3Poller(t *testing.T) {
9393
Key: aws.String("key5"),
9494
LastModified: aws.Time(time.Now()),
9595
},
96+
{
97+
ETag: aws.String("etag6"),
98+
Key: aws.String("2024-02-08T08:35:00+00:02.json.gz"),
99+
LastModified: aws.Time(time.Now()),
100+
},
96101
},
97102
}, nil
98103
})
@@ -124,6 +129,10 @@ func TestS3Poller(t *testing.T) {
124129
GetObject(gomock.Any(), gomock.Eq(bucket), gomock.Eq("key5")).
125130
Return(nil, errFakeConnectivityFailure)
126131

132+
mockAPI.EXPECT().
133+
GetObject(gomock.Any(), gomock.Eq(bucket), gomock.Eq("2024-02-08T08:35:00+00:02.json.gz")).
134+
Return(nil, errFakeConnectivityFailure)
135+
127136
s3ObjProc := newS3ObjectProcessorFactory(logp.NewLogger(inputName), nil, mockAPI, nil, backupConfig{}, numberOfWorkers)
128137
receiver := newS3Poller(logp.NewLogger(inputName), nil, mockAPI, mockPublisher, s3ObjProc, newStates(inputCtx), store, bucket, "key", "region", "provider", numberOfWorkers, pollInterval)
129138
require.Error(t, context.DeadlineExceeded, receiver.Poll(ctx))

0 commit comments

Comments
 (0)