Skip to content

Conversation

@rtm-ctrlz
Copy link
Contributor

@rtm-ctrlz rtm-ctrlz commented May 11, 2025

Description

With this change it will be possible to specify client-side TLS-certificate per origin.

It could be used in cases when a repository requires TLS-certificate to make an HTTPS request, ex. private package registry.
Technically without this PR it's possible to use client certificates for registries (by using repositories section of composer.json), but in that case path to certificate/key will we stored within the composer.lock, but when it is stored in VCS and each developer/CI has it's own certificate it stops working, for details see #12019.

Changes made by the way:

  • #6688f21 add AuthHelper::addAuthenticationOptions to allow AuthHelper configure request options not only headers (to make this pr possible) and deprecate AuthHelper::addAuthenticationHeader
  • #e8adca0 minor change to AuthHelper::addAuthenticationOptions, that helps simplify unit-test a bit - just noticed that during test implementation.

Examples (auth.json)

Minimal (certificate and key are in one file, the key is unencrypted):

{
    "client-certificate": {
        "exmaple.org": {
          "local_cert": "/path/to/cert.key.pem"
        }
    }
}
Certificate and key are in separated files file, the key is unencrypted
{
    "client-certificate": {
        "exmaple.org": {
          "local_cert": "/path/to/cert.pem",
          "local_pk": "/path/to/key.pem"
        }
    }
}
Certificate and key are in separated files file, the key is encrypted
{
    "client-certificate": {
        "exmaple.org": {
          "local_cert": "/path/to/cert.pem",
          "local_pk": "/path/to/key.pem",
          "passphrase": "$uper$ecret"
        }
    }
}

Is it breaking change?

In general - no.
There may be some packages that rely on the deprecated AuthHelper::addAuthenticationHeader method, usage of which will trigger E_USER_DEPRECATED.

Is there other issues?

This PR doesn't bring issues by itself.

But there could be issues when auth.json has options multiple configurations for one domain (http-basic + client-cerntifcate), but the same issue will appear when there is configuration http-basic + bearer; in this case there will be a warning in log saying You should avoid overwriting already defined auth settings.

Other suggestions?

  • current authentication array-shape (array{username: string|null, password: string|null}), forces all types of authentications to use this array in very odd way, ex. using password field as "authentication type", this PR use json_encode/json_decode to store configuration within username and using password to keep track authentication type;
  • currently there is no way to combine multiple authentication (for one origin) without conflicts (ex, http-basic + bearer or http-basic + client-certificate), because of the way authentications are stored (array<origin_name, mixed>);
  • it could be more efficient to add support for an option transport-options in auth.json (like is done in lock file), but in this case the file will be not about authentication, but "private transport configurations" (global or per-domain).

@Seldaek Seldaek added this to the 2.9 milestone May 12, 2025
@rtm-ctrlz rtm-ctrlz force-pushed the feat/auth-client-certificate branch 5 times, most recently from 82a61d2 to eaa9d7f Compare May 16, 2025 10:58
@rtm-ctrlz rtm-ctrlz closed this May 19, 2025
@rtm-ctrlz rtm-ctrlz force-pushed the feat/auth-client-certificate branch from eaa9d7f to 282bba0 Compare May 19, 2025 20:47
@rtm-ctrlz rtm-ctrlz reopened this May 19, 2025
@rtm-ctrlz rtm-ctrlz force-pushed the feat/auth-client-certificate branch from 2957295 to c33bc04 Compare May 19, 2025 20:56
@rtm-ctrlz
Copy link
Contributor Author

@Seldaek I updated PR:

  • AuthHelper::addAuthenticationHeader is present and deprecated, under the hood AuthHelper::addAuthenticationOptions is used, so it would be pretty easy to remove it in future;
  • removed unnecessary changes AuthHelper::addAuthenticationOptions for authentication type checks;
  • PR now contains also updates for docs and schema.

@rtm-ctrlz rtm-ctrlz force-pushed the feat/auth-client-certificate branch from c33bc04 to 9de82ab Compare May 20, 2025 07:48
@rtm-ctrlz rtm-ctrlz requested a review from stof May 21, 2025 16:24
@Seldaek
Copy link
Member

Seldaek commented May 28, 2025

  • there is a test to check that addAuthenticationHeader triggers deprecation warning; I'm not sure if we need that kind of test;

Not strictly needed I'd say, but now that it's there might as well keep it 🤷🏻 .

Thanks! Looking good now I'd say :)

@Seldaek Seldaek merged commit 8d239c7 into composer:main May 28, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants