Guida online ESET

Ricerca Italiano
Seleziona l'argomento

Creare client ESA RADIUS tramite API

Per facilitare la configurazione di numerosi client RADIUS in ESA in caso di integrazione di una protezione ESA per numerose autenticazioni desktop Linux/Mac tramite i moduli PAM, utilizzare il seguente script PowerShell.

Prerequisiti

1.Configurare un client RADIUS in ESA Web Console.

Impostazioni di base > Indirizzo IP: digitare l’indirizzo IP del computer che ospita il modulo PAM in base al quale il server ESA RADIUS può raggiungerlo

Impostazioni di base > Segreto condiviso: digitare lo stesso segreto condiviso impostato nell’accessorio VPN

Autenticazione > Tipo di client > Il client convalida il nome utente e la password: utilizzare Verifica accesso

2.Abilitare ESA API e aggiungere le credenziali API nel campo Management API di gestione in ESA Web Console.

3.Specificare l’indirizzo IP e il Segreto condiviso di ciascun accessorio virtuale VPN in un file .csv come coppie <IP address>;<Shared Secret> (Indirizzo IP-Segreto condivso).

Per esempio:

192.168.0.11;test1

192.168.0.12;test2

192.168.0.13;test3
 

In caso di esecuzione dello script su una macchina diversa da quella che ospita il server di autenticazione:

1.Assicurarsi che il certificato ESA sia attendibile sul computer in uso.

2.Assicurarsi che il certificato includa l’FQDN del server di autenticazione nell’elenco di nomi DNS alternativi.

Come funziona lo script?

Lo script legge ciascuna riga del file .csv e crea un numero di client RADIUS corrispondente al numero di righe delle coppie indirizzo IP/segreto condiviso trovate. La sezione Autenticazione di ciascun client RADIUS sarà configurata in base al client RADIUS preconfigurato.

Script PowerShell campione per creare nuovi client ESA RADIUS tramite ESA API: il file viene nominato create_radius_clients.ps1

# configuration

 

# Management API credentials - username:password

$credentials = "kjssgmarkm:dapweburnx"

 

# IP address or FQDN of the Authentication Server

$esaAuthenticationServer = "127.0.0.1:8001"

 

# Name of ESA RADIUS Server foudn in ESA Web Console at Componets > RADIUS

$radiusServerName = "BTSH00049D (Authentication Server computer)"

 

# Name of the pre-configured ESA RADIUS client

$baseRadiusClientName = "Base Client"

 

# List of IP Address and Shared Secret of each VPN appliance is saved in the clients.csv file.

# The clients.csv file is in the same directory where the this PowerShell script resides

$csvImportFilePath = $PSScriptRoot + "\\clients.csv"

 

# headers preparation

 

$ErrorActionPreference = "Stop"

 

$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credentials))

$basicAuthHeader = "Basic $encodedCredentials"

$headers = @{Authorization = $basicAuthHeader}

 

# find RADIUS server

 

$body = @{

  componentType = "radius"

}

$bodyStr = $body | ConvertTo-Json

$response = Invoke-WebRequest -Uri https://$esaAuthenticationServer/manage/v2/GetComponentSettings -Method POST -Body $bodyStr -ContentType "application/json" -Headers $headers

 

$components = $response.Content | ConvertFrom-Json

 

$radiusServerKey = $null

foreach ($component in $components)

{

  if ($component.Info.Name -ceq $radiusServerName) {

    $radiusServerKey = $component.Info.Key

  }

}

 

if ($radiusServerKey -ceq $null) {

  Throw "RADIUS server not found: " + $radiusServerName

}

 

# base RADIUS client

 

$body = @{

  componentKey = $radiusServerKey

}

$bodyStr = $body | ConvertTo-Json

$response = Invoke-WebRequest -Uri https://$esaAuthenticationServer/manage/v2/GetRadiusClients -Method POST -Body $bodyStr -ContentType "application/json" -Headers $headers

 

$clients = $response.Content | ConvertFrom-Json

 

$baseRadiusClientSettings = $null

foreach ($client in $clients)

{

  if ($client.ClientName -ceq $baseRadiusClientName) {

    $baseRadiusClientSettings = $client

  }

}

 

if ($baseRadiusClientSettings -ceq $null) {

    Throw "RADIUS client not found: " + $baseRadiusClientName

}

 

# create clients

 

foreach($line in [System.IO.File]::ReadLines($csvImportFilePath))

{

  $fields = $line.Split(';')

  if ($fields.Count -cne 2) {

    Throw "Invalid fields count: " + $line

  }

 

  $ip = $fields[0]

  $sharedSecret = $fields[1]

 

  $newClientSettings = $baseRadiusClientSettings | ConvertTo-Json | ConvertFrom-Json

  $newClientSettings.Id = [guid]::NewGuid().ToString("d")

  $newClientSettings.ClientName = "Generated - " + $ip

  $newClientSettings.ClientIp = $ip

  $newClientSettings.SharedSecret = $sharedSecret

 

  $body = @{

    componentKey = $radiusServerKey;

    client = $newClientSettings

  }

  $bodyStr = $body | ConvertTo-Json

  $response = Invoke-WebRequest -Uri https://$esaAuthenticationServer/manage/v2/CreateRadiusClient -Method POST -Body $bodyStr -ContentType "application/json" -Headers $headers

}

 

echo "success"