mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
Require deploy permission for API changes that trigger server side effects, including resource deletion, storage access, provider operations, and database imports. Also escape Docker cleanup filters and sanitize log drain server names.
29 lines
874 B
PHP
29 lines
874 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Concerns;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* The `write` permission changes what runs on a server, and the `deploy` permission makes it run. A
|
|
* change that Coolify runs on a server without a deployment needs both, so it needs a token with the
|
|
* deploy permission (or root).
|
|
*/
|
|
trait RequiresDeployAbility
|
|
{
|
|
/**
|
|
* @param string $reason One sentence that tells why the change needs the deploy permission.
|
|
*/
|
|
private function deployAbilityForbiddenResponse(Request $request, string $reason): ?JsonResponse
|
|
{
|
|
if ($request->user()->tokenCan('deploy') || $request->user()->tokenCan('root')) {
|
|
return null;
|
|
}
|
|
|
|
return response()->json([
|
|
'message' => "Missing required permissions: deploy. {$reason}",
|
|
], 403);
|
|
}
|
|
}
|