-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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(auth): Fixes authentication conditions and logic with registries #5216
Conversation
This change will increase the build size from 10.4 MB to 10.4 MB, an increase of 1.86 KB (0%)
|
const customHostSuffix = this.getRegistryOrGlobalOption(registryUrl, 'custom-host-suffix'); | ||
|
||
const requestToRegistryHost = () => request.host === registry.host; |
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.
Why is it a function?
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.
Yeah, this is a bit silly. I might have been trying to "optimise" by avoiding expression evaluation until needed, but it's just string comparisons and perhaps creating functions inline is more expensive.
In any case - refactored this function slightly for overall readability:
#5321
I'm going to go ahead and merge it for the release, but please check that the function is required :) |
@KidkArolis Is there a specific reason why only |
…readdir_files * upstream/master: (34 commits) feat(upgrade, add): Separately log added/upgraded dependencies (yarnpkg#5227) feat(publish): Publish command uses publishConfig.access in package.json (yarnpkg#5290) fix(CLI): Use process exit instead of exitCode for node < 4 (yarnpkg#5291) feat(cli): error on missing workspace directory (yarnpkg#5206) (yarnpkg#5222) feat: better error when package is not found (yarnpkg#5213) Allow scoped package as alias source (yarnpkg#5229) fix(cli): Use correct directory for upgrade-interactive (yarnpkg#5272) nohoist baseline implementation (yarnpkg#4979) 1.4.1 1.4.0 Show current version, when new version is not supplied on "yarn publish" (yarnpkg#4947) fix(install): use node-gyp from homebrew npm (yarnpkg#4994) Fix transient symlinks overriding direct ones v2 (yarnpkg#5016) fix(auth): Fixes authentication conditions and logic with registries (yarnpkg#5216) chore(package): move devDeps to appropriate place (yarnpkg#5166) fix(resolution) Eliminate "missing peerDep" warning when dep exists at root level. (yarnpkg#5088) fix(cli): improve guessing of package names that contain a dot (yarnpkg#5102) (yarnpkg#5135) feat(cli): include notice with license when generating disclaimer (yarnpkg#5072) (yarnpkg#5111) feat(cli): group by license in licenses list (yarnpkg#5074) (yarnpkg#5110) feat(cli): improve error message when file resolver can't find file (yarnpkg#5134) (yarnpkg#5145) ...
@JoostK Basic auth should work fine, it's handled in yarn/src/registries/npm-registry.js Lines 338 to 344 in 7fcf4dd
|
@KidkArolis I was referring to |
Ah, right! Hm, I suppose I could add that for completeness. You can still use username/password if you specify But I suppose this PR is proposing to avoid using |
@KidkArolis Thanks! I wasn't aware of I prefer your approach with this PR as it is far more intuitive to configure and also more generic. In fact, I don't see a need for Perhaps renaming the const isToRegistry = this.isRequestToRegistry(requestUrl, registry) || this.requestNeedsAuth(requestUrl); |
There are a lot of conditions that are taken into account before we call const isToRegistry = this.isRequestToRegistry(requestUrl, registry) || this.requestNeedsAuth(requestUrl);
// this.token must be checked to account for publish requests on non-scopped packages
if (this.token || (isToRegistry && (alwaysAuth || this.isScopedPackage(packageIdent)))) {
const authorization = this.getAuth(packageIdent);
if (authorization) {
headers.authorization = authorization;
}
} All of these conditions ultimately decide if the request So the There must be a way to rewrite this block into something better, but oh my, not sure how.. Maybe something like: const tokenInUse = !!this.token
const isToRegistry = this.isRequestToRegistry(requestUrl, registry)
const isScopedPackage = this.isScopedPackage(packageIdent)
const registryAuthRequired = this.requestNeedsAuth(requestUrl);
const requestNeedsAuth = (isToRegistry || registryAuthRequired) && (alwaysAuth || isScopedPackage)
if (tokenInUse || requestNeedsAuth) { I'm just worried about making these expressions no longer lazy, could impact perf if calcs done for each package. Maybe the only issue is the naming of |
Summary
Supersedes #5162 (for now). Fixes #4157, #4451, #4672, #4119.
This PR brings 2 changes.
Fix for private npm packages
Fixes unauthed requests to yarnpk.com by treating yarnpkg.com as requests to npmjs.org in
isRequestToRegistry
.Feature - simpler support for multipath registries
Before, if you wanted to use something like artifactory, Nexus or VSTS where meta url's differ from tarball urls, you had to configure like so:
But now you can do this instead:
This way we don't introduce a new option, we're just saying, aha, when accessing this kind of URL, make sure to authenticate it. I personally find it slightly more intuitive.
Test plan
I've added a new test case to
requestIsToRegistry
unit test.I've redone the request authorisation tests. It's a small hit to the ergonomics of the tests (harder to comment some of them or use skip/only feature). But compacting them all from code to data means we can be a lot more thorough with all the different cases. The intention was to preserve all of the existing test cases, but add many more. In particular, here are the different common scenarios I tested:
And then also tested
The PR is split into somewhat independent commits if that helps.