DevOps How To's

How to install OpenSSL Module in Azure Automation

OpenSSL is a widely-used open source tool for secure communication over the internet. It allows you to create and manage SSL/TLS certificates, encrypt and decrypt files, and perform other cryptographic tasks. Azure Automation is a cloud-based automation service in Azure that allows you to automate the management of your resources. In this blog post, we’ll show you how to use OpenSSL in Azure Automation.

Prerequisites

Before you begin, you need to have the following:

  • An Azure subscription
  • An Azure Automation account
  • A basic understanding of PowerShell

Installing the OpenSSL Module

The first step is to install the OpenSSL module in your Azure Automation account. To do this, follow these steps:

  1. Go to your Azure Automation account in the Azure portal.
  2. Click on “Modules” in the left-hand menu.
  3. In the “Modules” blade, click on “Browse gallery”.
  4. Search for “OpenSSL” and select the “OpenSSL” module.
  5. Click on “Import” to import the module into your Automation account.
In the “Modules” blade, click on “Browse gallery”.
Search for “OpenSSL” and select the “OpenSSL” module.

Creating a PowerShell Runbook

Once you have the OpenSSL module installed, you can create a PowerShell runbook to use it. Follow these steps to create a PowerShell runbook:

  1. Go to your Azure Automation account in the Azure portal.
  2. Click on “Runbooks” in the left-hand menu.
  3. Click on “Create a runbook” and select “PowerShell” as the runbook type.
  4. Give your runbook a name and click on “Create”.

Writing a PowerShell Script

Next, you need to write a PowerShell script that uses the OpenSSL module. Here is an example script that generates a private key and a self-signed certificate:

Import-Module OpenSSL

$pass = ConvertTo-SecureString "yourpassword" -AsPlainText -Force
$thumbprint = ""

# Generate a private key
$key = New-OpenSSLKey -Passphrase $pass -Algorithm RSA -KeyLength 2048 -OutFilePath "C:\OpenSSL\private.key"

# Generate a self-signed certificate
$cert = New-OpenSSLCertificate -Key $key -Passphrase $pass -Subject "CN=yourdomain.com" -NotBefore (Get-Date) -NotAfter (Get-Date).AddYears(1) -OutFilePath "C:\OpenSSL\certificate.crt"

# Get the certificate thumbprint
$certObject = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$certObject.Import("C:\OpenSSL\certificate.crt")
$thumbprint = $certObject.Thumbprint

This script generates a private key and a self-signed certificate using the OpenSSL module. It then imports the certificate and gets the certificate thumbprint.

Testing the Runbook

Once you have written your PowerShell script, you can test your runbook by clicking on the “Test pane” button in the top menu. This will allow you to run your script and see the output.

Publishing the Runbook

If your script works correctly, you can publish your runbook to make it available for use. To do this, click on the “Publish” button in the top menu.

Conclusion

Using OpenSSL in Azure Automation allows you to automate the management of SSL/TLS certificates, encrypt and decrypt files, and perform other cryptographic tasks in the cloud. By following the steps in this blog post, you can get started using OpenSSL in Azure Automation today.

Thanks to my team Khairul Azri & Gabriel cheers.

Post Comment