Skip to content

Prefer signature version from service models over endpoints.json #3465

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

Merged
merged 4 commits into from
May 13, 2025

Conversation

ashovlin
Copy link
Contributor

@ashovlin ashovlin commented May 9, 2025

Background

An upcoming service is re-using an existing endpoint prefix that is still present in endpoints.json with an explicit signatureVersions.

The new service is specifying a different signatureVersion in its service model. However botocore is still preferring the version from endpoints.json

#2816 in 2022 last touched this area. However this logic:

botocore/botocore/client.py

Lines 836 to 843 in 6f783fe

if (
self.service_signature_version is not None
and self.service_signature_version
not in _LEGACY_SIGNATURE_VERSIONS
):
# Prefer the service model as most specific
# source of truth for new signature versions.
potential_versions = [self.service_signature_version]

only prefers the service model over endpoints.json if the service model's signature version is not in the this list:

_LEGACY_SIGNATURE_VERSIONS = frozenset(
(
'v2',
'v3',
'v3https',
'v4',
's3',
's3v4',
)
)

My interpretation is that this allowed new services to model new signature versions such as bearer, but preserved our original behavior of using endpoints.json as the source of truth.

Approach

Now, I removed that _LEGACY_SIGNATURE_VERSIONS set. We'll prefer the service model it its set, but still fall back to endpoints.json if not.

This required some custom handling for S3, S3Control, and Import/Export to preserve their current resolved values.

For Reviewers: Long term, we likely want to remove endpoints.json entirely. I didn't do so yet, as that resolved is plumbed around pretty heavily, and we do have unit tests that are guarding the current code paths. But let me know if you'd rather do so now.

Testing

  1. Added a unit test exercising the scenario that the upcoming service is hitting.
  2. Ran the following both before and after this change, confirmed that there was not a diff in the output:
import json
import botocore.session

session = botocore.session.get_session()
signature_versions = {}
for service_name in session.get_available_services():
    client = session.create_client(service_name)
    signature_versions[service_name] = client.meta.config.signature_version

print(json.dumps(signature_versions, indent=2))

Comment on lines 1 to 5
{
"type": "bugfix",
"category": "``endpoints``",
"description": "Prefer signature version from service models over endpoints.json."
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unsure if we want this, as it should be transparent. #2816 didn't have a changelog entry.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably a nuance we don't need to highlight. These aren't public interfaces and as long as the change is a no-op for the end user, it's kind of moot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 1 to 5
{
"type": "bugfix",
"category": "``endpoints``",
"description": "Prefer signature version from service models over endpoints.json."
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably a nuance we don't need to highlight. These aren't public interfaces and as long as the change is a no-op for the end user, it's kind of moot.

Comment on lines 832 to 836
# importexport is modeled with V2, but we previously allowed
# endpoints.json to move it to v4 before switching this method
# to prefer the service models
if service_name == 'importexport':
return 'v4'
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any other options for this? S3 has it's own special cases throughout the code but adding more random service conditionals is ideally avoided. I'd maybe suggest we add a handler to set this explicitly for the service instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One note on the approach in b2da232:

client.meta.config.signature_version for importexport will now return v2 (instead of v4) since this doesn't execute the choose-signer event.

I removed that assertion from the functional test, but left the assertion that the request ultimately has the V4 header.

@codecov-commenter
Copy link

codecov-commenter commented May 9, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.04%. Comparing base (6300f6b) to head (1724736).
Report is 254 commits behind head on develop.

Files with missing lines Patch % Lines
botocore/client.py 95.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3465      +/-   ##
===========================================
+ Coverage    92.94%   93.04%   +0.10%     
===========================================
  Files           66       67       +1     
  Lines        14956    15132     +176     
===========================================
+ Hits         13901    14080     +179     
+ Misses        1055     1052       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@nateprewitt nateprewitt left a comment

Choose a reason for hiding this comment

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

Comment on a nit, but otherwise LGTM.

Co-authored-by: Nate Prewitt <[email protected]>
@ashovlin ashovlin merged commit 4c37007 into boto:develop May 13, 2025
48 of 49 checks passed
@ashovlin ashovlin deleted the shovlia/signature-selection branch May 13, 2025 17:29
aws-sdk-python-automation added a commit that referenced this pull request May 13, 2025
* release-1.38.15:
  Bumping version to 1.38.15
  Update to latest models
  Prefer signature version from service models over endpoints.json (#3465)
  Bump jinja2 from 3.1.4 to 3.1.6
hswong3i pushed a commit to alvistack/boto-botocore that referenced this pull request May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants