Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vhost headers interpolate string as variable #2316

Closed
zilchms opened this issue Sep 20, 2022 · 3 comments
Closed

vhost headers interpolate string as variable #2316

zilchms opened this issue Sep 20, 2022 · 3 comments

Comments

@zilchms
Copy link

zilchms commented Sep 20, 2022

Describe the Bug

I am trying to set a header for a vhost I am declaring with hiera.
The header is:
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
To achieve this, I put the following into the hiera:

apache::vhosts:
  'url-com-ssl':
    servername: 'url.com'
    headers:
      - 'add Set-Cookie \"ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/\" env=BALANCER_ROUTE_CHANGED'

This results in:
Header add Set-Cookie "ROUTEID=.e; path=/" env=BALANCER_ROUTE_CHANGED

It seems that the module/template interpolates the variable in the single quoted string resulting in an empty substring. This would make it hard/impossible to use the environment variables functionalities of apache.

I tried several different ways to escape the %{BALANCER_WORKER_ROUTE} part, but had no success.
Maybe there is a way I am not aware of? Help is much appreciated.

Expected Behavior

I expected the apache module to set the header correctly without interpolating the string before writing it into the file.

Steps to Reproduce

  1. Setup the apache-module on the puppetmaster with hiera as described above
  2. Run the agent
  3. View the resulting output file

Environment

  • Module-Version 8.2.0
  • Platform SLES 12-SP5 (both master and agent)
  • Puppetversion 6.28.0
  • Puppetserver Version 6.20.0

Additional Context

If there is a way to correctly escape or configure variables in headers, it is not really apparent from the docs. Maybe there needs to be a bit more documentation, if this is not a bug?

@chutzimir
Copy link
Contributor

chutzimir commented Apr 14, 2023

The solution to your problem is literally implemented with a literal function documented here: https://www.puppet.com/docs/puppet/7/hiera_merging.html#interpolation_functions-literal-function

The following is quoting the above section:

The literal function

The literal interpolation function lets you escape a literal percent sign (%) in Hiera data, to avoid triggering interpolation where it isn’t wanted.

This is useful when dealing with Apache config files, for example, which might include text such as %{SERVER_NAME}. For example:

server_name_string: "%{literal('%')}{SERVER_NAME}"

The value of server_name_string would be %{SERVER_NAME}, and Hiera would not attempt to interpolate a variable named SERVER_NAME.

The only legal argument for literal is a single % sign.

@zilchms
Copy link
Author

zilchms commented Apr 14, 2023

Thanks for the hint, I will test of that works for my setup :)

@Ramesh7
Copy link
Contributor

Ramesh7 commented Aug 29, 2023

Thanks @chutzimir for your pointers.
BTW @zilchms I have tried with literal and it worked for me, here is hiera values which I put :

    headers:
      - 'add Set-Cookie "ROUTEID=.%{literal("%")}{BALANCER_ROUTE_CHANGED}e; path=/" env=BALANCER_ROUTE_CHANGED'

And in vhost config file below is output I got :

Header add Set-Cookie "ROUTEID=.%{BALANCER_ROUTE_CHANGED}e; path=/" env=BALANCER_ROUTE_CHANGED

Using literal we don't need escape, this works like charm.

@Ramesh7 Ramesh7 removed the bugfix label Aug 29, 2023
@Ramesh7 Ramesh7 closed this as completed Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants