# Azure Automation の接続

## 概要

{% embed url="<https://www.youtube.com/watch?v=Ijp9XnE8UuA>" %}

RealmJoin Portal が提供できるようにするには [runbooks ](/ja/zi-dong-hua/runbooks.md)日常タスクの自動化のために、次のいずれかに接続する必要があります [Azure Automation](https://learn.microsoft.com/en-us/azure/automation/overview) アカウント。この Automation Account は runbooks のホストとして機能し、 [permissions](/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md) 環境内で runbooks が機能するために必要なものを提供します。

## 考慮事項

Automation Account の [Managed Identity](https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview) には広範な [permissions ](/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md)権限が必要です。たとえば、Entra ID でグループやユーザーのオブジェクトを変更したり、Exchange Online でメールボックスを管理したりする機能などです。これらの特権の悪用を防ぐため、このアカウントへの管理アクセスは制限してください。

既存の Automation Account を使用する場合、RealmJoin Portal は [shared online repository of runbooks](https://github.com/realmjoin/realmjoin-runbooks)から取得した runbooks を自動的に作成、更新、削除することに注意してください。この機能は既存の Automation Account ではサポートされない場合があります。不確かな場合は、RealmJoin Runbooks 用に専用の Azure Automation Account を作成することをお勧めします。

## 前提条件

* 全体管理者権限
* 次を使用した PowerShell へのアクセス [Az](https://learn.microsoft.com/en-us/powershell/azure/?view=azps-15.3.0) モジュールまたは [AZ CLI](https://learn.microsoft.com/en-us/cli/azure/?view=azure-cli-latest)
* Azure サブスクリプションに対する Contributor 権限
* [Runbook の要件](/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md)

## 手順

{% stepper %}
{% step %}

#### Azure Automation Account を作成する

1. 次へ移動します [Azure Portal > Automation Accounts](https://portal.azure.com/#create/Microsoft.AutomationAccount)
2. 新しい Automation Account を作成する
3. Basics タブで、希望する Subscription、Resource Group、Automation Account 名、Region を選択します<br>

   <figure><img src="/files/558807d9e5dc3ff69a1f10e95dd9467cea3711ee" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
Automation Account 用に別の Resource Group を用意することをお勧めします
{% endhint %}

4. Advanced タブで、System Assigned Managed Identity が有効になっていることを確認します

   <figure><img src="/files/cebce7ea795223f29dc5b7c19035707ae50ca89f" alt=""><figcaption></figcaption></figure>
5. Review + Create を選択し、Automation Account を作成します
6. Azure Automation Account を含む Resource Group に移動します
7. IAM タブで、Azure Automation Account に Contributor を割り当てます
   {% endstep %}

{% step %}

#### Azure Automation Account に権限を割り当てる

RealmJoin の共有 runbooks は、Azure Automation の system assigned managed identity を使用して Entra ID、MS Graph API などと連携します。

Managed Identity の権限は現在、Azure Portal 経由では付与できません。これらの権限を割り当てるには Microsoft Graph または PowerShell を使用してください。

1. 次の PowerShell スクリプトと JSON ファイルを同じフォルダーにダウンロードしてください。\
   このスクリプトは、RealmJoin に必要な完全な権限セットを割り当てます。ロールと権限は、 [要件](/ja/zi-dong-hua/connecting-azure-automation/azure-ad-roles-and-permissions.md) セクションで確認でき、必要に応じて JSON ファイルで調整できます。

{% tabs %}
{% tab title="GrantAppPermToEntApp.ps1" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/GrantAppPermToEntApp.ps1>" %}
{% endtab %}

{% tab title="AssignAzureADRoleToEntApp.ps1" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/AssignAzureADRoleToEntApp.ps1>" %}
{% endtab %}

{% tab title="RJvNextPermissions.json" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/RealmJoinVnext/RJvNextPermissions.json>" %}
{% endtab %}

{% tab title="RJvNextRoles.json" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/RealmJoinVnext/RJvNextRoles.json>" %}
{% endtab %}
{% endtabs %}

2. Account Settings > Identity で、Azure Automation Account の Managed Identity の Object ID を控えておきます

   <figure><img src="/files/8aeef31c277a4dbf352d75304e181d617737a475" alt=""><figcaption></figcaption></figure>
3. PowerShell ウィンドウを開きます。
4. ダウンロードしたファイルが含まれるフォルダーに移動します

```
cd c:\temp\myfolder
```

5. 必要に応じてスクリプトのブロックを解除します\
   ![](/files/000f14430797f2dc09cacdb8829c22d9e00f4cbc)
6. GrantAppPermToEntApp.ps1 を使用して Azure Automation Account に MS Graph Permissions を割り当てます。xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx は Automation Account の Object ID に置き換えてください

```
. .\GrantAppPermToEntApp.ps1 -enterpriseAppObjId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -permissionsTemplate .\RJvNextPermissions.json
```

7. AssignAzureADRoleToEntApp.ps1 を使用して Azure Automation Account に Entra ID 管理ロールを割り当てます。xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx は Automation Account の Object ID に置き換えてください

```
. .\AssignAzureADRoleToEntApp.ps1 -objectId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -rolesTemplate .\RJvNextRoles.json
```

8. これで Azure Automation Account には Runbooks を実行するための正しい権限が付与されているはずです<br>
   {% endstep %}

{% step %}

#### RealmJoin Runbook Configuration - Part 1

1. RealmJoin Portal で '[Settings -> Runbooks](https://portal.realmjoin.com/settings/runbooks-configuration)'.<br>

   <figure><img src="/files/73e470bc8262e8f5956298238e47bcecc72cbb04" alt=""><figcaption></figcaption></figure>
2. Azure Automation Account に対応する Tenant ID、Subscription ID、Resource Group 名を入力します\
   &#x20;[Entra ID Overview page](https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Overview)

   <figure><img src="/files/4651a9dcb9e1cd6a07d9ec2dcab8ea37dd146eea" alt=""><figcaption></figcaption></figure>
3. 下に赤色で示されているスクリプトをコピーします *ResourceGroup.*\
   このスクリプトは、Entra ID に Service Principal を作成し、Automation Account へのアクセスを付与します。これにより RealmJoin は runbooks を管理、実行、監視できるようになります。\
   このスクリプトは、Tenant ID、Subscription ID、Resource Group の入力に基づいて更新されます。<br>

   <figure><img src="/files/5221b368bf8ec49f8d0beb372006fb3e8097d72a" alt=""><figcaption></figcaption></figure>
4. ウィザードは今のところ開いたままにしておいてください。part 2 ですぐに戻ります。
   {% endstep %}

{% step %}

#### RealmJoin に Azure Automation へのアクセスを付与する

{% hint style="info" %}
次を使用できます [Azure CloudShell](https://docs.microsoft.com/en-us/azure/cloud-shell/overview)。そのため、AZ CLI のローカルコピーをインストールして認証する必要はありません。
{% endhint %}

1. 先ほどコピーしたスクリプトを PowerShell で実行します。

   <figure><img src="/files/9e791e225e968fff364176be96bd3447ce177a15" alt=""><figcaption></figcaption></figure>
2. 次の値を控えておきます `appId` と `password`。\
   App Registration "RealmJoin Runbook Management" が作成されます。<br>

   ![Azure Portal の App Registrations](/files/16ce1f21dd091192d47b796c064d4dd959bb6088)
   {% endstep %}

{% step %}

#### RealmJoin Runbook Configuration - Part 2

1. RealmJoin Portal で ' の開いているウィンドウ/ウィザードに戻ります[Settings -> Runbooks](https://portal.realmjoin.com/settings/runbooks-configuration)'
2. 次の不足している値を入力します `appId` と `password` 前の手順で作成された
3. 作成した Automation Account の名前を入力します [前に](#create-an-azure-automation-account)
4. 使用する共有 runbook リポジトリの Branch を選択します。\
   不明な場合は、次を選択してください `production`\
   すべての runbook ブランチはここで確認できます: <https://github.com/realmjoin/realmjoin-runbooks>
5. runbooks が正しい場所で実行されるように、Azure Automation Account と同じ location を選択してください [Azure region](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview)

![RealmJoin Portal での Automation Account 接続](/files/7136a85ec0d1d89eb9598c65ba74c02a2590659b)

6. "Save" を押して runbooks の初回インポートを開始します。"Sync completed" というメッセージが表示されるまで、このウィンドウを開いたままにしてください。

![](/files/7bca85aae4b6c741b94769171f3a95bd3ef0a4d1)
{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.realmjoin.com/ja/zi-dong-hua/connecting-azure-automation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
