How to import the keys and secrets from Azure Key Vault in my katalon

Hi All,

I want to that how to import the keys and secrets from Azure Key Vault in my katalon so I can save my imported secrets to Global Variable during the execution for the usage.

Any help will be appreciated.

Hi there, :wave:

Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.

In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!

Thanks! :sunglasses:
Katalon Community team

I have the same question as @svc_irs_ktln_prod, any updates from the Katalon team @system ?

My team has a web application that requires elevated/admin credentials and I cannot have the creds simply stored within Katalon Studio if at all possible.

Just a note that @system is a smart-less bot. I’m not sure if it is still going. People that may give you an update to help could be @Elly_Tran or @vu.tran.

Katalon has a feature to encrypt text; main menu Help > Encrypt Text. I’m not sure if that would be secure enough for you. I put my username along with my encrypted password (which needs to be changed every 90 days) in a spreadsheet in my personal folder. Yes, a Senior Network person could get access, but not just anybody with less creds as that was the way it was set up.

Maybe like:
	/**
	 * sign into NNN using the references in the spreadsheet
	 */
	@Keyword
	def signIntoNNN(String pathway) {
         // get username and password from spreadsheet
		FileInputStream fis = new FileInputStream (pathway)
		XSSFWorkbook workbook = new XSSFWorkbook (fis)

		XSSFSheet sheet = workbook.getSheet("Sheet1")

		// cell A2
		Row row = sheet.getRow(1)
		Cell cell = row.getCell(0)
		GlobalVariable.gUsername = cell.getStringCellValue()

		// cell A3
		row = sheet.getRow(2)
		cell = row.getCell(0)
		GlobalVariable.gPassword = cell.getStringCellValue()

		fis.close()

		// WebUI.comment(GlobalVariable.gUsername)
		// WebUI.comment(GlobalVariable.gPassword)

        WebUI.waitForElementVisible(findTestObject('myPage/input_Sign in_UserName'), 10)
		WebUI.setText(findTestObject('myPage/input_Sign in_UserName'), GlobalVariable.gUsername)
		WebUI.verifyElementAttributeValue(findTestObject('myPage/input_Sign in_UserName'), "value", GlobalVariable.gUsername, 10)

		WebUI.setEncryptedText(findTestObject('myPage/input_Sign in_Password'), GlobalVariable.gPassword)

		WebUI.click(findTestObject('myPage/span_Sign in'))
		WebUI.waitForPageLoad(10)
	}

From Azure point of view, Katalon Studio is a kind of “Java Application”. So you want to import keys and secrets from Azure Key Valut into your Java Application named “Katalon Studio”.

Microsoft published the following article. Just do as it tells you.

If you require an out-of-box solution provided by Katalon, raise an officail support ticket to Katalon and ask them.

hi @jonathan.martin @svc_irs_ktln_prod

you do not need the azure sdk jars for this (they drag in netty and jackson versions that fight with katalon’s own). key vault has a plain rest api, so two WS calls in a test listener are enough. register an app in entra, give it “get” on secrets in the vault access policy (or key vault secrets user role), then:

import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.RestRequestObjectBuilder
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import groovy.json.JsonSlurper
import internal.GlobalVariable

class KeyVaultListener {
    @BeforeTestSuite
    def loadSecrets() {
        String tenant = System.getenv('AZ_TENANT_ID')
        String body = "grant_type=client_credentials&client_id=${System.getenv('AZ_CLIENT_ID')}" +
            "&client_secret=${System.getenv('AZ_CLIENT_SECRET')}&scope=https%3A%2F%2Fvault.azure.net%2F.default"
        RequestObject tokenReq = new RestRequestObjectBuilder()
            .withRestUrl("https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token")
            .withRestRequestMethod('POST')
            .withHttpHeaders([new com.kms.katalon.core.testobject.TestObjectProperty('Content-Type', com.kms.katalon.core.testobject.ConditionType.EQUALS, 'application/x-www-form-urlencoded')])
            .withTextBodyContent(body)
            .build()
        String token = new JsonSlurper().parseText(WS.sendRequest(tokenReq).responseText).access_token

        RequestObject secretReq = new RestRequestObjectBuilder()
            .withRestUrl('https://<your-vault>.vault.azure.net/secrets/admin-password?api-version=7.4')
            .withRestRequestMethod('GET')
            .withHttpHeaders([new com.kms.katalon.core.testobject.TestObjectProperty('Authorization', com.kms.katalon.core.testobject.ConditionType.EQUALS, 'Bearer ' + token)])
            .build()
        GlobalVariable.adminPassword = new JsonSlurper().parseText(WS.sendRequest(secretReq).responseText).value
    }
}

the three AZ_ values live as environment variables on the machine or as masked variables in your pipeline, so nothing sensitive is in the project. on an azure devops agent or a vm with managed identity you can skip the client secret and get the token from the imds endpoint (http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://vault.azure.net with header Metadata: true).

one caveat, GlobalVariable values show up in the report if you log them, so do not WebUI.comment them and use setEncryptedText where it fits.