1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Azure : Azure AD 認証で Azure Virtual Machine (Linux) にログインする

Last updated at Posted at 2022-06-13

Azure Active Directory 認証と連携させたつもりの Virtual Machine (Ubuntu 20.04 LTS) にログインしようとしたところ、エラーが発生しました。

PS C:¥> az ssh vm --hostname test-vm.japaneast.cloudapp.azure.com
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
azuread-user@test.onmicrosoft.com@test-vm.japaneast.cloudapp.azure.com: Permission denied (publickey).

VM 作成時に指定したユーザーと秘密鍵ファイルを使用したログインは可能です。

PS C:¥> ssh -l azureuser test-vm.japaneast.cloudapp.azure.com -i identity.file

VM 作成手順

以下2パターンを実施し、いずれも VM のログインに失敗しました。

  • Azure portal から VM を作成する際に、「Azure Active Directory でログインする」を ON にする。
  • Terraform から VM を作成する際に、拡張機能 AADSSHLoginForLinux を追加する。

VM は東日本リージョンに作成しています。

解決方法

AADSSHLoginForLinuxを追加したのちに、AADLoginForLinuxを追加することで解決しました。

Terraform から VM を作成することで確認しています。

Azure portal から作成した VM については試していませんが、同様の処置が必要かと思います。

Terraform

Terraform で拡張機能を追加した際のコードを掲載します。

resource "azurerm_virtual_machine_extension" "aadsshlogin" {
  name                       = "AADSSHLoginForLinux"
  virtual_machine_id         = azurerm_virtual_machine.example.id
  publisher                  = "Microsoft.Azure.ActiveDirectory"
  type                       = "AADSSHLoginForLinux"
  type_handler_version       = "1.0"
  auto_upgrade_minor_version = true
}

resource "azurerm_virtual_machine_extension" "aadlogin" {
  name                       = "AADLoginForLinux"
  virtual_machine_id         = azurerm_virtual_machine.example.id
  publisher                  = "Microsoft.Azure.ActiveDirectory.LinuxSSH"
  type                       = "AADLoginForLinux"
  type_handler_version       = "1.0"
  auto_upgrade_minor_version = true

  # ポイント!
  depends_on = [
    azurerm_virtual_machine_extension.aadsshlogin
  ]
}

「ポイント!」部分について、depends_onを指定してAADSSHLoginForLinuxの後にAADLoginForLinuxが追加されるようにしないと、terraform apply で以下のエラーが発生しました。

Error: Code="VMExtensionHandlerNonTransientError" Message="The handler for VM extension type 'Microsoft.Azure.ActiveDirectory.AADSSHLoginForLinux' has reported terminal failure for VM extension 'AADSSHLoginForLinux' with error message: '[ExtensionOperationError] Non-zero exit code:23, ...

気になること

2022年1,2月頃に VM を作成した際は、AADLoginForLinuxが無くてもログインできました。
本現象が発生した、2022年6月時点でも、すでに作成済みの VM にはAADLoginForLinuxの追加なしにログインできました。
また、2022年6月時点の公式ページ(後述の参考サイト)には、AADLoginForLinuxの追加が必要とは記載されていませんでした。

この現象が突如発生するようになった要因が不明です。

参考サイト

OpenSSH 証明書ベースの認証を使用した Azure Active Directory で Azure の Linux 仮想マシンにログインする

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?