77import sys
88import copy
99
10+ from botocore .vendored import six
11+
1012import kmsauth .services
1113from kmsauth .utils import lru
1214
@@ -35,9 +37,9 @@ def __init__(
3537 """Create a KMSTokenValidator object.
3638
3739 Args:
38- auth_key: The KMS key ARN or alias to use for service
40+ auth_key: A list of KMS key ARNs or aliases to use for service
3941 authentication. Required.
40- user_auth_key: The KMS key ARN or alias to use for user
42+ user_auth_key: A list of KMS key ARNs or aliases to use for user
4143 authentication. Required.
4244 to_auth_context: The KMS encryption context to use for the to
4345 context for authentication. Required.
@@ -103,6 +105,21 @@ def _validate(self):
103105 'minimum_token_version can not be greater than'
104106 ' self.minimum_token_version'
105107 )
108+ self .auth_key = self ._format_auth_key (self .auth_key )
109+ self .user_auth_key = self ._format_auth_key (self .user_auth_key )
110+
111+ def _format_auth_key (self , keys ):
112+ if isinstance (keys , six .string_types ):
113+ logging .debug (
114+ 'Passing auth key as string is deprecated, and will be removed'
115+ ' in 1.0.0'
116+ )
117+ return [keys ]
118+ elif (keys is None or isinstance (keys , list )):
119+ return keys
120+ raise ConfigurationError (
121+ 'auth_key and user_auth_key must be a string, list, or None'
122+ )
106123
107124 def _get_key_arn (self , key ):
108125 if key not in self .KEY_METADATA :
@@ -126,8 +143,9 @@ def _get_key_alias_from_cache(self, key_arn):
126143 def _valid_service_auth_key (self , key_arn ):
127144 if self .auth_key is None :
128145 return False
129- if key_arn == self ._get_key_arn (self .auth_key ):
130- return True
146+ for key in self .auth_key :
147+ if key_arn == self ._get_key_arn (key ):
148+ return True
131149 for key in self .scoped_auth_keys :
132150 if key_arn == self ._get_key_arn (key ):
133151 return True
@@ -136,8 +154,9 @@ def _valid_service_auth_key(self, key_arn):
136154 def _valid_user_auth_key (self , key_arn ):
137155 if self .user_auth_key is None :
138156 return False
139- if key_arn == self ._get_key_arn (self .user_auth_key ):
140- return True
157+ for key in self .user_auth_key :
158+ if key_arn == self ._get_key_arn (key ):
159+ return True
141160 return False
142161
143162 def _parse_username (self , username ):
0 commit comments