-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to configure mirror public access
- Loading branch information
Showing
19 changed files
with
257 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,8 @@ nelmio_security: | |
- 'self' | ||
script-src: | ||
- 'self' | ||
- 'https://cdn.jsdelivr.net' | ||
- 'https://cdn.jsdelivr.net/npm/[email protected]/' | ||
- 'https://cdn.jsdelivr.net/npm/[email protected]/' | ||
connect-src: | ||
- 'self' | ||
img-src: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ services: | |
ADMIN_PASSWORD: 123456 | ||
ADMIN_EMAIL: [email protected] | ||
TRUSTED_PROXIES: 172.16.0.0/12 | ||
# Default SQLite | ||
# DATABASE_URL: "mysql://app:[email protected]:3306/app?serverVersion=8&charset=utf8mb4" | ||
ports: | ||
- '127.0.0.1:8088:80' | ||
volumes: | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
# Mirroring and Composer proxies | ||
|
||
Packeton may work as a proxy for the composer's repository, including requiring an authorization. | ||
This can be used to give all developers and clients access to private repositories like Magento. | ||
Also, possible to create zip archives from git repositories of mirroring packages, if http dist is not available. | ||
Packeton can function as a proxy for the Composer repository, including requiring an authorization. | ||
This feature can be used to grant all developers and clients access to private repositories such as Magento. | ||
Additionally, it is possible to create ZIP archives from mirrored Git repositories of packages, in cases where HTTP dist | ||
is unavailable. | ||
|
||
Main Features | ||
------------- | ||
|
||
- Support full and lazy sync for all - smail and big composer repositories. | ||
- Support Packagist fast `metadata-changes-url` API. | ||
- Strict mode and Dependencies approvement. | ||
- Dist mirroring | ||
- Supports full and lazy synchronization for small and large Composer repositories. | ||
- Supports the Packagist fast `metadata-changes-url` API. | ||
- Includes Strict Mode and Dependencies Approval functionality. | ||
- Supports Dist/SSH mirroring of source code. | ||
|
||
Example metadata with Strict mode and manual dependencies approvement. | ||
Example metadata with Strict mode and manual dependencies' approval. | ||
|
||
```json | ||
{ | ||
|
@@ -61,15 +62,16 @@ Original metadata is: | |
+ 57 packages | ||
``` | ||
|
||
For performance if composer user-agent is not 1 we remove `includes` and use `providers-lazy-url` | ||
For performance if composer user-agent == 1 then `includes` replaced with `providers-lazy-url` | ||
|
||
|
||
[](../img/packeton_proxies.png) | ||
|
||
## Configuration | ||
|
||
Example how to enable proxies in your local configuration. | ||
Create a file `config/packages/any-name.yaml` with config. | ||
To enable proxies in your local configuration, create a file with any name | ||
like `config/packages/any-name.yaml` and add the following configuration: | ||
|
||
```yaml | ||
packeton: | ||
|
@@ -87,20 +89,33 @@ packeton: | |
http_basic: | ||
username: 123 | ||
password: 123 | ||
public_access: true # Allow public access, default false | ||
sync_lazy: true # default false | ||
enable_dist_mirror: false # default true | ||
available_package_patterns: # Additional restriction, but you can restrict it in UI | ||
- 'vend1/*' | ||
available_packages: | ||
- 'pack1/name1' # but you can restrict it in UI | ||
composer_auth: '{"..."}' # JSON. auth.json to pass composer opts. | ||
composer_auth: '{"auth.json..."}' # JSON. auth.json to pass composer opts. | ||
sync_interval: 3600 # default auto. | ||
info_cmd_message: "\n\u001b[37;44m#Слава\u001b[30;43mУкраїні!\u001b[0m\n\u001b[40;31m#Смерть\u001b[30;41mворогам\u001b[0m" # Info message | ||
``` | ||
|
||
## Metadata proxy specification. | ||
The configuration allows you to use multiple SSH key settings for different GitHub accounts. | ||
|
||
It depends on the type of repository and sync strategy. | ||
``` | ||
... | ||
git_ssh_keys: | ||
[email protected]:oroinc: '/var/www/.ssh/private_key1' | ||
[email protected]:org2: '/var/www/.ssh/private_key2' | ||
|
||
# Or one key | ||
git_ssh_keys: '/var/www/.ssh/private_key1' | ||
``` | ||
|
||
## Metadata Proxy Specification. | ||
|
||
The specification for the metadata proxy depends on the type of repository and the synchronization strategy being used. | ||
|
||
| API | Full sync | Lazy sync | Mirroring (strict) | | ||
|-----|------------------------------------------------|--------------------|------------------------------| | ||
|
@@ -136,17 +151,31 @@ Options: | |
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug | ||
``` | ||
|
||
## Manual approve dependencies | ||
## Manual Approval of Dependencies | ||
|
||
By default, all new packages are automatically enabled and added to your repository then you run composer update. But you can | ||
enable strict mode to use only approved packages and avoid including into metadata untrusted packages. | ||
This can be useful to prevent dependency confusion attacks, for example if you use 3-d party composer repo like this `https://satis.oroinc.com/` | ||
See about [dependency confusion](https://blog.packagist.com/preventing-dependency-hijacking) | ||
By default, all new packages are automatically enabled and added to your repository when you run composer update. | ||
However, you can enable strict mode to use only approved packages and avoid including untrusted packages in your metadata. | ||
This can be useful in preventing dependency confusion attacks, especially if you use a 3rd-party Composer repository | ||
like `https://satis.oroinc.com/`. For more information on preventing dependency hacking, please see [dependency confusion](https://blog.packagist.com/preventing-dependency-hijacking) | ||
|
||
To enable strict mode go to proxy settings page Composer proxies -> Packagist (or any name) -> Settings | ||
To enable strict mode, go to the Proxy Settings page and select Composer Proxies -> Packagist (or any other name) -> Settings. | ||
|
||
[](../img/mirr1.png) | ||
|
||
Next go to view proxy page and click "Mass mirror packages" button | ||
Next, go to the View Proxy page and click the "Mass Mirror Packages" button. | ||
|
||
[](../img/mirr2.png) | ||
|
||
## Mirror Public Access | ||
|
||
Use the following configuration: | ||
|
||
```yaml | ||
packeton: | ||
mirrors: | ||
youname: | ||
url: https://repo.example.org | ||
public_access: true | ||
``` | ||
|
||
[](../img/mirr3.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packeton\Composer\Cache; | ||
|
||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Contracts\Cache\CacheInterface; | ||
|
||
class MetadataCache | ||
{ | ||
public function __construct( | ||
private readonly RequestStack $requestStack, | ||
private readonly CacheInterface $packagesCachePool, | ||
private readonly int $maxTtl = 1800 // TTL default / 2 | ||
) { | ||
} | ||
|
||
public function get(string $key, callable $callback, int $lastModify = null) | ||
{ | ||
// Use host key to prevent Cache Poisoning attack, if dist URL generated dynamic. | ||
// But for will protection must be used trusted_hosts | ||
$httpKey = $this->requestStack->getMainRequest()?->getSchemeAndHttpHost(); | ||
|
||
$cacheKey = sha1($key . $httpKey); | ||
$item = $this->packagesCachePool->getItem($cacheKey); | ||
@[$ctime, $data] = $item->get(); | ||
|
||
$needRefresh = false; | ||
if ($lastModify !== null) { | ||
$needRefresh = $ctime < $lastModify || $ctime + $this->maxTtl < time(); | ||
} | ||
|
||
if (!$item->isHit() || $needRefresh || empty($data)) { | ||
$data = $callback($item); | ||
|
||
$item->set([time(), $data]); | ||
$this->packagesCachePool->save($item); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function delete(string $key): bool | ||
{ | ||
return $this->packagesCachePool->delete($key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.