Skip to content
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

Add --update-all option and update all dependencies with their hashes? #63

Closed
jotes opened this issue May 18, 2018 · 13 comments
Closed

Comments

@jotes
Copy link
Contributor

jotes commented May 18, 2018

Hey @peterbe!
I work with a lot of legacy projects that don't add hashes to their dependencies and I'd like to improve their security.
What do you think about an option which would just scan through all entries and add hashes to them?
Currently, I'm working around this with shell scripts but maybe it's a good idea to include it here.

I can even implement it if you think it will be useful.

Thanks in advance, hashin is awesome!

@peterbe
Copy link
Owner

peterbe commented May 18, 2018

What would be totally neat! When you do hashin Django lxml foobar and you already have those packages in the requirements.txt it will basically do an upgrade.

So you could basically do something like this:

if not args.packages and args.update_all:
  args.packages = get_all_current_package_names(args.file or 'requirements.txt')

(I don't know if mutating the Argparse object is a good idea, but the idea is there).

I look forward to a pull request. If you struggle to test it or how to format anything, let me know and we can complete it together.

@peterbe
Copy link
Owner

peterbe commented May 18, 2018

Another option would be to make it interactive. E.g. hashin -i --update-all -r requirements/default.txt. Then it could show an interactive prompt for each and every possible upgrade. E.g.

You have Django==2.0.4 installed, Django==2.0.5 is available. Upgrade? [Y/n]

How does yarn do interactive upgrades?

@jotes
Copy link
Contributor Author

jotes commented May 19, 2018

Thanks @peterbe, I'll reach out you in the next week.

@peterbe
Copy link
Owner

peterbe commented May 30, 2018

Any luck with this one?

@peterbe
Copy link
Owner

peterbe commented May 30, 2018

hashin doesn't have a dry-run functionality because it's never really been necessary. However, for a functionality like this it certainly would be useful.

@jotes
Copy link
Contributor Author

jotes commented May 30, 2018

hey @peterbe, I was totally busy last week and couldn't look into this. However, I'm free tomorrow and this issue is on the top of the list.

peterbe added a commit that referenced this issue Oct 25, 2018
peterbe added a commit that referenced this issue Oct 26, 2018
@peterbe peterbe mentioned this issue Oct 26, 2018
peterbe pushed a commit that referenced this issue Oct 26, 2018
* --update-all

Part of #63

* py 2.7 fix

* update changelog
@peterbe
Copy link
Owner

peterbe commented Nov 8, 2018

Hi @jotes Check out what just landed! #96

Can help me test it? I haven't made a release yet.

@jotes
Copy link
Contributor Author

jotes commented Nov 9, 2018

@peterbe YUP! I'll ping you in 10-12h with the results of QA.
I've realized that you've basically made this whole feature... Thanks and I apologize for so long time with no response.
HUGE kudos :)

@jotes
Copy link
Contributor Author

jotes commented Nov 10, 2018

@peterbe hey,
I've ran hashin on my current project :)

I'm not sure if that's a bug, but I've noticed missing hashes in some of dependencies.

For easier debug you can take a look at these files:
requirements-before-hashin.txt
https://gist.github.com/jotes/c4942951bd09d6a4153815508446d382
requirements-after-hashin.txt
https://gist.github.com/jotes/b73829d018117ec2531072cae31a47a5

I hope this bug is reproducible. Feel free to ask if you need anything :-)

Thanks again!

@peterbe
Copy link
Owner

peterbe commented Nov 12, 2018

@jotes Thanks! It's not really a bug in the code. It's just a confusion of expectations. You have a requirements file that did not already have hashes. Generally, this is not something hashin is used to deal with. Independent of the new --update-all --interactive feature, what would you expect if you run:

$ hashin -r requirements-before-hashin.txt alembic

I think the output of that would become something like this: https://gist.github.com/peterbe/bb003c7bfbabfeaa682027234176b2fe

Then, if you try to use that file with pip install you'd get this error:

$ pip install -r requirements-before-hashin.txt
...

Hashes are required in --require-hashes mode, but they are missing from some requirements. Here is a list of those requirements along with the hashes their downloaded archives actually had. Add lines like these to your requirements files to prevent tampering. (If you did not enable --require-hashes manually, note that it turns on automatically when any package has a hash.)
    amqp==2.2.2 --hash=sha256:4e28d3ea61a64ae61830000c909662cb053642efddbe96503db0e7783a6ee85b
    anyjson==0.3.3 --hash=sha256:37812d863c9ad3e35c0734c42e0bf0320ce8c3bed82cd20ad54cb34d158157ba
    behave==1.2.5
...

@peterbe
Copy link
Owner

peterbe commented Nov 12, 2018

In short, I don't think that's a bug in the new feature of the context of this issue. However, it's an interesting thing that will/can happen. How should hashin deal with it?

Perhaps it could analyze the requirements file and do something like:

$ hashin -r my-requirements.txt Django celery requests
Traceback (most recent call last):
...
Exception: Requirements file does not have hashes for all packages.

@peterbe
Copy link
Owner

peterbe commented Nov 12, 2018

What do you think?

@jotes
Copy link
Contributor Author

jotes commented Nov 13, 2018

@peterbe You're right, thanks for the clarification :-) I think that an explicit exception is totally okay.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants