Skip to content

Adjust the way arguments are being escaped. #870

Merged
dmikusa merged 3 commits intomainfrom
appd_escaping
May 5, 2021
Merged

Adjust the way arguments are being escaped. #870
dmikusa merged 3 commits intomainfrom
appd_escaping

Conversation

@dmikusa
Copy link
Contributor

@dmikusa dmikusa commented Apr 29, 2021

PR #837 can result in double escaping of application names when the default value is used. This is because the value gets escaped at runtime when it's selected, so it's not necessary to escape it at build time also.

It also only handles spaces. If there were a " in the name, that would cause an error.


This PR will ensure that values for the app name that are selected during build time by the buildpack are escaped at build time and that values that are pulled at runtime before an app starts are escaped at that point in time, but not both. That way we avoid double escaping values.

In addition, it uses Shellwords.escape to escape the values not just surrounding them in double-quotes. This will result in properly shell escaping double quotes also.

Resolves #871

…during build time by the buildpack are escaped now. Values that are pulled at runtime before an app starts are escaped at that point in time, so we skip that here or it results in double escaping of values.
@dmikusa dmikusa merged commit 906044b into main May 5, 2021
@dmikusa dmikusa deleted the appd_escaping branch May 5, 2021 15:44
dmikusa pushed a commit that referenced this pull request Jun 11, 2021
PR #870 reversed the logic overriding the default_unique_host_name with
the application_name.  This results in problems with AppDynamics where
applications running on multiple foundations are unable to add metrics
when using the same application name in Cloud Foundry.

Really, application_name should never be used. unique_host_name is
by definition a unique identifier vs an application_name, which is not
guaranteed to be unique.

But this restores the previous logic, which was functional and may have
handled cases I am not aware of.
dmikusa pushed a commit that referenced this pull request Oct 12, 2021
…pDynamnics config

[Previous PRs escaped configuration values for AppD](#870). This was done to support things like names with spaces and other characters that, if used, would result in a broken start command.

The PR broke a use case which was documented for the node or tier name. In some cases, you may want to set the node or tier name to a dynamic value that is loaded at runtime so that you can incorporate things like the application instance index. For example `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`.

This new PR will use `Shellwords.escape(..)` on the value for all properties unless that property value contains what looks like a subshell `$(..)` or environment variable `${..}` reference. If it looks like a subshell or env variable is being referenced, we will not escape but just wrap the value in escaped quotes. We wrap it in escaped quotes in case the shell variable or subshell returns something which includes spaces. This is not perfect though, and you need to be careful if using subshell/env variables, you should ensure the output is properly escaped.

For example:
- `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`
- `$(echo 'Hello world!') and stuff` becomes `\"$(echo 'Hello world!') and stuff\"`
- `--> ${SOME_VAR} <--` becomes `\"--> ${SOME_VAR} <--\"`

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
dmikusa pushed a commit that referenced this pull request Oct 18, 2021
…pDynamnics config (#911)

[Previous PRs escaped configuration values for AppD](#870). This was done to support things like names with spaces and other characters that, if used, would result in a broken start command.

The PR broke a use case which was documented for the node or tier name. In some cases, you may want to set the node or tier name to a dynamic value that is loaded at runtime so that you can incorporate things like the application instance index. For example `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`.

This new PR will use `Shellwords.escape(..)` on the value for all properties unless that property value contains what looks like a subshell `$(..)` or environment variable `${..}` reference. If it looks like a subshell or env variable is being referenced, we will not escape but just wrap the value in escaped quotes. We wrap it in escaped quotes in case the shell variable or subshell returns something which includes spaces. This is not perfect though, and you need to be careful if using subshell/env variables, you should ensure the output is properly escaped.

For example:
- `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`
- `$(echo 'Hello world!') and stuff` becomes `\"$(echo 'Hello world!') and stuff\"`
- `--> ${SOME_VAR} <--` becomes `\"--> ${SOME_VAR} <--\"`

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
ramonskie pushed a commit that referenced this pull request Dec 4, 2025
Adjusts the way App Dynamics configuration properties are being escaped. They are passed into the JVM process via system properties, so the values require proper escaping or they can cause issues. 

This PR uses `Shellwords.escape` to perform the escaping of the configuration set at build time. Values that are selected at runtime before an app starts are escaped at that point in time (using `jq`'s `@sh`), so those are *not* escaped at build time otherwise it results in double escaping of those values (like seeing `'`'s in the app name).

This PR also updates the docs as the set of required properties for the App Dynamic agent have changed.
ramonskie pushed a commit that referenced this pull request Dec 4, 2025
PR #870 reversed the logic overriding the default_unique_host_name with
the application_name.  This results in problems with AppDynamics where
applications running on multiple foundations are unable to add metrics
when using the same application name in Cloud Foundry.

Really, application_name should never be used. unique_host_name is
by definition a unique identifier vs an application_name, which is not
guaranteed to be unique.

But this restores the previous logic, which was functional and may have
handled cases I am not aware of.
ramonskie pushed a commit that referenced this pull request Dec 4, 2025
…pDynamnics config (#911)

[Previous PRs escaped configuration values for AppD](#870). This was done to support things like names with spaces and other characters that, if used, would result in a broken start command.

The PR broke a use case which was documented for the node or tier name. In some cases, you may want to set the node or tier name to a dynamic value that is loaded at runtime so that you can incorporate things like the application instance index. For example `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`.

This new PR will use `Shellwords.escape(..)` on the value for all properties unless that property value contains what looks like a subshell `$(..)` or environment variable `${..}` reference. If it looks like a subshell or env variable is being referenced, we will not escape but just wrap the value in escaped quotes. We wrap it in escaped quotes in case the shell variable or subshell returns something which includes spaces. This is not perfect though, and you need to be careful if using subshell/env variables, you should ensure the output is properly escaped.

For example:
- `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`
- `$(echo 'Hello world!') and stuff` becomes `\"$(echo 'Hello world!') and stuff\"`
- `--> ${SOME_VAR} <--` becomes `\"--> ${SOME_VAR} <--\"`

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single quotes added to appd application name

1 participant