Verdaccio是什么?
Verdaccio 是一款轻量级私有 npm 代理服务器解决方案,支持在本地或私有网络环境中实现 npm 包的托管、缓存及权限管理。该工具能有效提升开发团队的包管理效率,同时保障私有包的分发安全,尤其适用于企业级开发、闭源项目或需要定制化包管理策略的场景。
私有包托管:支持私有 npm 包的发布与管理,避免敏感代码泄露至公共仓库。
缓存机制:自动缓存下载的公共包,降低外部依赖延迟,支持离线环境持续开发。
权限控制:基于用户/用户组的访问策略配置,支持读写权限分离管理。
插件生态系统:提供存储、认证、UI 等模块的插件扩展能力。
环境要求
- Runtime: Node.js ≥ v18(推荐 LTS 版本)
- 包管理器: npm ≥6.x | yarn ≥1.x/2.x | pnpm ≥6.x
- 浏览器: Chrome/Firefox/Edge 等浏览器(IE11 兼容模式支持)
Docker安装
-
获取镜像
# 加速镜像:registry.cn-shanghai.aliyuncs.com/kubesec/verdaccio:6.1.2docker pull verdaccio/verdaccio:6.1.2
-
初始化存储目录
mkdir -p /opt/verdaccio/{conf,storage,plugins}
-
获取标准配置文件模板
sudo curl -L https://raw.githubusercontent.com/verdaccio/verdaccio/6.x/conf/docker.yaml -o /opt/verdaccio/conf/config.yaml
-
备用配置方案,当网络环境限制导致配置文件下载失败时,可通过执行下面命令生成基础配置文件
cat <<EOF | sudo tee /opt/verdaccio/conf/config.yaml## This is the default configuration file. It allows all users to do anything,# please read carefully the documentation and best practices to# improve security.## Do not configure host and port under `listen` in this file# as it will be ignored when using docker.# see https://verdaccio.org/docs/en/docker#docker-and-custom-port-configuration## Look here for more config file examples:# https://github.com/verdaccio/verdaccio/tree/6.x/conf## Read about the best practices# https://verdaccio.org/docs/best# path to a directory with all packagesstorage: /verdaccio/storage/data# path to a directory with plugins to includeplugins: /verdaccio/plugins# https://verdaccio.org/docs/webuiweb: title: Verdaccio# comment out to disable gravatar support# gravatar: false# by default packages are ordercer ascendant (asc|desc)# sort_packages: asc# convert your UI to the dark side# darkMode: true# html_cache: true# by default all features are displayed# login: true# showInfo: true# showSettings: true# In combination with darkMode you can force specific theme# showThemeSwitch: true# showFooter: true# showSearch: true# showRaw: true# showDownloadTarball: true# HTML tags injected after manifest <scripts/># scriptsBodyAfter:# - '<script type="text/javascript" src="https://my.company.com/customJS.min.js"></script>'# HTML tags injected before ends </head># metaScripts:# - '<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>'# - '<script type="text/javascript" src="https://browser.sentry-cdn.com/5.15.5/bundle.min.js"></script>'# - '<meta name="robots" content="noindex" />'# HTML tags injected first child at <body/># bodyBefore:# - '<div id="myId">html before webpack scripts</div>'# Public path for template manifest scripts (only manifest)# publicPath: http://somedomain.org/# https://verdaccio.org/docs/configuration#authenticationauth: htpasswd: file: /verdaccio/storage/htpasswd# Maximum amount of users allowed to register, defaults to "+infinity".# You can set this to -1 to disable registration.# max_users: 1000# Hash algorithm, possible options are: "bcrypt", "md5", "sha1", "crypt".# algorithm: bcrypt # by default is crypt, but is recommended use bcrypt for new installations# Rounds number for "bcrypt", will be ignored for other algorithms.# rounds: 10# https://verdaccio.org/docs/configuration#uplinks# a list of other known repositories we can talk touplinks: npmjs: url: https://registry.npmjs.org/# Learn how to protect your packages# https://verdaccio.org/docs/protect-your-dependencies/# https://verdaccio.org/docs/configuration#packagespackages:'@*/*':# scoped packages access: $all publish: $authenticated unpublish: $authenticated proxy: npmjs'**':# allow all users (including non-authenticated users) to read and# publish all packages## you can specify usernames/groupnames (depending on your auth plugin)# and three keywords: "$all", "$anonymous", "$authenticated" access: $all# allow all known users to publish/publish packages# (anyone can register by default, remember?) publish: $authenticated unpublish: $authenticated# if package is not available locally, proxy requests to 'npmjs' registry proxy: npmjs# To improve your security configuration and avoid dependency confusion# consider removing the proxy property for private packages# https://verdaccio.org/docs/best#remove-proxy-to-increase-security-at-private-packages# https://verdaccio.org/docs/configuration#server# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.server: keepAliveTimeout: 60# Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer# See: https://expressjs.com/en/guide/behind-proxies.html# trustProxy: '127.0.0.1'# https://verdaccio.org/docs/configuration#offline-publish# publish:# allow_offline: false# https://verdaccio.org/docs/configuration#url-prefix# url_prefix: /verdaccio/# VERDACCIO_PUBLIC_URL='https://somedomain.org';# url_prefix: '/my_prefix'# // url -> https://somedomain.org/my_prefix/# VERDACCIO_PUBLIC_URL='https://somedomain.org';# url_prefix: '/'# // url -> https://somedomain.org/# VERDACCIO_PUBLIC_URL='https://somedomain.org/first_prefix';# url_prefix: '/second_prefix'# // url -> https://somedomain.org/second_prefix/'# https://verdaccio.org/docs/configuration#security# security:# api:# legacy: true# # recomended set to true for older installations# migrateToSecureLegacySignature: true# jwt:# sign:# expiresIn: 29d# verify:# someProp: [value]# web:# sign:# expiresIn: 1h # 1 hour by default# verify:# someProp: [value]# https://verdaccio.org/docs/configuration#user-rate-limit# userRateLimit:# windowMs: 50000# max: 1000# https://verdaccio.org/docs/configuration#max-body-size# max_body_size: 10mb# https://verdaccio.org/docs/configuration#listen-port# listen:# - localhost:4873 # default value# - http://localhost:4873 # same thing# - 0.0.0.0:4873 # listen on all addresses (INADDR_ANY)# - https://example.org:4873 # if you want to use https# - "[::1]:4873" # ipv6# - unix:/tmp/verdaccio.sock # unix socket# The HTTPS configuration is useful if you do not consider use a HTTP Proxy# https://verdaccio.org/docs/configuration#https# https:# key: ./path/verdaccio-key.pem# cert: ./path/verdaccio-cert.pem# ca: ./path/verdaccio-csr.pem# https://verdaccio.org/docs/configuration#proxy# http_proxy: http://something.local/# https_proxy: https://something.local/# https://verdaccio.org/docs/configuration#notifications# notify:# method: POST# headers: [{ "Content-Type": "application/json" }]# endpoint: https://usagge.hipchat.com/v2/room/3729485/notification?auth_token=mySecretToken# content: '{"color":"green","message":"New package published: * {{ name }}*","notify":true,"message_format":"text"}'middlewares: audit: enabled: true# https://verdaccio.org/docs/logger# log settingslog: { type: stdout, format: pretty, level: http }#experiments:# # support for npm token command# token: false# # enable tarball URL redirect for hosting tarball with a different server, the tarball_url_redirect can be a template string# tarball_url_redirect: 'https://mycdn.com/verdaccio/${packageName}/${filename}'# # the tarball_url_redirect can be a function, takes packageName and filename and returns the url, when working with a js configuration file# tarball_url_redirect(packageName, filename) {# const signedUrl = // generate a signed url# return signedUrl;# }# translate your registry, api i18n not available yet# i18n:# list of the available translations https://github.com/verdaccio/verdaccio/blob/master/packages/plugins/ui-theme/src/i18n/ABOUT_TRANSLATIONS.md# web: en-USEOF
-
权限适配(容器使用非root用户运行)
chown -R 10001:65533 /opt/verdaccio
-
启动容器服务
docker run -d --name verdaccio -p 4873:4873 -v /opt/verdaccio/conf:/verdaccio/conf -v /opt/verdaccio/storage:/verdaccio/storage -v /opt/verdaccio/plugins:/verdaccio/plugins verdaccio/verdaccio:6.1.2
浏览器访问: http://<服务器IP>:4873/
-
全局代理设置
npm set registry http://<verdaccio-host>:4873/
-
项目级配置(.npmrc)
registry=http://<verdaccio-host>:4873/
参考资料:
-
https://verdaccio.org/zh-cn/docs/what-is-verdaccio/
-
https://github.com/verdaccio/verdaccio
clamd_exporter与ClamAV Grafana Dashboard
原文始发于微信公众号(KubeSec):verdaccio私有npm仓库服务
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论