Skip to content
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

Composer support: private packages #2354

Closed
swissspidy opened this issue Aug 7, 2018 · 14 comments · Fixed by #2650
Closed

Composer support: private packages #2354

swissspidy opened this issue Aug 7, 2018 · 14 comments · Fixed by #2650
Labels
manager:composer Composer (PHP) package manager priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others type:feature Feature (new functionality)

Comments

@swissspidy
Copy link

What would you like Renovate to be able to do?

Since Composer support is underway (see #1357), it would be great if it would also support private package repositories, e.g. packages that aren't on Packagist or public GitHub repositories. Without that, Renovate Bot won't be able to update all PHP dependencies when Composer can't access these packages.

I first raised this at renovatebot/config-help#73 (comment)

Describe the solution you'd like

Private repositories are usually protected using HTTP authentication, for which the credentials can be stored in ~/.composer/auth.json (see https://getcomposer.org/doc/articles/http-basic-authentication.md).

According to #1357 (comment) Renovate already creates a auth.json file for Composer.

What is now needed is a way to pass credentials for a private composer repository to Renovate that it then can add to auth.json.

@rarkins
Copy link
Collaborator

rarkins commented Aug 7, 2018

Currently, Renovate will set a token in a temporary auth.json for github.com only, if Renovate already has a token for it. Hence composer will be able to access the same list of repositories on github.com that the bot itself has been granted access to.

The next steps are:

  1. Configuring a custom packagist registry URL
  2. Setting a valid token in auth.json for that registry

@swissspidy where/when is the custom registry URL defined in your project? e.g. is it committed as part of composer.json ?

@rarkins rarkins added type:feature Feature (new functionality) needs-requirements priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others manager:composer Composer (PHP) package manager labels Aug 7, 2018
@swissspidy
Copy link
Author

Yes, the custom registry is set in the composer.json file of the project in the repositories array.

Here's a simplified example:

composer.json

{
  "name": "acme/my-awesome-site",
  "description": "My WordPress site",
  "license": "GPL-2.0-or-later",
  "config": {
    "vendor-dir": "wordpress/vendor",
    "sort-packages": true
  },
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    },
    {
      "type": "composer",
      "url": "https://composer.acme.com"
    },
    {
      "type": "git",
      "url": "git@github.com:acme/some-private-repository.git"
    }
  ],
  "require": {
    "php": ">=7.2",
    "acme/some-private-repository": "dev-master",
    "acme/foo-package": "^1.0",
    "acme/bar-package": "^1.0"
  },
  "minimum-stability": "dev",
  "prefer-stable": true
}

Explanation:

auth.json

{
  "http-basic": {
    "composer.acme.com": {
      "username": "johndoe",
      "password": "..."
    }
  },
  "github-oauth": {
    "github.com": "...."
  },
  "bitbucket-oauth": {
    "bitbucket.org": {

    }
  }
}

While some Composer repositories (like Packagist) just point to GitHub repositories, some use projects like Satis or Release Belt where simple ZIP files can be exposed as Composer packages.

@Jamesking56
Copy link
Contributor

Its been a couple of months on this issue, I've now hit this issue with my own private satis repository.

I need to specify HTTP basic auth credentials for mine, does Renovate Docker take in an auth.json file?

@rarkins
Copy link
Collaborator

rarkins commented Oct 13, 2018

Can you specify exactly what the scenario is? Eg self hosted, GitLab, and what type of private composer host?

@Jamesking56
Copy link
Contributor

Jamesking56 commented Oct 13, 2018

I have a Satis repository for private composer packages which uses HTTP Basic Authentication. Composer would normally popup and ask for credentials but obviously instead I get an error because we are non-interactive.

I'm using the Docker repo and GitLab CI for this. So I just need some way I can pass in the authentication credentials OR alternatively provide the auth.json file that the container can copy into Composer's $COMPOSER_HOME.

@rarkins
Copy link
Collaborator

rarkins commented Oct 14, 2018

There will be two parts to this:

  1. Making sure we do the lookup with auth using our own code
  2. Making sure we write appropriate credentials to auth.json for composer

In fact I think there's one step missing at the start:

  1. Ensure we look up from the correct host and not packagist (Support custom register for composer #2574)

For (0), are you looking up all packages from Satis, or just some? How is it specified in composer.json?

For (1), the credentials would need to be configured into hostRules and then the packagist datasource code extended to look up hostRules and use any auth found.

For (2), we already write auth.json with GitHub credentials next to composer.json(not COMPOSER_HOME) and it seems to work fine, so we just need to add logic to add the additional auth. I'm not sure whether to (a) add every single hostRules auth we find, or (b) add a new config option called hostAuth where you can specify which hosts we add auth for, but this would mean configuring each host in two places - hostRules and hostAuth. Maybe a better solution is that we look through all hostRules and use every single one that has http basic authentication.

@Jamesking56
Copy link
Contributor

@rarkins

For 0, I only have 1 package which is from my private repo, the rest are from packagist. I specify the repository in my project's composer.json like so:

"repositories": [
    {
        "type": "composer",
        "url": "https://composer.momentum.studio"
    }
],

My repo above requires HTTP Basic Auth which what I need to give to Renovate. I think composer tries custom repositories first and then tries packagist if the package doesn't exist in the private repo.

Yes you can add auth.json per project by adding it next to composer.json.

@rarkins
Copy link
Collaborator

rarkins commented Oct 14, 2018

In that case:

  • we should read and try that url automatically in our packagist data source (already a WIP)
  • you will need to configure a hostRule for that host with auth set to username:password
  • before updating composer.lock we should scan the list of “repositories” in composer.json and check if any have a hostRule with auth and if so then write it to auth.json, in addition to any auth we find for github.com

@Jamesking56
Copy link
Contributor

@rarkins I don't think I'd like to commit secrets though, is there a way to specify hostRules on the CLI or using Environment Variables?

@rarkins
Copy link
Collaborator

rarkins commented Oct 15, 2018

@Jamesking56 you can supply --host-rules="[]" as a JSON-stringified CLI input. In theory we could support the same for env too but it's not enabled/tested yet. (ref)

For the hosted app, users would encrypt the field with Renovate's public key so that it's unreadable to anyone but the bot.

rarkins added a commit that referenced this issue Oct 16, 2018
Adds support for custom Packagist registries.

- [x] Support dynamic packages.json interface for wpackagist.org
- [x] Support static packages.json for satis
- [x] Support basic auth using hostRules
- [x] Write basic auth to `auth.json`

Closes #2574, Closes #2354
@renovate-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 13.101.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Jamesking56
Copy link
Contributor

Thanks for this @rarkins , what is the documentation on how to configure the credentials for the Docker app? Is it specifying --hostRules?

@rarkins
Copy link
Collaborator

rarkins commented Oct 16, 2018

I forgot to add that to docs and will do. Configure it like:

hostRules: [{
endpoint: “https://your.endpoint”,
username: “foo”,
password: “bar”,
}]

corecanarias pushed a commit to corecanarias/renovate that referenced this issue Oct 24, 2018
Adds support for custom Packagist registries.

- [x] Support dynamic packages.json interface for wpackagist.org
- [x] Support static packages.json for satis
- [x] Support basic auth using hostRules
- [x] Write basic auth to `auth.json`

Closes renovatebot#2574, Closes renovatebot#2354
@viceice
Copy link
Member

viceice commented Oct 26, 2020

@marijoo Please open a new issue in config-help repo for support and don't pollute old closed issues.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
manager:composer Composer (PHP) package manager priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others type:feature Feature (new functionality)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants