Deploy Node.js web app with Enterprise Network Authentication
Contents
This article describes how to deploy node.js web app to be accessible in a Windows domain controlled (ActiveDirectory) network. For the ease of discussion, lets assume:
- the machine hosting the app is named
DOMAIN\MACHINE
- the users access the website at
http://machine
- the website should only be accessible by users within the ActiveDirectory security group
DOMAIN\SecurityGroup
Approach 1 - Plain Vanilla Node.js
Now, to achieve the above three goals, we can do it the plain vanilla way:
- Host the app directly with Node.js http module, or anything built on top of that.
- In the app, authenticate with NTLM/Kerboros (maybe with express-ntml module)
- Roll your own AD code to check if the authenticated user is a member of
DOMAIN\SecurityGRoup
. This step is extremely easy. Even doable in PowerShell. Proof in the last section. To use .NET in node, edge.js can be used.
Totally doable. But is it necessary? I think not.
Approach 2 - IIS + Node.js
This approach delegates the entire authentication and authorization to the IIS. And uses iisnode
to integrate the node.js app into IIS. I'm going to talk about the steps in detail.
Setup IIS for Security Group Authorization
For this step I'm mostly based on this article.
- Install IIS, ensure URL authorization and Windows Authentication are enabled (under IIS/WWW Server/Security)
- Go to the desired web site in IIS manager
- Enable Windows Authentication
- Configure Authorization Rules to ONLY allow the security group. Specify it in the form of "DOMAIN\SecurityGroup"
Setup iisnode
For this step I'm mainly following the guidance here.
- Enable ASP 4.6 in IIS
- Install URL rewrite module for IIS
- Install node of course (matching OS bitness)
- Install iisnode matching OS bitness
- Install iisnode samples by running
%programfiles%\iisnode\setupsamples.bat
in admin cmd - Go to http://localhost/node for verification (make sure your authentication works in previous section!)
Check if a domain user is a member of a security group
This SO answer helped.
1 | Add-Type -AssemblyName System.DirectoryServices.AccountManagement |