Skip to content

dependabot/dependabot-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Repository files navigation

Dependabot

Welcome to the public home of Dependabot:dependabot:.

Table of Contents


What is Dependabot-Core?

Dependabot-Core is the library at the heart ofDependabotsecurity / version updates.

Use it to generate automated pull requests updating dependencies for projects written in Ruby, JavaScript, Python, PHP, Dart, Elixir, Elm, Go, Rust, Java and.NET. It can also update git submodules, Docker files, and Terraform files. Features include:

  • Check for the latest version of a dependencythat's resolvable given a project's other dependencies
  • Generate updated manifest and lockfiles for a new dependency version
  • Generate PR descriptions that include the updated dependency's changelogs, release notes, and commits

How to run Dependabot

Most people are familiar with the Dependabot service that runs on GitHub and GitHub Enterprise. Enabling that is as simple aschecking adependabot.ymlconfiguration file in to your repository's.githubdirectory.

However, if you want to run a custom version of Dependabot or run it on another platform, you're not left out in the cold. This repo provides the logic necessary for hosting your own standalone Dependabot. It currently supports opening Pull Requests against repositories hosted on GitHub, Github Enterprise, Azure DevOps, GitLab, BitBucket, and AWS CodeCommit.

Dependabot-Core is a library, so you'll need an entrypoint script of some kind. Here are a few examples to help you get started.

Note:If you're looking to run Dependabot locally for development/debugging purposes, see theDevelopment Guide.

Dependabot-Script

Thedependabot-scriptrepo provides a collection of example scripts for configuring the Dependabot-Core library. It is intended as a starting point for advanced users to run a self-hosted version of Dependabot within their own projects.

Note:We recently refactored the monolithic docker image used within the Dependabot Core library into one-image-per-ecosystem. Unfortunately, that broke dependabot-scripts, and we haven't had time to update them yet. We are aware of the problem and hope to provide a solution soon.

Dependabot CLI

TheDependabot CLIis a newer tool that may eventually replacedependabot-scriptfor standalone use cases. While it creates dependency diffs, it's currently missing the logic to turn those diffs into actual PRs. Nevertheless, it may be useful for advanced users looking for examples of how to hack on Dependabot.

Dependabot on CI

In an environment such as GitHub where Dependabot is running in a container, if you want to change your build or installation process depending on whether Dependabot is checking, you can determine it by the existence ofDEPENDABOTenvironment variable.

Contributing to Dependabot

Reporting issues and Feature Requests

👋 Want to give us feedback on Dependabot, or contribute to it? That's great - thank you so much!

Reproducible Example

Most bug reports should be accompanied by a link to a public repository that reproduces the problem. Bug reports that cannot be reproduced on a public repo using theCLI toolordry-run scriptmay be closed as "cannot reproduce".

No "+1" Comments

Our issue tracker is quite active, and as a result there's a good chance someone already filed the same issue. If so, please upvote that issue, because we use 👍 reactions on issues as one signal to gauge the impact of a feature request or bug.

However, please do not leave comments that contribute nothing new to the discussion. For details, seehttps://github /golang/go/wiki/NoPlusOne.This is open source, if you see something you want fixed, we are happy to coach you through contributing a pull request to fix it.

Don't file issues about Security Alerts or Dependency Graph

The issue-tracker is meant solely for issues related to Dependabot's updating logic. Issues aboutsecurity alertsorDependency Graphshould instead be filed as aCode Security discussion.

A good rule of thumb is that if you have questions about thediffin a PR, it belongs here.

Disclosing Security Issues

If you believe you have found a security vulnerability in Dependabot, please reviewour security policyfor details about disclosing them to the GitHub Bug Bounty program, so we can work to resolve the issue before it is disclosed publicly.

Submitting Pull Requests

Want to contribute to Dependabot? That's great - thank you so much!

Contribution workflow:

  1. Fork the project.
  2. Get thedevelopment environment running.
  3. Make your feature addition or bug fix.
  4. Addtests for it.This is important so we don't break it in a future version unintentionally.
  5. Send a pull request. The tests will run on it automatically, so don't worry if you couldn't get them running locally.

Please refer to theCONTRIBUTINGguidelines for more information.

New Ecosystems

If you're interested in contributing support for a new ecosystem, please refer to thecontributing guidelinesfor more information.

Development Guide

Getting a Development Environment Running

The first step to debugging a problem or writing a new feature is getting a development environment going. We provide a customDocker-baseddeveloper shell that bakes in all required dependencies. In most cases this is the best way to work with the project.

The developer shell uses volume mounts to incorporate your local changes to Dependabot's source code. This way you can edit locally using your favorite editor and the changes are immediately reflected within the docker container for performing dry-runsor executingtests. Note: See caveat aboutediting the native package manager helper scripts.

Quickstart

The script to launch the developer shell builds the docker images from scratch if it can't find them locally. This can take a while.

Skip the wait by pulling the pre-built image for the ecosystem you want to work on. The image name uses theYAML ecosystem name to specify the ecosystem. For example, for Go Modules, the YAML name isgomod:

$ docker pull ghcr.io/dependabot/dependabot-updater-gomod

Note:Pre-built images are currently only available for AMD64 / Intel architecture. Theywillrun on ARM, but 2x-3x slower than if youmanually build ARM-specific images.

Next, run the developer shell, specifying the desired ecosystemusing the top-level directory name of the ecosystem in this project.For example, for Go Modules, the top-level directory is namedgo_modules:

$ bin/docker-dev-shell go_modules
=>running docker development shell
[dependabot-core-dev]~$cdgo_modules&&rspec spec#to run tests for a particular package

Building Images from Scratch

Normally theQuickstartis all you need, but occasionally you'll need to rebuild the underlying images.

For example, while we don't yet publish ARM-specific images, if youareworking on an ARM-based platform, we recommend manually building the images because the resulting containers run much faster.

The developer shell runs within a Dependabot Development docker image, which is built on top of an ecosystem image.

flowchart LR
A[ "docker-dev-shell script" ] --> B( "Dependabot Development docker image" )
B --> C( "Dependabot Updater Ecosystem docker image (ecosystem specific)" )
C --> D( "Dependabot Updater Core docker image" )
Loading

Changes to the docker files for any of these images requires building one or more of the images locally in order to be reflected in the development shell.

The simple but slow way is to delete any existing images and then runbin/docker-dev-shellwhich automatically builds missing images.

The faster way is to pull all the pre-built images that are dependencies of the image you actually need to build. To (re)build a specific one:

  • The Updater core image:

    $ docker pull ghcr.io/dependabot/dependabot-updater-core#OR
    $ docker build -f Dockerfile.updater-core.#recommended on ARM
  • The Updater ecosystem image:

    $ docker pull ghcr.io/dependabot/dependabot-updater-gomod#OR
    $ script/build go_modules#recommended on ARM
  • The development container using the--rebuildflag:

    $ bin/docker-dev-shell go_modules --rebuild

Making Changes to native Package Manager helpers

Several Dependabot packages make use of 'native helpers', small executables in their host language.

Changes to these files are not automatically reflected inside the development container.

Once you have made any edits to the helper files, run the appropriate build script to update the installed version with your changes like so:

$ bin/docker-dev-shell bundler
=>running docker development shell
$ bundler/helpers/v2/build
$ bin/dry-run.rb bundler dependabot/demo --dir="/ruby"

To view logs and stdout from the native package manager helpers, seedebugging native helpers.

Debugging Problems

The first step to debugging is getting thedevelopment environment running.

Within the development environment, you have two options for simulating a dependency update job: You can use the newly-developedCLI toolor the originalDry-run script.

CLI tool

TheDependabot CLIis a newly-developed tool that incorporates theGitHub Credentials Proxyto more realistically simulate what's happening within the Dependabot-at-GitHub service when talking to private registries.

It has adedicated debugging guide,including support for dropping into the Ruby debugger.

Dry-Run Script

Note: Before running the dry-run script, you'll need toget the development environment running.

You can use thebin/dry-run.rbscript to simulate a dependency update job, printing the diff that would be generated to the terminal. It takes two positional arguments: the package manager and the GitHub repo name (including the account):

$ bin/docker-dev-shell go_modules
=>running docker development shell
$ bin/dry-run.rb go_modules rsc/quote
=>fetching dependency files
=>parsing dependency files
=>updating 2 dependencies
...

Helpful options to speed up dry-run testing

TheDry-Run scriptsupports many other options, all of which are documented at thetop of the script's source code.For example:

  1. LOCAL_GITHUB_ACCESS_TOKEN= "fake-GitHub-PAT"allows specifying aGitHub Personal Access Token (PAT)to avoid rate-limiting.
  2. --dir= "path/to/subdir/containing/manifestis required if the manifest file is located in a subdirectory.
  3. --dep= "dep-name-that-I-want-to-test"allows specifying a single dep to try to update and all others are ignored.
  4. --cache=filesallows caching remote dep files locally for faster re-runs when testing local logic changes.
  5. --updater-options=feature_flag_nameallows passing in feature flags.

Here's an example of how to string all these together

LOCAL_GITHUB_ACCESS_TOKEN=github_pat_123_fake_string \
bin/dry-run.rb docker jeffwidman/secrets-store-driver \
--dir"/manifest_staging/charts/secrets-store-provider"\
--cache=files \
--dep="secrets-store"\
--updater-options=kubernetes_updates

Adding debug breakpoints

You can add adebuggerstatement anywhere in the ruby code, for example:

deflatest_resolvable_version
debugger
latest_version_finder.latest_version
end

When you execute the job, the Ruby debugger will open. It should look something like this:

[11,20]in~/go_modules/lib/dependabot/go_modules/update_checker.rb
11|moduleGoModules
12|classUpdateChecker<Dependabot::UpdateCheckers::Base
13|require_relative"update_checker/latest_version_finder"
14|
15|deflatest_resolvable_version
=>16|debugger
17|latest_version_finder.latest_version
18|end
19|
20|# This is currently used to short-circuit latest_resolvable_version,
=>#0 Dependabot::GoModules::UpdateChecker#latest_resolvable_version at ~/go_modules/lib/dependabot/go_modules/update_checker.rb:16
#1 Dependabot::GoModules::UpdateChecker#latest_version at ~/go_modules/lib/dependabot/go_modules/update_checker.rb:24
# and 9 frames (use `bt' command for all frames)
(rdbg)

At this prompt, you can rundebugger commandsto navigate around, or enter methods and variables to see what they contain. Try enteringdependencyto see what dependency Dependabot is currently working on.

NoteWhile in the debugger, changes made to the source code will not be picked up. You will have to end your debugging session and restart it.

Debugging Native Package Manager Helpers

When you're debugging an issue you often need to peek inside these scripts that run in a separate process.

Print all log statements from native helpers usingDEBUG_HELPERS=true:

DEBUG_HELPERS=true bin/dry-run.rb bundler dependabot/demo --dir="/ruby"

Pause execution to debug a single native helper function usingDEBUG_FUNCTION=<function name>.The function maps to a native helper function name, for example, one of the functions inbundler/helpers/v2/lib/functions.rb.

When this function is being executed adebuggeris inserted, pausing execution of thebin/dry-run.rbscript, this leaves the current updatestmpdirectory in place allowing you tocdinto the directory and run the native helper function directly:

DEBUG_FUNCTION=parsed_gemfile bin/dry-run.rb bundler dependabot/demo --dir="/ruby"
=>fetching dependency files
=>dumping fetched dependency files:./dry-run/dependabot/demo/ruby
=>parsing dependency files
$cd/home/dependabot/dependabot-core/tmp/dependabot_TEMP/ruby&&echo"{\ "function\ ":\ "parsed_gemfile\ ",\ "args\ ":{\ "gemfile_name\ ":\ "Gemfile\ ",\ "lockfile_name\ ":\ "Gemfile.lock\ ",\ "dir\ ":\ "/home/dependabot/dependabot-core/tmp/dependabot_TEMP/ruby\ "}}"|BUNDLER_VERSION=1.17.3 BUNDLE_GEMFILE=/opt/bundler/v1/Gemfile GEM_HOME=/opt/bundler/v1/.bundle bundleexecruby /opt/bundler/v1/run.rb

Copy and run thecd...command:

cd/home/dependabot/dependabot-core/tmp/dependabot_TEMP/ruby&&echo"{\ "function\ ":\ "parsed_gemfile\ ",\ "args\ ":{\ "gemfile_name\ ":\ "Gemfile\ ",\ "lockfile_name\ ":\ "Gemfile.lock\ ",\ "dir\ ":\ "/home/dependabot/dependabot-core/tmp/dependabot_TEMP/ruby\ "}}"|BUNDLER_VERSION=1.17.3 BUNDLE_GEMFILE=/opt/bundler/v1/Gemfile GEM_HOME=/opt/bundler/v1/.bundle bundleexecruby /opt/bundler/v1/run.rb

This should log out the output of theparsed_gemfilefunction:

{"result":[{"name":"business","requirement":"~> 1.0.0","groups":["default"],"source":null,"type":"runtime"},{"name":"uk_phone_numbers","requirement":"~> 0.1.0","groups":["default"],"source":null,"type":"runtime"}]}

Keep in mind that unlike changes to the ruby source, changes on your host machine to the native helpers source code are not synced to the development container. So you have two choices for editing the native helper:

  • You can directly edit the temporary copy of the native helper within the development container, for example:vi /opt/bundler/v1/lib/functions/file_parser.rb.And then re-run thecd...command. This is the fastest way to debug, but any changes won't be saved outside the container.
  • You can edit your local copy, and thenrebuild the native helper.This will require re-running the dry-run script to pickup the change.

Debugging Ignore Conditions

Most of the ecosystems in Dependabot-Core supportignoreconditions which allow a user to specify dependency names or versions to exclude from upgrades. The docs for the Dependabot service at GitHubdescribe the feature in more detail.

TheDependabot CLIsupports passing in ignore conditions as part of the job definition. Seethe example.

Thedry-run scriptsupports passing in one or more ignore conditions via the env varIGNORE_CONDITIONS:

IGNORE_CONDITIONS='[{ "dependency-name": "*", "update-types": [ "version-update:semver-major" ]}]'\
bin/dry-run.rb docker test_org/test-dependabot`

Debugging Security Updates

Many of the ecosystems in Dependabot-Core supportsecurity updates.These are a special form of version update where a dependency name and range of vulnerable versions are passed in. Dependabot-Core will try to upgrade any instance of that dependency to theminimumnon-vulnerable version. This is in contrast to a normal version update which tries to update to thelatestversion.

The env varSECURITY_ADVISORIESallows passing one or more security alert notifications to thedry-run scriptin order to simulate a security update:

SECURITY_ADVISORIES='[{ "dependency-name": "buffer", "patched-versions":[], "unaffected-versions":[], "affected-versions":[ "<= 2.0.0" ]}]'\
bin/dry-run.rb pub dart-lang/pub-dev --dir"/app"--cache=files --dep="buffer"

Visual Studio Code and Docker

There's built-in support for leveraging Visual Studio Code'sability for debugginginside a Docker container. After installing the recommendedDev Containersextension, simply pressCtrl+Shift+P(⇧⌘Pon macOS) and selectDev Containers: Reopen in Container. You can also access the dropdown by clicking on the green button in the bottom-left corner of the editor. If the development Docker image isn't present on your machine, it will be built automatically. Once that's finished, start theDebug Dry Runconfiguration(F5)and you'll be prompted to select a package manager and a repository to perform a dry run on. Feel free to place breakpoints on the code.

There is also support to debug individual test runs by running theDebug Testsconfiguration(F5) and you'll be prompted to select an ecosystem and provide an rspec path.

⚠️TheClone Repository...commands of the Remote Containers extension are currently missing some functionality and are therefore not supported. You have to clone the repository manually and use theReopen in ContainerorOpen Folder in Container... command.

Running Tests

Once you get thedevelopment environment for a particular ecosystemgoing, execute the tests for that ecosystem by runningrspec specinside that ecosystem's folder, e.g.

$cdgo_modules
$ rspec spec

You can also limit the tests to only the file you're working on, or only tests that previously failed, for example:

$ rspec spec/dependabot/file_updaters/elixir --only-failures

Style is enforced byRuboCop.To check for style violations, simply runrubocopin each of the packages, e.g.

$cdgo_modules
$ rubocop

Profiling

You can profile adry-runby passing the--profileflag when running it, or tag anrspectest with:profile. This will generate astackprof-<datetime>.dumpfile in thetmp/folder, and you can generate a flamegraph from this by running:

stackprof --d3-flamegraph tmp/stackprof-<data or spec name>.dump>tmp/flamegraph.html

Architecture and Code Layout

Dependabot-Core is a collection of Ruby packages (gems), which contain the logic for updating dependencies in several languages.

dependabot-common

Thecommonpackage contains all general-purpose/shared functionality. For instance, the code for creating pull requests for the different supported platforms lives here, as does most of the logic for handling Git dependencies (as most languages support Git dependencies in one way or another). There are also base classes defined for each of the major concerns required to implement support for a language or package manager.

dependabot-{package-manager}

There is a gem for each package manager or language that Dependabot supports. At a minimum, each of these gems will implement the following classes:

Service Description
FileFetcher Fetches the relevant dependency files for a project (e.g., theGemfileandGemfile.lock). See theREADMEfor more details.
FileParser Parses a dependency file and extracts a list of dependencies for a project. See theREADMEfor more details.
UpdateChecker Checks whether a given dependency is up-to-date. See theREADMEfor more details.
FileUpdater Updates a dependency file to use the latest version of a given dependency. See theREADMEfor more details.
MetadataFinder Looks up metadata about a dependency, such as its GitHub URL. See theREADMEfor more details.
Version Describes the logic for comparing dependency versions. See thehex Version classfor an example.
Requirement Describes the format of a dependency requirement (e.g.>= 1.2.3). See thehex Requirement classfor an example.

The high-level flow looks like this:

Dependabot high-level architecture diagram

dependabot-omnibus

This is a "meta" gem, that simply depends on all the others. If you want to automatically include support for all languages, you can just include this gem and you'll get all you need.

Private Registry Credential Management

For many ecosystems, Dependabot-Core supports private registries. Sometimes this happens by passing the private registry credentials directly to the native package managers (npm,pip,bundler,etc), other times it happens within the Dependabot-Core Ruby code.

sequenceDiagram
Private Registry Credentials->>Dependabot-Core:<br />
Dependabot-Core->>Native Package Managers:<br />
Native Package Managers->>Package Registries:<br />
Dependabot-Core->>Package Registries:<br />
Loading

While simple and straightforward, this is a security risk for ecosystems that allow running untrusted code within their manifest files. For examplesetup.pyand.gemspecallow running native Python and Ruby code. If a package in the dependency tree gets hacked, an attacker could push a malicious manifest that forces the native package manager to expose the creds.

To guard against this, for the Dependabot service that Github runs, we wrap Dependabot-Core with a credential proxy so those private registry secrets are never exposed to Dependabot-Core.

sequenceDiagram
Dependabot-Core->>Credentials Proxy: All requests are unauthenticated
Credentials Proxy->>Package Registries: Creds are injected by the Proxy
Note left of Dependabot-Core: The Dependabot Service<br /> that GitHub Runs
Package Registries->>Credentials Proxy: Creds are stripped by the Proxy
Credentials Proxy->>Dependabot-Core: Dependabot-Core never sees private registry credentials
Loading

This also means if Dependabot-Core ever has a security vulnerability, those creds are still not at risk of being exposed.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of GitHub trademarks or logos is subject to and must followGitHub Logos and Usage.Use of GitHub trademarks or logos in modified versions of this project must not cause confusion or imply GitHub sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.

History

Dependabot and dependabot-core started life asBumpand Bump Core,back when @hmarr and @greysteil were working at GoCardless.

Dependabot became a part of GitHub in 2019!

Notes for project maintainers

📖 Release guide

Publish a new release to RubyGems by running theGems - Bump Versionworkflow and following the instructions on the job summary.

In a nutshell the process will be:

  1. Run the action to generate a version bump PR.
  2. Merge the PR.
  3. Tag that merge commit as a new release using the formatv1.2.3.The job summary contains a URL pre-populated with the correct version for the title and tag.
  4. Once the release is tagged, another GitHub Action workflow automatically pushes it to RubyGems.