44
44
UnknownCredentialError ,
45
45
)
46
46
from botocore .tokens import SSOTokenProvider
47
- from botocore .useragent import register_feature_id
47
+ from botocore .useragent import register_feature_id , register_feature_ids
48
48
from botocore .utils import (
49
49
ArnParser ,
50
50
ContainerMetadataFetcher ,
@@ -705,6 +705,7 @@ def __init__(self, cache=None, expiry_window_seconds=None):
705
705
if expiry_window_seconds is None :
706
706
expiry_window_seconds = self .DEFAULT_EXPIRY_WINDOW_SECONDS
707
707
self ._expiry_window_seconds = expiry_window_seconds
708
+ self .feature_ids = set ()
708
709
709
710
def _create_cache_key (self ):
710
711
raise NotImplementedError ('_create_cache_key()' )
@@ -885,6 +886,7 @@ def __init__(
885
886
886
887
def _get_credentials (self ):
887
888
"""Get credentials by calling assume role."""
889
+ register_feature_ids (self .feature_ids )
888
890
kwargs = self ._assume_role_kwargs ()
889
891
client = self ._create_client ()
890
892
response = client .assume_role (** kwargs )
@@ -971,6 +973,7 @@ def __init__(
971
973
972
974
def _get_credentials (self ):
973
975
"""Get credentials by calling assume role."""
976
+ register_feature_ids (self .feature_ids )
974
977
kwargs = self ._assume_role_kwargs ()
975
978
# Assume role with web identity does not require credentials other than
976
979
# the token, explicitly configure the client to not sign requests.
@@ -1367,6 +1370,7 @@ def load(self):
1367
1370
)
1368
1371
token = self ._get_session_token (config )
1369
1372
account_id = self ._get_account_id (config )
1373
+ register_feature_id ('CREDENTIALS_PROFILE' )
1370
1374
return Credentials (
1371
1375
access_key ,
1372
1376
secret_key ,
@@ -1434,6 +1438,7 @@ def load(self):
1434
1438
)
1435
1439
token = self ._get_session_token (profile_config )
1436
1440
account_id = self ._get_account_id (profile_config )
1441
+ register_feature_id ('CREDENTIALS_PROFILE' )
1437
1442
return Credentials (
1438
1443
access_key ,
1439
1444
secret_key ,
@@ -1513,6 +1518,11 @@ class AssumeRoleProvider(CredentialProvider):
1513
1518
# remaining time left until the credentials expires is less than the
1514
1519
# EXPIRY_WINDOW.
1515
1520
EXPIRY_WINDOW_SECONDS = 60 * 15
1521
+ NAMED_PROVIDER_FEATURE_MAP = {
1522
+ 'Ec2InstanceMetadata' : 'CREDENTIALS_IMDS' ,
1523
+ 'Environment' : 'CREDENTIALS_ENV_VARS' ,
1524
+ 'EcsContainer' : 'CREDENTIALS_HTTP' ,
1525
+ }
1516
1526
1517
1527
def __init__ (
1518
1528
self ,
@@ -1575,6 +1585,7 @@ def __init__(
1575
1585
self ._credential_sourcer = credential_sourcer
1576
1586
self ._profile_provider_builder = profile_provider_builder
1577
1587
self ._visited_profiles = [self ._profile_name ]
1588
+ self ._feature_ids = set ()
1578
1589
1579
1590
def load (self ):
1580
1591
self ._loaded_config = self ._load_config ()
@@ -1625,10 +1636,13 @@ def _load_creds_via_assume_role(self, profile_name):
1625
1636
mfa_prompter = self ._prompter ,
1626
1637
cache = self .cache ,
1627
1638
)
1639
+ fetcher .feature_ids = self ._feature_ids .copy ()
1628
1640
refresher = fetcher .fetch_credentials
1629
1641
if mfa_serial is not None :
1630
1642
refresher = create_mfa_serial_refresher (refresher )
1631
1643
1644
+ self ._feature_ids .add ('CREDENTIALS_STS_ASSUME_ROLE' )
1645
+ register_feature_ids (self ._feature_ids )
1632
1646
# The initial credentials are empty and the expiration time is set
1633
1647
# to now so that we can delay the call to assume role until it is
1634
1648
# strictly needed.
@@ -1757,18 +1771,20 @@ def _has_static_credentials(self, profile):
1757
1771
def _resolve_source_credentials (self , role_config , profile_name ):
1758
1772
credential_source = role_config .get ('credential_source' )
1759
1773
if credential_source is not None :
1774
+ self ._feature_ids .add ('CREDENTIALS_PROFILE_NAMED_PROVIDER' )
1760
1775
return self ._resolve_credentials_from_source (
1761
1776
credential_source , profile_name
1762
1777
)
1763
1778
1764
1779
source_profile = role_config ['source_profile' ]
1765
1780
self ._visited_profiles .append (source_profile )
1781
+ self ._feature_ids .add ('CREDENTIALS_PROFILE_SOURCE_PROFILE' )
1766
1782
return self ._resolve_credentials_from_profile (source_profile )
1767
1783
1768
1784
def _resolve_credentials_from_profile (self , profile_name ):
1769
1785
profiles = self ._loaded_config .get ('profiles' , {})
1770
1786
profile = profiles [profile_name ]
1771
-
1787
+ self . _feature_ids . add ( 'CREDENTIALS_PROFILE' )
1772
1788
if (
1773
1789
self ._has_static_credentials (profile )
1774
1790
and not self ._profile_provider_builder
@@ -1824,6 +1840,11 @@ def _resolve_credentials_from_source(
1824
1840
f'in profile { profile_name } '
1825
1841
),
1826
1842
)
1843
+ named_provider_feature_id = self .NAMED_PROVIDER_FEATURE_MAP .get (
1844
+ credential_source
1845
+ )
1846
+ if named_provider_feature_id :
1847
+ self ._feature_ids .add (named_provider_feature_id )
1827
1848
return credentials
1828
1849
1829
1850
@@ -1854,6 +1875,7 @@ def __init__(
1854
1875
if token_loader_cls is None :
1855
1876
token_loader_cls = FileWebIdentityTokenLoader
1856
1877
self ._token_loader_cls = token_loader_cls
1878
+ self ._feature_ids = set ()
1857
1879
1858
1880
def load (self ):
1859
1881
return self ._assume_role_with_web_identity ()
@@ -1876,8 +1898,15 @@ def _get_env_config(self, key):
1876
1898
def _get_config (self , key ):
1877
1899
env_value = self ._get_env_config (key )
1878
1900
if env_value is not None :
1901
+ self ._feature_ids .add ('CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN' )
1879
1902
return env_value
1880
- return self ._get_profile_config (key )
1903
+
1904
+ config_value = self ._get_profile_config (key )
1905
+ if config_value is not None :
1906
+ self ._feature_ids .add ('CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN' )
1907
+ return config_value
1908
+
1909
+ return None
1881
1910
1882
1911
def _assume_role_with_web_identity (self ):
1883
1912
token_path = self ._get_config ('web_identity_token_file' )
@@ -1907,6 +1936,10 @@ def _assume_role_with_web_identity(self):
1907
1936
extra_args = extra_args ,
1908
1937
cache = self .cache ,
1909
1938
)
1939
+ fetcher .feature_ids = self ._feature_ids .copy ()
1940
+
1941
+ self ._feature_ids .add ('CREDENTIALS_STS_ASSUME_ROLE_WEB_ID' )
1942
+ register_feature_ids (self ._feature_ids )
1910
1943
# The initial credentials are empty and the expiration time is set
1911
1944
# to now so that we can delay the call to assume role until it is
1912
1945
# strictly needed.
0 commit comments