Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions apps/ideploy/app/Jobs/ApplicationDeploymentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2403,17 +2403,6 @@ private function generate_compose_file()
// It's a "key=value" string, split it
[$labelKey, $labelValue] = explode('=', $label, 2);

// CRITICAL FIX: Remove quotes from CrowdsecLapiKey values
// The CrowdSec bouncer plugin validates against: /^[a-zA-Z0-9 !#$%&'*+-.^_`|~=/]*$/
// Quotes are NOT in this regex, so we must remove them
if (str_contains($labelKey, 'CrowdsecLapiKey')) {
$labelValue = trim($labelValue, '"\'');
}

// Escape YAML special chars with quotes
if (str_contains($labelValue, ':')) {
$labelValue = '"' . str_replace('"', '\\"', $labelValue) . '"';
}
$labelsArray[$labelKey] = $labelValue;
}
}
Expand Down Expand Up @@ -2627,7 +2616,11 @@ private function generate_compose_file()
// Ignore debug errors
}

$this->docker_compose = Yaml::dump($docker_compose, 10);
// CRITICAL FIX: Quote all label values containing special YAML chars BEFORE Yaml::dump
// This prevents "yaml: line X: could not find expected ':'" errors
$this->quoteYamlSpecialChars($docker_compose);

$this->docker_compose = Yaml::dump($docker_compose, 10, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
$this->docker_compose_base64 = base64_encode($this->docker_compose);
$this->execute_remote_command(
[
Expand All @@ -2637,6 +2630,31 @@ private function generate_compose_file()
);
}

/**
* Recursively quote YAML special characters in all string values
* This prevents YAML parsing errors like "could not find expected ':'"
*/
private function quoteYamlSpecialChars(&$array)
{
foreach ($array as $key => &$value) {
if (is_array($value)) {
// Recursively process nested arrays
$this->quoteYamlSpecialChars($value);
} elseif (is_string($value)) {
// Quote if contains : or starts with special chars
if (str_contains($value, ':') ||
str_starts_with($value, '@') ||
str_starts_with($value, '`') ||
str_starts_with($value, '#')) {
// Only quote if not already quoted
if (!str_starts_with($value, '"') && !str_starts_with($value, "'")) {
$value = '"' . str_replace('"', '\\"', $value) . '"';
}
}
}
}
}

private function generate_local_persistent_volumes()
{
$local_persistent_volumes = [];
Expand Down