Configures security preferences for RAM users.

Description

This topic provides an example on how to enable multi-factor authentication (MFA) for all RAM users by calling the SetSecurityPreference operation. After the operation succeeds, MFA is required for all RAM users when the RAM users log on to the Alibaba Cloud Management Console by using usernames and passwords. In this example, you must set EnforceMFAForLogin to true and can retain the default values of other parameters.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes SetSecurityPreference

The operation that you want to perform. Set the value to SetSecurityPreference.

EnableSaveMFATicket Boolean No false

Specifies whether to remember the MFA devices for seven days. Valid values:

  • true: remembers the MFA devices for seven days.
  • false: does not remember the MFA devices. This is the default value.
AllowUserToChangePassword Boolean No true

Specifies whether RAM users can change their passwords. Valid values:

  • true: RAM users can change their passwords. This is the default value.
  • false: RAM users cannot change their passwords.
AllowUserToManageAccessKeys Boolean No false

Specifies whether RAM users can manage their AccessKey pairs. Valid values:

  • true: RAM users can manage their AccessKey pairs.
  • false: RAM users cannot manage their AccessKey pairs. This is the default value.
AllowUserToManageMFADevices Boolean No true

Specifies whether RAM users can manage their MFA devices. Valid values:

  • true: RAM users can manage their MFA devices. This is the default value.
  • false: RAM users cannot manage their MFA devices.
LoginSessionDuration Integer No 6

The validity period of the logon session of RAM users.

Valid values: 6 to 24. Unit: hours.

Default value: 6.

LoginNetworkMasks String No 10.0.0.0/8

The subnet mask that specifies the IP addresses from which you can log on to the Alibaba Cloud Management Console. This parameter takes effect on password-based logon and single sign-on (SSO). However, this parameter does not take effect on API calls that are authenticated by using AccessKey pairs.

  • If you specify a subnet mask, RAM users can use only the IP addresses in the subnet mask to log on to the Alibaba Cloud Management Console.
  • If you do not specify a subnet mask, RAM users can use all IP addresses to log on to the Alibaba Cloud Management Console.

If you need to specify multiple subnet masks, separate the subnet masks with semicolons (;). Example: 192.168.0.0/16;10.0.0.0/8.

You can specify up to 25 subnet masks. The total length of the subnet masks can be a maximum of 512 characters.

EnforceMFAForLogin Boolean No true

Specifies whether MFA is required for all RAM users when they log on to the Alibaba Cloud Management Console by using usernames and passwords. Valid values:

  • true: MFA is required for all RAM users when they log on to the Alibaba Cloud Management Console by using usernames and passwords.
  • false: User-specific settings are applied. This is the default value.
VerificationTypes Array of String No ["mfa"]

The verification method that is used to achieve access control for RAM users. Valid value: mfa, which indicates that the verification method is MFA.

This parameter is empty by default, which indicates that the verification method is disabled.

For more information about common request parameters, see Common parameters.

Response parameters

Parameter Type Example Description
SecurityPreference Object

The details of security preferences.

AccessKeyPreference Object

The AccessKey pair preference.

AllowUserToManageAccessKeys Boolean false

Indicates whether RAM users can manage their AccessKey pairs.

LoginProfilePreference Object

The logon preference.

EnableSaveMFATicket Boolean false

Indicates whether RAM users can remember the MFA devices for seven days.

LoginSessionDuration Integer 6

The validity period of the logon session of RAM users.

LoginNetworkMasks String 10.0.0.0/8

The subnet mask.

AllowUserToChangePassword Boolean true

Indicates whether RAM users can change their passwords.

EnforceMFAForLogin Boolean true

Indicates whether MFA is required for all RAM users when they log on to the Alibaba Cloud Management Console by using usernames and passwords.

MFAPreference Object

The MFA preference.

AllowUserToManageMFADevices Boolean false

Indicates whether RAM users can manage their MFA devices.

VerificationPreference Object

The verification method preference that is used to achieve access control.

VerificationTypes String ["mfa"]

The verification method that is used to achieve access control for RAM users.

RequestId String 17494710-B4BA-4185-BBBB-C1A6ABDE1639

The ID of the request.

Examples

Sample requests

https://[Endpoint]/?Action=SetSecurityPreference
&EnforceMFAForLogin=true
&<Common Request Parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<SetSecurityPreferenceResponse>
    <SecurityPreference>
        <LoginProfilePreference>
            <EnforceMFAForLogin>true</EnforceMFAForLogin>
            <LoginSessionDuration>6</LoginSessionDuration>
            <LoginNetworkMasks/>
            <AllowUserToChangePassword>true</AllowUserToChangePassword>
            <EnableSaveMFATicket>false</EnableSaveMFATicket>
        </LoginProfilePreference>
        <AccessKeyPreference>
            <AllowUserToManageAccessKeys>false</AllowUserToManageAccessKeys>
        </AccessKeyPreference>
        <VerificationPreference>
        </VerificationPreference>
        <MFAPreference>
            <AllowUserToManageMFADevices>false</AllowUserToManageMFADevices>
        </MFAPreference>
    </SecurityPreference>
    <RequestId>17494710-B4BA-4185-BBBB-C1A6ABDE1639</RequestId>
</SetSecurityPreferenceResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "SecurityPreference" : {
    "LoginProfilePreference" : {
      "EnforceMFAForLogin" : true,
      "LoginSessionDuration" : 6,
      "LoginNetworkMasks" : "",
      "AllowUserToChangePassword" : true,
      "EnableSaveMFATicket" : false
    },
    "AccessKeyPreference" : {
      "AllowUserToManageAccessKeys" : false
    },
    "VerificationPreference" : {
      "VerificationTypes" : [ ]
    },
    "MFAPreference" : {
      "AllowUserToManageMFADevices" : false
    }
  },
  "RequestId" : "17494710-B4BA-4185-BBBB-C1A6ABDE1639"
}

Error codes

For a list of error codes, visit the API Error Center.