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

fix(s3-deployment): User metadata keys have redundant triple x-amz prefix #12414

Merged
merged 4 commits into from
Jan 21, 2021
Merged

fix(s3-deployment): User metadata keys have redundant triple x-amz prefix #12414

merged 4 commits into from
Jan 21, 2021

Conversation

bmwalters
Copy link
Contributor

@bmwalters bmwalters commented Jan 7, 2021

Without this fix, keys are prefixed with x-amzn-meta- by the TypeScript code,
then the Python code runs and prefixes metadata keys again with x-amz-meta-.
Then, the Python shells out to aws-cli which makes a request to the S3 service.
There, the keys are prefixed yet again with x-amz-meta- unconditionally.

Thus no matter what keys the user specified, the keys in S3 would be:
x-amz-meta-x-amz-meta-x-amzn-meta-.

This issue was originally reported as #8459.

#10678 attempted to fix this issue, and fixed the Python, but missed the TS.
It also suffers from the S3 service adding the prefix unconditionally.

After this change, neither the TypeScript code nor the Python code will attempt
to prepend to the metadata key. Instead we rely on the S3 service to do it.

BREAKING CHANGE: User metadata keys of bucket objects will change from x-amz-meta-x-amz-meta-x-amzn-meta-mykey to x-amz-meta-mykey.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Jan 7, 2021

@bmwalters

This comment has been minimized.

@bmwalters
Copy link
Contributor Author

bmwalters commented Jan 7, 2021

@iliapolo @ayush987goyal The S3 service which is accessed by the CLI command which the s3_deploy lambda shells out to here:

s3_command.extend(create_metadata_args(user_metadata, system_metadata))
aws_command(*s3_command)

seems to already adds the x-amz-meta- prefix. Can we just remove the logic from the TypeScript and Python code that attempts to add the prefix and rely on S3 doing it? Seems simpler and also might be where the snag is.

@bmwalters
Copy link
Contributor Author

bmwalters commented Jan 7, 2021

Yeah, I confirmed that without even using this library, running

$ AWS_SDK_LOAD_CONFIG=1 AWS_PROFILE=my-profile \
    aws s3 sync ./my-contents/ s3://my-bucket//my-path/ \
        --metadata '{ "x-amz-meta-sourceurl": "static" }'  \
        --metadata-directive REPLACE

results in duplicate x-amz-meta-x-amz-meta-sourceurl. This means that S3 is adding the prefix for us unconditionally when using the S3 CLI like this.

I'll update this patch to remove adding the prefix in TS and Python entirely.

Copy link
Contributor

@iliapolo iliapolo left a comment

Choose a reason for hiding this comment

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

@bmwalters This is great. It was indeed pretty messy, my only question/concern is how is this going to affect existing objects in the bucket? will their metadata change?

@iliapolo iliapolo added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 15, 2021
@bmwalters
Copy link
Contributor Author

Yes, the metadata keys will change. For example, to access metadata created by s3-deployment using an SDK:

// before
let metadata = s3Object.metadata?["x-amz-meta-x-amzn-meta-mykey"]
// after
let metadata = s3Object.metadata?["mykey"]

The previous version is awkward so I'm not sure how many users there actually are. If we want to preserve the incorrect metadata keys as well we could internally duplicate each key, so if the user passes in "mykey" they end up with both "x-amz-meta-mykey" and "x-amz-meta-x-amz-meta-x-amzn-meta-mykey". Otherwise this could be listed as a potentially breaking change.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 16, 2021
@iliapolo
Copy link
Contributor

@bmwalters Ok, lets mention this as a breaking change 👍

P.S: Notice there are conflicts needs resolving

@iliapolo iliapolo added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 17, 2021
Without this fix, keys are prefixed with x-amzn-meta- by the TypeScript code,
then the Python code runs and prefixes metadata keys again with x-amz-meta-.
Then, the Python shells out to aws-cli which makes a request to the S3 service.
There, the keys are prefixed *yet again* with x-amz-meta- _unconditionally_.

Thus no matter what keys the user specified, the keys in S3 would be:
x-amz-meta-x-amz-meta-x-amzn-meta-<user input>.

This issue was originally reported as #8459.

After this change, neither the TypeScript code nor the Python code will attempt
to prepend to the metadata key. Instead we rely on the S3 service to do it.
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 19, 2021
iliapolo
iliapolo previously approved these changes Jan 21, 2021
@mergify mergify bot dismissed iliapolo’s stale review January 21, 2021 19:43

Pull request has been modified.

@iliapolo iliapolo changed the title fix(s3-deployment): Fix x-amz-meta- prefix for user metadata fix(s3-deployment): User metadata keys have tripled x-amz prefix Jan 21, 2021
@iliapolo iliapolo changed the title fix(s3-deployment): User metadata keys have tripled x-amz prefix fix(s3-deployment): User metadata keys have redundant triple x-amz prefix Jan 21, 2021
@mergify
Copy link
Contributor

mergify bot commented Jan 21, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: fd16d8d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Jan 21, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 6716181 into aws:master Jan 21, 2021
mohanrajendran pushed a commit to mohanrajendran/aws-cdk that referenced this pull request Jan 24, 2021
…prefix (aws#12414)

Without this fix, keys are prefixed with x-amzn-meta- by the TypeScript code,
then the Python code runs and prefixes metadata keys again with x-amz-meta-.
Then, the Python shells out to aws-cli which makes a request to the S3 service.
There, the keys are prefixed *yet again* with x-amz-meta- _unconditionally_.

Thus no matter what keys the user specified, the keys in S3 would be:
x-amz-meta-x-amz-meta-x-amzn-meta-<user input>.

This issue was originally reported as aws#8459.

aws#10678 attempted to fix this issue, and fixed the Python, but missed the TS.
It also suffers from the S3 service adding the prefix unconditionally.

After this change, neither the TypeScript code nor the Python code will attempt
to prepend to the metadata key. Instead we rely on the S3 service to do it.

BREAKING CHANGE: User metadata keys of bucket objects will change from `x-amz-meta-x-amz-meta-x-amzn-meta-mykey` to `x-amz-meta-mykey`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants