你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Microsoft.Compute.CredentialsCombo UI 元素

CredentialsCombo 元素是一组控件,其中包含 Windows 密码和 Linux 密码或 SSH 公钥的内置验证。

UI 示例

对于 Windows,将显示密码控件。

Windows 密码的凭据和用户界面元素的屏幕截图。

对于选择了“密码”的 Linux,将显示密码控件:

Linux 密码的凭据和用户界面元素的屏幕截图。

对于选择了“SSH 公钥”的 Linux,将显示 SSH 密钥控件:

SSH 公钥的凭据和用户界面元素的屏幕截图。

“SSH 公钥源”有三个选项:

  • 生成新密钥对:提供名称以在 Azure 中创建新的 SSH 密钥对。
  • 使用 Azure 中存储的现有密钥:选择 Azure 中存储的现有 SSH 公钥。
  • 使用现有的公钥:使用已创建的 SSH 公钥。 例如,在本地计算机上创建的 SSH 公钥。

Linux SSH 公钥的凭据和用户界面元素及相关选项的屏幕截图。

对于“生成新密钥对”选项,选择“创建”和“下载私钥并创建资源”后,将在“查看+ 创建”选项卡上生成密钥。

生成新 SSH 密钥对并选择“下载私钥并创建资源”的屏幕截图。

架构

对于 Windows,请使用以下架构:

{
  "name": "element1",
  "type": "Microsoft.Compute.CredentialsCombo",
  "label": {
    "password": "Password",
    "confirmPassword": "Confirm password"
  },
  "toolTip": {
    "password": ""
  },
  "constraints": {
    "required": true,
    "customPasswordRegex": "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{12,}$",
    "customValidationMessage": "The password must be alphanumeric, contain at least 12 characters, and have at least 1 letter and 1 number."
  },
  "options": {
    "hideConfirmation": false
  },
  "osPlatform": "Windows",
  "visible": true
}

对于 Linux,请使用以下架构:

{
  "name": "element1",
  "type": "Microsoft.Compute.CredentialsCombo",
  "label": {
    "authenticationType": "Authentication type",
    "password": "Password",
    "confirmPassword": "Confirm password",
    "sshPublicKey": "SSH public key"
  },
  "toolTip": {
    "authenticationType": "",
    "password": "",
    "sshPublicKey": ""
  },
  "constraints": {
    "required": true,
    "customPasswordRegex": "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{12,}$",
    "customValidationMessage": "The password must be alphanumeric, contain at least 12 characters, and have at least 1 letter and 1 number."
  },
  "options": {
    "hideConfirmation": false,
    "hidePassword": false
  },
  "osPlatform": "Linux",
  "visible": true
}

示例输出

如果 osPlatformWindows 或者 osPlatformLinux,并且用户提供了密码而非 SSH 公钥,则控件将返回以下输出:

{
  "authenticationType": "password",
  "password": "p4ssw0rddem0",
}

如果 osPlatformLinux 并且用户提供了 SSH 公钥,则控件将返回以下输出:

{
  "authenticationType": "sshPublicKey",
  "sshPublicKey": "AAAAB3NzaC1yc2EAAAABIwAAAIEA1on8gxCGJJWSRT4uOrR13mUaUk0hRf4RzxSZ1zRbYYFw8pfGesIFoEuVth4HKyF8k1y4mRUnYHP1XNMNMJl1JcEArC2asV8sHf6zSPVffozZ5TT4SfsUu/iKy9lUcCfXzwre4WWZSXXcPff+EHtWshahu3WzBdnGxm5Xoi89zcE=",
  "sshKeyName": "demo-public-key-name",
  "generateNewSshKey": false
}
  • 选择“生成新密钥对”时,sshPublicKey 属性为空。 原因是选择“创建”和“下载私钥并创建资源”后,“查看 + 创建”选项卡上会生成密钥。
  • 仅当在 Azure 中或为已存储在 Azure 中的密钥生成新的 SSH 密钥对时,sshKeyName 属性才包含名称。
  • 使用现有密钥时,generateNewSshKey 为 false。 生成新的密钥对时,该值为 true。

备注

  • 必须指定 osPlatform,它可以是 WindowsLinux
  • 如果 constraints.required 设置为 true,则密码或 SSH 公钥文本框中必须有值才能成功通过验证。 默认值为 true
  • 如果 options.hideConfirmation 设置为 true,则用于确认用户密码的第二个文本框会被隐藏。 默认值是 false秒。
  • 如果 options.hidePassword 设置为 true,则使用密码身份验证这一选项会被隐藏。 只有当 osPlatformLinux 时才能使用它。 默认值是 false秒。
  • 可以使用 customPasswordRegex 属性实现对允许的密码的更多约束。 当密码没有通过自定义验证时,会显示 customValidationMessage 中的字符串。 两个属性的默认值都是 null。 架构显示每个属性的示例。

后续步骤