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.

chore: merge main into release/v4.5

Andras Bacsai65a7bd5c0573
diff --cc app/Jobs/ApplicationDeploymentJob.php
index 41c5cbb18d,80b92f7723..eefc9880bb
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@@ -4300,10 -4293,10 +4302,14 @@@ COPY ./nginx.conf /etc/nginx/conf.d/def
if ($this->pull_request_id === 0) {
$custom_compose = convertDockerRunToCompose($this->application->custom_docker_run_options);
+ if ($this->application->settings->is_gpu_enabled && data_get($custom_compose, 'deploy.resources.reservations.devices')) {
+ data_forget($custom_compose, 'deploy.resources.reservations.devices');
+ $this->application_deployment_queue->addLogEntry('GPU access is enabled in the GPU settings, so --gpus in Custom Docker Options is ignored.');
+ }
+ $unsupported_options = unsupportedDockerRunOptions($this->application->custom_docker_run_options);
+ if (count($unsupported_options) > 0) {
+ $this->application_deployment_queue->addLogEntry('Warning: These custom Docker options are not supported and were not applied: '.implode(', ', $unsupported_options).'. See https://coolify.io/docs/applications/builds/custom-docker-options for the supported options.', 'stderr');
+ }
if ((bool) $this->application->settings->is_consistent_container_name_enabled) {
$docker_compose['services'][$this->application->uuid] = $docker_compose['services'][$this->container_name];
if ($this->container_name !== $this->application->uuid) {
diff --cc app/Jobs/SendMessageToTelegramJob.php
index c6bf073b56,babebad956..87d9625eed
--- a/app/Jobs/SendMessageToTelegramJob.php
+++ b/app/Jobs/SendMessageToTelegramJob.php
@@@ -78,11 -92,7 +92,7 @@@ class SendMessageToTelegramJob implemen
if ($this->threadId) {
$payload['message_thread_id'] = $this->threadId;
}
- $response = $this->sendNotificationRequest('Telegram', $url, fn () => Http::post($url, $payload));
- // 401: invalid bot token, 403: the bot was blocked or removed from the chat, 400 "chat not found": wrong chat ID.
- $isConfigurationError = in_array($response->status(), [401, 403], true)
- || ($response->status() === 400 && Str::contains((string) $response->json('description'), 'chat not found', true));
- $this->handleNotificationResponse($response, 'Telegram', $isConfigurationError);
- return Http::post($url, $payload);
++ return $this->sendNotificationRequest('Telegram', $url, fn () => Http::post($url, $payload));
}
}
diff --cc app/Models/Team.php
index 869bff88c5,864c47be2f..05c9287491
--- a/app/Models/Team.php
+++ b/app/Models/Team.php
@@@ -92,44 -85,63 +86,69 @@@ class Team extends Model implements Sen
});
static::deleting(function (Team $team) {
- RevokeUserTeamTokens::forTeam($team->id);
+ $team->deleteOwnedRecords();
+ });
+
- foreach ($team->privateKeys as $key) {
- $key->delete();
- }
++ static::deleted(function (Team $team) {
++ app(TeamAvatarStorageService::class)->deleteTeamFile($team);
++ });
+ }
- // Transfer instance-wide sources to root team so they remain available
- $systemWideSources = GithubApp::where('team_id', $team->id)->where('is_system_wide', true)->get()
- ->concat(GitlabApp::where('team_id', $team->id)->where('is_system_wide', true)->get())
- ->concat(GiteaApp::where('team_id', $team->id)->where('is_system_wide', true)->get());
- foreach ($systemWideSources as $source) {
- $source->update(['team_id' => 0]);
- }
+ /**
+ * Creates the notification settings rows every team needs, with their default values.
+ */
+ public function createDefaultNotificationSettings(): void
+ {
+ $this->emailNotificationSettings()->create([
+ 'use_instance_email_settings' => isDev(),
+ ]);
+ $this->discordNotificationSettings()->create();
+ $this->slackNotificationSettings()->create();
+ $this->telegramNotificationSettings()->create();
+ $this->pushoverNotificationSettings()->create();
+ $this->webhookNotificationSettings()->create();
+ }
- // Delete non-instance-wide sources owned by this team
- $teamSources = GithubApp::where('team_id', $team->id)->get()
- ->concat(GitlabApp::where('team_id', $team->id)->get())
- ->concat(GiteaApp::where('team_id', $team->id)->get());
- foreach ($teamSources as $source) {
- $source->delete();
- }
+ /**
+ * Deletes the API tokens, private keys, sources, tags, shared variables, and S3 storages of the
+ * team. Instance-wide sources move to the root team instead.
+ */
+ public function deleteOwnedRecords(): void
+ {
+ RevokeUserTeamTokens::forTeam($this->id);
- foreach (Tag::whereTeamId($team->id)->get() as $tag) {
- $tag->delete();
- }
+ foreach ($this->privateKeys()->get() as $key) {
+ $key->delete();
+ }
- foreach ($team->environment_variables()->get() as $sharedVariable) {
- $sharedVariable->delete();
- }
+ // Transfer instance-wide sources to root team so they remain available
+ $systemWideSources = GithubApp::where('team_id', $this->id)->where('is_system_wide', true)->get()
- ->concat(GitlabApp::where('team_id', $this->id)->where('is_system_wide', true)->get());
++ ->concat(GitlabApp::where('team_id', $this->id)->where('is_system_wide', true)->get())
++ ->concat(GiteaApp::where('team_id', $this->id)->where('is_system_wide', true)->get());
+ foreach ($systemWideSources as $source) {
+ $source->update(['team_id' => 0]);
+ }
- foreach ($team->s3s as $s3) {
- $s3->delete();
- }
- });
+ // Delete non-instance-wide sources owned by this team
+ $teamSources = GithubApp::where('team_id', $this->id)->get()
- ->concat(GitlabApp::where('team_id', $this->id)->get());
++ ->concat(GitlabApp::where('team_id', $this->id)->get())
++ ->concat(GiteaApp::where('team_id', $this->id)->get());
+ foreach ($teamSources as $source) {
+ $source->delete();
+ }
- static::deleted(function (Team $team) {
- app(TeamAvatarStorageService::class)->deleteTeamFile($team);
- });
+ foreach (Tag::whereTeamId($this->id)->get() as $tag) {
+ $tag->delete();
+ }
+
+ foreach ($this->environment_variables()->get() as $sharedVariable) {
+ $sharedVariable->delete();
+ }
+
+ // Also unusable storages, which the s3s relation hides.
+ foreach (S3Storage::query()->where('team_id', $this->id)->get() as $s3) {
+ $s3->delete();
+ }
}
public static function serverLimitReached(?Team $team = null)
diff --cc app/Services/Security/SensitiveDataRedactor.php
index 4ea688d1c6,0000000000..df9495868c
mode 100644,000000..100644
--- a/app/Services/Security/SensitiveDataRedactor.php
+++ b/app/Services/Security/SensitiveDataRedactor.php
@@@ -1,325 -1,0 +1,326 @@@
+<?php
+
+namespace App\Services\Security;
+
+use DateTimeInterface;
+use Illuminate\Contracts\Support\Arrayable;
+use JsonSerializable;
+use RuntimeException;
+use Stringable;
+use Throwable;
+use UnitEnum;
+
+final class SensitiveDataRedactor
+{
+ public const FAILURE_MESSAGE = '[LOG SUPPRESSED: REDACTION FAILED]';
+
+ private const CHUNK_BYTES = 262144;
+
+ private const MIN_KNOWN_SECRET_LENGTH = 8;
+
+ private const EMAIL_PATTERN = '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}/';
+
+ private bool $redactEmails = true;
+
+ private const SENSITIVE_KEYS = ['password', 'passwd', 'secret', 'client_secret', 'api_key', 'apikey', 'access_key', 'private_key', 'token', 'access_token', 'refresh_token', 'auth_token', 'authorization', 'proxy_authorization', 'cookie', 'set_cookie', 'webhook_secret', 'signing_secret', 'credential', 'credentials', 'connection_string', 'database_url'];
+
+ /**
+ * Return a copy that keeps email addresses, for sinks such as the audit log that must record who acted.
+ */
+ public function withoutEmailRedaction(): self
+ {
+ $redactor = clone $this;
+ $redactor->redactEmails = false;
+
+ return $redactor;
+ }
+
+ /**
+ * Tell if redactText() would hide one of these known secrets in the text.
+ *
+ * @param array<array-key, mixed> $knownSecrets
+ */
+ public function containsKnownSecret(string $text, array $knownSecrets): bool
+ {
+ foreach ($knownSecrets as $secret) {
+ if (is_scalar($secret) && trim((string) $secret) !== '' && strlen((string) $secret) >= self::MIN_KNOWN_SECRET_LENGTH && str_contains($text, (string) $secret)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @param array<array-key, mixed> $knownSecrets Exact values to replace when they are long enough to be safe to match, such as unlocked environment values.
+ * @param array<array-key, mixed> $lockedSecrets Exact values to always replace, whatever their length, such as locked or remote secrets.
+ */
+ public function redactText(string $text, array $knownSecrets = [], array $lockedSecrets = []): string
+ {
+ try {
+ $text = $this->normalizeText($text);
+ $text = $this->replaceKnownSecrets($text, $knownSecrets, $lockedSecrets);
+
+ $redacted = '';
+ foreach ($this->chunks($text) as $chunk) {
+ $redacted .= $this->redactChunk($chunk);
+ }
+
+ return $redacted;
+ } catch (Throwable) {
+ return self::FAILURE_MESSAGE;
+ }
+ }
+
+ /**
+ * @param array<array-key, mixed> $knownSecrets
+ */
+ public function redactValue(mixed $value, array $knownSecrets = [], ?string $key = null): mixed
+ {
+ try {
+ if ($key !== null && $this->isSensitiveKey($key)) {
+ return REDACTED;
+ }
+ if (is_array($value)) {
+ $redacted = [];
+ foreach ($value as $itemKey => $itemValue) {
+ $redacted[$itemKey] = $this->redactValue($itemValue, $knownSecrets, is_string($itemKey) ? $itemKey : null);
+ }
+
+ return $redacted;
+ }
+ if (is_string($value)) {
+ return $this->redactText($value, $knownSecrets);
+ }
+ if (! is_object($value) || $value instanceof UnitEnum || $value instanceof DateTimeInterface) {
+ return $value;
+ }
+ if ($value instanceof Arrayable) {
+ return $this->redactValue($value->toArray(), $knownSecrets);
+ }
+ if ($value instanceof JsonSerializable) {
+ return $this->redactValue($value->jsonSerialize(), $knownSecrets);
+ }
+ if ($value instanceof Stringable) {
+ return $this->redactText((string) $value, $knownSecrets);
+ }
+
+ return '[object '.$value::class.']';
+ } catch (Throwable) {
+ return self::FAILURE_MESSAGE;
+ }
+ }
+
+ /**
+ * Redact one chunk. When a pattern hits a PCRE limit, redact the chunk line by line so one huge line
+ * or an unterminated private key does not suppress the whole log. A line that still fails is suppressed.
+ */
+ private function redactChunk(string $chunk): string
+ {
+ try {
+ return $this->redactAssignments($this->redactPatterns($chunk));
+ } catch (RuntimeException) {
+ $redacted = '';
+ $insidePrivateKey = false;
+ foreach (preg_split('/(?<=\n)/', $chunk) ?: [$chunk] as $line) {
+ if (! $insidePrivateKey && preg_match('/-----BEGIN [A-Z ]*PRIVATE KEY-----/', $line) === 1 && preg_match('/-----END [A-Z ]*PRIVATE KEY-----/', $line) !== 1) {
+ $insidePrivateKey = true;
+ $redacted .= REDACTED.(str_ends_with($line, "\n") ? "\n" : '');
+
+ continue;
+ }
+ if ($insidePrivateKey) {
+ $insidePrivateKey = preg_match('/-----END [A-Z ]*PRIVATE KEY-----/', $line) !== 1;
+
+ continue;
+ }
+ try {
+ $redacted .= $this->redactAssignments($this->redactPatterns($line));
+ } catch (RuntimeException) {
+ $redacted .= self::FAILURE_MESSAGE.(str_ends_with($line, "\n") ? "\n" : '');
+ }
+ }
+
+ return $redacted;
+ }
+ }
+
+ private function normalizeText(string $text): string
+ {
+ $text = sanitize_utf8_text($text);
+ $text = preg_replace('/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -\/]*[@-~])/', '', $text);
+ if ($text === null) {
+ throw new RuntimeException('Log normalization failed.');
+ }
+ $text = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/', '', $text);
+ if ($text === null) {
+ throw new RuntimeException('Log normalization failed.');
+ }
+
+ return $text;
+ }
+
+ /**
+ * Split large text on line boundaries so the regular expressions stay inside PCRE limits.
+ * A chunk never ends inside a private key block.
+ *
+ * @return iterable<int, string>
+ */
+ private function chunks(string $text): iterable
+ {
+ $length = strlen($text);
+ $offset = 0;
+ while ($offset < $length) {
+ $end = $this->lineEnd($text, $offset + self::CHUNK_BYTES);
+ $chunk = substr($text, $offset, $end - $offset);
+ if (preg_match('/-----BEGIN [A-Z ]*PRIVATE KEY-----(?![\s\S]*-----END [A-Z ]*PRIVATE KEY-----)/', $chunk) === 1) {
+ $end = preg_match('/-----END [A-Z ]*PRIVATE KEY-----/', $text, $match, PREG_OFFSET_CAPTURE, $end) === 1
+ ? $this->lineEnd($text, $match[0][1] + strlen($match[0][0]))
+ : $length;
+ $chunk = substr($text, $offset, $end - $offset);
+ }
+
+ yield $chunk;
+ $offset = $end;
+ }
+ }
+
+ /**
+ * Find the end of the line that contains $position, without copying the text.
+ */
+ private function lineEnd(string $text, int $position): int
+ {
+ if ($position >= strlen($text)) {
+ return strlen($text);
+ }
+
+ $newline = strpos($text, "\n", $position);
+
+ return $newline === false ? strlen($text) : $newline + 1;
+ }
+
+ /**
+ * @param array<array-key, mixed> $knownSecrets
+ * @param array<array-key, mixed> $lockedSecrets
+ */
+ private function replaceKnownSecrets(string $text, array $knownSecrets, array $lockedSecrets): string
+ {
+ $variants = [];
+ $shortVariants = [];
+ foreach ([[$knownSecrets, self::MIN_KNOWN_SECRET_LENGTH], [$lockedSecrets, 1]] as [$secrets, $minimumLength]) {
+ foreach ($secrets as $secret) {
+ if (! is_scalar($secret) || trim((string) $secret) === '' || strlen((string) $secret) < $minimumLength) {
+ continue;
+ }
+ $secret = (string) $secret;
+ $json = json_encode($secret, JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_SUBSTITUTE);
+ // Short locked values such as "ab" would hit inside ordinary words, so they only match as whole tokens.
+ if (strlen($secret) < self::MIN_KNOWN_SECRET_LENGTH) {
+ array_push($shortVariants, $secret, rawurlencode($secret), substr($json, 1, -1));
+ } else {
+ array_push($variants, $secret, rawurlencode($secret), substr($json, 1, -1));
+ }
+ }
+ }
+ $byLengthDescending = fn (string $left, string $right): int => strlen($right) <=> strlen($left);
+ $variants = array_values(array_unique(array_filter($variants)));
+ usort($variants, $byLengthDescending);
+ $text = str_replace($variants, REDACTED, $text);
+
+ // The text is valid UTF-8 after normalization, so a variant that is not valid UTF-8 cannot appear in it.
+ $shortVariants = array_values(array_unique(array_filter($shortVariants, fn (string $variant): bool => $variant !== '' && mb_check_encoding($variant, 'UTF-8'))));
+ if ($shortVariants === []) {
+ return $text;
+ }
+ usort($shortVariants, $byLengthDescending);
+ $alternatives = implode('|', array_map(fn (string $variant): string => preg_quote($variant, '/'), $shortVariants));
+ $text = preg_replace('/(?<![\p{L}\p{M}\p{N}_])(?:'.$alternatives.')(?![\p{L}\p{M}\p{N}_])/u', REDACTED, $text);
+ if ($text === null) {
+ throw new RuntimeException('Log redaction failed.');
+ }
+
+ return $text;
+ }
+
+ private function redactAssignments(string $text): string
+ {
+ $assignmentKeys = array_diff(self::SENSITIVE_KEYS, ['authorization', 'proxy_authorization']);
+ $keys = implode('|', array_map(fn (string $key): string => preg_quote($key, '/'), $assignmentKeys));
+ // A key matches when it is a sensitive name or ends with one, such as smtp_password or github-token.
+ $keys = '(?i:(?:[a-z0-9]+[_-])*(?:'.$keys.'))|[A-Z][A-Z0-9_]*(?:SECRET|PASSWORD|TOKEN|PASSWD|API_KEY|PRIVATE_KEY)[A-Z0-9_]*';
+ $value = '(?<value>"(?:[^"\\\\\r\n]|\\\\.)*"|\'(?:[^\'\\\\\r\n]|\\\\.)*\'|[^\s,;}\]]+)';
+ // Skip values that an earlier rule already replaced, such as the token in https://x-access-token:<REDACTED>@host.
+ $alreadyRedacted = '(?!'.preg_quote(REDACTED, '/').')';
+ // Set when nothing but a delimiter follows the value on its line, as in YAML or object literals.
+ $endsValue = '(?<end>(?=[^\S\r\n]*(?:$|[\r\n,;}\]])))?';
+ // A quote that opens before the key and closes after the value wraps the whole assignment, as in
+ // the shell argument 'DB_PASSWORD=a b'. Hide everything up to the closing quote and keep the quote.
+ $text = preg_replace('/(?<![\w-])(["\'])((?:'.$keys.')\s*=\s*)'.$alreadyRedacted.'(?:(?!\1)[^\r\n])*\1/', '$1$2'.REDACTED.'$1', $text);
+ if ($text === null) {
+ throw new RuntimeException('Log redaction failed.');
+ }
+ $result = preg_replace_callback('/(?<![\w-])(?<prefix>["\']?(?<key>'.$keys.')["\']?\s*(?<separator>[=:])\s*)'.$alreadyRedacted.$value.$endsValue.'/m', function (array $match): string {
+ $value = $match['value'];
+ $quote = strlen($value) > 1 && in_array($value[0], ['"', "'"], true) && str_ends_with($value, $value[0]) ? $value[0] : '';
+ // Prose such as "Failed to refresh token: Connection refused" uses a plain word key, a colon, and a plain word value.
+ $isProse = $quote === ''
+ && $match['separator'] === ':'
+ && ! in_array($match['prefix'][0], ['"', "'"], true)
+ && preg_match('/^[A-Za-z][a-z]*$/', $match['key']) === 1
+ && ctype_alpha($value)
+ && $match['end'] === null;
+
+ return $isProse ? $match[0] : $match['prefix'].$quote.REDACTED.$quote;
+ }, $text, flags: PREG_UNMATCHED_AS_NULL);
+ if ($result === null) {
+ throw new RuntimeException('Log redaction failed.');
+ }
+
+ return $result;
+ }
+
+ private function redactPatterns(string $text): string
+ {
+ $patterns = [
+ '/((?:Authorization|Proxy-Authorization)\s*:\s*)[^\r\n]+/i' => '$1'.REDACTED,
+ '/x-access-token:.*?(?=@)/' => 'x-access-token:'.REDACTED,
+ '/oauth2:.*?(?=@)/' => 'oauth2:'.REDACTED,
- '/((?:https?|postgres|mysql|mongodb|rediss?|mariadb|ftp|sftp|ssh|amqp|amqps|ldap|ldaps|s3):\/\/[^:]+:)[^@]+(@)/i' => '$1'.REDACTED.'$2',
++ // User and password cannot contain whitespace, so a match never spans log lines.
++ '/((?:https?|postgres|mysql|mongodb|rediss?|mariadb|ftp|sftp|ssh|amqp|amqps|ldap|ldaps|s3):\/\/[^:\s@\/]+:)[^@\s]+(@)/i' => '$1'.REDACTED.'$2',
+ self::EMAIL_PATTERN => REDACTED,
+ '/Bearer\s+[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+/i' => 'Bearer '.REDACTED,
+ '/Bearer\s+[^\s,;]+/i' => 'Bearer '.REDACTED,
+ '/\bgh[pousr]_[A-Za-z0-9.\-_]{36,}(?![A-Za-z0-9.\-_])/' => REDACTED,
+ '/\b(gl(?:pat|cbt|rt)-[A-Za-z0-9\-_]{20,})\b/' => REDACTED,
+ '/\b(A(?:KIA|BIA|CCA|SIA)[A-Z0-9]{16})\b/' => REDACTED,
+ '/(aws_secret_access_key|AWS_SECRET_ACCESS_KEY)[=:]\s*[\'\"]?([A-Za-z0-9\/+\=]{40})[\'\"]?/i' => '$1='.REDACTED,
+ '/(api[_-]?key|apikey|api[_-]?secret|secret[_-]?key)[=:]\s*[\'\"]?[A-Za-z0-9\-_]{16,}[\'\"]?/i' => '$1='.REDACTED,
+ '/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/' => REDACTED,
+ ];
+ if (! $this->redactEmails) {
+ unset($patterns[self::EMAIL_PATTERN]);
+ }
+
+ foreach ($patterns as $pattern => $replacement) {
+ $text = preg_replace($pattern, $replacement, $text);
+ if ($text === null) {
+ throw new RuntimeException('Log redaction failed.');
+ }
+ }
+
+ return $text;
+ }
+
+ private function isSensitiveKey(string $key): bool
+ {
+ $normalized = strtolower(preg_replace(['/([a-z0-9])([A-Z])/', '/[-\s]+/'], ['$1_$2', '_'], $key) ?? $key);
+
+ foreach (self::SENSITIVE_KEYS as $sensitiveKey) {
+ if ($normalized === $sensitiveKey || str_ends_with($normalized, '_'.$sensitiveKey)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
diff --cc app/Traits/HandlesNotificationResponse.php
index 8cbc7e2968,77d8b8477d..ede61dbfa0
--- a/app/Traits/HandlesNotificationResponse.php
+++ b/app/Traits/HandlesNotificationResponse.php
@@@ -19,28 -14,6 +19,28 @@@ use Symfony\Component\HttpFoundation\Re
*/
trait HandlesNotificationResponse
{
+ /**
+ * Send the request and replace HTTP client exceptions, whose messages contain
+ * the full URL (bot token, secret webhook path), with one that only names the
+ * scheme and host. The original exception is not kept as `previous`, so the
- * URL never reaches failed_jobs or Sentry.
++ * URL never reaches failed_jobs or the logs.
+ *
+ * @param Closure(): Response $send
+ */
+ protected function sendNotificationRequest(string $channel, string $url, Closure $send): Response
+ {
+ try {
+ return $send();
+ } catch (ConnectionException|RequestException|TransferException $e) {
+ throw new RuntimeException(sprintf(
+ '%s notification request to %s failed (%s).',
+ $channel,
+ SafeWebhookUrl::redactedUrlForLog($url),
+ class_basename($e),
+ ));
+ }
+ }
+
/**
* Rate limits and server errors are retried by the queue. A configuration
* error (invalid token, deleted webhook) counts as a delivery failure and
diff --cc bootstrap/helpers/docker.php
index 7606c09ad0,4517fb11f2..c27eb4270d
--- a/bootstrap/helpers/docker.php
+++ b/bootstrap/helpers/docker.php
@@@ -774,20 -774,7 +774,20 @@@ function isNoindexDomain(string $domain
->contains($normalize($domain));
}
-function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, ?string $image = null, string $redirect_direction = 'both', ?string $predefinedPort = null, bool $is_http_basic_auth_enabled = false, ?string $http_basic_auth_username = null, ?string $http_basic_auth_password = null, ?Collection $noindex_domains = null, bool $is_traffic_analytics_enabled = false, array $domainPortOverrides = [], bool $supports_log_append = false, bool $supports_basic_auth_directive = false, bool $is_permanent_redirect_enabled = false)
+/**
+ * Caddy site address of a domain. Maintenance blocks in the base Caddyfile must use the same
+ * address as the labels, so caddy-docker-proxy merges them into one site block.
+ */
+function caddySiteAddress(string $scheme, string $host, bool $isForceHttpsEnabled): string
+{
+ if ($scheme === 'https' && ! $isForceHttpsEnabled) {
+ return "http://{$host}, https://{$host}";
+ }
+
+ return "{$scheme}://{$host}";
+}
+
- function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, ?string $image = null, string $redirect_direction = 'both', ?string $predefinedPort = null, bool $is_http_basic_auth_enabled = false, ?string $http_basic_auth_username = null, ?string $http_basic_auth_password = null, ?Collection $noindex_domains = null, bool $is_traffic_analytics_enabled = false, array $domainPortOverrides = [], bool $supports_log_append = false, bool $supports_basic_auth_directive = false, ?int $http_basic_auth_bcrypt_cost = null, array $http_basic_auth_argon2id_options = [])
++function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, ?string $image = null, string $redirect_direction = 'both', ?string $predefinedPort = null, bool $is_http_basic_auth_enabled = false, ?string $http_basic_auth_username = null, ?string $http_basic_auth_password = null, ?Collection $noindex_domains = null, bool $is_traffic_analytics_enabled = false, array $domainPortOverrides = [], bool $supports_log_append = false, bool $supports_basic_auth_directive = false, ?int $http_basic_auth_bcrypt_cost = null, array $http_basic_auth_argon2id_options = [], bool $is_permanent_redirect_enabled = false)
{
$labels = collect([]);
if ($serviceLabels) {
@@@ -943,7 -929,7 +944,7 @@@ function traefikHostRulesWithoutIpv6Bra
) : $label);
}
- function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, bool $generate_unique_uuid = false, ?string $image = null, string $redirect_direction = 'both', bool $is_http_basic_auth_enabled = false, ?string $http_basic_auth_username = null, ?string $http_basic_auth_password = null, ?Collection $noindex_domains = null, bool $escape_redirect_replacement_for_compose = true, array $domainPortOverrides = [], ?string $certificate_resolver = 'letsencrypt', ?int $http_basic_auth_bcrypt_cost = null)
-function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, bool $generate_unique_uuid = false, ?string $image = null, string $redirect_direction = 'both', bool $is_http_basic_auth_enabled = false, ?string $http_basic_auth_username = null, ?string $http_basic_auth_password = null, ?Collection $noindex_domains = null, bool $escape_redirect_replacement_for_compose = true, array $domainPortOverrides = [], ?string $certificate_resolver = 'letsencrypt', bool $is_permanent_redirect_enabled = false)
++function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, bool $generate_unique_uuid = false, ?string $image = null, string $redirect_direction = 'both', bool $is_http_basic_auth_enabled = false, ?string $http_basic_auth_username = null, ?string $http_basic_auth_password = null, ?Collection $noindex_domains = null, bool $escape_redirect_replacement_for_compose = true, array $domainPortOverrides = [], ?string $certificate_resolver = 'letsencrypt', ?int $http_basic_auth_bcrypt_cost = null, bool $is_permanent_redirect_enabled = false)
{
$labels = collect([]);
$labels->push('traefik.enable=true');
@@@ -1794,6 -1755,45 +1807,49 @@@ function convertDockerRunToCompose(?str
return $compose_options->toArray();
}
+ /**
+ * Returns the options (--network, -e, ...) that convertDockerRunToCompose() does not apply.
+ *
+ * @return array<int, string>
+ */
+ function unsupportedDockerRunOptions(?string $custom_docker_run_options): array
+ {
+ // Split into shell words, so text inside a quoted value is not taken as an option
+ preg_match_all('/(?:"(?:\\\\.|[^"])*"|\'[^\']*\'|[^\s"\']|["\'])+/', $custom_docker_run_options ?? '', $words);
+ $unsupported = [];
+ foreach ($words[0] as $word) {
+ if (! str_starts_with($word, '-') || preg_match('/^-\d/', $word)) {
+ continue;
+ }
++ // convertDockerRunToCompose() maps these outside DOCKER_RUN_OPTION_MAPPING
++ if (preg_match('/^(-[dit]+|--interactive|--tty)$/', $word)) {
++ continue;
++ }
+ $option = str_starts_with($word, '--') ? '--'.ltrim(strtok($word, '='), '-') : strtok($word, '=');
+ if (! array_key_exists($option, DOCKER_RUN_OPTION_MAPPING)) {
+ $unsupported[] = $option;
+ }
+ }
+
+ return array_values(array_unique($unsupported));
+ }
+
+ /**
+ * Returns --mount flags that make seccomp profile files from the custom Docker options readable in the deployment
+ * helper container, where docker compose reads them. The path stays the same, so security_opt works unchanged.
+ */
+ function seccompProfileMountFlags(?string $custom_docker_run_options): string
+ {
+ $flags = [];
+ foreach (data_get(convertDockerRunToCompose($custom_docker_run_options), 'security_opt', []) as $security_opt) {
+ if (preg_match('#^seccomp[=:](/[A-Za-z0-9._/-]+)$#', $security_opt, $profile) && ! str_contains($profile[1], '..')) {
+ $flags[] = '--mount '.escapeshellarg("type=bind,source={$profile[1]},target={$profile[1]},readonly");
+ }
+ }
+
+ return implode(' ', array_unique($flags));
+ }
+
function generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $network)
{
$ipv4 = data_get($docker_run_options, 'ip.0');
diff --cc resources/views/livewire/server/log-drains.blade.php
index 3f3d756414,425b4a2bdd..3f72f8609d
--- a/resources/views/livewire/server/log-drains.blade.php
+++ b/resources/views/livewire/server/log-drains.blade.php
@@@ -34,11 -34,11 +34,11 @@@
['value' => false, 'label' => 'Disabled'],
['value' => true, 'label' => 'Enabled'],
]"
- :disabled="$isLogDrainAxiomEnabled || $isLogDrainCustomEnabled || !auth()->user()->can('update', $server)" />
+ :disabled="$isLogDrainAxiomEnabled || $isLogDrainCustomEnabled || $isLogDrainCloudwatchEnabled || !auth()->user()->can('update', $server)" />
- <x-forms.input canGate="update" :canResource="$server" type="password" required
+ <x-forms.input canGate="update" :canResource="$server" type="password" :required="$isLogDrainNewRelicEnabled"
id="logDrainNewRelicLicenseKey" label="License key"
:disabled="$server->isLogDrainEnabled()" />
- <x-forms.input canGate="update" :canResource="$server" required
+ <x-forms.input canGate="update" :canResource="$server" :required="$isLogDrainNewRelicEnabled"
id="logDrainNewRelicBaseUri" label="Endpoint"
placeholder="https://log-api.eu.newrelic.com/log/v1"
helper="Use the EU or US New Relic Log API endpoint."
@@@ -53,38 -53,15 +53,38 @@@
['value' => false, 'label' => 'Disabled'],
['value' => true, 'label' => 'Enabled'],
]"
- :disabled="$isLogDrainNewRelicEnabled || $isLogDrainCustomEnabled || !auth()->user()->can('update', $server)" />
+ :disabled="$isLogDrainNewRelicEnabled || $isLogDrainCustomEnabled || $isLogDrainCloudwatchEnabled || !auth()->user()->can('update', $server)" />
- <x-forms.input canGate="update" :canResource="$server" type="password" required
+ <x-forms.input canGate="update" :canResource="$server" type="password" :required="$isLogDrainAxiomEnabled"
id="logDrainAxiomApiKey" label="API key"
:disabled="$server->isLogDrainEnabled()" />
- <x-forms.input canGate="update" :canResource="$server" required
+ <x-forms.input canGate="update" :canResource="$server" :required="$isLogDrainAxiomEnabled"
id="logDrainAxiomDatasetName" label="Dataset name"
:disabled="$server->isLogDrainEnabled()" />
</div>
</x-application.settings-section>
+ <x-application.settings-section id="server-cloudwatch-drain-section" title="Amazon CloudWatch Logs"
+ helper="Send container logs directly to CloudWatch Logs using the Docker awslogs logging driver.<br><br>AWS credentials are read by the Docker daemon on this server, not by Coolify. Attach an IAM instance role, or configure <code>AWS_ACCESS_KEY_ID</code> and <code>AWS_SECRET_ACCESS_KEY</code> for the Docker service or in <code>/root/.aws/credentials</code>.<br><br>The credentials need <code>logs:CreateLogStream</code> and <code>logs:PutLogEvents</code>, plus <code>logs:CreateLogGroup</code> if the log group does not exist yet.<br><br>Delivery errors do not stop containers; they appear in the Docker daemon logs (<code>journalctl -u docker</code>). Redeploy or restart resources to apply the logging driver.">
+ <div class="mb-4 max-w-sm">
+ <x-forms.listbox canGate="update" :canResource="$server" id="isLogDrainCloudwatchEnabled" label="Status"
+ onChange="instantSave" :options="[
+ ['value' => false, 'label' => 'Disabled'],
+ ['value' => true, 'label' => 'Enabled'],
+ ]"
+ :disabled="$isLogDrainNewRelicEnabled || $isLogDrainAxiomEnabled || $isLogDrainCustomEnabled || !auth()->user()->can('update', $server)" />
+ </div>
+ <div class="grid gap-4 lg:grid-cols-3">
- <x-forms.input canGate="update" :canResource="$server" required
++ <x-forms.input canGate="update" :canResource="$server" :required="$isLogDrainCloudwatchEnabled"
+ id="logDrainCloudwatchGroup" label="Log group" placeholder="/coolify/production"
+ :disabled="$server->isLogDrainEnabled()" />
+ <x-forms.input canGate="update" :canResource="$server"
+ id="logDrainCloudwatchStreamPrefix" label="Log stream prefix" placeholder="docker/"
+ helper="Optional. Log streams are named after the container, prefixed with this value (e.g. docker/&lt;container name&gt;)."
+ :disabled="$server->isLogDrainEnabled()" />
- <x-forms.input canGate="update" :canResource="$server" required
++ <x-forms.input canGate="update" :canResource="$server" :required="$isLogDrainCloudwatchEnabled"
+ id="logDrainCloudwatchRegion" label="Region" placeholder="us-east-1"
+ :disabled="$server->isLogDrainEnabled()" />
+ </div>
+ </x-application.settings-section>
<x-application.settings-section id="server-custom-drain-section" title="Custom Fluent Bit"
helper="Provide a custom Fluent Bit output and optional parser configuration.">
<div class="mb-4 max-w-sm">
@@@ -93,10 -70,10 +93,10 @@@
['value' => false, 'label' => 'Disabled'],
['value' => true, 'label' => 'Enabled'],
]"
- :disabled="$isLogDrainNewRelicEnabled || $isLogDrainAxiomEnabled || !auth()->user()->can('update', $server)" />
+ :disabled="$isLogDrainNewRelicEnabled || $isLogDrainAxiomEnabled || $isLogDrainCloudwatchEnabled || !auth()->user()->can('update', $server)" />
</div>
<div class="grid gap-4 lg:grid-cols-2">
- <x-forms.textarea canGate="update" :canResource="$server" rows="8" required
+ <x-forms.textarea canGate="update" :canResource="$server" rows="8" :required="$isLogDrainCustomEnabled"
id="logDrainCustomConfig" label="Fluent Bit configuration"
:disabled="$server->isLogDrainEnabled()" />
<x-forms.textarea canGate="update" :canResource="$server" rows="8"
diff --cc tests/Feature/BackupRunSafetyTest.php
index b80ea23d91,7f3475d846..5a19a72a45
--- a/tests/Feature/BackupRunSafetyTest.php
+++ b/tests/Feature/BackupRunSafetyTest.php
@@@ -277,32 -277,58 +277,84 @@@ it('stores service database backups in
->toContain("/rallly-rallly_db-{$service->uuid}/pg-dump-rallly-");
});
+it('backs up a service PostgreSQL database as the user from PGUSER or POSTGRESQL_USERNAME', function (string $env, string $user) {
+ $service = Service::factory()->create([
+ 'server_id' => $this->server->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ 'environment_id' => $this->environment->id,
+ ]);
+ $database = ServiceDatabase::create([
+ 'service_id' => $service->id,
+ 'name' => 'app_db',
+ 'image' => 'postgres:16-alpine',
+ 'status' => 'running:healthy',
+ ]);
+ $backup = backupRunSafetySchedule($database, $this->team);
+ $commands = backupRunSafetyFakeRemoteCommands(['| grep -E' => $env."\nPOSTGRES_DB=app"]);
+
+ (new DatabaseBackupJob($backup))->handle();
+
+ expect($commands->first(fn (string $command) => str_contains($command, 'pg_dump')))
+ ->toContain("--username '\\''{$user}'\\''");
+})->with([
+ 'PGUSER' => ['PGUSER=pguser', 'pguser'],
+ 'Bitnami POSTGRESQL_USERNAME' => ['POSTGRESQL_USERNAME=bitnami', 'bitnami'],
+ 'POSTGRES_USER wins' => ["POSTGRES_USER=app\nPGUSER=pguser", 'app'],
+]);
+
+ function backupRunSafetyServiceDatabase(Server $server, StandaloneDocker $destination, Environment $environment, string $image): ServiceDatabase
+ {
+ $service = Service::factory()->create([
+ 'server_id' => $server->id,
+ 'destination_id' => $destination->id,
+ 'destination_type' => $destination->getMorphClass(),
+ 'environment_id' => $environment->id,
+ ]);
+
+ return ServiceDatabase::create([
+ 'service_id' => $service->id,
+ 'name' => 'db',
+ 'image' => $image,
+ 'status' => 'running:healthy',
+ ]);
+ }
+
+ it('backs up a service database without a database env variable from the backup settings', function (string $image, string $env, array $settings, string $databaseName) {
+ $database = backupRunSafetyServiceDatabase($this->server, $this->destination, $this->environment, $image);
+ $backup = backupRunSafetySchedule($database, $this->team, $settings);
+ backupRunSafetyFakeRemoteCommands(["docker exec '{$database->name}-{$database->service->uuid}' env" => $env]);
+
+ (new DatabaseBackupJob($backup))->handle();
+
+ expect(ScheduledDatabaseBackupExecution::query()->sole())
+ ->status->toBe('success')
+ ->database_name->toBe($databaseName);
+ })->with([
+ 'mariadb, all databases' => ['mariadb:11', 'MARIADB_ROOT_PASSWORD=secret', ['dump_all' => true], 'all'],
+ 'mariadb, selected database' => ['mariadb:11', 'MARIADB_ROOT_PASSWORD=secret', ['databases_to_backup' => 'shop'], 'shop'],
+ 'mysql, all databases' => ['mysql:8', 'MYSQL_ROOT_PASSWORD=secret', ['dump_all' => true], 'all'],
+ 'mysql, selected database' => ['mysql:8', 'MYSQL_ROOT_PASSWORD=secret', ['databases_to_backup' => 'shop'], 'shop'],
+ ]);
+
+ it('records a failed execution and notifies when no service database to back up is known', function (string $image, string $env) {
+ $database = backupRunSafetyServiceDatabase($this->server, $this->destination, $this->environment, $image);
+ $backup = backupRunSafetySchedule($database, $this->team);
+ $this->team->emailNotificationSettings->update(['smtp_enabled' => true, 'backup_failure_email_notifications' => true]);
+ $commands = backupRunSafetyFakeRemoteCommands(["docker exec '{$database->name}-{$database->service->uuid}' env" => $env]);
+
+ (new DatabaseBackupJob($backup))->handle();
+
+ expect(ScheduledDatabaseBackupExecution::query()->sole())
+ ->status->toBe('failed')
+ ->message->toContain('No database to back up');
+ expect($commands->contains(fn (string $command) => str_contains($command, 'dump')))->toBeFalse();
+ Notification::assertSentTo($this->team, BackupFailed::class);
+ })->with([
+ 'mariadb' => ['mariadb:11', 'MARIADB_ROOT_PASSWORD=secret'],
+ 'mysql' => ['mysql:8', 'MYSQL_ROOT_PASSWORD=secret'],
+ ]);
+
// --- Worker timeout (M16) ---
it('stops the backup command at the backup timeout, before the worker timeout', function () {
diff --cc tests/Feature/Helpers/DockerCustomCommandsTest.php
index 341e9de31f,7a16d15446..b878d21c31
--- a/tests/Feature/Helpers/DockerCustomCommandsTest.php
+++ b/tests/Feature/Helpers/DockerCustomCommandsTest.php
@@@ -253,58 -431,40 +431,100 @@@ test('ConvertGpusCount', function ()
]);
});
+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([]);
+});
++
+ test('ConvertRuntimeHardeningOptions', function () {
+ $input = '--add-host host.docker.internal:host-gateway --add-host=db:10.0.0.5 --pids-limit 100 --runtime runc --read-only --tmpfs /run:rw,size=64m --tmpfs /tmp';
+ $output = convertDockerRunToCompose($input);
+ expect($output)->toBe([
+ 'extra_hosts' => ['host.docker.internal:host-gateway', 'db:10.0.0.5'],
+ 'pids_limit' => 100,
+ 'runtime' => 'runc',
+ 'read_only' => true,
+ 'tmpfs' => ['/run:rw,size=64m', '/tmp'],
+ ]);
+ });
+
+ test('ConvertNegativePidsLimitAndDisabledReadOnly', function () {
+ $input = '--pids-limit -1 --read-only=false';
+ $output = convertDockerRunToCompose($input);
+ expect($output)->toBe([
+ 'pids_limit' => -1,
+ 'read_only' => false,
+ ]);
+ });
+
+ test('UnsupportedDockerRunOptions', function () {
+ $input = '--network=host --name app -e FOO=bar -v /a:/b --entrypoint "sh -c \'run --verbose\'" --cap-add NET_ADMIN --pids-limit -1 ---privileged --network bridge';
+ expect(unsupportedDockerRunOptions($input))->toBe(['--network', '--name', '-e', '-v']);
+ });
+
+ test('UnsupportedDockerRunOptionsIsEmptyForSupportedOptions', function () {
+ expect(unsupportedDockerRunOptions('--cap-drop ALL --security-opt no-new-privileges:true --tmpfs /tmp'))->toBe([])
+ ->and(unsupportedDockerRunOptions(null))->toBe([]);
+ });
+
++test('UnsupportedDockerRunOptionsSkipsInteractiveAndTtyFlags', function () {
++ expect(unsupportedDockerRunOptions('-it -t --interactive --tty --cap-add NET_ADMIN'))->toBe([]);
++});
++
+ test('SeccompProfileMountFlags', function () {
+ $input = '--security-opt seccomp=/etc/docker/seccomp.json --security-opt "seccomp:/srv/app profile.json" --security-opt seccomp=/etc/../root/x.json --security-opt seccomp=unconfined --security-opt apparmor=unconfined';
+ expect(seccompProfileMountFlags($input))->toBe("--mount 'type=bind,source=/etc/docker/seccomp.json,target=/etc/docker/seccomp.json,readonly'")
+ ->and(seccompProfileMountFlags('--cap-drop ALL'))->toBe('')
+ ->and(seccompProfileMountFlags(null))->toBe('');
+ });
diff --cc tests/Feature/VolumeBackupTest.php
index 2d09e4ac8b,97fd82614f..14b0676aa3
--- a/tests/Feature/VolumeBackupTest.php
+++ b/tests/Feature/VolumeBackupTest.php
@@@ -1963,11 -1984,10 +1963,11 @@@ it('keeps the upload destination on th
$execution = ScheduledVolumeBackupExecution::query()->sole();
expect($execution->s3_storage_id)->toBe($s3Storage->id)
- ->and($execution->s3->is($s3Storage))->toBeTrue();
+ ->and($execution->s3->is($s3Storage))->toBeTrue()
+ ->and($execution->s3Replicas()->sole()->s3_storage_id)->toBe($s3Storage->id);
});
- it('streams S3-only volume backups without creating or copying a local archive', function () {
+ it('streams S3-only volume backups with Content-MD5 on Object Lock buckets and without a local archive', function () {
config(['broadcasting.default' => 'null']);
defined('CURLOPT_RESOLVE') || define('CURLOPT_RESOLVE', 10203);
Carbon::setTestNow('2026-08-15 12:00:00');