cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

SFTP connection using private key on Azure Databricks

orangepepino
New Contributor II

I need to connect to a server to retrieve some files using spark and a private ssh key. However, to manage the private key safely I need to store it as a secret in Azure Key Vault, which means I don't have the key as a file to pass down in the keyFilePat option.

The code I have is this:

import com.github.arcizon.spark.filetransfer._
val df= spark.read
  .option("host", "...")
  .option("port", "22")
  .option("username", "...")
  .option("keyFilePath", "path/to/privatekey")
  .option("fileFormat", "csv")
  .option("delimiter", "|")
  .option("header", "true")
  .option("inferSchema", "true")
  .option("encoding", "UTF-8")
  .sftp("path/to/my/data.csv")
 
Is there an alternative where I can pass down the contents of the private key to be able to load the data that I want to manipulate with spark? or maybe another way of solving this problem that I haven't seen?
2 REPLIES 2

Kaniz_Fatma
Community Manager
Community Manager

Hi @orangepepino

  • Instead of specifying the keyFilePath, you can pass the private key as a PEM string directly. This approach avoids the need for a physical key file.
  • Since you’re already using Azure Key Vault, consider storing the private key as a secret in Key Vault. Retrieve the secret programmatically in your Databricks Notebook and use it directly. You’ll need to set up authentication to access Key Vault from your Databricks cluster. Additionally, ensure that your Databricks cluster has the necessary permissions to access the Key Vault secrets if you choose this approach.

Hi @Kaniz_Fatma

Could you please specify or provide a code example of how I can provide the key as a PEM string? is it an option I can pass to spark.read? do I need a specific library?

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!