-
Notifications
You must be signed in to change notification settings - Fork 327
PS-1470 Fix issue where artifacts uploaded to custom s3 buckets would have a double slash prefix #3607
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
Conversation
zhming0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something we can write an new e2e test for?? with our new e2e test gear
|
oooh, good call! |
47cb0e5 to
d06c720
Compare
internal/e2e/testcase.go
Outdated
| pipeline *buildkite.Pipeline | ||
| } | ||
|
|
||
| var leadingTabsRe = regexp.MustCompile(`(?m)^(\t+)`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| var leadingTabsRe = regexp.MustCompile(`(?m)^(\t+)`) | |
| var leadingTabsRE = regexp.MustCompile(`(?m)^(\t+)`) |
internal/e2e/artifact_test.go
Outdated
| - commands: | ||
| - echo "hello world" > artifact.txt | ||
| - buildkite-agent artifact upload artifact.txt | ||
| - commands: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have a depends_on or wait to make the ordering clear?
internal/e2e/artifact_test.go
Outdated
| logs := tc.fetchLogs(ctx, build) | ||
| if !strings.Contains(logs, "\nsuccess") { | ||
| t.Errorf("tc.fetchLogs(ctx, build %q) logs as follows, did not contain 'success'\n%s", build.ID, logs) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on the job to succeed or fail might be enough. Having to pull the job logs might make the test run longer for not much benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you're working on a version that uses a custom S3 bucket?
d06c720 to
cacaf7b
Compare
.buildkite/steps/e2e-tests.sh
Outdated
| set -eo pipefail | ||
|
|
||
| if [[ -z "${BUILDKITE_TRIGGERED_FROM_BUILD_ID}" ]] ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about:
| set -eo pipefail | |
| if [[ -z "${BUILDKITE_TRIGGERED_FROM_BUILD_ID}" ]] ; then | |
| set -euo pipefail | |
| if [[ -z "${BUILDKITE_TRIGGERED_FROM_BUILD_ID:-}" ]] ; then |
ceb7a1c to
e3c643b
Compare
…double slash prefix There's an edge case in URL construction for artifacts uploaded to custom S3 buckets where the key for the object would be generated as `/object-key` (note preceding slash), and then directly appended to a url like `https://my-definitely-realy-s3-bucket.s3.amazonaws.com/`, leading to a final object url of `https://buildkite-benno-artifacts-test.s3.amazonaws.com//object-key` (note the double slash!). See [the implementation](https://github.com/buildkite/agent/blob/2a95448832f3fa4c2eb08dabb69db06ff01782fb/internal/artifact/s3_uploader.go#L147) for more details — `u.BucketPath` is empty by default in custom artifact bucket cases. When we were on the AWS Go SDK v1, this was fine, as the SDK [cleaned urls by default](aws/aws-sdk-go#2559), leading to the object's key being normalized from `/object-key` to `object-key`. However, in an [undocumented breaking change](aws/aws-sdk-go-v2#3095) (🫠), the SDK v2 doesn't do this cleaning, so the object would be uploaded with a leading slash on its key. The artifact downloader relied on the URL cleaning functionality of the go SDK, so when attempting to download the artifact, it would generate a key of `object-key`, without the leading slash, leading to consistent 404s when trying to download artifacts from custom buckets. This PR updates the artifact upload URL generation logic to do a path-join of the key rather than a crude append, essentially emulating the logic that was present in v1 of the AWS Go SDK.
e3c643b to
8e5dfb5
Compare
|
i'm going to merge this as is, and add an e2e test for artifact upload/download with a custom bucket in a followup — i've tested this and made sure it works, but there's quite a bit of infra stuff i'll need to do to set up the e2e test, and i don't want that to block shipping a fix to the customer. |
8e5dfb5 to
a79c5af
Compare
a79c5af to
537c838
Compare
Description
Fix issue where artifacts uploaded to custom s3 buckets would have a double slash prefix
There's an edge case in URL construction for artifacts uploaded to custom S3 buckets where the key for the object would be generated as
/object-key(note preceding slash), and then directly appended to a url likehttps://my-definitely-realy-s3-bucket.s3.amazonaws.com/, leading to a final object url ofhttps://my-definitely-real-s3-bucket.s3.amazonaws.com//object-key(note the double slash!). See the implementation for more details —u.BucketPathis empty by default in custom artifact bucket cases.When we were on the AWS Go SDK v1, this was fine, as the SDK cleaned urls by default, leading to the object's key being normalized from
/object-keytoobject-key. However, in an undocumented breaking change (🫠), the SDK v2 doesn't do this cleaning, so the object would be uploaded with a leading slash on its key.The artifact downloader relied on the URL cleaning functionality of the go SDK, so when attempting to download the artifact, it would generate a key of
object-key, without the leading slash, leading to consistent 404s when trying to download artifacts from custom buckets.This PR updates the artifact upload URL generation logic to do a path-join of the key rather than a crude append, essentially emulating the logic that was present in v1 of the AWS Go SDK.
Context
PS-1470
Testing
go test ./...). Buildkite employees may check this if the pipeline has run automatically.go tool gofumpt -extra -w .)\Disclosures / Credits
I used Amp to investigate the issue initially, then wrote the fourteen-character fix all by myself.