Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SM-1147] Switch to try_init with pyo3_log #676

Merged
merged 2 commits into from
Apr 11, 2024
Merged

[SM-1147] Switch to try_init with pyo3_log #676

merged 2 commits into from
Apr 11, 2024

Conversation

coltonhurst
Copy link
Member

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

When running the ansible-playbook command, we needed to export the following variable: export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES. This suppresses fork safety warnings on Mac OS. With this set, you can safely query for individual secrets. However, if you query for secrets within an Ansible loop or with a Jinja2 template, we receive an error that is caused by setting up a logger more than once. (This error comes from the pyo3_log crate.)

If we switch to using the pyo3_log::try_init function, we ignore the case where a logger is already set up if the attempt fails. This happens because the pyo3_log::init function can panic. This also introduces panic safety.

Code changes

  • client.rs: Switch to try_init

Before you submit

  • Please add unit tests where it makes sense to do so

@coltonhurst coltonhurst self-assigned this Mar 21, 2024
@coltonhurst coltonhurst requested review from Hinton, dani-garcia and a team March 21, 2024 19:51
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 60.59%. Comparing base (67e743f) to head (4c5b926).

Files Patch % Lines
crates/bitwarden-py/src/client.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #676      +/-   ##
==========================================
- Coverage   60.61%   60.59%   -0.02%     
==========================================
  Files         170      170              
  Lines       10387    10390       +3     
==========================================
  Hits         6296     6296              
- Misses       4091     4094       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

dani-garcia
dani-garcia previously approved these changes Mar 22, 2024
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thomas-Avery
Thomas-Avery previously approved these changes Mar 22, 2024
Copy link
Contributor

@Thomas-Avery Thomas-Avery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coltonhurst
Copy link
Member Author

Added a comment and let for consistency across crates in 4c5b926.

@Hinton Hinton mentioned this pull request Apr 9, 2024
1 task
@djsmith85 djsmith85 linked an issue Apr 9, 2024 that may be closed by this pull request
1 task
@coltonhurst coltonhurst merged commit b4205cc into main Apr 11, 2024
67 checks passed
@coltonhurst coltonhurst deleted the sm/sm-1147 branch April 11, 2024 13:59
@coltonhurst coltonhurst changed the title SM-1147: Switch to try_init with pyo3_log [SM-1147] Switch to try_init with pyo3_log Apr 11, 2024
@mittkkoo
Copy link

mittkkoo commented Apr 23, 2024

I'm sorry for the dumb question, but how to implement this fix on my side? I'm using Bitwarden Secrets with the ansible lookup plugin. I did cargo build in crates/bws as in the newest state of the main branch and then cargo install --path ., but what next? The lookup plugin still fails with a panic error as before.

@jacobfelknor
Copy link

jacobfelknor commented Apr 24, 2024

@mittkkoo, I'm facing the same issue as you with the Ansible integration.

If you followed the directions for setup in the Bitwarden Documentation, I believe it doesn't use the bws cli you installed/built with cargo (maintainer, please correct me if I'm wrong), but instead only uses the bitwarden-sdk PyPI package.

I think we must wait until a new version of bitwarden-sdk is published to PyPI

@jacobfelknor
Copy link

jacobfelknor commented Jun 5, 2024

@coltonhurst

Tagging you because you're the PR author and I'm not sure who else to ask, but feel free to delegate. This still appears to be unresolved for users following the official documentation I linked in my above reply for the same reason - no new PyPI package pushed.

When can the community expect this to be resolved (or how can I help us get there)?

@coltonhurst
Copy link
Member Author

@mittkkoo & @jacobfelknor thanks for asking & reaching out, sorry for the delay on this. We have an internal ticket on deck to fix the Python issue, we will be investigating soon!

@jacobfelknor
Copy link

Great, thank you!

@betermieux
Copy link

@mittkkoo & @jacobfelknor thanks for asking & reaching out, sorry for the delay on this. We have an internal ticket on deck to fix the Python issue, we will be investigating soon!

Any news on this? The ansible plugin is not usable if you use more then one secret lookup…

@felixklauke
Copy link

felixklauke commented Aug 4, 2024

@coltonhurst Would be great of you could give us an ETA for a new release.

@betermieux In the meantime, I created a dirty little fix for this:

- name: Deploy and configure Prometheus
  hosts: service_APP001_Prometheus
  become: true
  pre_tasks:
    - set_fact:
        netbox_api_url: "{{ lookup('bitwarden.secrets.lookup', 'xxx' )}}"
    - set_fact:
        netbox_api_token: "{{ lookup('bitwarden.secrets.lookup', 'xxx' )}}"
  roles:
    - prometheus.prometheus.prometheus

TL;DR: Put all lookups in it's own (!) set_fact task for now, until we have a release.

@betermieux
Copy link

@betermieux In the meantime, I created a dirty little fix for this…

Sorry for not replying earlier, I commented my findings at bitwardens forum:
Bitwarden lookup plugin for Ansible causes panick errors and “A worker was found in a dead state”

It basically works if you build a current version of this SDK and replace the packages in your ansible installation. Now someone just needs to publish a current version to the pip repository.

coltonhurst pushed a commit that referenced this pull request Sep 12, 2024
## 🎟️ Tracking

<!-- Paste the link to the Jira or GitHub issue or otherwise describe /
point to where this change is coming from. -->
https://bitwarden.atlassian.net/browse/SM-1384

## 📔 Objective

<!-- Describe what the purpose of this PR is, for example what bug
you're fixing or new feature you're adding. -->
When creating multiple WASM clients, a panic occurs `failed to
initialize logger: SetLoggerError())`.

Looks to be the same thing we fixed: 
#181
#676


## ⏰ Reminders before review

- Contributor guidelines followed
- All formatters and local linters executed and passed
- Written new unit and / or integration tests where applicable
- Protected functional changes with optionality (feature flags)
- Used internationalization (i18n) for all UI strings
- CI builds passed
- Communicated to DevOps any deployment requirements
- Updated any necessary documentation (Confluence, contributing docs) or
informed the documentation
  team

## 🦮 Reviewer guidelines

<!-- Suggested interactions but feel free to use (or not) as you desire!
-->

- 👍 (`:+1:`) or similar for great changes
- 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info
- ❓ (`:question:`) for questions
- 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry
that's not quite a confirmed
  issue and could potentially benefit from discussion
- 🎨 (`:art:`) for suggestions / improvements
- ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or
concerns needing attention
- 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or
indications of technical debt
- ⛏ (`:pick:`) for minor or nitpick changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PanicExecption in python sdk
8 participants