Allow Source Address and Port to be specified when creating a client
Describe the feature
We should be able to set the source IP address and source port when creating the client using an optional parameter, in the same manner as urllib3.
E.g.
- session.create_client('ec2', source_address=None)) # Default value for parameter, allow random port and default IP address
- session.create_client('ec2', source_address=('10.10.10.10', 0)) # Use address 10.10.10.10, allow randomly selected port
- session.create_client('ec2', source_address=('', 1234)) # Use default address, set source port as 1234
- session.create_client('ec2', source_address=('10.10.10.10', 1234)) # Use address 10.10.10.10, set source port as 1234
Use Case
As the endpoint IP address for requests is not static, local firewall rules on the machine need to allow traffic from port 443 to make requests. For some business use cases this unacceptable. Allowing to set source address and port allows greater granularity to the firewall rules.
Proposed Solution
The source_address parameter should be set in pool_manager_kwargs in URLLib3Session, for it to work with urllib3
Add the optional parameter into to Session.create_client() with default set as None (which will continue current behavior). Pass that value all the way through until create the URLLib3Session and it gets added to pool_manager_kwargs,
e.g.
def _get_pool_manager_kwargs(self, **extra_kwargs):
pool_manager_kwargs = {
'strict': True,
'timeout': self._timeout,
'maxsize': self._max_pool_connections,
'ssl_context': self._get_ssl_context(),
'socket_options': self._socket_options,
'cert_file': self._cert_file,
'key_file': self._key_file,
**'source_address': self._source_address,**
}
pool_manager_kwargs.update(**extra_kwargs)
return pool_manager_kwargs
Other Information
No response
Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
SDK version used
1.20.0
Environment details (OS name and version, etc.)
Debian 10
Hi @jmulcock-rbbn thanks for the feature request. I brought this up for discussion with the team and it’s something that may be considered at a future date. We suggest others who are also interested in this feature to 👍 the issue or leave additional feedback in the comments. And if there’s anything else you want to expand on or clarify regarding your use case please let us know.