Bug #37741
openIndentation of snippets can cause errors in bash scripts, if heredoc is used in the template
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.
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?
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
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