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 Namespace loading in PyYAML 5.4.x #6673

Merged
merged 5 commits into from
May 4, 2021

Conversation

chris-boson
Copy link
Contributor

@chris-boson chris-boson commented Mar 25, 2021

What does this PR do?

This fixes Namespace loading with PyYAML 5.4.x, which was restricted due to a security vulnerability.

Related issues:
#5606
#5619

Fixes #6666
fixes #7291

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@@ -350,7 +350,7 @@ def load_hparams_from_yaml(config_yaml: str, use_omegaconf: bool = True) -> Dict
return {}

with fs.open(config_yaml, "r") as fp:
hparams = yaml.load(fp, Loader=yaml.UnsafeLoader)
hparams = yaml.load(fp, Loader=yaml.Loader)
Copy link
Contributor

Choose a reason for hiding this comment

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

@chris-boson Why replace this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think this does just default to UnsafeLoader, but it doesn't seem to cause problems with pyyaml 5.4.x functionality wise.
I think if we want to use SafeLoader we need to add our own Loader and add constructors yaml/pyyaml#482 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

we are fine with declare own Loader, @chris-boson mind send a suggestion?

@Borda Borda changed the base branch from release/1.2.x to master March 25, 2021 10:12
@Borda
Copy link
Member

Borda commented Mar 25, 2021

@chris-boson pls target master as default branch

@mergify mergify bot removed the has conflicts label Mar 25, 2021
@chris-boson chris-boson marked this pull request as draft March 25, 2021 11:14
@codecov
Copy link

codecov bot commented Mar 25, 2021

Codecov Report

Merging #6673 (bf2f161) into master (df579a8) will decrease coverage by 4%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master   #6673    +/-   ##
=======================================
- Coverage      91%     87%    -4%     
=======================================
  Files         200     200            
  Lines       12929   12929            
=======================================
- Hits        11780   11222   -558     
- Misses       1149    1707   +558     

@chris-boson
Copy link
Contributor Author

@Borda Are we ok with just removing PyYAML!=5.4.x from requirements and continue using UnsafeLoading? What were the concerns with excluding this version? I think in terms of safety that would be equivalent to using PyYAML<5.4.

Alternatively we need to add our own SafeLoader and constructors #6673 (comment).

requirements.txt Outdated
@@ -4,7 +4,7 @@ numpy>=1.16.6
torch>=1.4
future>=0.17.1 # required for builtins in setup.py
# pyyaml>=3.13
PyYAML>=5.1, !=5.4.* # OmegaConf requirement >=5.1
PyYAML>=5.1 # OmegaConf requirement >=5.1
Copy link
Contributor

@omry omry Mar 25, 2021

Choose a reason for hiding this comment

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

OmegaConf 2.0 and newer declares it's version dependency on pyyaml so this line should no longer been needed (At some point in the far past it didn't, which was the reason for adding this in the first place).

https://github.com/omry/omegaconf/blob/2.0_branch/requirements/base.txt

@chris-boson chris-boson force-pushed the enhance/pyyaml54 branch 3 times, most recently from f29491e to 2eab087 Compare April 1, 2021 09:17
@Borda
Copy link
Member

Borda commented Apr 8, 2021

I think in terms of safety that would be equivalent to using PyYAML<5.4

we do not want any future versions like 6.x or so... so rather ban specific version if needed

@Borda Borda added the bug Something isn't working label Apr 8, 2021
@Borda Borda added this to the 1.2.x milestone Apr 8, 2021
@Borda Borda force-pushed the enhance/pyyaml54 branch from 2eab087 to 8c2833b Compare April 8, 2021 08:53
@Borda
Copy link
Member

Borda commented Apr 12, 2021

@chris-boson how is it going here?

@chris-boson
Copy link
Contributor Author

@chris-boson how is it going here?

@Borda I added a yaml loader for Namespace objects, we would need to add constructors for other objects we want to load safely (one of the tests is failing)

@carmocca
Copy link
Contributor

So to use SafeLoader we would need to add constructors for every object serialized?

Should we just use the UnsafeLoader then? AFAIK this was the case before, and we can't guarantee what will be saved to hparams

@chris-boson
Copy link
Contributor Author

So to use SafeLoader we would need to add constructors for every object serialized?

Should we just use the UnsafeLoader then? AFAIK this was the case before, and we can't guarantee what will be saved to hparams

Yeah, at least it wouldn't be any worse than it was before. So effectively we'd just take out the PyYAML!=5.4.* from requirements

@carmocca
Copy link
Contributor

Exactly, @Borda, do you agree?

@Borda
Copy link
Member

Borda commented Apr 12, 2021

So effectively we'd just take out the PyYAML!=5.4.* from requirements

but isn't that change in PyYAML for the future, is there an expectation that 5.5 will be fine?

@chris-boson
Copy link
Contributor Author

So effectively we'd just take out the PyYAML!=5.4.* from requirements

but isn't that change in PyYAML for the future, is there an expectation that 5.5 will be fine?

We can put <=5.4.1?

@Borda Borda modified the milestones: 1.2.x, 1.3 Apr 18, 2021
@ananthsub ananthsub mentioned this pull request Apr 30, 2021
@awaelchli awaelchli linked an issue May 2, 2021 that may be closed by this pull request
@carmocca
Copy link
Contributor

carmocca commented May 3, 2021

@chris-boson what's blocking this?

@awaelchli awaelchli marked this pull request as ready for review May 4, 2021 10:58
@awaelchli awaelchli added the ready PRs ready to be merged label May 4, 2021
@Borda
Copy link
Member

Borda commented May 4, 2021

@chris-boson what's blocking this?

seems like your approval :]

@Borda Borda enabled auto-merge (squash) May 4, 2021 21:59
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

can we update our YAML usage to support also newer versions?

@Borda Borda requested review from kaushikb11 and removed request for teddykoker May 4, 2021 22:02
@Borda Borda merged commit 763a9a9 into Lightning-AI:master May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow PyYAML 5.4 Remove requirement of PyYAML!=5.4.x
8 participants