-
Notifications
You must be signed in to change notification settings - Fork 42
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
Added CLI args and set inject home directory #43
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
20006af
increase verbosity of test output
heartsucker f79664a
cli arg parsing
heartsucker cfea71e
update tests to accomodate cli arg parsing
heartsucker 4a5d29e
remove hard coded home dir
heartsucker 3fe048f
inject homedir into client
heartsucker 07e611e
tests for homedir injection
heartsucker 8d34cce
more helpful run script
heartsucker 0acb198
factor out hardcoded DB_PATH
heartsucker 3f9ce66
tests for directory permissions
heartsucker 4edbe33
allow passing homedir to run.sh
heartsucker bcc141b
updated readme
heartsucker 6b096b1
update to test logic
heartsucker a08d7bf
100% test coverage
heartsucker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
while [ -n "$1" ]; do | ||
param="$1" | ||
value="$2" | ||
case $param in | ||
--sdc-home) | ||
SDC_HOME="$value" | ||
shift | ||
;; | ||
*) | ||
break | ||
esac | ||
shift | ||
done | ||
|
||
SDC_HOME=${SDC_HOME:-$(mktemp -d)} | ||
|
||
echo "Running app with home directory: $SDC_HOME" | ||
|
||
# create the database for local testing | ||
|
||
python - << EOF | ||
from securedrop_client.models import Base, make_engine | ||
Base.metadata.create_all(make_engine("$SDC_HOME")) | ||
EOF | ||
|
||
exec python -m securedrop_client --sdc-home "$SDC_HOME" $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .app import run | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
|
||
|
||
def safe_mkdir(sdc_home: str, relative_path: str=None) -> None: | ||
''' | ||
Safely create directories while checking permissions along the way. | ||
''' | ||
check_dir_permissions(sdc_home) | ||
|
||
if not relative_path: | ||
return | ||
|
||
full_path = os.path.join(sdc_home, relative_path) | ||
if not full_path == os.path.abspath(full_path): | ||
raise ValueError('Path is not absolute: {}'.format(full_path)) | ||
|
||
path_components = split_path(relative_path) | ||
|
||
path_so_far = sdc_home | ||
for component in path_components: | ||
path_so_far = os.path.join(path_so_far, component) | ||
check_dir_permissions(path_so_far) | ||
os.makedirs(path_so_far, 0o0700, exist_ok=True) | ||
|
||
|
||
def check_dir_permissions(dir_path: str) -> None: | ||
''' | ||
Check that a directory has ``700`` as the final 3 bytes. Raises a | ||
``RuntimeError`` otherwise. | ||
''' | ||
if os.path.exists(dir_path): | ||
stat_res = os.stat(dir_path).st_mode | ||
masked = stat_res & 0o777 | ||
if masked & 0o077: | ||
raise RuntimeError('Unsafe permissions ({}) on {}' | ||
.format(oct(stat_res), dir_path)) | ||
|
||
|
||
def split_path(path: str) -> list: | ||
out = [] | ||
|
||
while path: | ||
path, tail = os.path.split(path) | ||
out.append(tail) | ||
|
||
out.reverse() | ||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import os | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def safe_tmpdir(tmpdir): | ||
os.chmod(str(tmpdir), 0o0700) | ||
return tmpdir |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the log directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to keep the directory logic all in one place so I pulled that out for now. I can readd it but...
I guess this brings up a broader question which is how strict do we want to be on data directory permissions? Like I think every dir needs to have
00
for the final two bytes, and we should bail otherwise. I know it's Qubes already, but if the directories don't need globalrwx
, then it shouldn't be set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep the logs dir to prevent clutter
agreed on permissions