-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[Entitlements] Fix: consider case sensitiveness differences #126990
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
[Entitlements] Fix: consider case sensitiveness differences #126990
Conversation
Pinging @elastic/es-core-infra (Team:Core/Infra) |
Hi @ldematte, I've created a changelog YAML for you. |
…s://github.com/ldematte/elasticsearch into entitlements/fileaccesstree-fix-windows-casing
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 wonder if we'd be better of solving this via normalization rather than changing the comparator? If we normalize to lowercase on Windows, then the comparator will just work.
libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/FileUtils.java
Outdated
Show resolved
Hide resolved
libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/FileUtils.java
Outdated
Show resolved
Hide resolved
I'm not sure this is the right way to do it; probably in the case of a Windows FS it does not matter (the char comparison in WindowsPath do lower case after all), but usually "case insensitive comparison" and "normalize to lower case" are different. Since we already have a comparator, I thought it was a comparable amount of work/comparable change. |
I just worry that our comparator is going to become rather incomprehensible. Adding Do you have an example where normalize-then-compare is different from a case-insensitive compare? |
|
Do I understand correctly that the concern would be that a user would supply two different path strings that compare equal under |
I notice there's a reply to the above post that mentions |
Yeah
the startsWith thing for isParent is OK though.I wonder if we should "do better", but ... better than WindowsPath? Not sure is worth it at all. Still, I like the approach of fixing the comparator better; I don't like the idea of having a "broken" comparator around, that happens to work because we normalized strings beforehand. |
On the other hand it's true that normalization happens once, so there is a little performance benefit there... IDK. |
Agreed, the idea of overachieving relative to
But this is the heart of why normalization is beneficial: it reduces the space of cases to consider, and then subsequent processing is greatly simplified. The comparator isn't "broken" if the cases it doesn't handle are ones that never occur thanks to normalization. (In fact, the only reason I didn't propose normalizing the path separators is that there exists no reasonable separator character that would solve our sorting problem.) |
A note: at the team meeting, we chose to proceed with improved comparator instead of normalization, primarily based on the performance impact of doing a |
…cesstree-fix-windows-casing
…ub.com:ldematte/elasticsearch into entitlements/fileaccesstree-fix-windows-casing
…cesstree-fix-windows-casing
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.
LGTM
return 0; | ||
} | ||
return Character.compare(c1, c2); | ||
return Character.compare(Character.toLowerCase(c1), Character.toLowerCase(c2)); |
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.
Is there a significance to the fact that we switched from uppercase to lowercase?
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.
Nope, just a suggestion from Ryan to make it shorter and more readable
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.
toUpperCase
is equally short and readable, no?
I just think if we use one that's different from the actual filesystem code you referenced, we're asking for unexpected corner cases.
…126990) Our path comparison for file access is string based, due to the fact that we need to support Paths created for different file systems/platforms. However, Windows files and paths are (sort of) case insensitive. This PR fixes the problem by abstracting String comparison operations and making them case sensitive or not based on the host OS.
…126990) Our path comparison for file access is string based, due to the fact that we need to support Paths created for different file systems/platforms. However, Windows files and paths are (sort of) case insensitive. This PR fixes the problem by abstracting String comparison operations and making them case sensitive or not based on the host OS.
…126990) Our path comparison for file access is string based, due to the fact that we need to support Paths created for different file systems/platforms. However, Windows files and paths are (sort of) case insensitive. This PR fixes the problem by abstracting String comparison operations and making them case sensitive or not based on the host OS.
…#127276) Our path comparison for file access is string based, due to the fact that we need to support Paths created for different file systems/platforms. However, Windows files and paths are (sort of) case insensitive. This PR fixes the problem by abstracting String comparison operations and making them case sensitive or not based on the host OS.
…#127275) Our path comparison for file access is string based, due to the fact that we need to support Paths created for different file systems/platforms. However, Windows files and paths are (sort of) case insensitive. This PR fixes the problem by abstracting String comparison operations and making them case sensitive or not based on the host OS.
…#127274) Our path comparison for file access is string based, due to the fact that we need to support Paths created for different file systems/platforms. However, Windows files and paths are (sort of) case insensitive. This PR fixes the problem by abstracting String comparison operations and making them case sensitive or not based on the host OS.
Our path comparison for file access is string based, due to the fact that we need to support Paths created for different file systems/platforms.
However, Windows files and paths are (sort of) case insensitive - see https://discuss.elastic.co/t/not-entitled-component-repository-s3-after-update-from-8-17-4-to-8-18-0/377166 for a real issue where we hit this problem.
This PR fixes the problem by abstracting String comparison operations (moving them to
FileUtils
) and making them case sensitive or not based on the host OS.Closes #127047