Skip to content

Commit 791c332

Browse files
Merge pull request #18 from lyft/ramonpetgrave64-max-connection-pool
add kms performance parameters
2 parents b136df7 + 0f50807 commit 791c332

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ validator.decrypt_token(username, token)
104104
Note: 'to', 'from', and 'user_type' keys are not allowed to be set in
105105
extra_context.
106106

107+
## Performance Tuning
108+
109+
With the [boto defaults](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html), the AWS KMS client used in `KMSTokenValidator` may not be performant under higher loads, due to latency when communicating with AWS KMS. Try tuning these parameters below with the given starting points.
110+
111+
```python
112+
...
113+
max_pool_connections=100,
114+
connect_timeout=1,
115+
read_timeout=1,
116+
...
117+
```
118+
107119
## Reporting security vulnerabilities
108120

109121
If you've found a vulnerability or a potential vulnerability in kmsauth

kmsauth/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def __init__(
5757
endpoint_url=None,
5858
token_cache_size=4096,
5959
stats=None,
60+
max_pool_connections=None,
61+
connect_timeout=None,
62+
read_timeout=None,
6063
):
6164
"""Create a KMSTokenValidator object.
6265
@@ -107,13 +110,19 @@ def __init__(
107110
aws_access_key_id=self.aws_creds['AccessKeyId'],
108111
aws_secret_access_key=self.aws_creds['SecretAccessKey'],
109112
aws_session_token=self.aws_creds['SessionToken'],
110-
endpoint_url=endpoint_url
113+
endpoint_url=endpoint_url,
114+
max_pool_connections=max_pool_connections,
115+
connect_timeout=connect_timeout,
116+
read_timeout=read_timeout,
111117
)
112118
else:
113119
self.kms_client = kmsauth.services.get_boto_client(
114120
'kms',
115121
region=self.region,
116-
endpoint_url=endpoint_url
122+
endpoint_url=endpoint_url,
123+
max_pool_connections=max_pool_connections,
124+
connect_timeout=connect_timeout,
125+
read_timeout=read_timeout,
117126
)
118127
if extra_context is None:
119128
self.extra_context = {}

kmsauth/services.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Module for accessing boto3 clients, resources and sessions."""
22

33
import boto3
4+
import botocore
45
import logging
56

67
CLIENT_CACHE = {}
@@ -13,7 +14,10 @@ def get_boto_client(
1314
aws_access_key_id=None,
1415
aws_secret_access_key=None,
1516
aws_session_token=None,
16-
endpoint_url=None
17+
endpoint_url=None,
18+
max_pool_connections=None,
19+
connect_timeout=None,
20+
read_timeout=None,
1721
):
1822
"""Get a boto3 client connection."""
1923
cache_key = '{0}:{1}:{2}:{3}'.format(
@@ -37,7 +41,12 @@ def get_boto_client(
3741

3842
CLIENT_CACHE[cache_key] = session.client(
3943
client,
40-
endpoint_url=endpoint_url
44+
endpoint_url=endpoint_url,
45+
config=botocore.config.Config(
46+
max_pool_connections=max_pool_connections,
47+
connect_timeout=connect_timeout,
48+
read_timeout=read_timeout,
49+
)
4150
)
4251
return CLIENT_CACHE[cache_key]
4352

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from setuptools import setup, find_packages
1515

16-
VERSION = "0.6.1"
16+
VERSION = "0.6.2"
1717

1818
requirements = [
1919
# Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK)

0 commit comments

Comments
 (0)