fix(escape): Escape double quotes and all other characters reliably

This commit is contained in:
Paul Gabriel
2023-02-20 16:49:47 +01:00
parent 25e8b91569
commit f81ba12aa5
3 changed files with 8 additions and 4 deletions

View File

@@ -58,7 +58,7 @@ class Mrsk::Configuration::Role
def traefik_labels
if running_traefik?
{
"traefik.http.routers.#{config.service}.rule" => 'PathPrefix(\`/\`)',
"traefik.http.routers.#{config.service}.rule" => "PathPrefix(`/`)",
"traefik.http.services.#{config.service}.loadbalancer.healthcheck.path" => config.healthcheck["path"],
"traefik.http.services.#{config.service}.loadbalancer.healthcheck.interval" => "1s",
"traefik.http.middlewares.#{config.service}.retry.attempts" => "3",

View File

@@ -5,7 +5,7 @@ module Mrsk::Utils
def argumentize(argument, attributes, redacted: false)
Array(attributes).flat_map do |k, v|
if v.present?
[ argument, redacted ? redact("#{k}=\"#{v}\"") : "#{k}=\"#{v}\"" ]
[ argument, redacted ? redact("#{k}=#{escape_bash_string v.to_s}") : "#{k}=#{escape_bash_string v.to_s}" ]
else
[ argument, k ]
end
@@ -26,4 +26,8 @@ module Mrsk::Utils
def redact(arg) # Used in execute_command to hide redact() args a user passes in
arg.to_s.extend(SSHKit::Redaction) # to_s due to our inability to extend Integer, etc
end
def escape_bash_string(string)
string.dump.gsub(/`/, '\\\\`')
end
end