From f8a3a54df95d0da4448dc1f3ab371c6c2d9a3603 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Sun, 28 Apr 2024 17:31:13 +0530 Subject: [PATCH] chore: Use CS to get Appsmith server IP (#32998) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're currently relying on ipify.org for this, and this PR will move to using CS for this information. This is so that all external communication from the core of the product's backend, is only to cs.appsmith.com, which makes whitelisting easier for users. Also removing the unused variables `APPSMITH_CLOUD_SERVICES_USERNAME` and `APPSMITH_CLOUD_SERVICES_PASSWORD`. ⚠️ This will cause conflicts on sync. /ok-to-test tags="@tag.Sanity" > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 46576ca46adcba288693c3d5aaa9cc547c1e8f57 > Cypress dashboard url: Click here! ## Summary by CodeRabbit - **Refactor** - Removed username and password fields from cloud services configuration to enhance security. - Updated network utilities to initialize with new cloud services configuration, improving integration and functionality. - **Bug Fixes** - Adjusted the method of fetching and handling IP address data to improve reliability and accuracy of network services. - **Chores** - Updated application properties and deployment scripts to align with the new configuration and address retrieval methods. --- .../configurations/CloudServicesConfig.java | 6 ------ .../appsmith/server/helpers/NetworkUtils.java | 7 ++++++- .../server/helpers/ce/NetworkUtilsCE.java | 17 +++++++++-------- .../src/main/resources/application.properties | 2 -- deploy/docker/fs/opt/appsmith/entrypoint.sh | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/CloudServicesConfig.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/CloudServicesConfig.java index 71c89f21fa..28cf52700a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/CloudServicesConfig.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/CloudServicesConfig.java @@ -11,12 +11,6 @@ import org.springframework.context.annotation.Configuration; public class CloudServicesConfig { private String baseUrl; - @Value("${appsmith.cloud_services.username}") - private String username; - - @Value("${appsmith.cloud_services.password}") - private String password; - @Value("${appsmith.cloud_services.template_upload_auth_header}") private String templateUploadAuthHeader; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/NetworkUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/NetworkUtils.java index 263d78e018..052177b427 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/NetworkUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/NetworkUtils.java @@ -1,7 +1,12 @@ package com.appsmith.server.helpers; +import com.appsmith.server.configurations.CloudServicesConfig; import com.appsmith.server.helpers.ce.NetworkUtilsCE; import org.springframework.stereotype.Component; @Component -public class NetworkUtils extends NetworkUtilsCE {} +public class NetworkUtils extends NetworkUtilsCE { + public NetworkUtils(CloudServicesConfig cloudServicesConfig) { + super(cloudServicesConfig); + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/NetworkUtilsCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/NetworkUtilsCE.java index 5a044ea580..71b529bbe2 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/NetworkUtilsCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/NetworkUtilsCE.java @@ -1,23 +1,24 @@ package com.appsmith.server.helpers.ce; +import com.appsmith.server.configurations.CloudServicesConfig; +import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.util.WebClientUtils; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import reactor.core.publisher.Mono; -import java.net.URI; import java.time.Duration; @Slf4j +@RequiredArgsConstructor public class NetworkUtilsCE { - private static final URI GET_IP_URI = URI.create("https://api64.ipify.org"); + private final CloudServicesConfig cloudServicesConfig; protected static String cachedAddress = null; protected static final String FALLBACK_IP = "unknown"; - protected NetworkUtilsCE() {} - /** * This method hits an API endpoint that returns the external IP address of this server instance. * @@ -30,12 +31,12 @@ public class NetworkUtilsCE { return WebClientUtils.create() .get() - .uri(GET_IP_URI) + .uri(cloudServicesConfig.getBaseUrl() + "/api/v1/ip") .retrieve() - .bodyToMono(String.class) + .bodyToMono(ResponseDTO.class) .map(address -> { - cachedAddress = address; - return address; + cachedAddress = (String) address.getData(); + return cachedAddress; }) .timeout(Duration.ofSeconds(60)) .onErrorResume(throwable -> { diff --git a/app/server/appsmith-server/src/main/resources/application.properties b/app/server/appsmith-server/src/main/resources/application.properties index 15e2bb96e3..563add9229 100644 --- a/app/server/appsmith-server/src/main/resources/application.properties +++ b/app/server/appsmith-server/src/main/resources/application.properties @@ -83,8 +83,6 @@ emails.welcome.enabled = ${APPSMITH_EMAILS_WELCOME_ENABLED:true} # Appsmith Cloud Services appsmith.cloud_services.base_url = ${APPSMITH_CLOUD_SERVICES_BASE_URL:} appsmith.cloud_services.signature_base_url = ${APPSMITH_CLOUD_SERVICES_SIGNATURE_BASE_URL:} -appsmith.cloud_services.username = ${APPSMITH_CLOUD_SERVICES_USERNAME:} -appsmith.cloud_services.password = ${APPSMITH_CLOUD_SERVICES_PASSWORD:} appsmith.cloud_services.template_upload_auth_header = ${APPSMITH_CLOUD_SERVICES_TEMPLATE_UPLOAD_AUTH:} github_repo = ${APPSMITH_GITHUB_REPO:} diff --git a/deploy/docker/fs/opt/appsmith/entrypoint.sh b/deploy/docker/fs/opt/appsmith/entrypoint.sh index 3f30e7a522..e736883fa8 100644 --- a/deploy/docker/fs/opt/appsmith/entrypoint.sh +++ b/deploy/docker/fs/opt/appsmith/entrypoint.sh @@ -15,7 +15,7 @@ mkdir -pv "$SUPERVISORD_CONF_TARGET" "$WWW_PATH" # As we want derived props alongwith the ip address we are sharing the ip address in separate keys # https://help.mixpanel.com/hc/en-us/articles/360001355266-Event-Properties if [[ -n ${APPSMITH_SEGMENT_CE_KEY-} ]]; then - ip="$(curl -sS https://api64.ipify.org || echo unknown)" + ip="$(set -o pipefail; curl -sS https://cs.appsmith.com/api/v1/ip | grep -Eo '\d+(\.\d+){3}' || echo "unknown")" curl \ --user "$APPSMITH_SEGMENT_CE_KEY:" \ --header 'Content-Type: application/json' \