Trying to generate MFA Caching Key (in PPK format) with REST API for use with PSMP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Welcome Idira to LIVEcommunity!

Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.

Meet Idira

Trying to generate MFA Caching Key (in PPK format) with REST API for use with PSMP

L2 Linker

Hi,

 

Generating an MFA Caching Key through the PVWA works no problem & I am able to download the key as a PPK for use with Putty connections via PSMP. Redacted output as follows -

 

Field_Content_versions_oct20__068Ht00000QTztQIAT.pngI am attempting to automate key generation through a simple Powershell script, calling the REST API. A key is returned <USERNAME>.ppk, but, the problem I am having is that the key is always returned as a PEM and in an unusable format.

 

A redacted version of my script & output file content are as follows -

 

Script =

 

Field_Content_versions_oct20__068Ht00000QTzu9IAD.png<USERNAME>.ppk =

 

Field_Content_versions_oct20__068Ht00000QTzsrIAD.png 

I'm new to using the Cyberark REST APIs & expect I'm making some kind of basic error, but any / all pointers and feedback would be much appreciated 😀

 

1 accepted solution

Accepted Solutions

L6 Presenter

I see two issues:

 

Your call is only returning the key in a single format (PEM) but it should return just the PPK. Because the default when you do not specify which format you want in the body is to return the private key only in PEM, then I am guessing your body is not actually being recognized by the API. Can you try something like the below? This should return only the PPK.

-Body (@{formats = "PPK"; keyPassword = $password} | ConvertTo-Json))

With -OutFile being passed to Invoke-RestMethod, the entire output (the JSON response) is being put in $keyfile whereas you only want the private key. You should save the response of Invoke-RestMethod to a variable (like $response = Invoke-RestMethod ... ) and once you are getting the response you like, do something like:

$privateKey = $response.value[0].privateKey $privateKey = Out-File -FilePath $PathOfWhereIWantThePrivateKeyToBe

Note that I did not fully test the above snippets so you may need to slightly tweak them.

View solution in original post

5 REPLIES 5

L6 Presenter

I see two issues:

 

Your call is only returning the key in a single format (PEM) but it should return just the PPK. Because the default when you do not specify which format you want in the body is to return the private key only in PEM, then I am guessing your body is not actually being recognized by the API. Can you try something like the below? This should return only the PPK.

-Body (@{formats = "PPK"; keyPassword = $password} | ConvertTo-Json))

With -OutFile being passed to Invoke-RestMethod, the entire output (the JSON response) is being put in $keyfile whereas you only want the private key. You should save the response of Invoke-RestMethod to a variable (like $response = Invoke-RestMethod ... ) and once you are getting the response you like, do something like:

$privateKey = $response.value[0].privateKey $privateKey = Out-File -FilePath $PathOfWhereIWantThePrivateKeyToBe

Note that I did not fully test the above snippets so you may need to slightly tweak them.

L2 Linker

Thanks Tim. Much appreciated. That's spat out a Private key 👍

I now need to deal with the Public key side, but I'm getting there slowly 😁

 

Just to add some context ...

 

I did try initially with web page automation through AutoIT but came a cropper at the clicking the ppk download part.

 

Ultimately I'm trying to create a connector so the non-priv account, logging into the PVWA, will be prompted for a password & when clicking to initiate the connection; a new MFA key will be created for the privileged (managed) account & dropped into the users netshare in the privileged domain. They configure & save Putty sessions that are targeted to go via the PSMP & se to use that key.

I am not sure what you are trying to do so likely I am not understanding the use case but when you create a MFA caching key, this key is valid for the non-privileged account when it attempts to authenticate to the PSMP. Are you attempting to eliminate the need for the end user to explicitly generate a MFA caching key in the PVWA but instead have the 'connect' function play this role?

 

If you want to automate the MFA caching key part, I don't think I would do this with a connection component but rather provide them a PowerShell script like you've written above that downloads the caching key to a location and launches putty via the command line (passing the private key with the -i argument and also the PSMP syntax.)

I agree with @Tim Schindler​ ... your use-case makes no sense to me. The "MFA caching" feature is designed so end-user can authenticate via PSMP (and only via PSMP, not via PVWA or via PSM) with this temporary, user-specific SSH private key and not have to enter their Vault authentication credentials (whether that be LDAP or Radius or a static password) for every connection. The private key that is generated authenticates a specific Vault user, not a specific account.

L2 Linker

Again, thanks for the input 😁

 

We have a number of ways we are attacking this issue & this is but one of them. It will most likely become somewhat of an intellectual dev exercise, rather than the actual solution

 

We are, in parallel with this investigation, pushing for our 'preferred' solution of simply allowing SSO for the non-priv user on the priv domain PVWA. This is going through the usual investigation / change / authorisation channels as I type & will hopefully become a reality.

​

However, and just for those that are interested .....

 

OK, a very rough overview (excuse the quick paint picture) =

​

Field_Content_versions_oct20__068Ht00000QUWyoIAH.png​

Typical (non-Cyberark) operation

  1. User has a non-priv account to access their non-priv laptop (uses key authentication, no password known by user)
  2. User opens RDP session to a Windows server in the priv domain, logging on with their priv ad account (known password)
  3. User opens SSH session within the RDP session and authenticates to a target using their priv ad account (known password)

​

Cyberark operation

  1. User authenticates to PVWA in non-priv domain via SSO (Azure)
  2. User uses RDP connector to reach Windows server in the priv domain, via PSM, using their Cyberark 'managed' priv ad account
  3. User needs an alternate way of initiating SSH connection as they no longer know their priv account password. Need MFA caching & connection via PSMP

​

Challenges

A - Generation of an MFA caching key from the PVWA will allow download of that key to the users non-priv device. but, that MFA caching key is of no use in the non-priv domain.

  1. No SSH connection to a priv AD target is allowed from the non-priv device, it must originate from the priv-domain RDP desktop. That includes barring an ssh connection from non-priv to the PSMP in the priv domain.
  2. No file transfer into the priv domain is permitted. This prevents sending the MFA caching key to the priv domain RDP server
  3. The RDP connection to the Windows server CANNOT allow any data transfer (no clipboard, drive mapping, ...)

​

B - The priv domain has no off-site connectivity, so SSO cannot be used to authenticate to the PVWA inside the priv domain.

  1. The non-priv user cannot authenticate into the priv-PVWA, within the PSM generated RDP session, as SSO doesn't function & they have no password knowledge for either their non-priv account or their priv account, so cannot use LDAP on the priv-PVWA.
  2. No authentication into priv-PVWA means they cannot generate a MFA caching key inside the priv domain

​

Possible solutions

  1. Create an AutoIT script, using Cyberark skeleton. Present a connector that allows the user to enter a password (for MFA key) which then automates logon to the priv-PVWA ,uses the stored priv domain credentials for logon, clicks through the MFA caching key generation & finally downloads the key to a location inside the priv-domain. This key is then available for use in a PSM generated RDP session. This works upto the point where DOWNLOAD ppk needs to be clicked & the logic falls over at this point. Cannot get it to click the web object properly.
  2. Create an AutoIT script, using Cyberark skeleton. Present a connector that allows the user to enter a password (for MFA key) which is then passed to the REST APIs, executed within a Powershell script, to try and generate a suitable key. The problem here is that the PVWA generated .ppk is all in the correct format. There is no REST API that spits out a key in the same format as the PVWA & so I'm trying to piece it together.
  3. Publish the priv-PVWA as a connector. This works fine & the 'logged in priv-user' is able to generate & download a MFA caching key. Unfortunately, this is obviously dropped into a Shadow User profile location on the PSM & the PVWA user cannot select a file store area outside of the PVWA. The PSM has no access to the priv-domain file stores.

​

So, in a nutshell. The user CAN generate an MFA caching key themselves in the non-priv domain. It's of no use here, because they cannot transfer files from non-priv to priv & cannot initiate SSH sessions non-priv to priv.

​

The non-priv user CANNOT generate an MFA caching key within the priv domain, as they cannot authenticate to the priv-PVWA within that domain as SSO is uncontactable.

​

The priv user CAN logon to the PVWA in the priv domain, BUT, only via non-priv initiated Cyberark PSM connector, as they no longer know the password for their priv domain account which is Cyberark managed.

​

​

​

​

​

​

​

​

​

  • 1 accepted solution
  • 673 Views
  • 5 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!