Updated on 2024-12-25 GMT+08:00

Syntax of Identity Conversion Rules

An identity conversion rule is a JSON object which can be modified. The following is an example JSON object:
[
          {
                    "local": [
                              {
                                        "<user> or <group> or <groups>"
                              }
                    ],
                    "remote": [
                              {
                                        "<condition>"
                              }
                    ]
          }
]

Parameter description:

  • local: Identity information of a federated user mapped to IAM. The value of this field can contain placeholders, such as {0...n}. The attributes {0} and {1} represent the first and second remote attributes of the user information, respectively.
  • remote: Information about a federated user of the IdP. This field is an expression consisting of assertion attributes and operators. The value of this field is determined by the assertion.
    • condition: Conditions for the identity conversion rule to take effect. The following three types of conditions are supported:
      • empty: The rule is matched to all claims containing the attribute type. This condition does not need to be specified. The condition result is the argument that is passed as input.
      • any_one_of: The rule is matched only if any of the specified strings appear in the attribute type. The condition result is Boolean, not the argument that is passed as input.
      • not_any_of: The rule is not matched if any of the specified strings appear in the attribute type. The condition result is Boolean, not the argument that is passed as input.

The user information mapped to IAM can only contain letters, digits, spaces, hyphens (-), underscores (_), and periods (.), and cannot start with a digit.

Examples of the Empty Condition

The empty condition returns character strings to replace the local attributes {0..n}.

  • In the following example, the username of the federated user is "the first remote attribute value+space+the second remote attribute value" in IAM, that is, FirstName LastName. The name of the group that the user belongs to is the third remote attribute value, which is Group. The Group attribute has only one value.
    [ 
            { 
                "local": [ 
                    { 
                        "user": { 
                            "name": "{0} {1}" 
                        } 
                    }, 
                    { 
                        "group": { 
                            "name": "{2}" 
                        } 
                    } 
                ], 
                "remote": [ 
                    { 
                        "type": "FirstName" 
                    }, 
                    { 
                        "type": "LastName" 
                    }, 
                    { 
                        "type": "Group" 
                    } 
                ] 
            } 
    ]     

    The following assertion (simplified for easy understanding) indicates that the username of the federated user is John Smith and the user only belongs to the admin group.

    {FirstName: John} 
    {LastName: Smith} 
    {Group: admin}
  • If a federated user belongs to multiple user groups in IAM, the identity conversion rule can be configured as follows.

    In the following example, the username of the federated user is "the first remote attribute value+space+the second remote attribute value" in IAM, that is, FirstName LastName. The groups that the user belongs to are the third remote attribute value, that is, Groups.

    [  
            {  
                "local": [  
                    {  
                        "user": {  
                            "name": "{0} {1}"  
                        }  
                    },  
                    {  
                        "group":   {  
                            "name": "{2}"  
                        }   
                    }  
                ],  
                "remote": [  
                    {  
                        "type": "FirstName"  
                    },  
                    {  
                        "type": "LastName"  
                    },  
                    {  
                        "type": "Groups"  
                    }  
                ]  
            }  
    ]  

    The following assertion indicates that the username of the federated user is John Smith and the user belongs to the admin and manager groups.

    {FirstName: John}  
    {LastName: Smith}  
    {Groups: [admin, manager]}

Examples of the "any one of" and "not any of" Conditions

Unlike the empty condition, the any one of and not any of conditions return Boolean values. These values will not be used to replace the local attributes. In the following example, only {0} is replaced by the returned value of the first empty condition in the remote block. The value of group is fixed as admin.

  • The username of the federated user in IAM is the first remote attribute value, that is, UserName. The federated user belongs to the admin group. This rule takes effect only for users who are members of the idp_admin group in the IdP.
    [ 
            { 
                "local": [ 
                    { 
                        "user": { 
                            "name": "{0}" 
                        } 
                    }, 
                    { 
                        "group": { 
                            "name": "admin" 
                        } 
                    } 
                ], 
                "remote": [ 
                    { 
                    "type": "UserName" 
                    }, 
                    { 
                        "type": "Groups", 
                        "any_one_of": [ 
                            "idp_admin" 
                        ] 
                    } 
                ] 
            } 
    ]     
  • If a federated user belongs to multiple user groups in IAM, the identity conversion rule can be configured as follows.
    The username of the federated user in IAM is the first remote attribute value, that is, UserName. The federated user belongs to the admin and manager groups. This rule takes effect only for users who are members of the idp_admin group in the IdP.
    [  
            {  
                "local": [  
                    {  
                        "user": {  
                            "name": "{0}"  
                        }  
                    },  
                    {  
                        "group": {
                               "name":"admin"
                        }
                    },
                    {  
                        "group": {
                               "name":"manager"
                        }
                    }
                ],  
                "remote": [  
                    {  
                    "type": "UserName"  
                    },  
                    {  
                        "type": "Groups",  
                        "any_one_of": [  
                            "idp_admin"  
                        ]  
                    }  
                ]  
            }  
    ]     
    • The following assertion indicates that the federated user John Smith is a member of the idp_admin group. Therefore, the user can access Huawei Cloud.
      {UserName: John Smith} 
      {Groups: [idp_user, idp_admin, idp_agency]}
    • The following assertion indicates that the federated user John Smith is not a member of the idp_admin group. Therefore, the rule does not take effect for the user and the user cannot access Huawei Cloud.
      {UserName: John Smith} 
      {Groups: [idp_user, idp_agency]}

Example Condition Containing a Regular Expression

You can add "regex": true to a condition to calculate results using a regular expression.

This rule takes effect for any user whose username ends with @mail.com. The username of each applicable federated user is UserName in IAM and the user belongs to the admin group.
[ 
        { 
            "local": [ 
                { 
                    "user": { 
                        "name": "{0}" 
                    } 
                }, 
                { 
                    "group": { 
                        "name": "admin" 
                    } 
                } 
            ], 
            "remote": [ 
                { 
                "type": "UserName" 
                }, 
                { 
                    "type": "Groups", 
                    "any_one_of": [ 
                        ".*@mail.com$" 
                    ], 
                    "regex": true 
                } 
            ] 
        } 
]     

Examples of Combined Conditions

Multiple conditions can be combined using the logical operator AND.

This rule takes effect only for the federated users who do not belong to the idp_user or idp_agent user group in the IdP. The username of each applicable federated user is UserName in IAM and the user belongs to the admin group.
[ 
        { 
            "local": [ 
                { 
                    "user": { 
                        "name": "{0}" 
                    } 
                }, 
                { 
                    "group": { 
                        "name": "admin" 
                    } 
                } 
            ], 
            "remote": [ 
                { 
                "type": "UserName" 
                }, 
                { 
                    "type": "Groups", 
                    "not_any_of": [ 
                        "idp_user" 
                    ] 
                }, 
                { 
                    "type": "Groups", 
                    "not_any_of": [ 
                        "idp_agent" 
                    ] 
                } 
            ] 
        } 
]     

The preceding rule is equivalent to the following:

[ 
        { 
            "local": [ 
                { 
                    "user": { 
                        "name": "{0}" 
                    } 
                }, 
                { 
                    "group": { 
                        "name": "admin" 
                    } 
                } 
            ], 
            "remote": [ 
                { 
                "type": "UserName" 
                }, 
                { 
                    "type": "Groups", 
                    "not_any_of": [ 
                        "idp_user", 
                        "idp_agent" 
                    ] 
                } 
            ] 
        } 
]     

Examples of Combined Rules

If multiple rules are combined, the methods for matching usernames and user groups are different.

The username of the federated user is the username matched in the first rule that takes effect. A federated user can log in to Huawei Cloud only if there is at least one rule taking effect to match the username. The user belongs to all groups matched in all rules that take effect. For easy understanding, username and user group rules can be configured separately.

In the following example, the rules take effect for users in the idp_admin group. The username of each applicable federated user is UserName in IAM and the user belongs to the admin group.

[ 
    { 
        "local": [ 
            { 
                "user": { 
                    "name": "{0}" 
                } 
            } 
        ], 
        "remote": [ 
            { 
                "type": "UserName" 
            } 
        ] 
    }, 
    { 
        "local": [ 
            { 
                "group": { 
                    "name": "admin" 
                } 
            } 
        ], 
        "remote": [ 
            { 
                "type": "Groups", 
                "any_one_of": [ 
                    "idp_admin" 
                ] 
            } 
        ] 
    }
]

The following assertion indicates that user John Smith is a member of the idp_admin group in the IdP and therefore meets the rules. The username of this user is John Smith in IAM, and the user belongs to the admin group.

{UserName: John Smith} 
{Groups: [idp_user, idp_admin, idp_agency]}