passbolt / lab-passbolt-ansible-collection

Source repository for https://galaxy.ansible.com/anatomicjc/passbolt
MIT No Attribution
9 stars 10 forks source link

Error with unencrypted description #9

Closed pavriet-boxtal closed 8 months ago

pavriet-boxtal commented 1 year ago

Hello,

I am trying to use this collection to fetch values from my passbolt. Any lookup gives:

{"msg": "An unhandled exception occurred while running the lookup plugin 'anatomicjc.passbolt.passbolt'. Error was a <class 'json.decoder.JSONDecodeError'>, original message: Expecting value: line 1 column 1 (char 0). Expecting value: line 1 column 1 (char 0)"}

I tracked the error to this specific call to json: https://github.com/passbolt/lab-passbolt-ansible-collection/blob/8f8726e9b4e42cf6cee4e7513db6878f07a60d90/plugins/lookup/passbolt.py#L303

Adding debug prints, I get self.dict_config.get("gpg_library", "PGPy") == "gnupg" -> False self.p.decrypt(self.p.get_resource_secret(resource.get("id"))) -> MyPassword type(self.p.decrypt(self.p.get_resource_secret(resource.get("id")))) -> <class 'str'>

And so json.loads gets a malformed json (or no json at all ...), and raises a json.decoder.JSONDecodeError.

The culprit seems to be passbolt.PassboltAPI.decrypt not returning a json string.

According to ansible-galaxy collection list, I have anatomicjc.passbolt v0.0.11 installed According to pip list, I have py-passbolt v0.0.15 installed

paulfi94 commented 10 months ago

Hey, i also hit this Issue. I fixed it by enabling encryption on the Description of the Object in the Passbolt GUI. This makes the decrypt function return a json object instead of str since there is a second encrypted field. Seems like the decrypt function only returns json if there is more than one field returned by py-passbolt. Screenshot_20231205_111801

AnatomicJC commented 10 months ago

Thank you both for tackling this issue and @paulfi94 for the explanation. I will try to properly mitigate this in the ansible plugin.

AnatomicJC commented 8 months ago

I just published 0.0.12 version with a fix for this issue: https://galaxy.ansible.com/ui/repo/published/anatomicjc/passbolt/ thanks to @RobinR1 pull request.