问题标签 [spring-cloud-gateway]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
2836 浏览

spring-boot-actuator - spring cloud gateway,你能排除路径吗(做一个全局的!=)

我希望有人可以在这里提供一些想法。我正在玩一些用于 spring 云网关的示例应用程序并浏览文档,但我没有看到任何路由到自我或进行全局忽略的方法。这里的想法是,有些路径总是需要指向自身,例如执行器,而其他路径可能需要全局阻止(可能出于安全原因,例如您发现了严重的漏洞并需要禁用对具体资源)。现在据我所知,没有办法做到这一点,但我希望我错了!

我已经设置了应用程序,执行器在端口 8081 上运行,服务器在 8080 上运行。我有两个简单的规则:

但是通用 /** 确保对 localhost:8081/actuator/* 的任何调用也被路由到 uri。如何从路由规则中免除管理端口,以便服务器本身处理请求?

我认为像 - Path!=${management.server.port}/* 这样的默认过滤器可能会起作用,但似乎 != 不受支持。

0 投票
0 回答
427 浏览

spring-cloud - 如何spring cloud gateway自定义FilterFactory设置响应体

如何获取 spring cloud gateway 自定义 FilterFactory 设置体响应,我创建了一个自定义过滤器 extends AbstractGatewayFilterFactory 。但我不知道我是如何得到失败响应的请帮助这里是我的片段

0 投票
0 回答
656 浏览

spring-cloud-gateway - 在 Spring Cloud Gateway 中启用 CSRF

我想启用 CSRF 是 Spring Cloud Gateway。这是一个好习惯吗?如果是,可以使用 Spring Security 完成吗?

0 投票
1 回答
6120 浏览

spring-cloud-sleuth - 如何配置 spring-cloud-gateway 以使用 sleuth 记录请求/响应正文

我希望开发一个基于 spring-cloud-gateway:2.0.2-RELEASE 的网关服务器,并希望利用 sleuth 进行日志记录。自从我写入日志以来,我一直在运行 sleuth,我看到了 Sleuth 详细信息(跨度 ID 等),但我希望看到自动记录的消息正文。我需要做些什么来让 Sleuth 使用 Spring-Cloud-Gateway 开箱即用地记录请求/响应吗?

这是到达我的下游服务的请求标头

网关服务中的 Gradle 文件..

最后是网关服务的 application.yml 文件...

0 投票
1 回答
7388 浏览

spring-cloud-gateway - Spring Cloud Gateway 动态路由

Spring Cloud Gateway 真的很新——但它“似乎”很容易。我真的很苦恼的一个问题。我的要求是为路径添加前缀,检查标头变量,根据该变量查找 URI,然后再进行检查。

问题是 uri 始终是下面的 DEFAULT_IMPLEMENTION,即使我在 idResolvingGatewayFilter 中更改了它。我怎样才能做到这一点?可以随时添加新的 id - 这就是“动态”部分。因此,在网关过滤器中,我正在读取标题并查找 uri(我正在查看的数据源可以随时更新)。但是下面的代码似乎覆盖了我在过滤器中分配的任何内容 - 如果不提​​供 URI,您将无法执行此操作。例如:

header-id=123
uri= http://www.somedestination.com/something/services/v1.0

header-id=999
uri= http://www.anotherdestination.com/something/services/v1.0

在 idResolvingGatewatFilter 中,我正在进行更改(并且日志语句看起来很正确......它只是不去那里!

0 投票
0 回答
133 浏览

spring-cloud - 是否可以使用 Spring Cloud Gateway 进行威胁防护?

我将使用 Spring Cloud Gateway ( https://cloud.spring.io/spring-cloud-gateway/ ) 实现 API Gateway。是否可以设置任何规则来防止:

SQL 注入、XML 威胁防护 JSON 威胁防护 我发现只有外部解决方案(API 网关)支持它:(

之前我一直在寻找 Netflix Zull 解决方案(Is it possible to use Spring API Gateway for threat protection?),但我切换到了 Spring Cloud Gateway。

0 投票
1 回答
859 浏览

spring-cloud-gateway - Spring Cloud Gateway - RedisRateLimiter - 如何指向除 localhost 之外的其他 Redis?

我正在使用 Spring Cloud Gateway 为我的项目创建一个服务网关。目前,我正在尝试为我的一个 API 做 rateLimiting。我尝试了 github 上提供的几个使用 RedisRateLimiter 的示例。我对每个请求都有以下异常-

2018-11-01 21:33:39.321 错误 15568 --- [parallel-2] oscgfratelimit.RedisRateLimiter:确定用户是否允许从 redis org.springframework.data.redis.RedisConnectionFailureException 出错:无法连接到 Redis;嵌套异常是 io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379

我的问题是 - 改变 redis 配置的方法是什么?我在另一台机器上安装了 Redis。是否有一些属性可以提供我的 Redis 主机和端口,以便它不指向本地主机?

0 投票
0 回答
2104 浏览

java - Spring Cloud Gateway 和 Spring Security 将经过身份验证的角色传递给微服务

让我们假设;

我们有 Spring Boot(2) 服务;微服务 A、微服务 B、微服务 C、

我们希望将它们与 Spring Cloud Gateway 聚合,并在需要特定服务的 http 路径时进行令牌身份验证。

现在假设我们在 api-gateway 中进行了身份验证,然后担任角色等。但我不想一一允许特定的 http 路径,如/service-b/public-areaServerHttpSecurity 链接。

而不是这个,我想在我的映射方法上使用microservice B注释@PreAuthorize("hasRole(ROLE_USER)")。所以我可以处理微服务中的部分独立授权。因为当我有任何任务时,我只需要处理特定的微服务。

但是我没有任何关于在Spring Cloud Gateway docs中传递 spring 安全角色的文档。

任何人都可以对这个问题有任何答案或经验和建议吗?

0 投票
1 回答
1558 浏览

java - 由于 netty 问题,spring cloud gateway 无法路由

我比较spring-cloud-gateway陌生,我正在为此建立一个 POC。我为此制作了一个示例网关应用程序和一个微服务应用程序。我已验证微服务应用程序运行良好且可在以下位置访问port: 8080

这两个应用程序都运行良好。因此,我不在POMs这里分享。但是,请参阅下面的代码详细信息。

网关

application.yml

the springboot app

微服务应用

application.properties

springboot file

我正在尝试使用邮递员访问localhost:8081/first. 下面是错误。

就是这样。任何帮助将不胜感激!

0 投票
0 回答
107 浏览

spring-cloud-gateway - Spring-cloude-gateway fluent java api有不同的谓词定义方式

在我们的代码中,我们使用 Spring Cloud Gateway 使用 fluent java 路由 API 动态配置到服务的路由。假设我们要过滤传入请求的路径。我们可以通过两种方式实现这一点,我的问题是关于两者之间的区别:

  • 在第一个路由中,我们通过调用PredicateSpec.path().

  • 在第二个示例中,我们使用Route.AsyncBuilder.and()(Route.AsyncBuilder.uri()方法返回的类型) 配置路径。

显然,第一种方式更具可读性和简单性。但我想在方法之后定义谓词有一个用例uri()吗?在调用 to 之前或之后定义谓词有什么区别uri()