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

#912 allow leading period #9867

Merged
merged 5 commits into from
Jan 31, 2024
Merged

#912 allow leading period #9867

merged 5 commits into from
Jan 31, 2024

Conversation

@edolstra
Copy link
Member

I think this sets a bad precedent of having to support bugs that accidentally snuck in forever. Also, flip-flopping on this behaviour again just makes the situation even more confusing.

@roberth
Copy link
Member Author

roberth commented Jan 29, 2024

bug

It was requested as a feature, #912

a bad precedent of having to support bugs that accidentally snuck in forever.

What if denying . is the bug?

a bad precedent

Since when do we make decisions based on precedent?
You're basically suggesting that we're just imitating the past, and we're not allowed to correct our mistakes?

The author of #9095 has shown no interest in helping users with the consequences of their PR. I don't blame them for that; they can have all sorts of reasons, and it's a risk I took when accepting their PR.
However, unlike them, I am a maintainer, and that makes me responsible for this issue by default.

If I were to hand responsibility to you, how would you deal with the problem? We have users with broken stores now, who can't upgrade their Nix. Do you plan to fix the problem in a different way? What about #912?

@roberth
Copy link
Member Author

roberth commented Jan 30, 2024

@Ericson2314 this fixes two Arbitrary instances. Some more still remain.

@Ericson2314
Copy link
Member

Glad to hear it!

@roberth roberth added backport 2.19-maintenance Automatically creates a PR against the branch backport 2.20-maintenance Automatically creates a PR against the branch labels Jan 30, 2024
@@ -3,6 +3,6 @@

namespace nix {

static constexpr std::string_view nameRegexStr = R"([0-9a-zA-Z\+\-_\?=][0-9a-zA-Z\+\-\._\?=]*)";
static constexpr std::string_view nameRegexStr = R"((?!\.\.?(-|$))[0-9a-zA-Z\+\-\._\?=]+)";
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite understand this one. Maybe it needs some comments?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +15 to +18
if (name.size() == 1)
throw BadStorePath("store path '%s' has invalid name '%s'", path, name);
if (name[1] == '-')
throw BadStorePath("store path '%s' has invalid name '%s': first dash-separated component must not be '%s'", path, name, ".");
Copy link
Member

Choose a reason for hiding this comment

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

Could pull this out into a lambda (with param for . or ..) and use twice

Copy link
Member Author

Choose a reason for hiding this comment

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

They're slightly different though, because of the second error message.
I don't think the lambda would help with understanding or reuse.

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

Looks good! None of my nits be low I care very much about :)

Gen::just is the constant generator. Don't just return that!
Gen::just is the constant generator. Don't just return that!
As discussed in the maintainer meeting on 2024-01-29.

Mainly this is to avoid a situation where the name is parsed and
treated as a file name, mostly to protect users.
.-* and ..-* are also considered invalid because they might strip
on that separator to remove versions. Doesn't really work, but that's
what we decided, and I won't argue with it, because .-* probably
doesn't seem to have a real world application anyway.
We do still permit a 1-character name that's just "-", which still
poses a similar risk in such a situation. We can't start disallowing
trailing -, because a non-zero number of users will need it and we've
seen how annoying and painful such a change is.

What matters most is preventing a situation where . or .. can be
injected, and to just get this done.
@roberth roberth merged commit 4072a8f into NixOS:master Jan 31, 2024
8 checks passed
Copy link

Backport failed for 2.19-maintenance, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.19-maintenance
git worktree add -d .worktree/backport-9867-to-2.19-maintenance origin/2.19-maintenance
cd .worktree/backport-9867-to-2.19-maintenance
git switch --create backport-9867-to-2.19-maintenance
git cherry-pick -x 9ddd0f2af8fd95e1380027a70d0aa650ea2fd5e4 b13e6a76b4f289c6db69ffaa7bd35b7e44f2a391 69bbd5852af9b2f0b794162bd1debcdf64fc6648 8406da28773f050e00a006e4812e3ecbf919a2a9 f1b4663805a9dbcb1ace64ec110092d17c9155e0

Copy link

Successfully created backport PR for 2.20-maintenance:

@thufschmitt
Copy link
Member

thufschmitt commented Feb 2, 2024

(bit late, but): Discussed during the Nix maintainers meeting on 2024-01-30.
Agreement to merge with a few extra restrictions (forbid things like . or ..).

  • Path with a leading . used to be forbidden, then got allowed by accident, and forbidden again

    • Problematic because users might now have invalid paths in their store, that Nix can't do anything with
    • Suggestion by @roberth: Allow them for good
  • @edolstra: Is it just a matter of a few people having them in their store? Because that can be worked around

  • @thufschmitt: What are the cost of allowing that for good?

    • @roberth: 2.3 doesn't support them
    • Might be security-relevant?
      • Dotfiles being hidden, this might be relied on for security reasons
      • Example: Some nixpkgs code somewhat relying on things not starting with a dot
  • @edolstra: These names are meant to be package names, not arbitrary ones (and we actually forbid a lot of characters already). What would it mean to have a package starting with a .?

  • @roberth: Nix is also used as a config manager. Shouldn't we use it for that?

  • @edolstra: Is there any package manager that allows package names starting with a .

  • @thufschmitt: If we don't allow these, how do make sure that people who already have them don't get bitten?

    • No real solution except allowing them internally (just forbid creating new ones)
  • Need to forbid things like ., .., ..-* and the like

Agreement

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-01-30-nix-team-meeting-minutes-119/39185/1

@ryantm
Copy link
Member

ryantm commented Mar 21, 2024

Did this get rolled back? I'm seeing

error: store path '1gzd3gdn5ff8ndinqdxsbpbw08yzcl87-.gitignore' starts with illegal character '.'

when running sudo nix-collect-garbage -d
in nix 2.18.2 and nix 2.21.0

@roberth
Copy link
Member Author

roberth commented Mar 21, 2024

@ryantm It didn't get reverted. Maybe you're getting this from a daemon or remote builder?

@ryantm
Copy link
Member

ryantm commented Mar 22, 2024

@roberth Thanks for the quick reply, that was a good hint. I had:

$ nix store ping
Store URL: daemon
Version: 2.18.2
Trusted: 1

then I updated my NixOS nix to be

$ nix store info
Store URL: daemon
Version: 2.21.0
Trusted: 1

and garbage collection worked fine.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/store-path-starts-with-illegal-character/42050/2

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/store-path-starts-with-illegal-character/42050/3

Copy link

Backport failed for 2.18-maintenance, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.18-maintenance
git worktree add -d .worktree/backport-9867-to-2.18-maintenance origin/2.18-maintenance
cd .worktree/backport-9867-to-2.18-maintenance
git switch --create backport-9867-to-2.18-maintenance
git cherry-pick -x 9ddd0f2af8fd95e1380027a70d0aa650ea2fd5e4 b13e6a76b4f289c6db69ffaa7bd35b7e44f2a391 69bbd5852af9b2f0b794162bd1debcdf64fc6648 8406da28773f050e00a006e4812e3ecbf919a2a9 f1b4663805a9dbcb1ace64ec110092d17c9155e0

Copy link

Backport failed for 2.19-maintenance, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.19-maintenance
git worktree add -d .worktree/backport-9867-to-2.19-maintenance origin/2.19-maintenance
cd .worktree/backport-9867-to-2.19-maintenance
git switch --create backport-9867-to-2.19-maintenance
git cherry-pick -x 9ddd0f2af8fd95e1380027a70d0aa650ea2fd5e4 b13e6a76b4f289c6db69ffaa7bd35b7e44f2a391 69bbd5852af9b2f0b794162bd1debcdf64fc6648 8406da28773f050e00a006e4812e3ecbf919a2a9 f1b4663805a9dbcb1ace64ec110092d17c9155e0

Copy link

Backport failed for 2.20-maintenance, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.20-maintenance
git worktree add -d .worktree/backport-9867-to-2.20-maintenance origin/2.20-maintenance
cd .worktree/backport-9867-to-2.20-maintenance
git switch --create backport-9867-to-2.20-maintenance
git cherry-pick -x 9ddd0f2af8fd95e1380027a70d0aa650ea2fd5e4 b13e6a76b4f289c6db69ffaa7bd35b7e44f2a391 69bbd5852af9b2f0b794162bd1debcdf64fc6648 8406da28773f050e00a006e4812e3ecbf919a2a9 f1b4663805a9dbcb1ace64ec110092d17c9155e0

@thufschmitt
Copy link
Member

This doesn't seem to have been backported to 2.18? We need to

@edef1c
Copy link
Member

edef1c commented Apr 16, 2024

The author of #9095 has shown no interest in helping users with the consequences of their PR. I don't blame them for that; they can have all sorts of reasons, and it's a risk I took when accepting their PR.
However, unlike them, I am a maintainer, and that makes me responsible for this issue by default.

To be clear, my initial proposal (#9091) was to document and codify the change in behaviour, rather than revert it, given that it was likely to have snuck into real-world use already, as experience has now indeed borne out.

I can't spend all my time glued to GitHub currently, so this is the first time I'm seeing the fallout. It seemed like a perhaps risky but worthwhile experiment, that you endorsed as a maintainer (before code for the stricter validation was even written), and I'm fine with how this has concluded.

We don't have an "ecosystem test run" environment like Rust's Crater, so I would not (and could not) have undertaken a live-fire test like this without a maintainer taking responsibility for it. Building a Crater equivalent seems abstractly worthwhile, but right now I don't have the bandwidth for such an undertaking, and I don't particularly expect anyone to volunteer.

As far as I can tell, the only alternative unexplored was making it a warning and treating it as an explicitly deprecated behaviour, but I don't think that would have done much good.

My sole goal here was to ensure that there is clear agreement on what constitutes in-spec Nix behaviour, so that other implementers (such as the TVL nix-compat Rust library, which I co-maintain) can match it in behaviour exactly, since we lack a formal specification.

@roberth
Copy link
Member Author

roberth commented Apr 17, 2024

Hi @edef1c and thank you for your response.
We all did the best we could do with our limited resources.

You're making good points about the ecosystem test run and a formal specification. We're trying to improve both, but for the formal specification, that takes a different form. Making a separate spec document is an effort that's hard to justify (for the Nix team), but we are making the documentation more precise. A spec is also reference documentation, so I think there's a lot that can be done about this issue, just by improving the Nix manual. So, contributions are welcomed; especially small and incremental ones.

tvlbot pushed a commit to tvlfyi/tvix that referenced this pull request May 1, 2024
Nix 2.4 accidentally permitted this behaviour, but the revert came
too late to beat Hyrum's law. It is now considered permissible.

Link: NixOS/nix#9867
Change-Id: Ie97777af6765fe1c12c8aa593afe1c9b69125775
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11553
Tested-by: BuildkiteCI
Reviewed-by: flokli <[email protected]>
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/broken-nix-store-path-starts-with-illegal-character/47776/1

@vcunat
Copy link
Member

vcunat commented Sep 17, 2024

I believe this hasn't been applied to 2.19 (yet). Though 9ddd0f2 would at least apply cleanly.

@roberth
Copy link
Member Author

roberth commented Sep 17, 2024

We don't actively support 2.19, but feel free to open a PR

@vcunat
Copy link
Member

vcunat commented Sep 17, 2024

Sad that the current Hydra is based on 2.19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.18-maintenance Automatically creates a PR against the branch backport 2.19-maintenance Automatically creates a PR against the branch backport 2.20-maintenance Automatically creates a PR against the branch bug feature Feature request or proposal
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Support file paths with a dotted basename
8 participants