Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Merge remote-tracking branch 'origin/release/v4.5' into release/v4.5

Andras Bacsaidd456625ec50
diff --cc app/Actions/Server/StartLogDrain.php
index 11bf160f57,e72ddef02d..4fce8b7168
--- a/app/Actions/Server/StartLogDrain.php
+++ b/app/Actions/Server/StartLogDrain.php
@@@ -220,17 -218,9 +228,17 @@@ Files
}
}
+ /**
+ * Fluent Bit reads its config line by line, so a value with a line break could add sections.
+ */
+ private function fluentBitValue(string $value): string
+ {
+ return trim(preg_replace('/\s*[\x00-\x1F\x7F]+\s*/', ' ', $value));
+ }
+
private function logDrainNetworkConnectCommands(Server $server): array
{
- if (! $server->isLogDrainEnabled()) {
+ if (! $server->isFluentBitLogDrainEnabled()) {
return [];
}
diff --cc app/Http/Controllers/Api/ServerLogDrainsController.php
index 8084070b82,f07d95cc86..af5aaa1dfd
--- a/app/Http/Controllers/Api/ServerLogDrainsController.php
+++ b/app/Http/Controllers/Api/ServerLogDrainsController.php
@@@ -170,8 -184,12 +186,12 @@@ class ServerLogDrainsController extend
'logdrain_axiom_dataset_name' => ['nullable', 'string', 'regex:/^[a-zA-Z0-9_\-\.]+$/'],
'logdrain_axiom_api_key' => ['nullable', 'string', 'regex:/^[a-zA-Z0-9_\-\.]+$/'],
'is_logdrain_custom_enabled' => 'boolean',
- 'logdrain_custom_config' => 'nullable|string',
- 'logdrain_custom_config_parser' => 'nullable|string',
+ 'logdrain_custom_config' => ['nullable', 'string', new ValidFluentBitConfig],
+ 'logdrain_custom_config_parser' => ['nullable', 'string', new ValidFluentBitConfig(parsersOnly: true)],
+ 'is_logdrain_cloudwatch_enabled' => 'boolean',
+ 'logdrain_cloudwatch_region' => ['nullable', 'string', 'max:64', 'regex:/^[a-z]{2}(-[a-z]+)+-\d+$/'],
+ 'logdrain_cloudwatch_group' => ['nullable', 'string', 'regex:/^[\.\-_\/#A-Za-z0-9]{1,512}$/'],
+ 'logdrain_cloudwatch_stream_prefix' => ['nullable', 'string', 'max:256', 'regex:/^[A-Za-z0-9_\-\.\/#]*$/'],
]);
$extraFields = array_diff(array_keys($request->all()), self::ALLOWED_FIELDS);
diff --cc app/Livewire/Server/LogDrains.php
index ef9addf231,577941ec00..c48816aa40
--- a/app/Livewire/Server/LogDrains.php
+++ b/app/Livewire/Server/LogDrains.php
@@@ -5,8 -5,8 +5,9 @@@ namespace App\Livewire\Server
use App\Actions\Server\StartLogDrain;
use App\Actions\Server\StopLogDrain;
use App\Models\Server;
+use App\Rules\ValidFluentBitConfig;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+ use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Validate;
use Livewire\Component;
@@@ -280,9 -352,14 +353,14 @@@ class LogDrains extends Componen
'logDrainAxiomApiKey' => ['required', 'regex:/^[a-zA-Z0-9_\-\.]+$/'],
]),
'custom' => $this->validate([
- 'logDrainCustomConfig' => ['required'],
- 'logDrainCustomConfigParser' => ['string', 'nullable'],
+ 'logDrainCustomConfig' => ['required', new ValidFluentBitConfig],
+ 'logDrainCustomConfigParser' => ['string', 'nullable', new ValidFluentBitConfig(parsersOnly: true)],
]),
+ 'cloudwatch' => $this->validate([
+ 'logDrainCloudwatchRegion' => ['required', 'max:64', 'regex:/^[a-z]{2}(-[a-z]+)+-\d+$/'],
+ 'logDrainCloudwatchGroup' => ['required', 'regex:/^[\.\-_\/#A-Za-z0-9]{1,512}$/'],
+ 'logDrainCloudwatchStreamPrefix' => ['string', 'nullable', 'max:256', 'regex:/^[A-Za-z0-9_\-\.\/#]*$/'],
+ ]),
default => throw new \InvalidArgumentException('Unknown log drain type.'),
};
}
diff --cc app/Models/ServerSetting.php
index 6085320080,c1dfc5bf2b..25b430b851
--- a/app/Models/ServerSetting.php
+++ b/app/Models/ServerSetting.php
@@@ -197,9 -198,7 +205,10 @@@ class ServerSetting extends Mode
'compose_version_checked_at' => 'datetime',
'backup_compression_cpu_percentage' => 'integer',
'server_disk_usage_notification_interval_hours' => 'integer',
+ 'patch_check_result' => 'array',
+ 'patch_checked_at' => 'datetime',
+ 'is_auto_security_updates_enabled' => 'boolean',
+ 'is_logdrain_cloudwatch_enabled' => 'boolean',
];
/**
diff --cc tests/Feature/Api/ServerSubsystemsApiTest.php
index 631ae83241,c5bd5e3841..a131bf22ab
--- a/tests/Feature/Api/ServerSubsystemsApiTest.php
+++ b/tests/Feature/Api/ServerSubsystemsApiTest.php
@@@ -188,58 -188,89 +188,141 @@@ describe('Log drains API', function ()
->and($settings->logdrain_axiom_api_key)->toBe('axiom-key-123');
});
+ test('PATCH requires the deploy permission to change the custom log drain config', function (string $field) {
+ Queue::fake();
+ $writeOnlyToken = $this->user->createToken('server-subsystems-write', ['write'])->plainTextToken;
+
+ $this->withHeaders([
+ 'Authorization' => 'Bearer '.$writeOnlyToken,
+ 'Accept' => 'application/json',
+ ])
+ ->patchJson("/api/v1/servers/{$this->server->uuid}/log-drains", [
+ $field => "[OUTPUT]\n Name stdout",
+ ])
+ ->assertForbidden()
+ ->assertJsonPath('message', 'Missing required permissions: deploy');
+
+ $settings = $this->server->settings->fresh();
+ expect($settings->{$field})->toBeNull();
+ })->with(['logdrain_custom_config', 'logdrain_custom_config_parser']);
+
+ test('PATCH lets a write and deploy token enable the custom log drain with its saved config', function () {
+ Queue::fake();
+ $this->server->settings->update(['logdrain_custom_config' => "[OUTPUT]\n Name stdout"]);
+ $deployToken = $this->user->createToken('server-subsystems-deploy', ['write', 'deploy'])->plainTextToken;
+
+ $this->withHeaders([
+ 'Authorization' => 'Bearer '.$deployToken,
+ 'Accept' => 'application/json',
+ ])
+ ->patchJson("/api/v1/servers/{$this->server->uuid}/log-drains", [
+ 'is_logdrain_custom_enabled' => true,
+ 'logdrain_custom_config' => "[OUTPUT]\n Name stdout",
+ ])
+ ->assertOk();
+
+ expect($this->server->settings->fresh()->is_logdrain_custom_enabled)->toBeTruthy();
+ });
+
+ test('PATCH changes the custom log drain config with the deploy permission', function () {
+ Queue::fake();
+ $deployToken = $this->user->createToken('server-subsystems-deploy', ['write', 'deploy'])->plainTextToken;
+
+ $this->withHeaders([
+ 'Authorization' => 'Bearer '.$deployToken,
+ 'Accept' => 'application/json',
+ ])
+ ->patchJson("/api/v1/servers/{$this->server->uuid}/log-drains", [
+ 'logdrain_custom_config' => "[OUTPUT]\n Name stdout",
+ ])
+ ->assertOk();
+
+ expect($this->server->settings->fresh()->logdrain_custom_config)->toBe("[OUTPUT]\n Name stdout");
+ });
+
+ test('PATCH enables the Amazon CloudWatch Logs drain', function () {
+ Queue::fake();
+
+ $this->withHeaders(serverSubsystemsHeaders())
+ ->patchJson("/api/v1/servers/{$this->server->uuid}/log-drains", [
+ 'is_logdrain_cloudwatch_enabled' => true,
+ 'logdrain_cloudwatch_group' => '/coolify/prod',
+ 'logdrain_cloudwatch_region' => 'us-east-1',
+ 'logdrain_cloudwatch_stream_prefix' => 'docker/',
+ ])
+ ->assertOk()
+ ->assertJsonPath('is_logdrain_cloudwatch_enabled', true)
+ ->assertJsonPath('logdrain_cloudwatch_group', '/coolify/prod')
+ ->assertJsonPath('logdrain_cloudwatch_stream_prefix', 'docker/');
+
+ $settings = $this->server->settings->fresh();
+ expect($settings->is_logdrain_cloudwatch_enabled)->toBeTrue()
+ ->and($settings->logdrain_cloudwatch_region)->toBe('us-east-1');
+ });
+
+ test('PATCH rejects enabling CloudWatch without a log group', function () {
+ Queue::fake();
+
+ $this->withHeaders(serverSubsystemsHeaders())
+ ->patchJson("/api/v1/servers/{$this->server->uuid}/log-drains", [
+ 'is_logdrain_cloudwatch_enabled' => true,
+ 'logdrain_cloudwatch_region' => 'us-east-1',
+ ])
+ ->assertUnprocessable()
+ ->assertJsonValidationErrors('logdrain_cloudwatch_group');
+
+ expect($this->server->settings->fresh()->is_logdrain_cloudwatch_enabled)->toBeFalse();
+ });
+
+ test('PATCH rejects enabling CloudWatch without a region', function () {
+ Queue::fake();
+
+ $this->withHeaders(serverSubsystemsHeaders())
+ ->patchJson("/api/v1/servers/{$this->server->uuid}/log-drains", [
+ 'is_logdrain_cloudwatch_enabled' => true,
+ 'logdrain_cloudwatch_group' => 'coolify',
+ ])
+ ->assertUnprocessable()
+ ->assertJsonValidationErrors('logdrain_cloudwatch_region');
+
+ expect($this->server->settings->fresh()->is_logdrain_cloudwatch_enabled)->toBeFalse();
+ });
+
+ test('PATCH rejects CloudWatch values that could break the compose file', function (string $field, mixed $value) {
+ Queue::fake();
+
+ $this->withHeaders(serverSubsystemsHeaders())
+ ->patchJson("/api/v1/servers/{$this->server->uuid}/log-drains", [
+ $field => $value,
+ ])
+ ->assertUnprocessable()
+ ->assertJsonValidationErrors($field);
+ })->with([
+ 'prefix with interpolation' => ['logdrain_cloudwatch_stream_prefix', 'docker/${HOME}'],
+ 'prefix with colon' => ['logdrain_cloudwatch_stream_prefix', 'docker:'],
+ 'prefix with template braces' => ['logdrain_cloudwatch_stream_prefix', '{{.ID}}'],
+ 'invalid region' => ['logdrain_cloudwatch_region', 'not a region'],
+ 'group with spaces' => ['logdrain_cloudwatch_group', 'my group'],
+ ]);
+
+ test('PATCH rejects enabling CloudWatch together with another log drain', function () {
+ Queue::fake();
+ $this->server->settings->update([
+ 'is_logdrain_axiom_enabled' => true,
+ 'logdrain_axiom_dataset_name' => 'ds',
+ 'logdrain_axiom_api_key' => 'key',
+ ]);
+
+ $this->withHeaders(serverSubsystemsHeaders())
+ ->patchJson("/api/v1/servers/{$this->server->uuid}/log-drains", [
+ 'is_logdrain_cloudwatch_enabled' => true,
+ 'logdrain_cloudwatch_group' => 'coolify',
+ 'logdrain_cloudwatch_region' => 'us-east-1',
+ ])
+ ->assertUnprocessable()
+ ->assertJsonValidationErrors('is_logdrain_cloudwatch_enabled');
+ });
+
test('other-team log drains endpoints return 404', function () {
$this->withHeaders(serverSubsystemsHeaders())
->getJson("/api/v1/servers/{$this->otherServer->uuid}/log-drains")
diff --cc tests/Feature/Helpers/DockerCustomCommandsTest.php
index cf2408faf3,6d5a1c5a1c..341e9de31f
--- a/tests/Feature/Helpers/DockerCustomCommandsTest.php
+++ b/tests/Feature/Helpers/DockerCustomCommandsTest.php
@@@ -234,21 -234,58 +234,77 @@@ test('ConvertIpAndIp6Together', functio
]);
});
+test('ConvertGpusCount', function () {
+ $output = convertDockerRunToCompose('--gpus 2');
+ expect($output)->toBe([
+ 'deploy' => [
+ 'resources' => [
+ 'reservations' => [
+ 'devices' => [
+ [
+ 'driver' => 'nvidia',
+ 'capabilities' => ['gpu'],
+ 'count' => 2,
+ ],
+ ],
+ ],
+ ],
+ ],
+ ]);
+});
++
+ test('ConvertInteractiveShortFlag', function () {
+ // -i keeps STDIN open so `docker attach` can send input (e.g. game server consoles).
+ expect(convertDockerRunToCompose('-i'))->toBe([
+ 'stdin_open' => true,
+ ]);
+ });
+
+ test('ConvertTtyShortFlag', function () {
+ expect(convertDockerRunToCompose('-t'))->toBe([
+ 'tty' => true,
+ ]);
+ });
+
+ test('ConvertInteractiveTtyCombinedShortFlag', function () {
+ expect(convertDockerRunToCompose('-it'))->toBe([
+ 'stdin_open' => true,
+ 'tty' => true,
+ ]);
+ });
+
+ test('ConvertTtyInteractiveCombinedShortFlag', function () {
+ expect(convertDockerRunToCompose('-ti'))->toBe([
+ 'stdin_open' => true,
+ 'tty' => true,
+ ]);
+ });
+
+ test('ConvertInteractiveTtyLongFlags', function () {
+ expect(convertDockerRunToCompose('--interactive --tty'))->toBe([
+ 'stdin_open' => true,
+ 'tty' => true,
+ ]);
+ });
+
+ test('ConvertInteractiveTtyWithOtherOptions', function () {
+ expect(convertDockerRunToCompose('-it --cap-add SYS_ADMIN'))->toBe([
+ 'cap_add' => ['SYS_ADMIN'],
+ 'stdin_open' => true,
+ 'tty' => true,
+ ]);
+ });
+
+ test('DoesNotSetInteractiveTtyForUnrelatedShortFlags', function () {
+ // -d (detach) and other short flags without i/t must not enable stdin/tty.
+ expect(convertDockerRunToCompose('-d'))->toBe([]);
+ });
+
+ it('does not read interactive flags inside entrypoint arguments', function () {
+ expect(convertDockerRunToCompose('--entrypoint "python -i -t script.py"'))
+ ->toBe(['entrypoint' => 'python -i -t script.py']);
+ });
+
+ it('does not treat arbitrary short words as interactive flags', function () {
+ expect(convertDockerRunToCompose('-invalid'))->toBe([]);
+ });