-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Prevent m̶a̶l̶i̶c̶i̶o̶u̶s̶ invalid code updates #250
Conversation
# Prepare code auditing environment | ||
REPO_URL=$(git remote get-url origin) | ||
TEST_DIR=$(mktemp -d) | ||
git clone "$REPO_URL" "$TEST_DIR"; |
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.
Instead of a tmpdir, maybe just use a constant folder so we can just git pull
instead of a fresh clone every time.
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.
This may be embarrassing for future tests, which may leave data - junk.
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.
https://stackoverflow.com/a/1210012/345059 could be used to speed up the temp clone as the repo grows
Note that this doesn't prevent malicious code changes, but rather just syntax errors. Still 👍. |
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'd really rather test each PR individually and just not merge them in the first place if they don't pass, but this is still better than what we have now.
startup.d/10-git-pull.sh
Outdated
pushd "$TEST_DIR"; | ||
|
||
# Code auditing section | ||
python -m py_compile $(find . -name '*.py'); |
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.
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.
Syntax analysis only needs a consistent version of Python. It deliberately does not implement PEP8 analysis, as it may be too rigorous and embarrassing.
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 mentioned flake8 because it's what I use. I can see why you'd not want to fail on style though. Maybe use pyflakes directly instead? Regardless, like I said above, this is still better than what we have. We can refine it later.
You really do need to use the correct version of python though.
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.
@ad-m @reddraggone9 yep the chaos venv python lives in /root/.virtualenvs/chaos/bin/python
. We should do something so we don't have to hardcode it for too much longer in our script files
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.
@amoffat , drop virtualenv at all 👍
|
||
# Prepare code auditing environment | ||
REPO_URL=$(git remote get-url origin) | ||
TEST_DIR=$(mktemp -d) |
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.
This should either be cleaned up so we're not wasting disk space or (preferably) use a single, fixed directory. With the latter option, you could fetch and hard reset to origin/master
instead of cloning the entire repo every time.
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.
You're right, it could be cleaned up.
startup.d/10-git-pull.sh
Outdated
|
||
# Code auditing section | ||
python -m py_compile $(find . -name '*.py'); | ||
if [ "$?" != "0" ] |
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.
Just if [ $? ]
will do here.
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.
Nevermind me, I'm an idiot.
@PlasmaPower , every syntax error interferes with our program, so I think it is malicious. Additional analysis will be available in the future. |
@ad-m Malicious implies meaning evil, which most syntax errors aren't. |
startup.d/10-git-pull.sh
Outdated
@@ -16,6 +16,7 @@ fi | |||
|
|||
# End code auditing section | |||
popd | |||
rm -r "$TEST_DIR"; |
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.
But what if it exits up above? Also needs -f
since git objects are write-protected.
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.
It will removed too. See a175ecb#diff-8d12b14fde22f0fe54cea293ca1caa32R14 .
malicious:
Aside from the fact that this is still a useful PR, regardless of being incorrectly titled. |
@ad-m are you able to test this in the docker dev env to confirm that everything works as designed? |
@amoffat , I have never use docker yet. |
@patricknelson , fixed! |
This will fail on files with spaces in their names: $ mkdir test
$ cd test
$ touch test.py 'with space.py'
$ python3 -m py_compile $(find . -name '*.py');
Traceback (most recent call last):
File "/usr/local/lib/python3.5/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.5/py_compile.py", line 186, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/py_compile.py", line 178, in main
compile(filename, doraise=True)
File "/usr/local/lib/python3.5/py_compile.py", line 122, in compile
source_bytes = loader.get_data(file)
File "<frozen importlib._bootstrap_external>", line 815, in get_data
FileNotFoundError: [Errno 2] No such file or directory: './with' Working around this in the shell seems painful. It'd probably be a good idea to eventually rewrite these scripts in python. |
@reddraggone9 , fixed.
|
Unvoted and revoted... will the vote count now? Relevant feature request: #196 |
You don't need to recast your vote anymore. See #117. |
@reddraggone9 does this currently document the entirety of how voting works? https://github.com/chaosbot/chaos#voting i.e. This means you can continuously push to a PR and it'll be valid, but the voting window closes entirely after 3hrs of opening the PR? Assuming this is is relative to that point in time:
|
There are corner cases, but that's mostly right. The window gets reset every time you push to your repo, but old votes still count. |
pushd "$TEST_DIR"; | ||
|
||
# Code auditing section | ||
find . -name '*.py' -print0 | xargs -0 python -m py_compile; |
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.
Looks like I commented on the wrong PR.
python3 -m py_compile **/*.py
would be cleaner.
#250: Prevent m̶a̶l̶i̶c̶i̶o̶u̶s̶ invalid code updates Description: :ok_woman: PR passed with a vote of 15 for and 1 against, with a weighted total of 14.0 and a threshold of 6.2. Vote record: @EtherTyper: 1 @JarJak: 1 @Mursaat: 1 @PlasmaPower: 1 @ad-m: 1 @chickenchuck040: 1 @dcstone09: 1 @ike709: 1 @kochmaxence: -1 @patricknelson: 1 @reddraggone9: 1 @rhengles: 1 @rudehn: 1 @sorcio: 1 @viktorsec: 1 @xyproto: 1
🙆♀️ PR passed with a vote of 15 for and 1 against, with a weighted total of 14.0 and a threshold of 6.2. See merge-commit 56ade60 for more details. |
error: Unknown subcommand: get-url
fatal: The empty string is not a valid path |
@rudehn , where did you find it? |
|
@ad-m I found it in the logs. http://chaosthebot.com:8081 |
No description provided.