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

Restrict connectionString to app service only #3191

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private DiagnosticsHelper() {}
"APPLICATIONINSIGHTS_DIAGNOSTICS_OUTPUT_DIRECTORY";

// visible for testing
static volatile boolean useAppSvcRpIntegrationLogging;
public static volatile boolean useAppSvcRpIntegrationLogging;
private static volatile boolean useFunctionsRpIntegrationLogging;

private static volatile char rpIntegrationChar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,9 @@ static Configuration getConfigurationFromEnvVar(String json) {

Configuration configuration = getConfiguration(json, JsonOrigin.ENV_VAR);

if (configuration.connectionString != null) {
// restrict connection string in APPLICATIONINSIGHTS_CONFIGURATION_CONTENT for App Service only
if (configuration.connectionString != null
&& DiagnosticsHelper.useAppSvcRpIntegrationLogging()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that this method name looks like it's related to logging, i'll send a follow-up PR to rename

throw new ConfigurationException(
"\"connectionString\" attribute is not supported inside of "
+ APPLICATIONINSIGHTS_CONFIGURATION_CONTENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.DiagnosticsHelper;
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.JmxMetric;
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.MatchType;
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.PreviewConfiguration;
Expand Down Expand Up @@ -104,6 +105,7 @@ void shouldParseFromEnvVar() throws IOException {

@Test
void shouldThrowFromEnvVarIfEmbeddedConnectionString() {
DiagnosticsHelper.useAppSvcRpIntegrationLogging = true;
String contentJson =
"{\"connectionString\":\"InstrumentationKey=55555555-5555-5555-5555-555555555555\","
+ "\"role\":{\"name\":\"testrole\"}}";
Expand Down