Search code examples
razuresshazure-active-directoryazure-dsvm

SSH public key authentication with Linux Azure DSVM through R


I'm trying to use the R AzureDSVM package to create a Linux DSVM through R. I am reading the guide https://raw.githubusercontent.com/Azure/AzureDSVM/master/vignettes/10Deploy.Rmd (Azure DSVM guide)

First the guide requests you create an Azure Active Directory application which will provide a "tenant ID", "client ID" and "user key", the guidelines described in http://htmlpreview.github.io/?https://github.com/Microsoft/AzureSMR/blob/master/inst/doc/Authentication.html (Azure SMR Auth guide)

As I understand it, this creates an app registered in Azure Active Directory, creates an "authentication key" for the app, which is the user key, and associates the app with a Resource Group. I've done this sucessfully.

The Azure DSVM guide then creates a VM with public key authentication in a similar way to what follows:

library(AzureSMR) 
library(AzureDSVM)   

TID <- "123abc"          # Tenant ID
CID <- "456def"          # Client ID
KEY <- "789ghi"          # User key

context <- createAzureContext(tenantID=TID, clientID=CID, authKey=KEY)

resourceGroup<-"myResouceGroup"
location<-"myAzureLocation"
vmUsername<-"myVmUsername"
size<-"Standard_D1_v2"
mrsVmPassword<-"myVmPassword"
hostname<-"myVmHostname"

ldsvm <- deployDSVM(context, 
                    resource.group = resourceGroup,
                    location       = location,
                    hostname       = hostname,
                    username       = vmUsername,
                    size           = size,
                    os = "Ubuntu",
                    pubkey         = PUBKEY)

The guide vaguely describes creating a public key (PUBKEY) from the users private key, which is sent to the VM to allow it to provide SSH authentication:

To get started we need to load our Azure credentials as well as the user’s ssh public key. Public keys on Linux are typically created on the users desktop/laptop machine and will be found within ~/.ssh/id_rsa.pub. It will be convenient to create a credentials file to contain this information. The contents of the credentials file will be something like the foloowing and we assume the user creates such a file in the current working directory, naming the file _credentials.R. Replace with the user’s username.

TID <- "72f9....db47"          # Tenant ID
CID <- "9c52....074a"          # Client ID
KEY <- "9Efb....4nwV....ASa8=" # User key

PUBKEY   <- readLines("~/.ssh/id_rsa.pub") # For Linux DSVM

My question:

Is this public key PUBKEY generated from the authentication/user key created by setting up the Azure Active Directory application in the Azure SMR Auth guide (the KEY variable in the above script)? If so, how? I've tried using the R sodium library pubkey(charToRaw(KEY)) to do this but I get "Invalid key, must be exactly 32 bytes".

If PUBKEY isn't generated from KEY, from what is it generated? And how does the package know how to authenticate with the private key to this public key?


Solution

  • The AAD key is used for authenticating to AAD. The public/private keypair is separate and is used for authenticating to the VM. If you do not have a public key (in the file ~/.ssh/id_rsa.pub), you can create one using ssh-keygen on Linux.

    SSH connections use the private key (in ~/.ssh/id_rsa) by default.