cdhunt / SecretManagement.1Password

This is a SecretManagement extension for 1Password.
MIT License
22 stars 14 forks source link

Get-Secret errors on converting JSON string #8

Open Windos opened 3 years ago

Windos commented 3 years ago

Hey Chris, good work on this module! You've got a hell of a lot farther than me! I've run into two issues that I'll file separately:

I'm not able to retrieve a secret from my vault (setting it works perfectly, I can see it in the GUI)

Set-Secret -Name 'PS Test' -Secret 'this is text'
Get-Secret -Name 'PS Test'

# also tested
Get-Secret -Name 'PS Test' -AsPlainText
ConvertFrom-Json: C:\Program Files\WindowsPowerShell\Modules\SecretManagement.1Password\0.0.4.1\SecretManagement.1Password.Extension\SecretManagement.1Password.Extension.psm1:63
Line |
  63 |  … ems --categories Login,Password --vault $VaultName | ConvertFrom-Json
     |                                                         ~~~~~~~~~~~~~~~~
     | Cannot convert the JSON string because it contains keys with different casing. Please use the -AsHashTable switch instead. The key
     | that was attempted to be added to the existing key 'B5UserUUID' was 'b5UserUUID'.

Get-Secret: The secret PS Test was not found.

Environment

Get-Module *SecretManagement*
ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     0.5.5      preview6   Microsoft.PowerShell.SecretManagem… {Get-Secret, Get-SecretInfo, Get-SecretVault, Register-SecretVault…}
Manifest   0.0.4.1               SecretManagement.1Password
$PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.2.0-preview.1
PSEdition                      Core
GitCommitId                    7.2.0-preview.1
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
op -v
1.8.0
cdhunt commented 3 years ago

Thanks for the feedback. Are there any usage scenarios that you covered or feel are important this version is still missing? Besides the basics actually working. :)

Windos commented 3 years ago

I haven't looked at what sort of additional metadata is possible to feed through SecretManagement... but being able to add URLs, OTPs, notes, etc would be sweet

cdhunt commented 3 years ago

OTP. That's an interesting scenario.

Definitely agree on setting other fields.

Windos commented 3 years ago

Strictly speaking, if I'm using that in code I'd probably just store the OTP secret as its own secret and use GoogleAuthenticator to get the pin if needed (yes... I have some APIs I use that ask for the OTP pin 🤦‍♂️)

cdhunt commented 3 years ago

For the original issue, it looks like an error in Get-SecretInfo. The SecretsModule doesn't like duplicate keys, but 1Password has no problem having duplicate Titles. I can't reproduce the same message you got, but I added duplicate items to 1Password with different casing and got the following error from SecretsManagement. I try to filter out duplicates and return only the first item, but Contains() of ArrayList is case sensitive comparison so it doesn't work in this case (haha).

Get-SecretInfo: An item with the same key has already been added. Key: [B5UserUUID, Microsoft.PowerShell.SecretManagement.SecretInformation]

cdhunt commented 3 years ago

Ok, duh, reproduced in Get-Secret. I don't know of a good way to disambiguate duplicate 1Password items.

cdhunt commented 3 years ago

It's easy to get a totp from op, but not sure how to handle that with Get-Secret. 🤔

op get totp <item>

cdhunt commented 3 years ago

maniacal laughing The trouble you can get into with Powershell.

image