Project

General

Profile

Actions

Bug #37741

open

Indentation of snippets can cause errors in bash scripts, if heredoc is used in the template

Added by Shimon Shtein 3 months ago. Updated 2 months ago.

Status:
Ready For Testing
Priority:
Normal
Assignee:
Category:
Templates
Target version:
-
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

Assume a snippet with a heredoc block, similar to ca_registration (that has the CA certificate as a heredoc).
If this snippet is used in indented code block, it will cause a syntax error in the bash.

Steps to reproduce:
render the redhat_register template and observe the ca_registration snippet block:

    if [ -f "$KATELLO_SERVER_CA_CERT" ]; then
      cat << EOF-eaebc9a8 > "$KATELLO_SERVER_CA_CERT" 
  -----BEGIN CERTIFICATE-----
  MIIHNzCCBR+gAwIBAgIUFZxXVC1gX8shPBN4T1PoxvyoIqQwDQYJKoZIhvcNAQEL
# snip
  -----END CERTIFICATE-----
  EOF-eaebc9a8
      if [ -f /etc/debian_version ]; then
        CA_TRUST_ANCHORS=/usr/local/share/ca-certificates/

Notice the two spaces before the EOF-eaebc9a8 marker. This causes a syntax error in bash, since it expects EOF at the beginning of the line.

Actions #1

Updated by Oleh Fedorenko 3 months ago

Is it possible to re-use the solution from #37495 by providing skip_content: 'EOF' to the indent() method?

Actions #2

Updated by Shimon Shtein 3 months ago

Oleh Fedorenko wrote in #note-1:

Is it possible to re-use the solution from #37495 by providing skip_content: 'EOF' to the indent() method?

I am not sure how would it work, since the indent is defined outside the template that uses save_to_file. So we can't know that save_to_file will be used when we are indenting the snippet.

I suggest changing the save_to_file implementation to be resilient to indentation, similar to this one: https://github.com/theforeman/foreman/pull/10283

Actions #3

Updated by The Foreman Bot 2 months ago

  • Status changed from New to Ready For Testing
  • Assignee set to Shimon Shtein
  • Pull request https://github.com/theforeman/foreman/pull/10283 added
Actions

Also available in: Atom PDF