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

feat(Config): read from QubesDB if available; otherwise from environment variables #1883

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

cfm
Copy link
Member

@cfm cfm commented Mar 1, 2024

Status

Work in progress

Description

Updates the Client for compatibility with freedomofpress/securedrop-workstation#956.

Test Plan

Checklist

If these changes modify code paths involving cryptography, the opening of files in VMs or network (via the RPC service) traffic, Qubes testing in the staging environment is required. For fine tuning of the graphical user interface, testing in any environment in Qubes is required. Please check as applicable:

  • I have tested these changes in the appropriate Qubes environment
  • I do not have an appropriate Qubes OS workstation set up (the reviewer will need to test these changes)
  • These changes should not need testing in Qubes

If these changes add or remove files other than client code, the AppArmor profile may need to be updated. Please check as applicable:

  • I have updated the AppArmor profile
  • No update to the AppArmor profile is required for these changes
  • I don't know and would appreciate guidance

If these changes modify the database schema, you should include a database migration. Please check as applicable:

  • I have written a migration and upgraded a test database based on main and confirmed that the migration is self-contained and applies cleanly
  • I have written a migration but have not upgraded a test database based on main and would like the reviewer to do so
  • I need help writing a database migration
  • No database schema changes are needed

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.

This is really great, I think it demonstrates the value in this approach pretty well

client/securedrop_client/config.py Outdated Show resolved Hide resolved
client/securedrop_client/config.py Outdated Show resolved Hide resolved
client/securedrop_client/config.py Show resolved Hide resolved
client/securedrop_client/config.py Outdated Show resolved Hide resolved
client/tests/test_config.py Outdated Show resolved Hide resolved
@cfm
Copy link
Member Author

cfm commented Mar 8, 2024

44cd324 gives a naïve wrapper script with-qubesdb like so:

user@sd:~/securedrop-client$ ./with-qubesdb -h
usage: with-qubesdb [-h] [-k KEY]

Use -k/--key one or more times to read the specified key from QubesDB. All subsequent
arguments will be interpreted as the command to be invoked with those keys set as
environment variables.

optional arguments:
  -h, --help         show this help message and exit
  -k KEY, --key KEY
user@sd:~/securedrop-client$ ./with-qubesdb -k SD_PROXY_ORIGIN env
SD_PROXY_ORIGIN=foobar
user@sd:~/securedrop-client$ ./with-qubesdb -k SD_PROXY_ORIGIN -k NONESUCH env
SD_PROXY_ORIGIN=foobar
NONESUCH=

My claim is that with envsubst this is all we need...

user@sd:~/securedrop-client$ cat > i-know-this-isnt-a-real-tor-config.json <<EOF
{"hidsrv": "\${SD_PROXY_ORIGIN}"}
EOF
user@sd:~/securedrop-client$ cat i-know-this-isnt-a-real-tor-config.json | ./with-qubesdb -k SD_PROXY_ORIGIN envsubst
{"hidsrv": "foobar"}

@legoktm
Copy link
Member

legoktm commented Mar 11, 2024

I'm not opposed to envsubst but I don't really see the advantage of using it - in the with-qubesdb script, couldn't we use something like basic Python string formatting (or even jinja2) and avoid the indirection of setting things in the environment?

The changes you made to the QubesDB usage in the client LGTM.

@cfm
Copy link
Member Author

cfm commented Mar 11, 2024 via email

@cfm
Copy link
Member Author

cfm commented Mar 11, 2024

At c1734bf:

user@sd:~/securedrop-client$ cat > i-know-this-isnt-a-real-tor-config.json.jinja2 <<EOF
> {"hidsrv": "{{ SD_PROXY_ORIGIN }}"}
> EOF
user@sd:~/securedrop-client$ ./with-qubesdb -k SD_PROXY_ORIGIN i-know-this-isnt-a-real-tor-config.json.jinja2 i-know-this-isnt-a-real-tor-config.json
user@sd:~/securedrop-client$ cat i-know-this-isnt-a-real-tor-config.json
{"hidsrv": "foobar"}

@@ -86,7 +87,7 @@ def __init__(self, sdc_home: str, session_maker: scoped_session, is_qubes: bool)
self.is_qubes = is_qubes
self.session_maker = session_maker

config = Config.from_home_dir(self.sdc_home)
config: Any = Config.load()
Copy link
Member Author

Choose a reason for hiding this comment

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

@legoktm, do you see a way around the Any annotation here if Config is populated via setattr()?

@cfm
Copy link
Member Author

cfm commented Apr 3, 2024

Rebased from main; envsubst approach removed in favor of Jinja templating; and typing corrected, with one caveat in https://github.com/freedomofpress/securedrop-client/pull/1883/files#r1550649219.

@cfm cfm added the blocked label Apr 23, 2024
@cfm cfm force-pushed the sdw-936-vm-config branch 2 times, most recently from 3d334ef to da587b7 Compare April 24, 2024 22:44
cfm added 4 commits April 24, 2024 15:53
…ent variables

This has the nice side effect of simplifying tests: we have to care only
about getting the values we expect, not about whether certain files are
in the right place, have the right contents, &c.
…ailable

We have so few items that it's not a big deal to do this in each
iteration of the loop.  But this is more elegant anyway.

thread: https://github.com/freedomofpress/securedrop-client/pull/1883/files#r1508504213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Blocked
Development

Successfully merging this pull request may close these issues.

None yet

2 participants