Artifactory's npm virtual repository lists the local repository first, yet a build got a public package carrying an internal name; why didn't order protect it?
answer
- finding a file versus listing versions
- metadata merged across members
- the higher version wins the range
- exclude the namespace on the remote
- Priority Resolution, Nexus routing rules
basics
~20 sOrder only says where a given file is looked for first; version metadata is merged from every member, so a higher public version of the same name can win. Exclude patterns or Priority Resolution, not order, keep internal names off the remote.
solid answer
~50 sArtifactory searches a virtual repository's members as local repositories, then remote repository caches, then remote repositories, in list order within each, but that governs where a **specific file** is found. For the latest version, its documentation says it searches all included repositories, and it describes the result as metadata merged from the members. A public package with the internal name and a higher version therefore appears in the merged npm packument, npm's client picks it for its range, and the tarball comes from the remote. Two repository-side controls change that: an **Exclude Pattern** on the remote repository covering the internal namespace, so that repository is never consulted for those paths, and **Priority Resolution** on the local repository, so metadata is merged only from priority repositories when the package is found there. Nexus Repository's comparable control is a **routing rule** in BLOCK mode on the proxy repository. Order is a performance choice; namespace rules are the protection.
go deeper
Recall that a virtual or group repository puts several repositories behind one URL and searches them in a configured order, local repositories first in Artifactory.
Explain the difference between finding a specific file, where order decides, and listing versions, where Artifactory merges metadata from every member.
Trace how a higher public version entered through merged metadata, then close it on the repository side with exclude patterns, Priority Resolution or a Nexus BLOCK routing rule, verified with build credentials.
Push for internal names under namespaces you control, so one exclusion rule per upstream covers everything, and decide who owns those rules as teams add packages.
## Two different questions a virtual repository answers A **virtual repository** in Artifactory (a *group* repository in Nexus Repository) puts several member repositories behind one URL. Builds ask it two kinds of question, and member order means something different for each: - **"Give me this exact file"**, such as the tarball for version 1.4.0. Order decides which member is asked first, and the first member that has the file serves it. - **"What versions exist?"**, such as the npm packument or `maven-metadata.xml`. To answer that, Artifactory looks across members, because a version list from only the first member could be incomplete. Most surprises come from assuming the first rule applies to the second question. ## How Artifactory orders and merges Artifactory documents the search order for a virtual repository as: 1. local repositories, 2. then remote repository caches, 3. then the remote repositories themselves, with the order *within* each category taken from the list in the configuration. Its documentation also notes that security privileges, include and exclude patterns, and snapshot and release policies affect the search. For the latest version, though, it states that Artifactory **searches all the included repositories** to return the most current one, still consulting the remote even after finding a version locally. The *Priority Resolution* setting is described in the same terms: it causes metadata to be merged only from repositories that carry it. So by default, the version list a build receives is a merge. ## How the public name gets in 1. The internal package exists in the local repository at version 1.4.0. 2. Someone publishes a package with the same name to the public registry at version 99.0.0. 3. A build asks the virtual repository for the package's metadata. The merged packument lists 1.4.0 and 99.0.0. 4. npm's client picks the highest version that satisfies the project's range, 99.0.0, and requests that tarball. 5. The local repository does not have it; the remote does. The order worked exactly as documented, and the public package was served. The same happens if the internal package is missing from the local repository altogether, for example after it was renamed or moved to a repository the virtual repository does not include. ## Repository-side controls | Control | Where it is set | Effect | |---|---|---| | Exclude Patterns | Artifactory remote or virtual repository | Matching paths are not resolved from that repository | | Priority Resolution | Artifactory member repository | Metadata is merged only from priority repositories when the package is found there | | Routing rule in BLOCK mode | Nexus Repository proxy repository | Request paths matching the rule are blocked from reaching that proxy's upstream | | Upstream priority | Cloudsmith repository | Upstreams are tried in order, 1 to n; an ordering tool, not a namespace guard | Artifactory's own documentation gives the pattern for this case: put the remote repositories in a virtual repository and give it an exclude pattern for your organisation's groupId, so any attempt to fetch an internal artifact from a remote is rejected. ## What each control does not do - **Exclude patterns apply to regular users only.** Artifactory states that admin users see all items regardless of the patterns, so a build authenticating as an admin bypasses them. - **A Nexus Repository routing rule belongs to the proxy, not the group.** Routing rules apply to proxy repositories only and take effect whatever group the proxy is in; each proxy takes one rule, while one rule can serve many proxies. Matchers are regular expressions, and the documentation warns that complex ones can be costly to evaluate. - **Custom npm dist-tags follow order.** For dist-tags other than `latest`, Artifactory by default returns the version from the first member, in order, that has the tag. Order is not irrelevant; it is simply not what decides a version range. - **None of this replaces naming discipline.** Internal names in a namespace you control are far easier to exclude than a scattering of bare names. ## Verifying the fix - Request the internal package's metadata through the virtual repository **using the build's own credentials**, and confirm only internal versions are listed. - Request an internal name through the remote repository alone and confirm it is refused. - In Nexus Repository, use the test section under the routing-rule editor to check sample request paths before assigning the rule.
- Why might an Exclude Pattern on the remote repository not protect one particular CI job?Artifactory applies include and exclude patterns to regular users only; admin users see all items regardless of them. A CI job authenticating with an admin token therefore bypasses the pattern. Give build identities ordinary read permissions, and test the pattern with the same identity the builds use.
- How do custom npm dist-tags resolve in an Artifactory virtual repository?By default, for dist-tags other than `latest`, Artifactory does not compare version numbers or publish dates: the first member repository in the virtual repository's order that has the tag decides the version. Setting the system property `artifactory.npm.merge.latest.dist.tag.base.strategy.enabled` to `true` makes it aggregate the tag across members and pick the latest instead.
- Where should the Nexus Repository equivalent be configured, and how do you check it?On each proxy repository that reaches a public upstream, as a routing rule in BLOCK mode whose matcher covers the internal namespace; the rule applies whatever group the proxy belongs to. Each proxy takes one rule, so one shared rule can cover several proxies. The routing-rule editor's test section lets you try sample request paths before assigning it.
- Putting the local repository first guarantees internal names never resolve from the public registry.
- This can only happen when the internal package is missing from the local repository.
- An Exclude Pattern protects every build, including ones using admin credentials.
- A Nexus Repository routing rule set on the group repository protects all its members.