From 19b95251da0b66224abbeda36cdaa77ae0672678 Mon Sep 17 00:00:00 2001 From: liuhy Date: Tue, 16 Jun 2026 11:45:36 +0800 Subject: [PATCH 1/2] Require trusted bootstrap nodes for websocket sync WebSocket sync currently exposes the full bootstrap data stream after an anonymous upgrade, including APP_AUTH records needed by gateway bootstrap. This change keeps the sync payload shape intact and moves the trust decision to the handshake by requiring a shared sync token from bootstrap clients. Admin validates the X-Shenyu-Sync-Token header before copying session attributes into the endpoint context. Bootstrap clients read the same token from shenyu.sync.websocket.token and send it with each WebSocket connection. The token is masked from WebsocketConfig.toString() so operational logging does not reveal the secret. Constraint: APP_AUTH.appSecret must remain in sync payloads because bootstrap sign-plugin behavior depends on it Rejected: Remove appSecret from APP_AUTH sync data | breaks bootstrap consumers that need the secret to verify signed requests Rejected: Require admin-user JWT on websocket upgrade | couples bootstrap nodes to user login/session token lifecycle Confidence: high Scope-risk: moderate Directive: Do not remove /websocket from the Shiro whitelist unless bootstrap has a non-user auth path through that filter Tested: ./mvnw -pl shenyu-admin,shenyu-sync-data-center/shenyu-sync-data-websocket -am -DfailIfNoTests=false -Dskip.checkstyle=true -DskipLicense=true -Dspotless.check.skip=true -Djacoco.skip=true -Dtest=WebsocketConfiguratorTest,WebsocketSyncPropertiesTest,WebsocketConfigTest test Tested: ./mvnw -pl shenyu-admin,shenyu-sync-data-center/shenyu-sync-data-websocket -am -DskipTests -DfailIfNoTests=false -DskipLicense=true -Dspotless.check.skip=true -Djacoco.skip=true package Tested: git diff --check Not-tested: End-to-end admin/bootstrap websocket connection with a live shared token --- .../properties/WebsocketSyncProperties.java | 23 ++++++ .../websocket/WebsocketConfigurator.java | 39 +++++++++ .../src/main/resources/application.yml | 1 + .../WebsocketSyncPropertiesTest.java | 2 + .../websocket/WebsocketConfiguratorTest.java | 41 ++++++++++ .../src/main/resources/application.yml | 1 + .../shenyu/common/constant/Constants.java | 5 ++ .../websocket/WebsocketSyncDataService.java | 80 ++++++------------- .../websocket/config/WebsocketConfig.java | 27 ++++++- .../websocket/config/WebsocketConfigTest.java | 11 ++- 10 files changed, 171 insertions(+), 59 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/WebsocketSyncProperties.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/WebsocketSyncProperties.java index e5b41302edb1..4dc730ddbd73 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/WebsocketSyncProperties.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/WebsocketSyncProperties.java @@ -40,6 +40,11 @@ public class WebsocketSyncProperties { */ private String allowOrigins; + /** + * WebSocket sync token. + */ + private String token; + /** * Gets the value of enabled. * @@ -91,4 +96,22 @@ public String getAllowOrigins() { public void setAllowOrigins(final String allowOrigins) { this.allowOrigins = allowOrigins; } + + /** + * get token. + * + * @return token + */ + public String getToken() { + return token; + } + + /** + * set token. + * + * @param token token + */ + public void setToken(final String token) { + this.token = token; + } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java index 2c020d6a4d7c..a4084443a5cc 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java @@ -26,6 +26,7 @@ import org.apache.shenyu.admin.config.properties.WebsocketSyncProperties; import org.apache.shenyu.admin.spring.SpringBeanUtils; import org.apache.shenyu.common.constant.Constants; +import org.apache.shenyu.common.exception.ShenyuException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,6 +34,13 @@ import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.context.annotation.Configuration; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; + import static org.apache.tomcat.websocket.server.Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM; import static org.apache.tomcat.websocket.server.Constants.TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM; @@ -52,6 +60,7 @@ public class WebsocketConfigurator extends ServerEndpointConfig.Configurator imp @Override public void modifyHandshake(final ServerEndpointConfig sec, final HandshakeRequest request, final HandshakeResponse response) { + checkSyncToken(request); HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(WebsocketListener.CLIENT_IP_NAME, httpSession.getAttribute(WebsocketListener.CLIENT_IP_NAME)); sec.getUserProperties().put(Constants.CLIENT_PORT_NAME, httpSession.getAttribute(Constants.CLIENT_PORT_NAME)); @@ -85,4 +94,34 @@ public void onStartup(final ServletContext servletContext) { String.valueOf(messageMaxSize)); } } + + private void checkSyncToken(final HandshakeRequest request) { + String configuredToken = websocketSyncProperties.getToken(); + if (StringUtils.isBlank(configuredToken)) { + throw new ShenyuException("websocket sync token is not configured"); + } + String requestToken = getHeader(request.getHeaders(), Constants.SHENYU_WEBSOCKET_SYNC_TOKEN); + if (StringUtils.isBlank(requestToken) || !isSameToken(configuredToken, requestToken)) { + throw new ShenyuException("websocket sync token is invalid"); + } + } + + private boolean isSameToken(final String configuredToken, final String requestToken) { + return MessageDigest.isEqual( + configuredToken.getBytes(StandardCharsets.UTF_8), + requestToken.getBytes(StandardCharsets.UTF_8)); + } + + private String getHeader(final Map> headers, final String name) { + return Optional.ofNullable(headers) + .orElse(Collections.emptyMap()) + .entrySet() + .stream() + .filter(entry -> StringUtils.equalsIgnoreCase(entry.getKey(), name)) + .map(Map.Entry::getValue) + .filter(values -> !values.isEmpty()) + .map(values -> values.get(0)) + .findFirst() + .orElse(null); + } } diff --git a/shenyu-admin/src/main/resources/application.yml b/shenyu-admin/src/main/resources/application.yml index 6d2c3af3bfe2..afcd9b94652e 100755 --- a/shenyu-admin/src/main/resources/application.yml +++ b/shenyu-admin/src/main/resources/application.yml @@ -70,6 +70,7 @@ shenyu: websocket: enabled: true messageMaxSize: 10240 + token: ${SHENYU_SYNC_WEBSOCKET_TOKEN:} allowOrigins: ws://localhost:9095;ws://localhost:9195; # apollo: # meta: http://localhost:8080 diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java index 14abcceaa176..e6b7f844b601 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java @@ -43,9 +43,11 @@ public void testWebsocketSyncPropertiesSetValue() { WebsocketSyncProperties websocketSyncProperties = getContext().getBean(WebsocketSyncProperties.class); websocketSyncProperties.setMessageMaxSize(0); websocketSyncProperties.setAllowOrigins("allowOrigins"); + websocketSyncProperties.setToken("token"); assertThat(websocketSyncProperties.isEnabled(), comparesEqualTo(false)); Assertions.assertEquals(websocketSyncProperties.getMessageMaxSize(), 0); Assertions.assertEquals(websocketSyncProperties.getAllowOrigins(), "allowOrigins"); + Assertions.assertEquals(websocketSyncProperties.getToken(), "token"); } @Configuration diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java index c802651e61c9..0ccbec9de73c 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java @@ -25,18 +25,22 @@ import org.apache.shenyu.admin.config.properties.WebsocketSyncProperties; import org.apache.shenyu.admin.spring.SpringBeanUtils; import org.apache.shenyu.common.constant.Constants; +import org.apache.shenyu.common.exception.ShenyuException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; import org.springframework.test.util.ReflectionTestUtils; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import static org.apache.tomcat.websocket.server.Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM; import static org.apache.tomcat.websocket.server.Constants.TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -64,11 +68,13 @@ void setUp() { @Test void testModifyHandshake() { + websocketSyncProperties.setToken("websocket-sync-token"); ServerEndpointConfig sec = mock(ServerEndpointConfig.class); Map userProperties = new HashMap<>(); when(sec.getUserProperties()).thenReturn(userProperties); HandshakeRequest request = mock(HandshakeRequest.class); + when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, List.of("websocket-sync-token"))); HttpSession httpSession = mock(HttpSession.class); when(request.getHttpSession()).thenReturn(httpSession); when(httpSession.getAttribute(WebsocketListener.CLIENT_IP_NAME)).thenReturn("192.168.1.1"); @@ -85,11 +91,13 @@ void testModifyHandshake() { @Test void testModifyHandshakePutsAllAttributes() { + websocketSyncProperties.setToken("websocket-sync-token"); ServerEndpointConfig sec = mock(ServerEndpointConfig.class); Map userProperties = new HashMap<>(); when(sec.getUserProperties()).thenReturn(userProperties); HandshakeRequest request = mock(HandshakeRequest.class); + when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, List.of("websocket-sync-token"))); HttpSession httpSession = mock(HttpSession.class); when(request.getHttpSession()).thenReturn(httpSession); @@ -104,6 +112,39 @@ void testModifyHandshakePutsAllAttributes() { assertTrue(userProperties.containsKey(Constants.SHENYU_NAMESPACE_ID)); } + @Test + void testModifyHandshakeRejectsMissingToken() { + websocketSyncProperties.setToken("websocket-sync-token"); + ServerEndpointConfig sec = mock(ServerEndpointConfig.class); + HandshakeRequest request = mock(HandshakeRequest.class); + when(request.getHeaders()).thenReturn(Collections.emptyMap()); + HandshakeResponse response = mock(HandshakeResponse.class); + + assertThrows(ShenyuException.class, () -> websocketConfigurator.modifyHandshake(sec, request, response)); + } + + @Test + void testModifyHandshakeRejectsInvalidToken() { + websocketSyncProperties.setToken("websocket-sync-token"); + ServerEndpointConfig sec = mock(ServerEndpointConfig.class); + HandshakeRequest request = mock(HandshakeRequest.class); + when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, List.of("invalid-token"))); + HandshakeResponse response = mock(HandshakeResponse.class); + + assertThrows(ShenyuException.class, () -> websocketConfigurator.modifyHandshake(sec, request, response)); + } + + @Test + void testModifyHandshakeRejectsBlankConfiguredToken() { + websocketSyncProperties.setToken(""); + ServerEndpointConfig sec = mock(ServerEndpointConfig.class); + HandshakeRequest request = mock(HandshakeRequest.class); + when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, List.of("websocket-sync-token"))); + HandshakeResponse response = mock(HandshakeResponse.class); + + assertThrows(ShenyuException.class, () -> websocketConfigurator.modifyHandshake(sec, request, response)); + } + @Test void testCheckOriginAllowedWhenAllowOriginsEmpty() { websocketSyncProperties.setAllowOrigins(""); diff --git a/shenyu-bootstrap/src/main/resources/application.yml b/shenyu-bootstrap/src/main/resources/application.yml index 9272726f6982..4c1df632a498 100644 --- a/shenyu-bootstrap/src/main/resources/application.yml +++ b/shenyu-bootstrap/src/main/resources/application.yml @@ -223,6 +223,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: ${SHENYU_SYNC_WEBSOCKET_TOKEN:} allowOrigin: ws://localhost:9195 # apollo: # appId: shenyu diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java index 5295c8552b8c..add65c494670 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java @@ -713,6 +713,11 @@ public interface Constants { */ String X_ACCESS_TOKEN = "X-Access-Token"; + /** + * X-Shenyu-Sync-Token. + */ + String SHENYU_WEBSOCKET_SYNC_TOKEN = "X-Shenyu-Sync-Token"; + /** * X-API-KEY; AI proxy key header. */ diff --git a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java index 4afa7de31908..96ad6ad6ad35 100644 --- a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java +++ b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java @@ -17,12 +17,12 @@ package org.apache.shenyu.plugin.sync.data.websocket; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.common.config.ShenyuConfig; +import org.apache.shenyu.common.constant.Constants; import org.apache.shenyu.common.enums.RunningModeEnum; import org.apache.shenyu.common.timer.AbstractRoundTask; import org.apache.shenyu.common.timer.Timer; @@ -41,6 +41,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties; import java.net.URI; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -119,34 +120,7 @@ public WebsocketSyncDataService( LOG.info("start init connecting..."); List urls = websocketConfig.getUrls(); for (String url : urls) { - if (StringUtils.isNotEmpty(websocketConfig.getAllowOrigin())) { - Map headers = - ImmutableMap.of(ORIGIN_HEADER_NAME, websocketConfig.getAllowOrigin()); - clients.add( - new ShenyuWebsocketClient( - URI.create(url), - headers, - Objects.requireNonNull(pluginDataSubscriber), - metaDataSubscribers, - authDataSubscribers, - proxySelectorDataSubscribers, - discoveryUpstreamDataSubscribers, - this.aiProxyApiKeyDataSubscribers, - namespaceId, - serverProperties.getPort())); - } else { - clients.add( - new ShenyuWebsocketClient( - URI.create(url), - Objects.requireNonNull(pluginDataSubscriber), - metaDataSubscribers, - authDataSubscribers, - proxySelectorDataSubscribers, - discoveryUpstreamDataSubscribers, - this.aiProxyApiKeyDataSubscribers, - namespaceId, - serverProperties.getPort())); - } + clients.add(createClient(url)); } LOG.info("start check task..."); this.timer.add(timerTask = new AbstractRoundTask(null, TimeUnit.SECONDS.toMillis(60)) { @@ -164,32 +138,7 @@ private void masterCheck() { if (CollectionUtils.isEmpty(clients)) { List urls = websocketConfig.getUrls(); for (String url : urls) { - if (StringUtils.isNotEmpty(websocketConfig.getAllowOrigin())) { - Map headers = - ImmutableMap.of(ORIGIN_HEADER_NAME, websocketConfig.getAllowOrigin()); - clients.add( - new ShenyuWebsocketClient( - URI.create(url), - headers, - Objects.requireNonNull(pluginDataSubscriber), - metaDataSubscribers, - authDataSubscribers, - proxySelectorDataSubscribers, - discoveryUpstreamDataSubscribers, - this.aiProxyApiKeyDataSubscribers, - namespaceId, serverProperties.getPort())); - } else { - clients.add( - new ShenyuWebsocketClient( - URI.create(url), - Objects.requireNonNull(pluginDataSubscriber), - metaDataSubscribers, - authDataSubscribers, - proxySelectorDataSubscribers, - discoveryUpstreamDataSubscribers, - this.aiProxyApiKeyDataSubscribers, - namespaceId, serverProperties.getPort())); - } + clients.add(createClient(url)); } } Iterator iterator = clients.iterator(); @@ -228,6 +177,27 @@ public void close() { } timer.shutdown(); } + + private ShenyuWebsocketClient createClient(final String url) { + Map headers = new HashMap<>(); + if (StringUtils.isNotEmpty(websocketConfig.getAllowOrigin())) { + headers.put(ORIGIN_HEADER_NAME, websocketConfig.getAllowOrigin()); + } + if (StringUtils.isNotBlank(websocketConfig.getToken())) { + headers.put(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, websocketConfig.getToken()); + } + return new ShenyuWebsocketClient( + URI.create(url), + headers, + Objects.requireNonNull(pluginDataSubscriber), + metaDataSubscribers, + authDataSubscribers, + proxySelectorDataSubscribers, + discoveryUpstreamDataSubscribers, + this.aiProxyApiKeyDataSubscribers, + namespaceId, + serverProperties.getPort()); + } /** * get websocket config. diff --git a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java index 10f0ba057360..9f0c54a0d5a0 100644 --- a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java +++ b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java @@ -33,6 +33,11 @@ public class WebsocketConfig { */ private String allowOrigin; + /** + * WebSocket sync token. + */ + private String token; + /** * get urls. * @@ -66,6 +71,22 @@ public String getAllowOrigin() { public void setAllowOrigin(final String allowOrigin) { this.allowOrigin = allowOrigin; } + + /** + * get token. + * @return token + */ + public String getToken() { + return token; + } + + /** + * set token. + * @param token token + */ + public void setToken(final String token) { + this.token = token; + } @Override public boolean equals(final Object o) { @@ -77,12 +98,13 @@ public boolean equals(final Object o) { } WebsocketConfig that = (WebsocketConfig) o; return Objects.equals(urls, that.urls) - && Objects.equals(allowOrigin, that.allowOrigin); + && Objects.equals(allowOrigin, that.allowOrigin) + && Objects.equals(token, that.token); } @Override public int hashCode() { - return Objects.hash(urls, allowOrigin); + return Objects.hash(urls, allowOrigin, token); } @Override @@ -92,6 +114,7 @@ public String toString() { + urls + ", allowOrigin='" + allowOrigin + + ", token='******" + '}'; } } diff --git a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java index 713ccce5561a..b1101baf162b 100644 --- a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java +++ b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java @@ -25,6 +25,7 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; /** @@ -36,6 +37,8 @@ public class WebsocketConfigTest { private static final String ALLOW_ORIGIN = "ws://localhost:9095"; + private static final String TOKEN = "websocket-sync-token"; + private WebsocketConfig websocketConfig; @BeforeEach @@ -43,12 +46,14 @@ public void setUp() { websocketConfig = new WebsocketConfig(); websocketConfig.setUrls(URLS); websocketConfig.setAllowOrigin(ALLOW_ORIGIN); + websocketConfig.setToken(TOKEN); } @Test public void testGetterSetter() { assertEquals(URLS, websocketConfig.getUrls()); assertEquals(ALLOW_ORIGIN, websocketConfig.getAllowOrigin()); + assertEquals(TOKEN, websocketConfig.getToken()); } @Test @@ -56,6 +61,7 @@ public void testEquals() { WebsocketConfig that = new WebsocketConfig(); that.setUrls(URLS); that.setAllowOrigin(ALLOW_ORIGIN); + that.setToken(TOKEN); assertEquals(websocketConfig, websocketConfig); assertEquals(websocketConfig, that); assertNotEquals(websocketConfig, null); @@ -64,13 +70,14 @@ public void testEquals() { @Test public void testHashCode() { - assertEquals(Objects.hash(websocketConfig.getUrls(), websocketConfig.getAllowOrigin()), websocketConfig.hashCode()); + assertEquals(Objects.hash(websocketConfig.getUrls(), websocketConfig.getAllowOrigin(), websocketConfig.getToken()), websocketConfig.hashCode()); } @Test public void testToString() { - String toString = "WebsocketConfig{urls='%s, allowOrigin='%s}"; + String toString = "WebsocketConfig{urls='%s, allowOrigin='%s, token='******}"; String expected = String.format(toString, URLS, ALLOW_ORIGIN); assertEquals(expected, websocketConfig.toString()); + assertFalse(websocketConfig.toString().contains(TOKEN)); } } From 6df09618e44a0f5024133f175f50ee11d60294bf Mon Sep 17 00:00:00 2001 From: liuhy Date: Tue, 16 Jun 2026 12:54:15 +0800 Subject: [PATCH 2/2] Keep websocket sync auth usable in test runtimes Websocket endpoint configurators can be created by the JSR-356 container outside Spring autowiring, so handshake auth now resolves sync properties through the same SpringBeanUtils fallback already used by origin checks. The test and e2e runtimes also configure the same sync token on both admin and bootstrap sides so the new mandatory handshake token does not break CI scenarios. Constraint: WebSocket handshake configurator instances are not guaranteed to be Spring-autowired. Constraint: The token is mandatory when websocket sync is enabled, so test runtimes must configure both admin and bootstrap. Rejected: Make admin accept blank tokens in test runtimes | would weaken the security behavior being added by the PR. Confidence: high Scope-risk: moderate Directive: Keep admin and bootstrap websocket sync token values paired in compose, k8s, and local integration-test resources. Tested: ./mvnw -pl shenyu-admin,shenyu-sync-data-center/shenyu-sync-data-websocket -am -DfailIfNoTests=false -Dskip.checkstyle=true -DskipLicense=true -Dspotless.check.skip=true -Djacoco.skip=true -Dtest=WebsocketConfiguratorTest,WebsocketConfigTest test Tested: ../mvnw -pl shenyu-integrated-test-sdk-http -am -DskipTests -DfailIfNoTests=false -Dskip.checkstyle=true -DskipLicense=true -Dspotless.check.skip=true -Djacoco.skip=true package (from shenyu-integrated-test/) Tested: docker compose config for shenyu-integrated-test-sdk-http and shenyu-sync-websocket compose files Tested: ruby YAML parse for representative e2e k8s config files Tested: git diff --check Not-tested: Full Docker e2e/IT containers locally --- .../websocket/WebsocketConfigurator.java | 13 ++++++--- .../websocket/WebsocketConfiguratorTest.java | 28 ++++++++++++++++--- .../shenyu/common/constant/Constants.java | 2 +- .../compose/storage/shenyu-storage-h2.yml | 2 ++ .../compose/storage/shenyu-storage-mysql.yml | 2 ++ .../storage/shenyu-storage-opengauss.yml | 2 ++ .../storage/shenyu-storage-postgres.yml | 2 ++ .../shenyu-sync-websocket-cluster-jdbc.yml | 3 ++ ...henyu-sync-websocket-cluster-zookeeper.yml | 3 ++ .../sync/shenyu-sync-websocket-eureka.yml | 2 ++ .../compose/sync/shenyu-sync-websocket.yml | 2 ++ .../shenyu-e2e-case/k8s/sync/shenyu-cm.yml | 2 ++ .../docker-compose.yml | 2 ++ .../k8s/shenyu-cluster-jdbc.yml | 6 ++++ .../k8s/shenyu-cluster-zookeeper.yml | 6 ++++ .../k8s/shenyu-cm.yml | 2 ++ .../k8s/shenyu-deployment-h2.yml | 2 ++ .../k8s/shenyu-deployment-mysql.yml | 2 ++ .../k8s/shenyu-deployment-opengauss.yml | 2 ++ .../k8s/shenyu-deployment-postgres.yml | 2 ++ .../docker-compose.yml | 2 ++ .../src/main/resources/application-local.yml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application-local.yml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application-local.yml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application.yml | 1 + .../docker-compose.yml | 1 + .../src/main/resources/application.yml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application-local.yml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application.yml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application.yml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application-local.yml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application-local.yml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application.yaml | 1 + .../docker-compose.yml | 2 ++ .../src/main/resources/application-local.yml | 1 + .../websocket/WebsocketSyncDataService.java | 2 +- .../websocket/config/WebsocketConfig.java | 4 ++- .../websocket/config/WebsocketConfigTest.java | 2 +- 47 files changed, 118 insertions(+), 12 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java index a4084443a5cc..3dc33711da43 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java @@ -70,7 +70,7 @@ public void modifyHandshake(final ServerEndpointConfig sec, final HandshakeReque @Override public boolean checkOrigin(final String originHeaderValue) { - final WebsocketSyncProperties bean = SpringBeanUtils.getInstance().getBean(WebsocketSyncProperties.class); + final WebsocketSyncProperties bean = getWebsocketSyncProperties(); if (StringUtils.isNotEmpty(bean.getAllowOrigins())) { String[] split = StringUtils.split(bean.getAllowOrigins(), ";"); for (String configAllow : split) { @@ -86,7 +86,7 @@ public boolean checkOrigin(final String originHeaderValue) { @Override public void onStartup(final ServletContext servletContext) { - int messageMaxSize = websocketSyncProperties.getMessageMaxSize(); + int messageMaxSize = getWebsocketSyncProperties().getMessageMaxSize(); if (messageMaxSize > 0) { servletContext.setInitParameter(TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM, String.valueOf(messageMaxSize)); @@ -96,16 +96,21 @@ public void onStartup(final ServletContext servletContext) { } private void checkSyncToken(final HandshakeRequest request) { - String configuredToken = websocketSyncProperties.getToken(); + String configuredToken = getWebsocketSyncProperties().getToken(); if (StringUtils.isBlank(configuredToken)) { throw new ShenyuException("websocket sync token is not configured"); } - String requestToken = getHeader(request.getHeaders(), Constants.SHENYU_WEBSOCKET_SYNC_TOKEN); + String requestToken = getHeader(request.getHeaders(), Constants.X_SHENYU_SYNC_TOKEN); if (StringUtils.isBlank(requestToken) || !isSameToken(configuredToken, requestToken)) { throw new ShenyuException("websocket sync token is invalid"); } } + private WebsocketSyncProperties getWebsocketSyncProperties() { + return Optional.ofNullable(websocketSyncProperties) + .orElseGet(() -> SpringBeanUtils.getInstance().getBean(WebsocketSyncProperties.class)); + } + private boolean isSameToken(final String configuredToken, final String requestToken) { return MessageDigest.isEqual( configuredToken.getBytes(StandardCharsets.UTF_8), diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java index 0ccbec9de73c..ddcc7262ab44 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java @@ -74,7 +74,7 @@ void testModifyHandshake() { when(sec.getUserProperties()).thenReturn(userProperties); HandshakeRequest request = mock(HandshakeRequest.class); - when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, List.of("websocket-sync-token"))); + when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN, List.of("websocket-sync-token"))); HttpSession httpSession = mock(HttpSession.class); when(request.getHttpSession()).thenReturn(httpSession); when(httpSession.getAttribute(WebsocketListener.CLIENT_IP_NAME)).thenReturn("192.168.1.1"); @@ -97,7 +97,7 @@ void testModifyHandshakePutsAllAttributes() { when(sec.getUserProperties()).thenReturn(userProperties); HandshakeRequest request = mock(HandshakeRequest.class); - when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, List.of("websocket-sync-token"))); + when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN, List.of("websocket-sync-token"))); HttpSession httpSession = mock(HttpSession.class); when(request.getHttpSession()).thenReturn(httpSession); @@ -112,6 +112,26 @@ void testModifyHandshakePutsAllAttributes() { assertTrue(userProperties.containsKey(Constants.SHENYU_NAMESPACE_ID)); } + @Test + void testModifyHandshakeUsesSpringBeanWhenConfiguratorIsNotAutowired() { + websocketSyncProperties.setToken("websocket-sync-token"); + ReflectionTestUtils.setField(websocketConfigurator, "websocketSyncProperties", null); + ServerEndpointConfig sec = mock(ServerEndpointConfig.class); + Map userProperties = new HashMap<>(); + when(sec.getUserProperties()).thenReturn(userProperties); + + HandshakeRequest request = mock(HandshakeRequest.class); + when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN, List.of("websocket-sync-token"))); + when(request.getHttpSession()).thenReturn(mock(HttpSession.class)); + + HandshakeResponse response = mock(HandshakeResponse.class); + websocketConfigurator.modifyHandshake(sec, request, response); + + assertTrue(userProperties.containsKey(WebsocketListener.CLIENT_IP_NAME)); + assertTrue(userProperties.containsKey(Constants.CLIENT_PORT_NAME)); + assertTrue(userProperties.containsKey(Constants.SHENYU_NAMESPACE_ID)); + } + @Test void testModifyHandshakeRejectsMissingToken() { websocketSyncProperties.setToken("websocket-sync-token"); @@ -128,7 +148,7 @@ void testModifyHandshakeRejectsInvalidToken() { websocketSyncProperties.setToken("websocket-sync-token"); ServerEndpointConfig sec = mock(ServerEndpointConfig.class); HandshakeRequest request = mock(HandshakeRequest.class); - when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, List.of("invalid-token"))); + when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN, List.of("invalid-token"))); HandshakeResponse response = mock(HandshakeResponse.class); assertThrows(ShenyuException.class, () -> websocketConfigurator.modifyHandshake(sec, request, response)); @@ -139,7 +159,7 @@ void testModifyHandshakeRejectsBlankConfiguredToken() { websocketSyncProperties.setToken(""); ServerEndpointConfig sec = mock(ServerEndpointConfig.class); HandshakeRequest request = mock(HandshakeRequest.class); - when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, List.of("websocket-sync-token"))); + when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN, List.of("websocket-sync-token"))); HandshakeResponse response = mock(HandshakeResponse.class); assertThrows(ShenyuException.class, () -> websocketConfigurator.modifyHandshake(sec, request, response)); diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java index add65c494670..c852bfe5a919 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java @@ -716,7 +716,7 @@ public interface Constants { /** * X-Shenyu-Sync-Token. */ - String SHENYU_WEBSOCKET_SYNC_TOKEN = "X-Shenyu-Sync-Token"; + String X_SHENYU_SYNC_TOKEN = "X-Shenyu-Sync-Token"; /** * X-API-KEY; AI proxy key header. diff --git a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml index 463820317e34..a54b97b9d021 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml @@ -31,6 +31,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -51,6 +52,7 @@ services: environment: - TZ=Asia/Beijing - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.sync.websocket.allowOrigin=ws://localhost:9195 healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ] diff --git a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml index 6f797f25300c..e909e9dce48c 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml @@ -63,6 +63,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -86,6 +87,7 @@ services: environment: - TZ=Asia/Beijing - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.sync.websocket.allowOrigin=ws://localhost:9195 healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ] diff --git a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml index 9859e92fb11a..4407a85e5cb8 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml @@ -62,6 +62,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/opengauss/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -85,6 +86,7 @@ services: environment: - TZ=Asia/Beijing - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.sync.websocket.allowOrigin=ws://localhost:9195 healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ] diff --git a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml index 956e07258d9b..884e36b6fb1d 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml @@ -62,6 +62,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/postgres/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -85,6 +86,7 @@ services: environment: - TZ=Asia/Beijing - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.sync.websocket.allowOrigin=ws://localhost:9195 healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ] diff --git a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml index e80b56f6b56b..506018034598 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml @@ -64,6 +64,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -96,6 +97,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -119,6 +121,7 @@ services: environment: - TZ=Asia/Beijing - shenyu.sync.websocket.urls=ws://shenyu-admin-1:9095/websocket,ws://shenyu-admin-2:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.sync.websocket.allowOrigin=ws://localhost:9195 healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ] diff --git a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml index 438371f8ad86..d73aeb9e5e20 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml @@ -83,6 +83,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -119,6 +120,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -144,6 +146,7 @@ services: environment: - TZ=Asia/Beijing - shenyu.sync.websocket.urls=ws://shenyu-admin-1:9095/websocket,ws://shenyu-admin-2:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.sync.websocket.allowOrigin=ws://localhost:9195 healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ] diff --git a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-eureka.yml b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-eureka.yml index f2e00ac65f14..44a15873edad 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-eureka.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-eureka.yml @@ -63,6 +63,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -86,6 +87,7 @@ services: environment: - TZ=Asia/Beijing - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.sync.websocket.allowOrigin=ws://localhost:9195 - spring.cloud.discovery.enabled=true - eureka.client.enabled=true diff --git a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket.yml b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket.yml index 6982c110f7c1..1da2a18e7e57 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket.yml @@ -63,6 +63,7 @@ services: - shenyu.sync.websocket.enabled=true - shenyu.sync.websocket.messageMaxSize=10240 - shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195; + - shenyu.sync.websocket.token=shenyu-sync-token volumes: - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib healthcheck: @@ -86,6 +87,7 @@ services: environment: - TZ=Asia/Beijing - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.sync.websocket.allowOrigin=ws://localhost:9195 healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ] diff --git a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml index 69c469256e10..275a4d2824a7 100644 --- a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml +++ b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml @@ -480,6 +480,7 @@ data: enabled: true messageMaxSize: 10240 allowOrigins: ws://localhost:9095;ws://localhost:9195; + token: shenyu-sync-token application-admin-sync-http.yml: | shenyu: @@ -521,6 +522,7 @@ data: sync: websocket: urls: ws://shenyu-admin:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 application-bootstrap-sync-http.yml: | diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/docker-compose.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/docker-compose.yml index 125b3c7a0446..b6dbb438b130 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/docker-compose.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/docker-compose.yml @@ -26,6 +26,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -68,6 +69,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-admin: condition: service_healthy diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-jdbc.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-jdbc.yml index 25e3468fdfdb..fd74744516d2 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-jdbc.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-jdbc.yml @@ -47,6 +47,8 @@ spec: value: "true" - name: shenyu.sync.websocket.allowOrigins value: ws://localhost:9095;ws://localhost:9195; + - name: shenyu.sync.websocket.token + value: shenyu-sync-token - name: spring.datasource.username value: root - name: spring.datasource.password @@ -116,6 +118,8 @@ spec: value: "true" - name: shenyu.sync.websocket.allowOrigins value: ws://localhost:9096;ws://localhost:9195; + - name: shenyu.sync.websocket.token + value: shenyu-sync-token - name: spring.datasource.username value: root - name: spring.datasource.password @@ -178,6 +182,8 @@ spec: env: - name: shenyu.sync.websocket.urls value: ws://shenyu-admin-master:9095/websocket,ws://shenyu-admin-slave:9096/websocket + - name: shenyu.sync.websocket.token + value: shenyu-sync-token ports: - containerPort: 9195 livenessProbe: diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-zookeeper.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-zookeeper.yml index bb7f4a451044..01843417559a 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-zookeeper.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-zookeeper.yml @@ -46,6 +46,8 @@ spec: value: "true" - name: shenyu.sync.websocket.allowOrigins value: ws://localhost:9095;ws://localhost:9195; + - name: shenyu.sync.websocket.token + value: shenyu-sync-token - name: shenyu.cluster.type value: "zookeeper" - name: shenyu.cluster.zookeeper.url @@ -119,6 +121,8 @@ spec: value: "true" - name: shenyu.sync.websocket.allowOrigins value: ws://localhost:9096;ws://localhost:9195; + - name: shenyu.sync.websocket.token + value: shenyu-sync-token - name: shenyu.cluster.type value: "zookeeper" - name: shenyu.cluster.zookeeper.url @@ -185,6 +189,8 @@ spec: env: - name: shenyu.sync.websocket.urls value: ws://shenyu-admin-master:9095/websocket,ws://shenyu-admin-slave:9096/websocket + - name: shenyu.sync.websocket.token + value: shenyu-sync-token ports: - containerPort: 9195 livenessProbe: diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml index 4211981aa2f0..9cde385a082d 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml @@ -448,6 +448,7 @@ data: enabled: true messageMaxSize: 10240 allowOrigins: ws://localhost:9095;ws://localhost:9195; + token: shenyu-sync-token application-admin-sync-http.yml: | shenyu: @@ -489,6 +490,7 @@ data: sync: websocket: urls: ws://shenyu-admin:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 application-bootstrap-sync-http.yml: | diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-h2.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-h2.yml index 9791bd1c0e1b..bc1d163efc5c 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-h2.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-h2.yml @@ -97,6 +97,8 @@ spec: env: - name: shenyu.sync.websocket.urls value: ws://shenyu-admin-h2:9095/websocket + - name: shenyu.sync.websocket.token + value: shenyu-sync-token ports: - containerPort: 9195 imagePullPolicy: IfNotPresent diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-mysql.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-mysql.yml index 57f64e828648..034a18931f0e 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-mysql.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-mysql.yml @@ -102,6 +102,8 @@ spec: env: - name: shenyu.sync.websocket.urls value: ws://shenyu-admin-mysql:9095/websocket + - name: shenyu.sync.websocket.token + value: shenyu-sync-token ports: - containerPort: 9195 livenessProbe: diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-opengauss.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-opengauss.yml index 3c2b9371a2c9..c50d64c71af2 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-opengauss.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-opengauss.yml @@ -99,6 +99,8 @@ spec: env: - name: shenyu.sync.websocket.urls value: ws://shenyu-admin-opengauss:9095/websocket + - name: shenyu.sync.websocket.token + value: shenyu-sync-token ports: - containerPort: 9195 livenessProbe: diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-postgres.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-postgres.yml index b168085d0c51..f5dbf68428ce 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-postgres.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-postgres.yml @@ -99,6 +99,8 @@ spec: env: - name: shenyu.sync.websocket.urls value: ws://shenyu-admin-postgres:9095/websocket + - name: shenyu.sync.websocket.token + value: shenyu-sync-token ports: - containerPort: 9195 livenessProbe: diff --git a/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/docker-compose.yml index f4f32f1a37d1..76a0a32c6a83 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/docker-compose.yml @@ -34,6 +34,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -76,6 +77,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-admin: condition: service_healthy diff --git a/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/src/main/resources/application-local.yml b/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/src/main/resources/application-local.yml index 8c4167785148..5f4df44ced67 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/src/main/resources/application-local.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/src/main/resources/application-local.yml @@ -36,6 +36,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-combination/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-combination/docker-compose.yml index 0e55c199a90c..fb4b4a8ea056 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-combination/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-combination/docker-compose.yml @@ -150,6 +150,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -166,6 +167,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-zk: condition: service_healthy diff --git a/shenyu-integrated-test/shenyu-integrated-test-combination/src/main/resources/application-local.yml b/shenyu-integrated-test/shenyu-integrated-test-combination/src/main/resources/application-local.yml index 8c4167785148..5f4df44ced67 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-combination/src/main/resources/application-local.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-combination/src/main/resources/application-local.yml @@ -36,6 +36,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-grpc/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-grpc/docker-compose.yml index aee2e037fffd..01b4bf18c4d7 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-grpc/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-grpc/docker-compose.yml @@ -25,6 +25,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -66,6 +67,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-admin: condition: service_healthy diff --git a/shenyu-integrated-test/shenyu-integrated-test-grpc/src/main/resources/application-local.yml b/shenyu-integrated-test/shenyu-integrated-test-grpc/src/main/resources/application-local.yml index 945b939961ca..a479f34dfda0 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-grpc/src/main/resources/application-local.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-grpc/src/main/resources/application-local.yml @@ -52,6 +52,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml index 7faa567123d9..0e001d67c24b 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml @@ -66,6 +66,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -82,6 +83,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-admin: condition: service_healthy diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml index a31615a32945..a7fbeb0ac83f 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml @@ -52,6 +52,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 # zookeeper: # url: localhost:2181 diff --git a/shenyu-integrated-test/shenyu-integrated-test-https/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-https/docker-compose.yml index 8da015aecdcc..1950b8bbc0b5 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-https/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-https/docker-compose.yml @@ -25,6 +25,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1" ] diff --git a/shenyu-integrated-test/shenyu-integrated-test-https/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-https/src/main/resources/application.yml index cfb3f24bfc86..3b1695efa58b 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-https/src/main/resources/application.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-https/src/main/resources/application.yml @@ -45,6 +45,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-rewrite/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-rewrite/docker-compose.yml index 02394a5fb846..e2591f3cabad 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-rewrite/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-rewrite/docker-compose.yml @@ -100,6 +100,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -116,6 +117,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-zk: condition: service_healthy diff --git a/shenyu-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application-local.yml b/shenyu-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application-local.yml index 8c4167785148..5f4df44ced67 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application-local.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application-local.yml @@ -36,6 +36,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/docker-compose.yml index bcb1ce255e4b..962fde218757 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/docker-compose.yml @@ -34,6 +34,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -93,6 +94,7 @@ services: environment: - dubbo.registry.address=zookeeper://shenyu-zk:2181 - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-admin: condition: service_healthy diff --git a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml index 031a7d8eef2a..225d1793b835 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml @@ -92,6 +92,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/docker-compose.yml index 45ea7d2639dd..3e7179183380 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/docker-compose.yml @@ -37,6 +37,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -103,6 +104,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.register.registerType=zookeeper - shenyu.register.serverLists=shenyu-zk:2181 depends_on: diff --git a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml index ea8e73bba623..27100bbc125e 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml @@ -92,6 +92,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-sofa/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-sofa/docker-compose.yml index f8b736a07b73..3dfffdc35d0b 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sofa/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-sofa/docker-compose.yml @@ -37,6 +37,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -79,6 +80,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-admin: condition: service_healthy diff --git a/shenyu-integrated-test/shenyu-integrated-test-sofa/src/main/resources/application-local.yml b/shenyu-integrated-test/shenyu-integrated-test-sofa/src/main/resources/application-local.yml index c74a79c76d83..e7c33aa98b7a 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sofa/src/main/resources/application-local.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-sofa/src/main/resources/application-local.yml @@ -36,6 +36,7 @@ shenyu: sync: websocket: urls: ws://shenyu-admin:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml index 6259f995f246..d79e1f852c9a 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml @@ -25,6 +25,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1" ] @@ -87,6 +88,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token - eureka.client.serviceUrl.defaultZone=http://shenyu-examples-eureka:8761/eureka/ depends_on: shenyu-admin: diff --git a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/application-local.yml b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/application-local.yml index 342277a65422..9344bbc56b47 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/application-local.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/application-local.yml @@ -48,6 +48,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/docker-compose.yml index 5f44f3dd1b4d..2280adb31332 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/docker-compose.yml @@ -25,6 +25,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: [ "CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1" ] @@ -42,6 +43,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-admin: condition: service_healthy diff --git a/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/shenyu-integrated-test-upload-plugin-case/src/main/resources/application.yaml b/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/shenyu-integrated-test-upload-plugin-case/src/main/resources/application.yaml index 27963a376431..2dbd8310288c 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/shenyu-integrated-test-upload-plugin-case/src/main/resources/application.yaml +++ b/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/shenyu-integrated-test-upload-plugin-case/src/main/resources/application.yaml @@ -36,6 +36,7 @@ shenyu: sync: websocket: urls: ws://localhost:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-websocket/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-websocket/docker-compose.yml index d3468dee0ef9..6f1585d2cdd7 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-websocket/docker-compose.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-websocket/docker-compose.yml @@ -26,6 +26,7 @@ services: - "9095:9095" environment: - SPRING_PROFILES_ACTIVE=h2 + - shenyu.sync.websocket.token=shenyu-sync-token - shenyu.database.init_script=sql-script/h2/schema.sql healthcheck: test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"] @@ -67,6 +68,7 @@ services: memory: 2048M environment: - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket + - shenyu.sync.websocket.token=shenyu-sync-token depends_on: shenyu-admin: condition: service_healthy diff --git a/shenyu-integrated-test/shenyu-integrated-test-websocket/src/main/resources/application-local.yml b/shenyu-integrated-test/shenyu-integrated-test-websocket/src/main/resources/application-local.yml index d61c6fe3e9da..b3f60e7348f9 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-websocket/src/main/resources/application-local.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-websocket/src/main/resources/application-local.yml @@ -36,6 +36,7 @@ shenyu: sync: websocket: urls: ws://shenyu-admin:9095/websocket + token: shenyu-sync-token allowOrigin: ws://localhost:9195 exclude: enabled: true diff --git a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java index 96ad6ad6ad35..c85fa83a3574 100644 --- a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java +++ b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java @@ -184,7 +184,7 @@ private ShenyuWebsocketClient createClient(final String url) { headers.put(ORIGIN_HEADER_NAME, websocketConfig.getAllowOrigin()); } if (StringUtils.isNotBlank(websocketConfig.getToken())) { - headers.put(Constants.SHENYU_WEBSOCKET_SYNC_TOKEN, websocketConfig.getToken()); + headers.put(Constants.X_SHENYU_SYNC_TOKEN, websocketConfig.getToken()); } return new ShenyuWebsocketClient( URI.create(url), diff --git a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java index 9f0c54a0d5a0..602dc5f23bcc 100644 --- a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java +++ b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java @@ -112,9 +112,11 @@ public String toString() { return "WebsocketConfig{" + "urls='" + urls + + '\'' + ", allowOrigin='" + allowOrigin - + ", token='******" + + '\'' + + ", token='******'" + '}'; } } diff --git a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java index b1101baf162b..c5f9bf2782af 100644 --- a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java +++ b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java @@ -75,7 +75,7 @@ public void testHashCode() { @Test public void testToString() { - String toString = "WebsocketConfig{urls='%s, allowOrigin='%s, token='******}"; + String toString = "WebsocketConfig{urls='%s', allowOrigin='%s', token='******'}"; String expected = String.format(toString, URLS, ALLOW_ORIGIN); assertEquals(expected, websocketConfig.toString()); assertFalse(websocketConfig.toString().contains(TOKEN));