Azure PowerShell and Azure CLI

It’s impossible to memorize all commands in PowerShell and Azure CLI. Good news is that Microsoft follows a standard pattern

Open this page;

https://learn.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest

If we look at Azure CLI command for Virtual Machine, they follow this naming convention;

az vm list
az vm create
az vm delete

Azure CLI start with az vm and a verb. another example is;

az keyvault list
az keyvault create
az keyvault delete

for a more complicated example;

az network vnet list
az network vnet create
az network vnet delete

In above example vnet is a sub-component of netowrk. another example is;

az network vnet subnet list
az network vnet subnet create
az network vnt subnet delete

Where subnet is a sub-component of vnet and vnet is a sub-component of network.

Let’s go over PowerShell now;

https://learn.microsoft.com/en-us/powershell/module/az.keyvault/new-azkeyvault?view=azps-12.0.0

Get-AzVM
New-AzVM
Remove-AzVM

Verb is the first part of the word.

Get-AzVirtualNetwork
New-AzVirtualNetwork
Remove-AzVirtualNetwork
Get-AzVirtualNetworkSubnetConfig
New-AzVirtualNetworkSubnetConfig
Remove-AzVirtualNetworkSubnetConfig

Standard PowerShell that comes with windows doesn’t work. We need to upgrade it to PowerShell7 which is a cross-plateform scripting engine. There are 3 Azure specific modules for PowerShell that we need to install (We can avoid to install anything by using Azure Cloud shell);

For demo purpose, I am using Azure Cloud shell. The advantage is that i don’t need to login to my account because i am already logged in to Azure Portal. The response that i will get here is JSON formatted.

PowerShell

Microsoft has switched from old “Azure RM” to “Az” module. They don’t run side by side. To install a new AZ Module, run this command;

Run as administrator

Install-Module -Name Az-AllowClobber -Repository PSGallery -Force

To update module if you have already installed it;

Run as administrator
Update-Module -Name Az -AllowClobber -Repository PSGallery

To connect to Azure from workstation, use this command in PowerShell terminal;

connect-AzAccount -TenantId {GUID} (We don't need curly brackets)

To check latest version of PowerShell, follow this link;

To view installed Az module, use this command;

Get-InstalledModule -Name Az -AllVersions | Select-Object -Property Name, Version

This will list down Name and Version of Az Module. My list has Az Version 8.1.0 installed.

To list my web app, run this command in PowerShell terminal

Get-AzWebApp

To get a shorter version of output, run this command;

Get-AzWebApp | Select-Object Name, Location | ConvertTo-CSV -NoTypeInformation

Azure Microservices

Here are the major services other than core services;

Service Fabric

Azure Functions

Small piece of code that we can write. There is a small editor build-in to the browser that we can use.

Azure Logic Apps

Logic apps are pretty much similar to SQL Server integration services or windows workflow where we have some logical steps that executes in parallel or sequential to perform a task.

API Management

Can be used to throttle or secure API. We can put this in front take advantage.

Azure Kubernetes Services

Azure Core Service

There are 3 core services. This is the foundation of cloud; Every Azure service is built on one or all of these. for example, if we are learning Machine Learning, its a combination of Virtual Machine and Storage.

Virtual Machines

Windows or Linus OS. Can be created in few minutes. Can be remotely connected. Install whatever software you want.

Virtual Machine is a foundation on top of which other compute services provide service;

a) Azure Batch

b) Virtual Machine Scale Sets

It’s a way to have load-balancer where virtual machine are setup with some auto-scaling rules.

c) Azure Kubernetes Services (AKS)

Working on AKS cluster is basically working with VM. AKS is abstraction to underlying VM.

d) Service Fabric

A different paradigm to Virtual Machine is App Services.

1- App Services;

Web apps or container apps, Windows or Linux OS, fully-managed servers, no ability to remote control and others

Virtual Networking

Refer to this article.

Storage

a) Storage can be upto 5 pb, Storage types are Blobs, queues, tables, files – Various levels of replication including from local to global. Storage account charges are based on size of the storage (currently 1.8 cents per GB).

Storage tiers are hot, cool and archive

Azure Networking

Azure Networking can be broken in 4 categories;

Networking – Connectivity

Items under this category are;

a) Virtual Network (VNet)

These are cables, routers, switches in a physical network. In Azure, these are software services and it’s called Virtual Network because it’s all database entries. Microsoft has their own physical devices and they are not plugging/unplugging base of our commands.

b) Virtual WAN

Wide area Networks allow offices to connect to each other being Azure as the middleman.

c) Express Route

Express route is the fastest way to connec over the internet. It cost more but its encrypted and fast.

e) VPN Gateway

If Express route is not an option, then traditional VPN can be used. Their are point to site and site to site VPN. Helps to connect office computer to Azure network securely.

f) Azure DNS

Public and private domain can be managed in the name server in Azure.

g) Peering

Peering is a way for connecting multiple virtual networks together. This help to communicate one region service to a different region. By default, these services are cut off. You will need to configure these.

h) Bastion

This allows you to remote into a server without opening any ports. It’s a more secure version of RDP.

Networking – Security

To restrict unauthorized access, Items under this category are;

a) Network Security groups (NSG)

Very simple Access Control List Style e.g. We can restrict certain IP addresses to connect to Database or VM.

b) Azure Private Link

c) DDoS Protection

e) Azure Firewall

f) Web Application Firewall (WAF)

This can prevent cross site scripting or SQL injection attacks.

g) Virtual Network Endpoints

Networking – Delivery

This is traffic shaping and load balancing. Items under this category are;

a) CDN

b) Azure Front Door

Global load-balancer

c) Traffic Manager

d) Application Gateway

Application level load balancer – This is software level-6 gateway.

e) Load Balancer

Transport level load balancer – This is hardware level-4 device.

Networking – Monitoring

Debug problems, Investigate traffic issues. Items under this list are;

a) Network Watcher

b) ExpressRoute Monitor

c) Azure Monitor

d) VNet Terminal Access Point

What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats?

SSL has been around for long enough you’d think that there would be agreed upon container formats. And you’re right, there are. Too many standards as it happens. In the end, all of these are different ways to encode Abstract Syntax Notation 1 (ASN.1) formatted data — which happens to be the format x509 certificates are defined in — in machine-readable ways.

  • .csr – This is a Certificate Signing Request. Some applications can generate these for submission to certificate-authorities. The actual format is PKCS10 which is defined in RFC 2986. It includes some/all of the key details of the requested certificate such as subject, organization, state, whatnot, as well as the public key of the certificate to get signed. These get signed by the CA and a certificate is returned. The returned certificate is the public certificate (which includes the public key but not the private key), which itself can be in a couple of formats.
  • .pem – Defined in RFC 1422 (part of a series from 1421 through 1424) this is a container format that may include just the public certificate (such as with Apache installs, and CA certificate files /etc/ssl/certs), or may include an entire certificate chain including public key, private key, and root certificates. Confusingly, it may also encode a CSR (e.g. as used here) as the PKCS10 format can be translated into PEM. The name is from Privacy Enhanced Mail (PEM), a failed method for secure email but the container format it used lives on, and is a base64 translation of the x509 ASN.1 keys.
  • .key – This is a (usually) PEM formatted file containing just the private-key of a specific certificate and is merely a conventional name and not a standardized one. In Apache installs, this frequently resides in /etc/ssl/private. The rights on these files are very important, and some programs will refuse to load these certificates if they are set wrong.
  • .pkcs12 .pfx .p12 – Originally defined by RSA in the Public-Key Cryptography Standards (abbreviated PKCS), the “12” variant was originally enhanced by Microsoft, and later submitted as RFC 7292. This is a password-protected container format that contains both public and private certificate pairs. Unlike .pem files, this container is fully encrypted. Openssl can turn this into a .pem file with both public and private keys: openssl pkcs12 -in file-to-convert.p12 -out converted-file.pem -nodes

A few other formats that show up from time to time:

  • .der – A way to encode ASN.1 syntax in binary, a .pem file is just a Base64 encoded .der file. OpenSSL can convert these to .pem (openssl x509 -inform der -in to-convert.der -out converted.pem). Windows sees these as Certificate files. By default, Windows will export certificates as .DER formatted files with a different extension. Like…
  • .cert .cer .crt – A .pem (or rarely .der) formatted file with a different extension, one that is recognized by Windows Explorer as a certificate, which .pem is not.
  • .p7b .keystore – Defined in RFC 2315 as PKCS number 7, this is a format used by Windows for certificate interchange. Java understands these natively, and often uses .keystore as an extension instead. Unlike .pem style certificates, this format has a defined way to include certification-path certificates.
  • .crl – A certificate revocation list. Certificate Authorities produce these as a way to de-authorize certificates before expiration. You can sometimes download them from CA websites.

In summary, there are four different ways to present certificates and their components:

  • PEM – Governed by RFCs, used preferentially by open-source software because it is text-based and therefore less prone to translation/transmission errors. It can have a variety of extensions (.pem, .key, .cer, .cert, more)
  • PKCS7 – An open standard used by Java and supported by Windows. Does not contain private key material.
  • PKCS12 – A Microsoft private standard that was later defined in an RFC that provides enhanced security versus the plain-text PEM format. This can contain private key and certificate chain material. Its used preferentially by Windows systems, and can be freely converted to PEM format through use of openssl.
  • DER – The parent format of PEM. It’s useful to think of it as a binary version of the base64-encoded PEM file. Not routinely used very much outside of Windows.

Reference

https://serverfault.com/questions/9708/what-is-a-pem-file-and-how-does-it-differ-from-other-openssl-generated-key-file