You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
若不存在优先级更高的凭据信息,Credentials工具将通过环境变量获取ALIBABA_CLOUD_ECS_METADATA(ECS实例RAM角色名称)的值。若该变量的值存在,程序将采用加固模式(IMDSv2)访问ECS的元数据服务(Meta Data Server),以获取ECS实例RAM角色的STS Token作为默认凭据信息。在使用加固模式时若发生异常,将使用普通模式兜底来获取访问凭据。您也可以通过设置环境变量ALIBABA_CLOUD_IMDSV1_DISABLED,执行不同的异常处理逻辑:
Copy file name to clipboardExpand all lines: README.md
+17-3Lines changed: 17 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,7 +123,15 @@ cred_type = cred.get_type()
123
123
124
124
#### ECS RAM Role
125
125
126
-
By specifying the role name, the credential will be able to automatically request maintenance of STS Token.
126
+
Both ECS and ECI instances support binding instance RAM roles. When the Credentials tool is used in an instance, the RAM role bound to the instance will be automatically obtained, and the STS Token of the RAM role will be obtained by accessing the metadata service to complete the initialization of the credential client.
127
+
128
+
The instance metadata server supports two access modes: hardened mode and normal mode. The Credentials tool uses hardened mode (IMDSv2) by default to obtain access credentials. If an exception occurs when using hardened mode, you can set disable_imds_v1 to perform different exception handling logic:
129
+
130
+
- When the value is false (default value), the normal mode will continue to be used to obtain access credentials.
131
+
132
+
- When the value is true, it means that only hardened mode can be used to obtain access credentials, and an exception will be thrown.
133
+
134
+
Whether the server supports IMDSv2 depends on your configuration on the server.
127
135
128
136
```python
129
137
from alibabacloud_credentials.client import Client
@@ -132,7 +140,7 @@ from alibabacloud_credentials.models import Config
132
140
config = Config(
133
141
type='ecs_ram_role', # credential type
134
142
role_name='roleName', # `role_name` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests.
135
-
enable_imds_v2=True# `enable_imds_v2` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_ECS_IMDSV2_ENABLE
143
+
disable_imds_v1=True# Optional, whether to forcibly disable IMDSv1, that is, to use IMDSv2 hardening mode, which can be set by the environment variable ALIBABA_CLOUD_IMDSV1_DISABLED
136
144
)
137
145
cred = Client(config)
138
146
@@ -250,7 +258,13 @@ The default credential provider chain looks for available credentials, with foll
250
258
251
259
3. Instance RAM Role
252
260
253
-
If the environment variable `ALIBABA_CLOUD_ECS_METADATA` is defined and not empty, the program will take the value of the environment variable as the role name and request <http://100.100.100.200/latest/meta-data/ram/security-credentials/> to get the temporary Security credentials.
261
+
If there is no credential information with a higher priority, the Credentials tool will obtain the value of ALIBABA_CLOUD_ECS_METADATA (ECS instance RAM role name) through the environment variable. If the value of this variable exists, the program will use the hardened mode (IMDSv2) to access the metadata service (Meta Data Server) of ECS to obtain the STS Token of the ECS instance RAM role as the default credential information. If an exception occurs when using the hardened mode, the normal mode will be used as a fallback to obtain access credentials. You can also set the environment variable ALIBABA_CLOUD_IMDSV1_DISABLED to perform different exception handling logic:
262
+
263
+
- When the value is false, the normal mode will continue to obtain access credentials.
264
+
265
+
- When the value is true, it means that only the hardened mode can be used to obtain access credentials, and an exception will be thrown.
266
+
267
+
Whether the server supports IMDSv2 depends on your configuration on the server.
0 commit comments