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-866: Add state to the SDK & BWS CLI #388

Merged
merged 48 commits into from
Dec 18, 2023
Merged

SM-866: Add state to the SDK & BWS CLI #388

merged 48 commits into from
Dec 18, 2023

Conversation

coltonhurst
Copy link
Member

Type of change

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

Objective

This PR adds the ability to manage basic state via the SDK. It also updates the bws crate to use this SDK change, implementing basic state management for auth tokens. The core benefit is that reauthentication per command will no longer be needed, so that server auth requests will be mitigated.

Code changes

(to be added)

  • file.ext: Description of what was changed and why

Before you submit

  • Please add unit tests where it makes sense to do so (encouraged but not required)

@bitwarden-bot
Copy link

bitwarden-bot commented Dec 3, 2023

Logo
Checkmarx One – Scan Summary & Details46489a45-7b43-4fcf-8bfc-dee0f6cc1927

New Issues

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Unpinned Actions Full Length Commit SHA /version-bump.yml: 56 Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps...

Fixed Issues

Severity Issue Source File / Package
MEDIUM Unpinned Actions Full Length Commit SHA /version-bump.yml: 59

@coltonhurst coltonhurst self-assigned this Dec 3, 2023
@coltonhurst coltonhurst marked this pull request as ready for review December 4, 2023 07:14
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.

Some quick review comments

crates/bitwarden/src/client/client.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/error.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/lib.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/client/client.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/client/client.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/client/client.rs Outdated Show resolved Hide resolved
Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

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

I had hoped we could leave the bitwarden crate mostly untouched and have the state mostly in the bws crate.

@dani-garcia
Copy link
Member

We will have the same problem with the PHP bindings, so having a solution just for bws won't solve all the issues at least.

@coltonhurst
Copy link
Member Author

coltonhurst commented Dec 4, 2023

I had hoped we could leave the bitwarden crate mostly untouched and have the state mostly in the bws crate.

Yeah, that's why I tried to leave "minimal" changes in the bitwarden crate, and a lot of the storage logic is in bws. However, as @dani-garcia mentioned, multiple integrations will need to be able to use state to avoid the reauthentication each time (PHP and Python specifically have been discussed).

If you're open to it we can leave the minimal "generalized" state changes in the bitwarden crate and keep the rest of the storage logic in bws. Then we can revisit a more robust approach to state as we discussed previously?

Update (Dec 5): PR has been updated, most of the logic is in the bitwarden crate so extensions can take advantage of state management, though it is in its own module. We can move this if needed, but it would be great to keep management in the bitwarden crate for integrations if possible.

coltonhurst added a commit that referenced this pull request Dec 5, 2023
## Type of change

<!-- (mark with an `X`) -->

```
- [ ] Bug fix
- [ ] New feature development
- [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
```

## Objective

<!--Describe what the purpose of this PR is. For example: what bug
you're fixing or what new feature you're adding-->

Refactor out the `Instant` type in Client and use unix timestamps. This
is to support this PR: #388 where
we need to serialize token expiry times.

It also brings benefits to other areas like WASM, where `Instant`
doesn't exist.

## Code changes

<!--Explain the changes you've made to each file or major component.
This should help the reviewer understand your changes-->
<!--Also refer to any related changes or PRs in other repositories-->

- **crates/bitwarden/src/auth/renew.rs:** Update the `renew_token`
function to use timestamps instead of the `Instant` type
- **crates/bitwarden/src/client/client.rs:** Update `Client` to store
the unix timestamp for token expiration

## Before you submit

- Please add **unit tests** where it makes sense to do so (encouraged
but not required)
@coltonhurst coltonhurst requested a review from Hinton December 5, 2023 21:58
dani-garcia
dani-garcia previously approved these changes Dec 12, 2023
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.

Some minor things to avoid some unneeded clones but otherwise LGTM

crates/bitwarden/src/auth/login/access_token.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/auth/login/access_token.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/auth/login/access_token.rs Outdated Show resolved Hide resolved
dani-garcia
dani-garcia previously approved these changes Dec 13, 2023
crates/bitwarden/src/client/client_settings.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/auth/login/access_token.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/secrets_manager/state.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/secrets_manager/state.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/auth/login/access_token.rs Outdated Show resolved Hide resolved
crates/bitwarden/src/auth/renew.rs Show resolved Hide resolved
crates/bitwarden/src/client/client.rs Show resolved Hide resolved
crates/bws/src/config.rs Outdated Show resolved Hide resolved
crates/bws/src/main.rs Show resolved Hide resolved
Copy link

codecov bot commented Dec 17, 2023

Codecov Report

Attention: 108 lines in your changes are missing coverage. Please review.

Comparison is base (4c079e8) 45.45% compared to head (bd3c420) 44.81%.
Report is 1 commits behind head on main.

Files Patch % Lines
crates/bitwarden/src/auth/login/access_token.rs 12.76% 41 Missing ⚠️
crates/bitwarden/src/secrets_manager/state.rs 0.00% 28 Missing ⚠️
crates/bitwarden/src/auth/renew.rs 5.88% 16 Missing ⚠️
crates/bws/src/main.rs 0.00% 11 Missing ⚠️
crates/bws/src/state.rs 0.00% 10 Missing ⚠️
crates/bws/src/config.rs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #388      +/-   ##
==========================================
- Coverage   45.45%   44.81%   -0.64%     
==========================================
  Files         149      151       +2     
  Lines        6771     6881     +110     
==========================================
+ Hits         3078     3084       +6     
- Misses       3693     3797     +104     

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

Hinton
Hinton previously approved these changes Dec 18, 2023
Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

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

Looks good, ideally we would have test cases for the new access token login logic, and ClientState logic.

@coltonhurst coltonhurst merged commit 9d4ec76 into main Dec 18, 2023
40 of 42 checks passed
@coltonhurst coltonhurst deleted the sm/sm-866 branch December 18, 2023 18:27
tangowithfoxtrot added a commit that referenced this pull request Jan 13, 2024
## Type of change

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

## Objective

Enable authentication with the state file. Relates to #388.

## Code changes

- **`languages/python/bitwarden_sdk/bitwarden_client.py`**: Add optional
`state_file_path` parameter to `access_token_login`

## Before you submit

- Please add **unit tests** where it makes sense to do so

---------

Co-authored-by: Daniel García <dani-garcia@users.noreply.github.com>
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.

4 participants