Copying environment variables

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Copying environment variables

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

Is it possible to "copy" an environment variable to another name?
Something like this:

SetEnv foo "bar"
SetEnv baz ${foo}e

Now, "baz" has value "bar".

It doesn't appear to work as written above, but the documentation
doesn't actually suggest you can do that kind of thing.

I have an environment variable whose value I need to copy into another
name. What are my options for doing that kind of thing?

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl77WEYACgkQHPApP6U8
pFhXgRAAvZe+AuQ2Vzhhz2r6arJ/rvjFoVuuvQj4TsZIsOtRR20Us0Lai21G+I3J
gVezJdJtUhAHQvR8unWSlcvLVpm0oqLo+AHkPtwJb4SvesH6X8B560TvTs9YKgFO
eFkr4c1kf35q3vpdWL7odA8KFPz5K2BMP9gUWO8eCJfh4uaraq9j/HYoI+fiCQRj
OADcfvhIJv3J2np9nBiS6dYnx0U2/3rq+x4NREodhBLlymxmNUJ3vyqllVdqa7AJ
SFR7Xp8IUX5OnGiS43Wxftlcj0XJD5Or1VQlano9Cz360aLq+Qel34bzYFJjHw/W
J4Zg764KvRWDD/QpZs9KxadGfnPf5slVzrN+u9E1sLHv+p/Fj95f+JSCtqXSM3Ks
l/AZp/cpW2RSDepySf6RVOMYUMnAs9a4YuPJaEruq9Qc2Ydt62PWj7pJ9dLSK0Qz
SEesldpWQuXrTdE1/G6b+TWKlf8gHkCAitd6NjqN6ZWAPqS4mXdCjTCSA3I9nl9O
l6EPEOP+4axDhou0BllQmoiKA6vW79IVTms5Ixxya5B6Z6hOc3wMvuPSuPoHoOjj
jZgjfA7EUCy+Nhm2cLIoDlB6TME/1GLgeM2rIhIQPKVY+1vq+Y8tqaD43sYiMM1J
W/xapLI6ygKRlKShXPBoSlu3NvVu9Kj3hIHgxyth6IKAmDtuBMM=
=NKRA
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Copying environment variables

Eric Covener
On Tue, Jun 30, 2020 at 11:20 AM Christopher Schultz
<[hidden email]> wrote:

>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> All,
>
> Is it possible to "copy" an environment variable to another name?
> Something like this:
>
> SetEnv foo "bar"
> SetEnv baz ${foo}e
>
> Now, "baz" has value "bar".

If it's set early enough, try SetEnvIf instead.  The 2nd parameter can
be an existing variable and the value can be a backreference.
If it's not set early enough, you can do a no-op RewriteRule .* -
[E=baz:%{ENV:foo}]

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Copying environment variables

Christopher Schultz-2
In reply to this post by Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

On 6/30/20 11:20, Christopher Schultz wrote:

> All,
>
> Is it possible to "copy" an environment variable to another name?
> Something like this:
>
> SetEnv foo "bar" SetEnv baz ${foo}e
>
> Now, "baz" has value "bar".
>
> It doesn't appear to work as written above, but the documentation
> doesn't actually suggest you can do that kind of thing.
>
> I have an environment variable whose value I need to copy into
> another name. What are my options for doing that kind of thing?

Actually, this is probably a very important clarification, so let me
explain exactly what I'm trying to do.

I'm working on BZ 64338 [1] which adds a new environment variable to
mod_proxy_balancer: BALANCER_PROXY_STATUS.

I'd like to forward that value over to Tomcat using mod_proxy_ajp.
mod_proxy_ajp will automatically forward any environment variable
called AJP_* across the wire to Tomcat. So I was hoping to do
something like this:

SetEnv AJP_BALANCER_WORKER_STATUS %{BALANCER_WORKER_STATUS}e

That doesn't work -- I get a literal ${BALANCER_WORKER_STATUS}e as my
value in Tomcat, so I tried this as well:

RewriteRule .* -
[E=AJP_BALANCER_WORKER_STATUS:%{ENV:BALANCER_WORKER_STATUS}]

This doesn't seem to send anything over, and Tomcat sees nothing.

I also tried this, since eventually I won't be using mod_proxy_ajp but
mod_proxy_http:

RequestHeader set test_ajp_balancer_worker_status
%{BALANCER_WORKER_STATUS}e

I can see the HTTP header on the Tomcat side, but its value is null.

I've put the BALANCER_WORKER_STATUS environment variable into the
access-log and I can see that it's got a value ("1"), so I'm guessing
that the environment variable is established in mod_proxy_balancer so
late in the process that neither RewriteRule nor RquestHeader have a
chance to see a real value, there.

I have altered my code to set both BALANCER_WORKER_STATUS *and*
AJP_BALANCER_WORKER_STATUS and there I can see the value being
sent-over the wire to Tomcat.

The primary use-case for this BALANCER_WORKER_STATUS value is to send
over the wire to the origin server, so what's the best thing for me to
do, here? For mod_proxy_ajp I can either have mod_proxy_balancer set
the AJP_ environment variable (or I suppose mod_proxy_ajp could *copy*
that variable, or use its value as-is which would probably be better),
but how should mod_proxy_http handle this? HTTP headers are really the
only way to communicate this kind of information to the back-end
server and "RequestHeader" isn't able to pick this up.

Does it need direct-support from mod_proxy instead of trying to cobble
the pieces together from BZ 64338 and other existing directives? My
goal with 64388 was to write the smallest patch that could get the job
done, but I'm not sure it's possible do to it in this way.

Thanks,
- -chris

[1] https://bz.apache.org/bugzilla/show_bug.cgi?id=64338
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl77XQQACgkQHPApP6U8
pFhcphAAy34KXHNi0gUberEHoS0ZAl4czwTddTpWDTuUtVZUtxP5EEoZVgrXNOmv
U6TlNMnjoY2Ea43/gpbblDLbgpaAndqwU0QOW8sQlRvs8an0Kz19Y670GPHPvhXL
xnnVr992CbBDaUhLxxZVMLPZzCte7pScimk65KTa9ZF2a6Chp6FhTtgZDH4OVrP/
vRRhxLcFv1m3WGL1MiUKpqwgLg+GoXN5pl4yWX+nyZLHvOoKDn7FxENw64FSG0nE
AEgzNNCrYOGFzjPqqEhk+oc+4E0kjODGjtN0F5S30n+Fr/q1YUi6RYK8iaArFHit
lEv/bfQZCIyZojqTfzdSQZISmbdgIambRULEAq5nFgzSYaZFWCSGmzECoKHa1Lj/
g1lIch4+E2rlEapvjmcRiWfXjY27VzadboeVEEHcDpR/M2E+H5LW0AJnWeK7EoSx
u+Q34qVIkdkzmW4N4ZcuWST0PFRwZ+yp6j2LE+O8rKuQlJJKsNPxUBApFYtCfXZg
8/27EQIpeP94+CzphmLd3LYcn8Ipot82HIQYGnQ4Gis6fJ/vjOHG0SjEBnxQQPhq
vaF19uw3ITBwitcF3ZG1P0iHd6OYx5M7Luicj2zXrwcaYfhP26hoKqAMtyYdE9/C
GW8JcCkDi29uEb3E7kzMiLvXf5MBSleDikAIGNJbsByLdmFbcME=
=t3xJ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Copying environment variables

Eric Covener
> Does it need direct-support from mod_proxy instead of trying to cobble
> the pieces together from BZ 64338 and other existing directives? My
> goal with 64388 was to write the smallest patch that could get the job
> done, but I'm not sure it's possible do to it in this way.

I think so.

The area you're editing runs in the middle of the mod_proxy handler so
nothing really has a chance to run between the time the real var is
set and when you need the 2nd var set.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Copying environment variables

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Eric,

On 6/30/20 11:47, Eric Covener wrote:

>> Does it need direct-support from mod_proxy instead of trying to
>> cobble the pieces together from BZ 64338 and other existing
>> directives? My goal with 64388 was to write the smallest patch
>> that could get the job done, but I'm not sure it's possible do to
>> it in this way.
>
> I think so.
>
> The area you're editing runs in the middle of the mod_proxy handler
> so nothing really has a chance to run between the time the real var
> is set and when you need the 2nd var set.

So it sounds like this should just be a feature of mod_proxy handled
completely internally.

Should it be an optional feature, or always enabled?

I was thinking something like this:

1. mod_proxy_balancer sets BALANCER_WORKER_STATUS env var as in BZ 64338
2. mod_proxy_ajp copies BALANCER_WORKER_STATUS to request-attribute
(that's a thing in AJP) and sends to origin server
3. mod_proxy_http copies BALANCER_WORKER_STATUS to X-Worker-Status (or
similar) request header and sends to origin server
4. other mod_proxy_* modules do similar things as necessary (?)

WDYT?

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl77a4IACgkQHPApP6U8
pFjMtxAAmnjEprfG9hBm/odPVt8DlajoZfFeiVBlD/zHGM6s072OiZQaxoWki2m2
Pr49FkGdmJbmt+u+09DLWfRswRptH1O3R9BP1qq490g1TONSsfgvJfLScEGWf5e1
79XW8v7UTlPTkDnZZEH40yLCYyO8XFsGjegrPDUpSUaWihnt7V1VrZnXjQlYIXi5
kRoY8o+71eYymB2kVMFRH5DtaE3YDZcNK24gAL5gJfZRDaB9lRUR9CCo77mGGpGC
xfMXJCj7dwImn6iqkOB89pROk9fH3sQ223O1hqd88HtEvcWD16vx4bEWRl+FyGVJ
1VfbIRdORfV1bApez5HdZl3r89zmVjsfRW5KipwNPjLgwGxjHbtV98f9hw0cthPq
Yq7n4QTQBWpnUHOLuE5y//RDF6Z/p2W8yXevXwgnM0euIkjoWaYRNdVf045C7VjH
FCwZZxL+PxXWza+3enZR34QJpf0sDWF4FuFPoOa0dlcUKiz3AqgOpO9Ac+C7qY8r
P+4NmqqTpMzC2XTDv0NWj/63n+5Rl7huDuFWqwB+PwsgO3mcdwRZVgI+DNu+9d3Z
FmnAzxBkuhartrDfM4rI4RAUiNnOT4c05qEGTeg9vkFh2pXVjtsyyBAcVei1ZcAv
L5vcRTrPAGCA2H1JzZK939DzFqvdpr1I7w+9rH4OGL0BDG+sLKw=
=FjRe
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Copying environment variables

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

On 6/30/20 12:42, Christopher Schultz wrote:

> Eric,
>
> On 6/30/20 11:47, Eric Covener wrote:
>>> Does it need direct-support from mod_proxy instead of trying
>>> to cobble the pieces together from BZ 64338 and other existing
>>> directives? My goal with 64388 was to write the smallest patch
>>> that could get the job done, but I'm not sure it's possible do
>>> to it in this way.
>
>> I think so.
>
>> The area you're editing runs in the middle of the mod_proxy
>> handler so nothing really has a chance to run between the time
>> the real var is set and when you need the 2nd var set.
>
> So it sounds like this should just be a feature of mod_proxy
> handled completely internally.
>
> Should it be an optional feature, or always enabled?
>
> I was thinking something like this:
>
> 1. mod_proxy_balancer sets BALANCER_WORKER_STATUS env var as in BZ
> 64338 2. mod_proxy_ajp copies BALANCER_WORKER_STATUS to
> request-attribute (that's a thing in AJP) and sends to origin
> server 3. mod_proxy_http copies BALANCER_WORKER_STATUS to
> X-Worker-Status (or similar) request header and sends to origin
> server 4. other mod_proxy_* modules do similar things as necessary
> (?)

I've updated my proposed patch in BZ 64388 which implements the above
(except #4).

Comments are appreciated. I'm trying to get mod_proxy and friends to
feature-parity with mod_jk.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl77dHcACgkQHPApP6U8
pFhc2xAAhqNS4dvTAC6f8U8rqlxjOmY+Sq/svB9zHo4j2HDpAZqBgfE6kuZ3qmMk
+OCRWq7URI9CIik1mSwt/bbpHw1Zko3EZS1PKJdJIXmvBmAxI8eCTBJS/hqsk58t
PM2IXjDK4F0mHNkMKylJ7Qi7aXJ1QR/cNfQRgZnbzUL5HWqeiHKXpMfRuCvW9NRv
JDyl3O3T/Aox3HJeTTd2NSrSshmPUcsLr2J1X7mn7npgKx7896T7e91N9GGAmOSm
P+lqUKJgohvniMjJusimXv2vU43BJzu5IkKqSOl8obnnNc0tl2tmqcU2T8Ih5BiL
g2iwFcJQuewy7tkfaYPWquQuCpvuiOMTMqL7YBzAzukDG/gkPTAWgSrr1uVfCTjd
15c4biPCGmCuhSF41qpfM3yTuQAfxQdbjQKgI1ia8OWGalKIas+KWdsAvveF4JT2
5cuBHzBG3mWsuh2zKxZhHDEjCRTPnOY1sLnoU1tU3BNMAvLhPUn05MvPvVGNSROZ
qEn+WMr6u/wKod0O5GTRkLFhM8v9KtbZIeuc8SWP4WTodh7j3sU0HuzWb4fjlM2Y
A4l+u/Xk53jmeVfEtFSPntnFZPrED5G3Nrrhdsmo6B/fCcVeUv8xeu5aZyxI6jW0
uHzMqcE3NoWCRe9LIXgzqynDwguTlxHCMtudBbupEoD9w3xJnJM=
=9VBq
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Copying environment variables

Eric Covener
> > 1. mod_proxy_balancer sets BALANCER_WORKER_STATUS env var as in BZ
> > 64338 2. mod_proxy_ajp copies BALANCER_WORKER_STATUS to
> > request-attribute (that's a thing in AJP) and sends to origin
> > server 3. mod_proxy_http copies BALANCER_WORKER_STATUS to
> > X-Worker-Status (or similar) request header and sends to origin
> > server 4. other mod_proxy_* modules do similar things as necessary
> > (?)
>
> I've updated my proposed patch in BZ 64388 which implements the above
> (except #4).
>
> Comments are appreciated. I'm trying to get mod_proxy and friends to
> feature-parity with mod_jk.

looks reasonable in concept, I wouldn't let #4 block APJ/HTTP.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]