|
| 1 | +# Active Directory with seamless Windows EC2 join |
| 2 | + |
| 3 | +The terraform code is built on top of |
| 4 | +[vpc-scenario1](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Scenario1.html) |
| 5 | +with two additional private subnets and a NAT gateway on a public |
| 6 | +subnet. |
| 7 | + |
| 8 | +## Environment creation and deployment |
| 9 | + |
| 10 | +To use this example set up AWS credentials and then run the commands in the |
| 11 | +following order: |
| 12 | + |
| 13 | +``` |
| 14 | +make ssh-key |
| 15 | +make init |
| 16 | +make plan-vpc |
| 17 | +make apply |
| 18 | +make plan-subnets |
| 19 | +make apply |
| 20 | +make plan-gateway |
| 21 | +make apply |
| 22 | +make plan |
| 23 | +make apply |
| 24 | +``` |
| 25 | + |
| 26 | +## Execution |
| 27 | + |
| 28 | +Once you run the above commands, you will get an output like this: |
| 29 | + |
| 30 | +``` shellsession |
| 31 | +... |
| 32 | +module.nat-gateway.aws_route_table_association.private-rta[0]: Refreshing state... [id=rtbassoc-0be4f2c71ef12e768] |
| 33 | +module.nat-gateway.aws_route_table_association.private-rta[1]: Refreshing state... [id=rtbassoc-08a1f878abab73841] |
| 34 | +aws_ssm_association.associate_ssm: Refreshing state... [id=996ff9a8-0931-4000-85aa-d01ef536f5a7] |
| 35 | + |
| 36 | +Outputs: |
| 37 | + |
| 38 | +microsoft-ad_dns_ip_addresses = [ |
| 39 | + "10.23.21.173", |
| 40 | + "10.23.22.20", |
| 41 | +] |
| 42 | +microsoft-ad_dns_name = dev.fpcomplete.local |
| 43 | +windows_ec2_public_dns = ec2-3-15-223-193.us-east-2.compute.amazonaws.com |
| 44 | +``` |
| 45 | + |
| 46 | +## Testing |
| 47 | + |
| 48 | +You need to test that the Windows EC2 instance actually joined the |
| 49 | +Active directory. There are two ways to test it: |
| 50 | + |
| 51 | +* RDP to your instance and verify |
| 52 | +* RDP using Active Directory authentication |
| 53 | + |
| 54 | +### Method 1 |
| 55 | + |
| 56 | +On a Linux client machine, something like |
| 57 | +[remmina](https://remmina.org) can be used to RDP into your Windows |
| 58 | +EC2 instance. You need to fill three information in the Remmina client |
| 59 | +to successfully RDP: |
| 60 | + |
| 61 | +* Server: This will be the output from `windows_ec2_public_dns` |
| 62 | +* User name: Administrator |
| 63 | +* User password: The password you used with the variable named |
| 64 | + `admin_password` in `variables.tf`. |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +Note that if you try to take the password from the AWS Console using |
| 69 | +your SSH private key, that won't work as it has been overridden using |
| 70 | +[bootstrap.win.txt](./bootstrap.win.txt). |
| 71 | + |
| 72 | +Once you connect into the instance, you need to check the properties |
| 73 | +of your machine there: |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +If you have a `Domain:` entry there, then that means the instance has |
| 78 | +successfully joined the Active directory. Instead, if you have an |
| 79 | +entry that starts with `Workgroup:` then your device is not joined to an |
| 80 | +Active Directory. |
| 81 | + |
| 82 | +### Method 2 |
| 83 | + |
| 84 | +In this method, you again try to RDP via the Active directory |
| 85 | +credentials. When you create a directory with AWS Managed Microsoft |
| 86 | +AD, it will create a directory administrator account with the user |
| 87 | +name `Admin` and the specified password (which you supplied through |
| 88 | +terraform). Let's again use Remmina to fill the following four |
| 89 | +information: |
| 90 | + |
| 91 | +* Server: This will be the output from `windows_ec2_public_dns` |
| 92 | +* User name: Admin |
| 93 | +* User password: The password you used with the variable named |
| 94 | + `active_directory_password` in `variables.tf`. |
| 95 | +* Domain: The domain name which you passed in the `locals.tf`. For |
| 96 | + this example, it is `dev.fpcomplete.local`. |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +If it's able to successfully connect to the instance, you can confirm |
| 101 | +that the EC2 instance has actually joined the AD. You can further verify that you have actually logged in via Active directory through the following steps: |
| 102 | + |
| 103 | +* Start the "CMD" program. |
| 104 | +* Type "set user". |
| 105 | +* You will recieve a output from the above command. Look at the line |
| 106 | + start with `USERDOMAIN:` entry. If it contains your computer's name, |
| 107 | + then you're logged in to the computer. If it contains the Active |
| 108 | + Directory's name, you're logged in to the Active Directory. In our |
| 109 | + case this is the output we receive which confirms that we are logged |
| 110 | + in via AD: |
| 111 | + |
| 112 | +``` shellsession |
| 113 | +C:\Users\Admin>set user |
| 114 | +USERDNSDOMAIN=DEV.FPCOMPLETE.LOCAL |
| 115 | +USERDOMAIN=dev |
| 116 | +USERDOMAIN_ROAMINGPROFILE=dev |
| 117 | +USERNAME=Admin |
| 118 | +USERPROFILE=C:\Users\Admin |
| 119 | +``` |
| 120 | + |
| 121 | +## Destruction |
| 122 | + |
| 123 | +To destroy the test environment run the following commands: |
| 124 | + |
| 125 | +``` |
| 126 | +$ make destroy |
| 127 | +$ make clean |
| 128 | +``` |
| 129 | + |
| 130 | +## Reference |
| 131 | + |
| 132 | +* [AWS docs on AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_getting_started.html) |
| 133 | +* [AWS docs on Joining an EC2 instance](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_join_instance.html) |
| 134 | +* [AWS docss on Systems manager and AD](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-systems-manager-dx-domain/) |
0 commit comments