Notakey Authentication Proxy 2.0.1 for Windows (x64)
============================================================

In this package

  notakey-authproxy.exe    the proxy. It needs nothing else installed.
  service.ps1              installs, updates and removes the Windows service
  authproxy.example.json   a configuration to start from
  INSTALL.txt              this text

You need

  - 64-bit Windows and an administrator account.
  - Notakey Authentication Server 5.2.2 or later, and in its dashboard an API client made for this proxy,
    with the scopes urn:notakey:auth and urn:notakey:user.
  - The addresses and RADIUS secrets of the gateways (VPN, firewall) and of the RADIUS server that checks
    passwords (NPS for instance).

Is version 1.2.x ("Notakey Heimdall") on this machine? Read "Coming from 1.2.x" below first.


Install
-------

1. Unpack the package. Open PowerShell as an administrator in the unpacked directory.

2. Install the service:

     powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\service.ps1 -Action Install -FirewallRule

   This copies the proxy to C:\Program Files\Notakey\AuthProxy, makes the directory
   C:\ProgramData\Notakey\AuthProxy for the configuration and the log, closes it to everyone but the
   system, the administrators and the service, and registers the service NotakeyAuthProxy
   ("Notakey Authentication Proxy") under an account of its own. The service is not started yet.

   -FirewallRule allows incoming UDP on port 1812 in Windows Firewall, for networks that Windows holds
   to be a domain or private network. For other ports name them all, for instance with accounting:

     ... -Action Install -FirewallRule -FirewallPorts 1812,1813

   On a network that Windows holds to be public the rule does nothing, and the gateways are not heard.
   The network of a server that is in no domain is often held to be public. service.ps1 says so when it
   finds such a network. Then either change the network to private:

     Get-NetConnectionProfile
     Set-NetConnectionProfile -InterfaceAlias "Ethernet" -NetworkCategory Private

   or make a firewall rule for that network by hand.

3. Write the configuration:

     Copy-Item .\authproxy.example.json C:\ProgramData\Notakey\AuthProxy\authproxy.json
     notepad C:\ProgramData\Notakey\AuthProxy\authproxy.json

   Fill in the gateways ("clients"), the RADIUS server ("passwordCheck") and the Notakey API ("notakey").
   The comments in the file say what each setting is. Write the secrets into the file; do not use
   environment variables for them on Windows.

4. Check it. The first command reads the file. The second also asks the Notakey API for a token and
   each RADIUS server whether it answers; it sends no login.

     & "C:\Program Files\Notakey\AuthProxy\notakey-authproxy.exe" --check-config
     & "C:\Program Files\Notakey\AuthProxy\notakey-authproxy.exe" --validate

5. Start the service and look at the log:

     Start-Service NotakeyAuthProxy
     Get-Content C:\ProgramData\Notakey\AuthProxy\logs\authproxy.log -Tail 20

   The line with "event":"started" names the address it listens on. From then on each login is one line.
   The service starts with Windows (beside 1.2.x only after the change-over below).

6. Point the gateways at this machine (UDP 1812) with the secrets of "clients". A request from an address
   that is not in "clients" is dropped unread and counted in the "counters" line as
   dropped_unknown_source.


If the service does not start
-----------------------------

The reason is the last line of the log file. "sc.exe query NotakeyAuthProxy" shows the exit code of the
proxy as SERVICE_EXIT_CODE:

  2    the configuration is not valid (run --check-config)
  3    a port is taken by another program, or the log file or a syslog socket could not be opened
  70   an error of the proxy itself; please report the last line of the log

One case leaves no line: the log file itself could not be opened. The exit code is 3 then, the log has
no new line or is not there, and the reason is written nowhere: a service has no other place for it,
and the proxy writes nothing to the event log of Windows. See that the directory
C:\ProgramData\Notakey\AuthProxy\logs is there, that the service may write in it and that no other
program has authproxy.log locked. Step 2 again (-Action Install) makes the directory and gives the
service its rights in it.

After a change of the configuration: Restart-Service NotakeyAuthProxy.


Coming from 1.2.x
-----------------

Version 1.2.x was installed by an MSI ("Notakey Heimdall") into
C:\Program Files (x86)\Authentication Proxy, as the service "Notakey Authentication Proxy (Heimdall)",
with its settings in winsw.xml in that directory.

This package does not read, change or remove any of that. The names, the directories and the service
are different, and both versions can be installed on one machine. Both cannot listen on the same port,
so only one of the two services can run at a time (unless they are given different ports).

 a. Install this version (steps 1 and 2). service.ps1 says that it found 1.2.x and leaves it running.
    Beside 1.2.x the new service is set to start by hand (Manual), not with Windows: otherwise, after
    a restart of the machine, the two would compete for the port.

 b. Write authproxy.json (step 3) from winsw.xml. A setting of 1.2.x stands there as two <argument>
    lines, the name and then the value, or as <env name="..." value="..."/> with the name of its
    variable. An argument wins over a variable. Where neither is there, 1.2.x used its default.

      argument, variable                 here

      -a, --notakey-access-id            "notakey"."serviceId"
        NOTAKEY_ACCESS_ID
      -h, --notakey-host                 "notakey"."url"
        NOTAKEY_HOST
      --notakey-timeout                  "notakey"."timeoutSeconds" (5 unless given, in both versions)
        NOTAKEY_TIMEOUT
      --message-title                    "notakey"."messageTitle". A brace in it is now written twice.
        MESSAGE_TITLE
      --message-description              "notakey"."messageDescription". A text written for 1.2.x works
        MESSAGE_DESCRIPTION                as it is; {0} still means the user.
      --message-ttl-seconds              "logins"."timeoutSeconds" (unless given 60 in 1.2.x
        NOTAKEY_TTL_SECONDS                and 30 here; from 5 to 300 here)
      --listen-address                   "listen"."address". Unless given, 1.2.x listened on 127.0.0.1;
        LISTEN_ADDRESS                     2.0 listens on 0.0.0.0.
      --port-in                          "listen"."port" (1812 unless given, in both versions)
        PORT_IN
      --address-secret-in                "clients": one entry for each ADDRESS:SECRET, with "address",
        ADDRESS_SECRET_IN                  "secret" and a "name" of your choice. The argument can be there
                                           several times; in the variable the pairs are separated by
                                           spaces. The address is an IP address or a network here, not
                                           a host name.
      --downstream-address               "passwordCheck"."servers": one entry for each address (several
        DOWNSTREAM_ADDRESS                 are separated by colons), with "name" and "address"
      --port-out                         "port" of each of these servers (1812 unless given, in both
        PORT_OUT                           versions). One value was for all of them.
      --secret-out                       "secret" of each of these servers. One value was for all of
        SECRET_OUT                         them.
      --proxy-receive-timeout            "passwordCheck"."timeoutSeconds": how long a request waits for
        PROXY_RECEIVE_TIMEOUT              the reply of the server before it is sent again (5 unless given
                                           in 1.2.x; here 3, from 1 to 30)
      --proxy-send-timeout               Nothing. 2.0 has no such limit: leave it out.
        PROXY_SEND_TIMEOUT
      --cisco-acl-passthrough            If true: "ciscoAclDownload": true at each client that is a Cisco
        CISCO_ACL_PASSTHROUGH              device. It was one switch for all gateways.
      --require-message-auth             "requireMessageAuthenticator" of each client. See below: the
        REQUIRE_MESSAGE_AUTH               default is the other way round.

    Message-Authenticator. In 1.2.x --require-message-auth was one switch for all gateways, and false
    unless given: a request without the Message-Authenticator attribute was taken. In 2.0 it is
    "requireMessageAuthenticator" of each client, and true unless given: such a request is dropped
    and the gateway gets no answer.

      - 1.2.x ran with --require-message-auth true: nothing to do.
      - 1.2.x ran without it, or with false: find out for each gateway whether it sends the attribute.
        Turn it on at the gateway if it has the setting. If it cannot send it, give that client
        "requireMessageAuthenticator": false; the proxy then says so with a warning at every start.
      - The replies of the RADIUS server are held to the same rule, which 1.2.x had no setting for. A
        server that cannot sign its replies gets "requireMessageAuthenticator": false in its entry of
        "passwordCheck"."servers".

    What 1.2.x did not have, or did otherwise:

      - "notakey"."clientId" and "clientSecret": the API client made for this proxy. They are required.
      - "notakey"."url" has to be an https:// address. An http:// address is taken only with
        "allowInsecureHttp": true beside it, and gives a warning.
      - 1.2.x took requests from any address when --address-secret-in said 0.0.0.0. Here the gateways
        are listed. "Any address" is written 0.0.0.0/0 and gives a warning at every start; better list
        the gateways.

 c. Check the file (step 4). Both commands can be run while 1.2.x works.

 d. Change over, at a time when a failed login or two does no harm:

      Stop-Service "Notakey Authentication Proxy (Heimdall)"
      Set-Service "Notakey Authentication Proxy (Heimdall)" -StartupType Disabled
      Set-Service NotakeyAuthProxy -StartupType Automatic
      Start-Service NotakeyAuthProxy

    Disabling the old service matters: with both starting with Windows, after a restart of the machine
    the one that comes second would find the port taken. If 1.2.x listened on another port than 1812,
    either keep that port in "listen" and allow it in the firewall (-FirewallRule -FirewallPorts PORT),
    or change the port at the gateways.

    Try a login. A line with "event":"message_authenticator_missing" in the log names a gateway that
    sends its requests without Message-Authenticator (see b).

 e. To go back:

      Stop-Service NotakeyAuthProxy
      Set-Service NotakeyAuthProxy -StartupType Manual
      Set-Service "Notakey Authentication Proxy (Heimdall)" -StartupType Automatic
      Start-Service "Notakey Authentication Proxy (Heimdall)"

 f. When 2.0 has done its work for a while and the way back is no longer needed, remove 1.2.x in
    "Apps and features" ("Notakey Heimdall"). Its settings in winsw.xml include the RADIUS secrets:
    make sure the file is gone afterwards.


Update
------

Unpack the newer package and run step 2 again. The service is stopped, the proxy replaced and the
service started again if it ran. The configuration, the log and the start mode of the service stay.


Remove
------

     powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\service.ps1 -Action Uninstall

The service, the firewall rule and the proxy are removed. The configuration and the log stay in
C:\ProgramData\Notakey\AuthProxy; add -RemoveData to delete them too.
