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

Fix Broken Logic in bootstrap.py #7088

Merged
merged 2 commits into from
Feb 15, 2024
Merged

Conversation

nathandyer
Copy link
Contributor

Status

Ready for review

Description of Changes

Fixes #7084

There were a few areas of broken logic in the is_missing_dependency function, which would result in broken or unidentified behavior if the underlying apt-cache was stale or non-existent.

If, while doing a search of the apt-cache, it only located a subset of the package list, or if it were completely unable to find a package (such as in the event of a missing cache), it would still return False, because the grep operation didn't find the "Installed: (none)" string it was looking for. So in those situations, even though the dependencies were missing, it did not return True as it should have.

The way the dependencies were listed at the top, with spaces inserted instead of tabs, meant that when we split the string using a space character as the delimiter to form the command, there were dozens of empty strings, which apt-cache would attempt to search for, and would turn up the same error as a missing package, making it impossible to determine when packages were missing.

This change eliminates those extra spaces, simplifies the logic to prefer built-in string-checking in Python rather than shelling out to grep, and fixes the broken return logic so it identifies when dependencies are missing due to not being in the apt cache at all.

Testing

Note: This test plan requires Tails 5.20

  1. Create a clean Tails 5.20 disk, enable persistent storage, and set an administrator password
  2. Clone the SecureDrop repo, staying on the develop branch for now, and run ./securedrop-admin setup
  3. Confirm that you receive a virtualenv error
  4. Switch to this branch and repeat ./securedrop-admin setup
  5. Confirm that this time you are asked for an admin password, and that it is able to update the package cache and install the dependencies
  6. Re-run ./securedrop-admin setup, and confirm that you are no longer prompted for an admin password, and that it sees the dependencies as having already been installed

@nathandyer nathandyer requested a review from a team as a code owner December 7, 2023 16:34
Copy link
Member

@legoktm legoktm left a comment

Choose a reason for hiding this comment

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

Nice, this looks much better and makes a lot of sense! I think you just need to fix some lint/formatting errors to make CI happy.

I am wondering if we're better off just doing os.file.exists('/usr/bin/virtualenv') or whatever instead of even bothering to look at the apt-cache...

@nathandyer
Copy link
Contributor Author

Thanks for reviewing @legoktm! I believe I have appeased the linter gods, so this is ready for another look at your convenience.

As for your note about possibbly just checking if the virtualenv exists, my gut instinct is that that may not be sufficient to ensure a consistent state, because I can imagine a situation where someone might have a virtual environment created, but have somehow uninstalled one of the dependencies along the way, which just checking for the virtual environment wouldn't catch.

Copy link
Member

@legoktm legoktm left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, overall looks good. One last comment about checking the return code of the apt-cache command

admin/bootstrap.py Show resolved Hide resolved
There were a few areas of broken logic in the is_missing_dependency
function, which would result in broken or unidentified behavior if
the underlying apt-cache was stale or non-existant.

If, while doing a search of the apt-cache, it only located a
subset of the package list, or if it were completely unable to find
a package (such as in the event of a missing cache), it would still
return False, because the grep operation didn't find the "Installed:
(none)" string it was looking for. So in those situations, even
though the dependencies were missing, it did not return True as it
should have.

The way the dependencies were listed at the top, with spaces
inserted instead of tabs, meant that when we split the string using
a space character as the delimiter to form the command, there were
dozens of empty strings, which apt-cache would attempt to search for,
and would turn up the same error as a missing package,
making it impossible to determine when packages were missing.

This change eliminates those extra spaces, simplifies the logic
to prefer built-in string-checking in Python rather than shelling
out to grep, and fixes the broken return logic so it identifies
when dependencies are missing due to not being in the apt cache
at all.
@zenmonkeykstop
Copy link
Contributor

(rebased to pull in a dependency bump and clear static analysis CI job)

Copy link
Member

@legoktm legoktm left a comment

Choose a reason for hiding this comment

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

Nice, LGTM!

@legoktm legoktm merged commit 2fb054c into develop Feb 15, 2024
18 checks passed
@legoktm legoktm deleted the fix-broken-dependency-check branch February 15, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Cannot create virtualenv with ./securedrop-admin setup on fresh Tails 5.20 disks
3 participants