WorkSpaces を 自前Active Directory に接続して立ち上げてみよう!

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

はじめに

くどうです。

WorkSpaces が Public Preview として公開されました。
この投稿ではActive Directoryに接続してWorkSpacesの立ち上げまでを書いています。
設定などは下記のドキュメントを参考に行っています。
Connect Amazon WorkSpaces to Your Directory
ただし、オンプレ環境は使用せずActive DirectoryもEC2上で利用する構成になっています。
Active Directoryもより実環境に近づけるためAZを分けた冗長構成でいます。

ここも参考に Amazon WorkSpacesがPublic Previewになった!のでやってみた!

構成図

本投稿での構成図を以下に示します。
workspace構成

Active Directoryの設定

WorkSpacesをActive Directoryへ接続する前に設定を行う必要があります。
ただし、Active Directoryは構成図のようにAZが分けられ構成されているものとします。
最初に、セキュリティグループに設定するポートを確認します。

Port Type of Traffic
TCP 53 DNS
TCP 88 Kerberos
TCP 135 EPM
TCP 139 NetBIOS Session Service
TCP 389 LDAP
TCP 445 DFS, LsaRpc, NbtSS, NetLogonR, SamR, SMB, SrvSvc
TCP 464 Kerberos Change/Set Password
TCP 636 LDAPS
TCP 3268 GC, LDAP
TCP 3269 GC, LDAPS
TCP 5722 DFS-R
TCP 9389 Active Directory Web Services
UDP 53 DNS
UDP 88 Kerberos
UDP 123 NTP
UDP 137 NetBIOS Name Service
UDP 138 NetBIOS Datagram Service
UDP 389 C-LDAP
UDP 445 SMB
UDP 464 Kerberos Change/Set Password
UDP 2535 MADCAP

事前に任意のセキュリティグループを作成し、Active Directory に適用します。

WorkSpaces用のグループを作成します。
ドメインルートを右クリックし新規作成→グループ
workspaces001

以下の値でグループを作成します。

フィールド
グループ名 WorkSpaces_Connectors
グローバルのスコープ グローバル
グローバルの種類 セキュリティ

上部メニューより操作→制御の委任
workspaces002

オブジェクト制御の委任ウィザードの開始。
ユーザまたはグループの追加画面へ進み追加します。
オブジェクトの種類は、ユーザー、コンピューターまたはグループを選択し、オブジェクト名に WorkSpaces_Connectors を入力し追加します。
workspaces003

委任するタスクは、すべてのユーザー情報の読み取り、コンピューターのドメインへの参加をチェックする。
workspaces004

これでウィザードを完了します。
次に、接続確認を行います。
接続確認には下記のツールPortQry をダウンロードします。
PortQry Command Line Port Scanner Version 2.0

PowerShellを起動し、Set-ExecutionPolicy Unrestricted を実行します。”Y”を入力します。 [PowerShell] PS C:\Users\Administrator.HOGE> Set-ExecutionPolicy Unrestricted

実行ポリシーの変更 実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリシーを変更すると、about_Execution_Policies のヘルプ トピック (http://go.microsoft.com/fwlink/?LinkID=135170) で説明されているセキュリティ上の危険にさらされる可能性があります。実行ポリシーを変更しますか? [Y] はい(Y) [N] いいえ(N) [S] 中断(S) [?] ヘルプ (既定値は "Y"): Y [/PowerShell]
PortQryV2の場所をPathに加えます。 [PowerShell] PS C:/> $env:Path = "C:\PortQryV2" [/PowerShell]
以下をコピーしてPowerShellスクリプトファイル(.ps1)として保存します。
[PowerShell] <# Verify the ports and credentials. #> $groups = @("domain admins","enterprise admins") $members = @() $memberNames = @() $hasPrivilege = $False $domainName = Read-Host "Please enter the domain name" $cred = Get-Credential $username = $cred.Username $password = $cred.GetNetWorkCredential().password

$assem = ("System.DirectoryServices.AccountManagement", "System") $source = @" using System; using System.Collections.Generic; using System.DirectoryServices.AccountManagement;

public class groupsOfUser { public List getGroups(string domainName, string username, string password) { List result = new List(); PrincipalContext domain = new PrincipalContext(ContextType.Domain, domainName, username, password); UserPrincipal user = UserPrincipal.FindByIdentity(domain, username); if(user != null) { PrincipalSearchResult groups = user.GetAuthorizationGroups(); foreach(Principal p in groups) { if(p is GroupPrincipal) { result.Add((GroupPrincipal)p); } } } return result; } } "@

Add-Type -ReferencedAssemblies $assem -TypeDefinition $source $getGroupsObject = New-Object groupsOfUser;

<# Check account credentials. #> Write-Host "======================================="; Write-Host "Checking domain name, user name, and password `n"; try { $groups = $getGroupsObject.getGroups($domainName, $username, $password); } catch [Exception] { Write-Host $_.Exception.ToString() "`n" -ForegroundColor red; } $groupNames = @(); $count = 0; while($groups[$count] -ne $null) { $groupNames += $groups[$count].name; $count++; }

<# Check forest functional level. #> Write-Host "======================================="; Write-Host "Checking forest functional level `n"; try { $ForestContext = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext("Forest", $domainName, $username, $password); $Forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetForest($ForestContext); } catch [Exception] { Write-Host $_.Exception.ToString() "`n" -ForegroundColor red; } Write-Host "`n The forest functional level is" $Forest.ForestMode; if($Forest.ForestMode -ge "Windows2008R2Forest") { Write-Host "`n The forest functional level is correct. `n" -ForegroundColor green; } else { Write-Host "`n The forest functional level must be Windows2008R2Forest or greater. You cannot connect to the directory! `n" -ForegroundColor red; }

<# Check domain functional level. #> Write-Host "======================================="; Write-Host "Checking domain functional level. `n"; try { $DomainContext = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext("Domain", $domainName, $username, $password); $Domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($DomainContext); } catch [Exception] { Write-Host $_.Exception.ToString() "`n" -ForegroundColor red; } Write-Host "`n The domain functional level is:" $Domain.DomainMode; if($Domain.DomainMode -ge "Windows2008R2Domain") { Write-Host "`n The domain functional level is correct. `n" -ForegroundColor green; } else { Write-Host "`n The domain functional level must be Windows2008R2Domain or greater. You cannot connect to the directory! `n" -ForegroundColor red; }

<# Verify identity of customer. #> Write-Host "======================================="; Write-Host "Verifying account privileges."; if(($groupNames -contains "domain admins") -or ($groupNames -contains "enterprise admins")) { Write-Host "`n The account has the privileges necessary to connect to the directory. `n" -Foregroundcolor green; } else { Write-Host "`n The account does not have the privileges necessary to connect to the directory. `n" -Foregroundcolor yellow; }

<#check ports#> $serviceName = "PortTest" $allTcpPorts = @(389,636,3268,3269,88,53,445,135,5722,464,9389,139) $allUdpPorts = @(389,88,53,445,123,464,138,2535,137) Write-Host "======================================="; Write-Host "Start to check ports `n"; Write-Host "In order to create an additional domain controller, please make sure all of the following ports are open. This test may take a while. `n";

foreach ($tcpPort in $allTcpPorts) { try { $cmd = "PortQry.exe"; $argList = "-n $domainName -e $tcpPort -p TCP"; $fileName = $serviceName + "output-TCP-$tcpPort.txt"; Start-Process "$cmd" "$argList" -NoNewWindow -RedirectStandardOutput "$fileName" -Wait; $content = Get-Content "$fileName"; $portListen = $content | Select-String "LISTENING"; $portNotListen = $content | Select-String "NOT LISTENING"; $portFiltered = $content | Select-String "FILTERED";

if(($portListen -ne $NULL) -and ($portNotListen -eq $NULL) -and ($portFiltered -eq $NULL)) { $result = $domainName + " has TCP " + $tcpPort + " Open"; Write-Host $result; }else { $result = $domainName + " has TCP " + $tcpPort + " Closed"; Write-Host $result -ForegroundColor yellow; } } catch [Exception] { Write-Host "`n" $_.Exception.ToString() -ForegroundColor red; break; } }

foreach ($udpPort in $allUdpPorts) { try { $cmd = "PortQry.exe"; $argList = "-n $domainName -e $udpPort -p UDP"; $fileName = $serviceName + "output-UDP-$udpPort.txt"; Start-Process "$cmd" "$argList" -NoNewWindow -RedirectStandardOutput "$fileName" -Wait; $content = Get-Content "$fileName"; $portListen = $content | Select-String "LISTENING"; $portNotListen = $content | Select-String "NOT LISTENING"; $portFiltered = $content | Select-String "FILTERED";

if(($portListen -ne $NULL) -and ($portNotListen -eq $NULL) -and ($portFiltered -eq $NULL)) { $result = $domainName + " has UDP " + $udpPort + " Open"; Write-Host $result; }else { $result = $domainName + " has UDP " + $udpPort + " Closed"; Write-Host $result -ForegroundColor yellow; } } catch [Exception] { Write-Host "`n" $_.Exception.ToString() -ForegroundColor red; break; } } [/PowerShell]
check.ps1として実行します。途中、資格情報を求められます。Administratorの資格情報を入力します。 以下のような結果が返ってきます。
[PowerShell] PS C:\Users\Administrator> C:\PortQryV2\check.ps1 Please enter the domain name: hoge.local

コマンド パイプライン位置 1 のコマンドレット Get-Credential 次のパラメーターに値を指定してください: Credential ======================================= Checking domain name, user name, and password

======================================= Checking forest functional level

The forest functional level is Windows8Forest

The forest functional level is correct.

======================================= Checking domain functional level.

The domain functional level is: Windows8Domain

The domain functional level is correct.

======================================= Verifying account privileges.

The account has the privileges necessary to connect to the directory.

======================================= Start to check ports

In order to create an additional domain controller, please make sure all of the following ports are open. This test may take a while.

hoge.local has TCP 389 Open hoge.local has TCP 636 Open hoge.local has TCP 3268 Open hoge.local has TCP 3269 Open hoge.local has TCP 88 Open hoge.local has TCP 53 Open hoge.local has TCP 445 Open hoge.local has TCP 135 Open hoge.local has TCP 5722 Closed hoge.local has TCP 464 Open hoge.local has TCP 9389 Open hoge.local has TCP 139 Closed hoge.local has UDP 389 Closed hoge.local has UDP 88 Closed hoge.local has UDP 53 Open hoge.local has UDP 445 Closed hoge.local has UDP 123 Closed hoge.local has UDP 464 Closed hoge.local has UDP 138 Closed hoge.local has UDP 2535 Closed hoge.local has UDP 137 Closed PS C:\Users\Administrator> [/PowerShell] 以上でActive Directoryの設定は完了です。
次は、WorkSpaces側の準備をします。

WorkSpacesの準備

Active Directoryに接続するには、WorkSpaces Connectを選択します。
workspaces005

事前にActive Directory側にユーザー(wsadmin)をグループ(WorkSpaces_Connectors)にて作成しておきます。
入力項目を入れます。

フィールド
Organization 会社名
Drirectory name ドメイン
NetBIOS(short) name NetBIOS名
Account username 事前作成したユーザー
Account password 事前作成したユーザーのパスワード
DNS address Active DrirectoryのIPアドレス
VPC VPC
Subnets 利用するサブネット2つ選択

workspaces006

確認画面にて設定を確認します。
workspaces007

Active Directoryとの接続を開始します。
workspaces008

Activeになれば完了です。
workspaces009

WorkSpacesを起動する

接続するディレクトリを選択します。
その後接続するためのユーザーを検索します。
ユーザーは事前に作成する必要があります。アカウント名とEメールは入力しておきましょう。
workspaces010

利用するプランを選択します。

workspaces011

確認画面です。 workspaces012

以上でWorksSpacesが利用できるようになります。
ただし、起動後20分程度たってから接続する必要があります。

workspaces013

接続には下記のURLからクライアントをダウンロードし、インストールを行います。 http://clients.amazonworkspaces.com/

registration codeを確認します。
workspaces014

registration codeを入力します。
workspaces015

Active Directoryで作成したユーザーでサインインします。
workspaces016

ユーザーでログインできていることが確認できます。
workspaces017

また、NATインスタンスの設定を行うことでインターネットへの接続も可能となります。
以上で、Active Directoryを使用したWorkSpacesの利用方法を紹介しました。

まとめ

今回はEC2でActive Directoryを構築し、WorkSpacesで利用する方法を紹介しましたが、当然オンプレのActive Directoryでも可能です。
今後はシンクライアントなどとの連携も期待されます。