Files
coolify/app/Livewire/Project/Application/Rollback.php
T
Andras Bacsai c75e7078b7 fix(access): restrict preview changes, rollbacks, and repo URL updates
- Require the write permission and update policy to open a preview or
  change its pull request URL, git type, or docker tag via the API;
  deploy-only tokens can only redeploy an existing preview
- Reject rollbacks to commits that are neither a listed rollback image
  nor a successful production deployment (GetRollbackImages::allows)
- Validate git_repository with ValidGitRepositoryUrl when it changes on
  application update
- Add RejectPublishedAppKey global middleware
- Show a "still starting" message when the root setup window is pending
- Document the new 403 responses and constraints in the OpenAPI spec
- Add tests for the new checks
2026-11-08 17:26:34 +01:00

100 lines
3.1 KiB
PHP

<?php
namespace App\Livewire\Project\Application;
use App\Actions\Application\GetRollbackImages;
use App\Models\Application;
use App\Traits\AuditsApplicationSettings;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Attributes\Validate;
use Livewire\Component;
class Rollback extends Component
{
use AuditsApplicationSettings;
use AuthorizesRequests;
public Application $application;
public $images = [];
public ?string $current = null;
public array $parameters;
#[Validate(['integer', 'min:0', 'max:100'])]
public int $dockerImagesToKeep = 2;
public bool $serverRetentionDisabled = false;
public function mount()
{
$this->parameters = get_route_parameters();
$this->dockerImagesToKeep = $this->application->settings->docker_images_to_keep ?? 2;
$server = $this->application->destination->server;
$this->serverRetentionDisabled = $server->settings->disable_application_image_retention ?? false;
}
public function saveSettings()
{
try {
$this->authorize('update', $this->application);
$this->validate();
$this->application->settings->docker_images_to_keep = $this->dockerImagesToKeep;
$this->saveApplicationSettingsWithAudit($this->application);
$this->dispatch('success', 'Settings saved.');
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function rollbackImage($commit)
{
$this->authorize('deploy', $this->application);
$commit = validateGitRef($commit, 'rollback commit');
if (! GetRollbackImages::allows($this->application, $commit)) {
$this->dispatch('error', 'Rollback did not start.', 'The commit is not a rollback image or a successful deployment of this application.');
return;
}
$deployment_uuid = new_public_id();
$result = queue_application_deployment(
application: $this->application,
deployment_uuid: $deployment_uuid,
commit: $commit,
rollback: true,
force_rebuild: false,
);
if ($result['status'] === 'queue_full') {
$this->dispatch('error', 'Deployment queue full', $result['message']);
return;
}
return redirectRoute($this, 'project.application.deployment.show', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $deployment_uuid,
'environment_uuid' => $this->parameters['environment_uuid'],
]);
}
public function loadImages($showToast = false)
{
$this->authorize('view', $this->application);
try {
['current' => $this->current, 'images' => $this->images] = GetRollbackImages::run($this->application);
$showToast && $this->dispatch('success', 'Images loaded.');
return [];
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
}