Ayuda en línea de ESET

Seleccionar el tema

Crear clientes de ESA RADIUS por medio de la API

Si tiene una protección ESA integrada para varios inicios de sesión en escritorio de Linux/Mac a través de módulos PAM y precisa configurar muchos clientes de RADIUS en ESA, el siguiente script de PowerShell puede simplificar su trabajo.

Requisito previo

1.Configure un cliente de RADIUS en la consola web ESA.

Configuración básica > Dirección IP: escriba la dirección IP del equipo en el que se aloja el módulo PAM mediante el cual puede acceder el servidor ESA RADIUS

Configuración básica > Secreto compartido: escriba el mismo secreto compartido que estableció en su aparato VPN

Autenticación > Tipo de cliente > El cliente valida el nombre de usuario y la contraseña: usar el desafío de acceso

2.Habilite la API de ESA y agregue credenciales API para la Management API en la consola web ESA.

3.Mencione la dirección IP y el Secreto compartido de cada aplicación VPN en un archivo .csv como pares <IP address>;<Shared Secret>.

Por ejemplo:

192.168.0.11;test1

192.168.0.12;test2

192.168.0.13;test3
 

Si ejecuta el script en otra máquina que no sea la que aloja al Servidor de autenticación:

1.Asegúrese de que el certificado ESA sea confiable en ese equipo.

2.Asegúrese de que el certificado incluya el FQDN del servidor de autenticación en la lista de nombres alternativos de DNS.

¿Cómo funciona el script?

El script lee cada una de las filas del archivo .csv y crea tantos clientes RADIUS como filas de pares de Direcciones IP y Secreto compartido se detectan. La sección Autenticación de cada cliente RADIUS se configurará en función del cliente RADIUS previamente configurado.

Tome una muestra de un script de PowerShell para crear nuevos clientes ESA RADIUS a través de la API de ESA. Llamaremos al archivo 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"