Keeper-Security / keeper-sdk-dotnet

.Net and PowerShell version of Keeper Commander, a CLI and SDK interface for the Keeper Security platform.
https://docs.keeper.io/secrets-manager/commander-cli/using-commander/dotnet-powershell
MIT License
29 stars 20 forks source link

[BUG] Unable to create/modify multi-line keyPair values with PowerCommander #109

Closed sethwalker1 closed 5 months ago

sethwalker1 commented 9 months ago

I'm trying to create an SSH Key record that holds a GPG key using PowerCommander.

$outputRecord = Add-KeeperRecord -RecordType sshKeys -Title $title -login $email -host $hostname -notes $notes "keyPair=$publicKey"

This code populates the Private Key field with the first line of the GPG key, but no more because multi-line inputs are not supported. I've tried saving without spacing, but the key is considered invalid if I do so.

Possible solutions:

  1. Adding keyPair argument to the Add-KeeperRecord cmdlet
  2. Some way of escaping new lines?
  3. Modifying this regex to allow using quotation marks for multi-line inputs
sk-keeper commented 9 months ago

keyPair is a complex field. You can see field format by running Get-KeeperRecordType -ShowFields

privateKey       privateKey       Optional {'publicKey': '', 'privateKey': ''}

Fields like keyPair expect hash tables as field value

$publicKey = @{'publicKey'='PUBLICKEY'; 'privateKey'='PRIVATE KEY'}
Add-KeeperRecord -RecordType sshKeys -Title $title -login $email -host $hostname -notes $notes -keyPair $publicKey

Multiline fields are set similarly

$ml = "Line1 `nLine 2"
Add-KeeperRecord ... '-multiline.Field Label' $ml

multiline defines a field type that is shown as multiline text edit by Keeper clients.

- dash in front of field means the field value is passed in the next argument

if there is no dash then the argument has format <FIELD_NAME>=<FIELD_VALUE>. Only simple text can be supplied using this format.

sethwalker1 commented 9 months ago

Thanks for the quick and detailed response!

I initially had issues with your suggested approach, but I've now identified the issue being an extra line at the end of the key contents. After trimming the string, all is working correctly! I definitely believe this behavior is worthy of documentation somewhere, but I'm still curious if it's intended or unexpected.