Giter VIP home page Giter VIP logo

windows-domain-controller-vagrant's Introduction

About

This is an example on how to create a Windows Domain Controller using Vagrant and PowerShell.

This also shows how to add a Computer to an existing domain using PowerShell.

This will create an example.com Active Directory Domain Forest.

This will also install a Certification Authority with a GPO to automatically enroll computers with a certificate signed by the trusted domain CA, Remote Desktop users will therefore see and use trusted certificates.

This will also set the user photo with a GPO.

This will also set the Remote Desktop Users group with a GPO.

This will also setup the whoami group Managed Service Account (gMSA).

This setup will use the following static IP addresses:

IP Hostname Description
192.168.56.2 dc.example.com Domain Controller Computer
192.168.56.3 windows.example.com Test Windows Computer
192.168.56.4 ubuntu.example.com Test Ubuntu Computer

NB these are hardcoded in several files. Find then with grep -r 192.168.56. ..

Usage

Install the Windows 2022 base box.

Install the Ubuntu 22.04 base box.

Install the required Vagrant plugins:

vagrant plugin install vagrant-windows-sysprep
vagrant plugin install vagrant-reload

Start by launching the Domain Controller environment:

# or --provider=hyperv (first see the Hyper-V Usage section bellow).
# or --provider=virtualbox
vagrant up --provider=libvirt

Launch the test nodes:

cd test-nodes
# or --provider=hyperv
# or --provider=virtualbox
vagrant up --provider=libvirt

Sign-in on the test nodes with one of the following accounts:

  • Username john.doe and password HeyH0Password.
    • This account is also a Domain Administrator.
  • Username jane.doe and password HeyH0Password.
  • Username Administrator and password HeyH0Password.
    • This account is also a Domain Administrator.
  • Username .\vagrant and password password.
    • NB you MUST use the local vagrant account. because the domain also has a vagrant account, and that will mess-up the local one...

You can login at the machine console.

You can login with remote desktop, e.g.:

xfreerdp \
  /v:dc.example.com \
  /u:john.doe \
  /p:HeyH0Password \
  /size:1440x900 \
  /dynamic-resolution \
  +clipboard

NB For an headless RDP example see the winps repository.

You can login with ssh, e.g.:

Active Directory LDAP

You can use a normal LDAP client for accessing the Active Directory.

It accepts the following Bind DN formats:

  • <userPrincipalName>@<DNS domain>, e.g. [email protected]
  • <sAMAccountName>@<NETBIOS domain>, e.g. jane.doe@EXAMPLE
  • <NETBIOS domain>\<sAMAccountName>, e.g. EXAMPLE\jane.doe
  • <DN for an entry with a userPassword attribute>, e.g. CN=jane.doe,CN=Users,DC=example,DC=com

NB sAMAccountName MUST HAVE AT MOST 20 characters.

Some attributes are available in environment variables:

Attribute Environment variable Example
sAMAccountName USERNAME jane.doe
sAMAccountName USERPROFILE C:\Users\jane.doe
NETBIOS domain USERDOMAIN EXAMPLE
DNS domain USERDNSDOMAIN EXAMPLE.COM

You can list all of the active users using ldapsearch as:

ldapsearch \
  -H ldap://dc.example.com \
  -D [email protected] \
  -w HeyH0Password \
  -x -LLL \
  -b CN=Users,DC=example,DC=com \
  '(&(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))' \
  sAMAccountName userPrincipalName userAccountControl displayName cn mail

NB To have ldapsearch you can install the msys2 mingw-w64-openldap package with pacman -Sy mingw-w64-x86_64-openldap.

For TLS, use -H ldaps://dc.example.com, after creating the ldaprc file with:

openssl x509 -inform der -in tmp/ExampleEnterpriseRootCA.der -out tmp/ExampleEnterpriseRootCA.pem
cat >ldaprc <<'EOF'
TLS_CACERT tmp/ExampleEnterpriseRootCA.pem
TLS_REQCERT demand
EOF

Troubleshoot TLS with:

# see the TLS certificate validation result:
echo | openssl s_client -connect dc.example.com:636 -servername dc.example.com -CAfile tmp/ExampleEnterpriseRootCA.pem
# see the TLS certificate being returned by the server:
echo | openssl s_client -connect dc.example.com:636 -servername dc.example.com | openssl x509 -noout -text -in -

Active Directory DNS

You can update the DNS zone using the computer principal credentials, e.g.:

kinit --keytab=/etc/sssd/sssd.keytab 'ubuntu$'
nsupdate -g <<'EOF'
server dc.example.com
zone example.com.
update delete ubuntu.example.com. in A
update add ubuntu.example.com. 60 in A 192.168.56.4
update delete ubuntu.example.com. in TXT
update add ubuntu.example.com. 60 in TXT "hello world"
send
EOF
kdestroy

Hyper-V Usage

Follow the rgl/windows-vagrant Hyper-V Usage section.

Create the required virtual switches:

PowerShell -NoLogo -NoProfile -ExecutionPolicy Bypass <<'EOF'
@(
  @{Name='windows-domain-controller'; IpAddress='192.168.56.1'}
) | ForEach-Object {
  $switchName = $_.Name
  $switchIpAddress = $_.IpAddress
  $networkAdapterName = "vEthernet ($switchName)"
  $networkAdapterIpAddress = $switchIpAddress
  $networkAdapterIpPrefixLength = 24

  # create the vSwitch.
  Hyper-V\New-VMSwitch -Name $switchName -SwitchType Internal | Out-Null

  # assign it an host IP address.
  $networkAdapter = Get-NetAdapter $networkAdapterName
  $networkAdapter | New-NetIPAddress `
    -IPAddress $networkAdapterIpAddress `
    -PrefixLength $networkAdapterIpPrefixLength `
    | Out-Null
}

# remove all virtual switches from the windows firewall.
Set-NetFirewallProfile `
  -DisabledInterfaceAliases (
        Get-NetAdapter -name "vEthernet*" | Where-Object {$_.ifIndex}
    ).InterfaceAlias
EOF

windows-domain-controller-vagrant's People

Contributors

matthiashertel avatar rgl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

windows-domain-controller-vagrant's Issues

provision-msys2.ps1 throws error

Line:

pacman --noconfirm -Sy man mingw-w64-x86_64-openldap

Throws:

 pacman --noconfirm -Sy man mingw-w64-x86_64-openldap
:: Synchronizing package databases...
 mingw32 is up to date
 mingw64 is up to date
 msys is up to date
resolving dependencies...
looking for conflicting packages...

Packages (29) db-5.3.28-2  gdbm-1.18.1-3  groff-1.22.4-1  libgdbm-1.18.1-3
              libpipeline-1.5.2-1  mingw-w64-x86_64-ca-certificates-20190110-1
              mingw-w64-x86_64-cyrus-sasl-2.1.27-1
              mingw-w64-x86_64-expat-2.2.9-1
              mingw-w64-x86_64-gcc-libs-10.1.0-2
              mingw-w64-x86_64-gdbm-1.18.1-2
              mingw-w64-x86_64-gettext-0.19.8.1-8  mingw-w64-x86_64-gmp-6.2.0-1
              mingw-w64-x86_64-libffi-3.3-1  mingw-w64-x86_64-libiconv-1.16-1
              mingw-w64-x86_64-libtasn1-4.16.0-1
              mingw-w64-x86_64-libtool-2.4.6-17
              mingw-w64-x86_64-libwinpthread-git-8.0.0.5814.9dbf4cc1-1
              mingw-w64-x86_64-mpc-1.1.0-1  mingw-w64-x86_64-mpfr-4.0.2-2
              mingw-w64-x86_64-openssl-1.1.1.g-1
              mingw-w64-x86_64-p11-kit-0.23.20-2
              mingw-w64-x86_64-readline-8.0.004-1
              mingw-w64-x86_64-sqlite3-3.31.1-1  mingw-w64-x86_64-tcl-8.6.10-1
              mingw-w64-x86_64-termcap-1.3.1-5  mingw-w64-x86_64-zlib-1.2.11-7
              perl-5.30.2-1  man-db-2.9.1-1  mingw-w64-x86_64-openldap-2.4.50-1

Total Installed Size:  237.63 MiB

:: Proceed with installation? [Y/n]
(29/29) checking keys in keyring                   [#####################] 100%
(29/29) checking package integrity                 [#####################] 100%
(29/29) loading package files                      [#####################] 100%
error: could not open file /var/cache/pacman/pkg/libgdbm-1.18.1-3-x86_64.pkg.tar.zst: Child process exited with status 127
error: could not open file /var/cache/pacman/pkg/gdbm-1.18.1-3-x86_64.pkg.tar.zst: Child process exited with status 127
error: could not open file /var/cache/pacman/pkg/mingw-w64-x86_64-gcc-libs-10.1.0-2-any.pkg.tar.zst: Child process exited with status 127
error: could not open file /var/cache/pacman/pkg/mingw-w64-x86_64-libtool-2.4.6-17-any.pkg.tar.zst: Child process exited with status 127
error: could not open file /var/cache/pacman/pkg/mingw-w64-x86_64-openldap-2.4.50-1-any.pkg.tar.zst: Child process exited with status 127
error: failed to commit transaction (cannot open package file)
Errors occurred, no packages were upgraded.

Functionality for Linux Host - SMB Shared Folders

Hi,
I'm curious... the README shows examples of using this project with either virtualbox or libvirt, yet the Vagrant Sync'd Folders are SMB based, which limits host OS's to Windows or Mac OSX. I notice in the Packer projects for building your base boxes, that rsync is installed on the windows boxes. Will rsync not work for this effort?

I run Linux as my host platform and was really looking to build off your work to include adding Windows AD infrastructure into my Vagrant multi-system infrastructure models.

The following WinRM command responded with a non-zero exit status.

hi @rgl,

i am on host ubuntu , provider libvirt and i got the following error due running vagrant up --provider=libvirt

The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

ip=$(which ip); ${ip:-/sbin/ip} addr show | grep -i 'inet ' | grep -v '127.0.0.1' | tr -s ' ' | cut -d' ' -f3 | cut -d'/' -f 1

Stdout from the command:



Stderr from the command:

At line:1 char:33
+ ip=$(which ip); ${ip:-/sbin/ip} addr show | grep -i 'inet ' | grep -v ...
+                                 ~~~~
Unexpected token 'addr' in expression or statement.
    + CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseException
    + FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand

what can i do?

Why local vagrant boxes?

Hi,

I notice rgl has vagrant cloud profile. Just curious why these Vagrantfiles aren't setup to use boxes from vagrant cloud.

Just want to say thanks!

Hi,

No problem. Just wanted to say thanks for sharing this work. It has been hugely helpful for my work in pre-prod testing environments.

๐Ÿบ

Enable "Virtual Machine Platform"

When starting the test-nodes with vagrant up --provider=virtualbox, the process exists with an error telling me to enable "Virtual Machine Platform". This feature is already enabled.

PS D:\Projects\Vagrant\WindowsDomain\test-nodes> vagrant up --provider=virtualbox
==> vagrant: You have requested to enabled the experimental flag with the following features:
==> vagrant:
==> vagrant: Features:  typed_triggers
==> vagrant:
==> vagrant: Please use with caution, as some of the features may not be fully
==> vagrant: functional yet.
Bringing machine 'windows' up with 'virtualbox' provider...
Bringing machine 'ubuntu' up with 'virtualbox' provider...
==> windows: Running action triggers before up ...
==> windows: Running trigger...
    windows: Running local: Inline script
    windows: bash -euc '
    windows: certs=(
    windows:     ../tmp/ExampleEnterpriseRootCA.der
    windows: )
    windows: for cert_path in "${certs[@]}"; do
    windows:     if [ -f $cert_path ]; then
    windows:         mkdir -p tmp
    windows:         cp $cert_path tmp
    windows:     fi
    windows: done
    windows: '
    windows:
    windows: Aktivieren Sie bitte das Windows-Feature ?Virtual Machine Platform? und stellen Sie sicher, dass die Virtualisierung im BIOS aktiviert ist.
    (Translation: Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.)
    windows: Weitere Informationen finden Sie unter https://aka.ms/wsl2-install
    (Translation: You can find more information on https://aka.ms/wsl2-install)
    windows:
==> windows: Trigger run failed
==> windows: A script exited with an unacceptable exit code 1.
A script exited with an unacceptable exit code 1.

Virtual Machine Platform is installed:

PS C:\Windows\system32> Get-WindowsOptionalFeature -Online | Where-Object {$_.FeatureName -match "virtualmachineplatform"}


FeatureName : VirtualMachinePlatform
State       : Enabled

Also there were no problems setting up the base machines.

Fails when running under libvirt

Hello,

The current master branch is failing to install properly when using a libvirt host, failing in domain-controller-configure.ps1, line 27:

Add-KdsRootKey -EffectiveTime (Get-Date).AddHours(-10) | Out-Null

with the following error:

The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

powershell -ExecutionPolicy Bypass -OutputFormat Text -file "C:\tmp\vagrant-shell.ps1" domain-controller-configure.ps1

Stdout from the command:

Running C:\vagrant\provision\domain-controller-configure.ps1...
ERROR: The request is not supported. (Exception from HRESULT: 0x80070032)
ERROR: at <ScriptBlock>, C:\vagrant\provision\domain-controller-configure.ps1: line 27
ERROR: at <ScriptBlock>, C:\tmp\vagrant-shell.ps1: line 51
ERROR EXCEPTION: System.Runtime.InteropServices.COMException (0x80070032): The request is not supported. (Exception from HRESULT: 0x80070032)
ERROR EXCEPTION:    at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)

Building from 29c54af works properly.

provisioning scripts encounter TLS problems for Windows Server 2016

Hi, is there a easy hack I can add to the provision scripts that will enable getting around this TLSv1 issue in 2016? Can't install chocolatey or do a number of other things in the provisioning.

Also, just curious, have you looked into making the provision scripts idempotent? ... so that provisioning can be run over and over again, such that anything that has already succeeded won't be tried on subsequent provisions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.