{"id":354133,"date":"2024-05-20T22:42:17","date_gmt":"2024-05-20T22:42:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=354133"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=354133","title":{"rendered":"<span>\u041f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 AD \u0432 FreeIPA<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0443\u0445\u043e\u0434\u043e\u043c Microsoft \u0438\u0437 \u0420\u043e\u0441\u0441\u0438\u0438 \u0443 \u043c\u043d\u043e\u0433\u0438\u0445 \u0432\u043e\u0437\u043d\u0438\u043a \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0435 \u0441\u043b\u0443\u0436\u0431\u044b \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u043d\u0430 open-source \u0438\u043b\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u0437 \u0440\u0435\u0435\u0441\u0442\u0440\u0430 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u041f\u041e. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f FreeIPA. \u041f\u0440\u043e\u0435\u043a\u0442 \u0436\u0438\u0432\u0435\u0442 \u043f\u0440\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 RedHat \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u0445 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043d\u0430\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u0438\u0437 Active Directory \u0432 FreeIPA 4.10.1. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c PowerShell 5.1, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0440\u043e\u043c\u0435 \u043d\u0435\u0433\u043e \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 AD \u043d\u0430\u043c \u043f\u043e \u0441\u0443\u0442\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0438 \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 API \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <em>json<\/em>. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c staged \u0443\u0447\u0435\u0442\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438. \u0412\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f API \u043e\u043f\u0438\u0441\u0430\u043d\u044b: <em>IPA Server\u2011API Browser.<\/em> \u0412 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<pre><code class=\"json\">{   \"method\": \"stageuser_add\",   \"params\": [     [       \"$($ADUser.SamAccountName)\"     ],     {       \"givenname\": \"$($ADUser.GivenName)\",       \"sn\": \"$($ADUser.Surname)\",       \"cn\": \"$($ADUser.Name)\",       \"mail\": \"$($ADUser.mail)\",       \"title\": \"$($ADUser.title)\",       \"employeenumber\": \"$($ADUser.employeeNumber)\",       \"telephonenumber\": \"$($ADUser.telephoneNumber)\",       \"mobile\": \"$($ADUser.mobile)\",       \"ou\": \"$($ADUser.department)\"     }   ] }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 PowerShell \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 REST \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043d\u0435\u0434\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430 FreeIPA. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0443 \u0441 PowerShell, \u043d\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0434\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442. \u041d\u0430\u0447\u0438\u043d\u0430\u044f c PowerShell 6 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 REST \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>-SkipCertificateCheck.<\/strong> \u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043c\u043b\u0430\u0434\u0448\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u0439, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443:<\/p>\n<pre><code class=\"powershell\"># Apply policy to trust all certificates add-type @\"  using System.Net;  using System.Security.Cryptography.X509Certificates;  public class TrustAllCertsPolicy : ICertificatePolicy {  public bool CheckValidationResult(  ServicePoint srvPoint, X509Certificate certificate,  WebRequest request, int certificateProblem) {  return true;  }  } \"@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'<\/code><\/pre>\n<p>\u0417\u0430\u043d\u0435\u0441\u0435\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435: Base DN \u0441 \u0443\u0447\u0435\u0442\u043d\u044b\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438 Active Directory, FQDN \u0441\u0435\u0440\u0432\u0435\u0440\u0430 FreeIPA \u0438 \u043f\u0443\u0442\u044c \u043a <em>json<\/em> \u0444\u0430\u0439\u043b\u0443 c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430 API FreeIPA. \u0422\u0430\u043a \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e.<\/p>\n<pre><code class=\"powershell\">$BaseDN = \"OU=Users,DC=local,DC=example,DC=domain\" $FreeIPAFqdn =\"freeipa.example.domain\" $Json = \".\\stageuser_add.json\"  # New web session $RestSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession<\/code><\/pre>\n<p>\u0412\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 Active Directory \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043d\u0430\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438<\/p>\n<pre><code class=\"powershell\"># Get Active Directory users $OrganizationalUnit = Get-ADOrganizationalUnit -Identity $BaseDN $ADUsers = Get-ADUser -Filter * -SearchBase $OrganizationalUnit -Properties employeeNumber,     title,mail,department,telephoneNumber,mobile<\/code><\/pre>\n<p>\u0417\u0430\u043d\u043e\u0441\u0438\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0443\u0447\u0435\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 FreeIPA<\/p>\n<pre><code class=\"powershell\"># Get FreeIPA credentials $FreeIPACredentials = Get-Credential -Message \"FreeIPA log in with username and password\"<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 API<\/p>\n<pre><code class=\"powershell\">function Invoke-FreeIPALogin {     param(         [parameter(Mandatory = $True)]$Session,         [parameter(Mandatory = $True)][string]$Fqdn,         [parameter(Mandatory = $True)][PSCredential]$Credentials     )     process {         $Credentials.Password | ConvertFrom-SecureString          $User = $Credentials.UserName         $Password = $Credentials.GetNetworkCredential().Password         $Body = @{\"user\" = \"$($User)\"; \"password\" = \"$($Password)\"}         $Header = @{\"Content-Type\" = \"application\/x-www-form-urlencoded\"; \"Accept\" = \"application\/json\"}         Invoke-RestMethod -Uri \"https:\/\/$($Fqdn)\/ipa\/session\/login_password\" -Method POST -Body $Body `             -WebSession $Session -Headers $Header     } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 API<\/p>\n<pre><code class=\"powershell\">function Invoke-FreeIPARequest {     param(         [parameter(Mandatory = $True)]$Session,         [parameter(Mandatory = $True)][string]$Fqdn,         [parameter(Mandatory = $True)][string]$Body     )     process {         $Header = @{\"Referer\" = \"https:\/\/$($Fqdn)\/ipa\"; \"Accept\" = \"application\/json\"}         $Type = \"application\/json; charset=utf-8\"         $Request = Invoke-RestMethod -Uri \"https:\/\/$($Fqdn)\/ipa\/session\/json\" -WebSession $Session `             -Method POST -Body $Body -Headers $Header -ContentType $Type         return $Request     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 API \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 FreeIPA \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0440\u0430\u043d\u0435\u0435<\/p>\n<pre><code class=\"powershell\"># Login to FreeIPA try {     Invoke-FreeIPALogin -Session $RestSession -Fqdn $FreeIPAFqdn -Credentials $FreeIPACredentials } catch {     Write-Host $_ -BackgroundColor Red     exit 1 }  # Transfer users to FreeIPA foreach ($ADUser in $ADUsers) { Invoke-Expression ('$Body = @\"' + \"`n\" + (Get-Content $Json -Encoding UTF8 | ForEach-Object {$_ + \"`n\"}) + \"`n\" + '\"@')     try {         $Request = Invoke-FreeIPARequest -Session $RestSession -Fqdn $FreeIPAFqdn -Body $Body         Write-Host ($Request.Result)     }     catch {         Write-Host $_ -BackgroundColor Red         continue      } }<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0448\u0430 \u0440\u0430\u0431\u043e\u0442\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430. \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 Active Directory \u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434\u044b API, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u0441\u043b\u0443\u0436\u0431\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 FreeIPA.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/759218\/\"> https:\/\/habr.com\/ru\/articles\/759218\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0443\u0445\u043e\u0434\u043e\u043c Microsoft \u0438\u0437 \u0420\u043e\u0441\u0441\u0438\u0438 \u0443 \u043c\u043d\u043e\u0433\u0438\u0445 \u0432\u043e\u0437\u043d\u0438\u043a \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0435 \u0441\u043b\u0443\u0436\u0431\u044b \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u043d\u0430 open-source \u0438\u043b\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u0437 \u0440\u0435\u0435\u0441\u0442\u0440\u0430 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u041f\u041e. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f FreeIPA. \u041f\u0440\u043e\u0435\u043a\u0442 \u0436\u0438\u0432\u0435\u0442 \u043f\u0440\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 RedHat \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u0445 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043d\u0430\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u0438\u0437 Active Directory \u0432 FreeIPA 4.10.1. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c PowerShell 5.1, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0440\u043e\u043c\u0435 \u043d\u0435\u0433\u043e \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 AD \u043d\u0430\u043c \u043f\u043e \u0441\u0443\u0442\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0438 \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 API \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <em>json<\/em>. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c staged \u0443\u0447\u0435\u0442\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438. \u0412\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f API \u043e\u043f\u0438\u0441\u0430\u043d\u044b: <em>IPA Server\u2011API Browser.<\/em> \u0412 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<pre><code class=\"json\">{   \"method\": \"stageuser_add\",   \"params\": [     [       \"$($ADUser.SamAccountName)\"     ],     {       \"givenname\": \"$($ADUser.GivenName)\",       \"sn\": \"$($ADUser.Surname)\",       \"cn\": \"$($ADUser.Name)\",       \"mail\": \"$($ADUser.mail)\",       \"title\": \"$($ADUser.title)\",       \"employeenumber\": \"$($ADUser.employeeNumber)\",       \"telephonenumber\": \"$($ADUser.telephoneNumber)\",       \"mobile\": \"$($ADUser.mobile)\",       \"ou\": \"$($ADUser.department)\"     }   ] }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 PowerShell \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 REST \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043d\u0435\u0434\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430 FreeIPA. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0443 \u0441 PowerShell, \u043d\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0434\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442. \u041d\u0430\u0447\u0438\u043d\u0430\u044f c PowerShell 6 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 REST \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>-SkipCertificateCheck.<\/strong> \u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043c\u043b\u0430\u0434\u0448\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u0439, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443:<\/p>\n<pre><code class=\"powershell\"># Apply policy to trust all certificates add-type @\"  using System.Net;  using System.Security.Cryptography.X509Certificates;  public class TrustAllCertsPolicy : ICertificatePolicy {  public bool CheckValidationResult(  ServicePoint srvPoint, X509Certificate certificate,  WebRequest request, int certificateProblem) {  return true;  }  } \"@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'<\/code><\/pre>\n<p>\u0417\u0430\u043d\u0435\u0441\u0435\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435: Base DN \u0441 \u0443\u0447\u0435\u0442\u043d\u044b\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438 Active Directory, FQDN \u0441\u0435\u0440\u0432\u0435\u0440\u0430 FreeIPA \u0438 \u043f\u0443\u0442\u044c \u043a <em>json<\/em> \u0444\u0430\u0439\u043b\u0443 c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430 API FreeIPA. \u0422\u0430\u043a \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e.<\/p>\n<pre><code class=\"powershell\">$BaseDN = \"OU=Users,DC=local,DC=example,DC=domain\" $FreeIPAFqdn =\"freeipa.example.domain\" $Json = \".\\stageuser_add.json\"  # New web session $RestSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession<\/code><\/pre>\n<p>\u0412\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 Active Directory \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043d\u0430\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438<\/p>\n<pre><code class=\"powershell\"># Get Active Directory users $OrganizationalUnit = Get-ADOrganizationalUnit -Identity $BaseDN $ADUsers = Get-ADUser -Filter * -SearchBase $OrganizationalUnit -Properties employeeNumber,     title,mail,department,telephoneNumber,mobile<\/code><\/pre>\n<p>\u0417\u0430\u043d\u043e\u0441\u0438\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0443\u0447\u0435\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 FreeIPA<\/p>\n<pre><code class=\"powershell\"># Get FreeIPA credentials $FreeIPACredentials = Get-Credential -Message \"FreeIPA log in with username and password\"<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 API<\/p>\n<pre><code class=\"powershell\">function Invoke-FreeIPALogin {     param(         [parameter(Mandatory = $True)]$Session,         [parameter(Mandatory = $True)][string]$Fqdn,         [parameter(Mandatory = $True)][PSCredential]$Credentials     )     process {         $Credentials.Password | ConvertFrom-SecureString          $User = $Credentials.UserName         $Password = $Credentials.GetNetworkCredential().Password         $Body = @{\"user\" = \"$($User)\"; \"password\" = \"$($Password)\"}         $Header = @{\"Content-Type\" = \"application\/x-www-form-urlencoded\"; \"Accept\" = \"application\/json\"}         Invoke-RestMethod -Uri \"https:\/\/$($Fqdn)\/ipa\/session\/login_password\" -Method POST -Body $Body `             -WebSession $Session -Headers $Header     } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 API<\/p>\n<pre><code class=\"powershell\">function Invoke-FreeIPARequest {     param(         [parameter(Mandatory = $True)]$Session,         [parameter(Mandatory = $True)][string]$Fqdn,         [parameter(Mandatory = $True)][string]$Body     )     process {         $Header = @{\"Referer\" = \"https:\/\/$($Fqdn)\/ipa\"; \"Accept\" = \"application\/json\"}         $Type = \"application\/json; charset=utf-8\"         $Request = Invoke-RestMethod -Uri \"https:\/\/$($Fqdn)\/ipa\/session\/json\" -WebSession $Session `             -Method POST -Body $Body -Headers $Header -ContentType $Type         return $Request     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 API \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 FreeIPA \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0440\u0430\u043d\u0435\u0435<\/p>\n<pre><code class=\"powershell\"># Login to FreeIPA try {     Invoke-FreeIPALogin -Session $RestSession -Fqdn $FreeIPAFqdn -Credentials $FreeIPACredentials } catch {     Write-Host $_ -BackgroundColor Red     exit 1 }  # Transfer users to FreeIPA foreach ($ADUser in $ADUsers) { Invoke-Expression ('$Body = @\"' + \"`n\" + (Get-Content $Json -Encoding UTF8 | ForEach-Object {$_ + \"`n\"}) + \"`n\" + '\"@')     try {         $Request = Invoke-FreeIPARequest -Session $RestSession -Fqdn $FreeIPAFqdn -Body $Body         Write-Host ($Request.Result)     }     catch {         Write-Host $_ -BackgroundColor Red         continue      } }<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0448\u0430 \u0440\u0430\u0431\u043e\u0442\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430. \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 Active Directory \u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434\u044b API, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u0441\u043b\u0443\u0436\u0431\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 FreeIPA.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/759218\/\"> https:\/\/habr.com\/ru\/articles\/759218\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-354133","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/354133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=354133"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/354133\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=354133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=354133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=354133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}