请问Cloud版每一个单体服务如何做到鉴权

Blade 未结 1 167
TomatoLay
TomatoLay 剑者 2023-06-01 08:58

一、该问题的重现步骤是什么?

现在所有的鉴权操作全是通过gateway,在开发的过程中发现单体服务启动之后,直接通过ip:端口访问单服务内的接口时不会鉴权直接返回数据,客户现场安全要求很高,所有的服务都需要鉴权,请问该怎么操作?


二、你期待的结果是什么?实际看到的又是什么?


三、你正在使用的是什么产品,什么版本?在什么操作系统上?


四、请提供详细的错误堆栈信息,这很重要。


五、若有更多详细信息,请在下面提供。

1条回答
  • 2023-06-01 10:17

    每个服务创建一个config类,并加入如下配置,开启内部鉴权。

    可以这么做但没有必要,因为部署的时候最终只会把gateway暴露在外,内部服务是无法访问到的。外部也无法进行渗透攻击,如果加上二次鉴权,那么token解析也会做两次,性能减半。

    这只是一个想当然的“安全隐患”但根本不存在,为了解决这个“隐患”要搭上一倍的性能不划算。

    image.png

    /**
     * 安全框架配置
     */
    @Bean
    public SecureRegistry secureRegistry() {
        SecureRegistry secureRegistry = new SecureRegistry();
        secureRegistry.setEnabled(true);
        secureRegistry.excludePathPatterns("/menu/routes");
        secureRegistry.excludePathPatterns("/menu/auth-routes");
        secureRegistry.excludePathPatterns("/menu/top-menu");
        secureRegistry.excludePathPatterns("/tenant/info");
        secureRegistry.excludePathPatterns("/process/resource-view");
        secureRegistry.excludePathPatterns("/process/diagram-view");
        secureRegistry.excludePathPatterns("/manager/check-upload");
        secureRegistry.excludePathPatterns("/doc.html");
        secureRegistry.excludePathPatterns("/js/**");
        secureRegistry.excludePathPatterns("/webjars/**");
        secureRegistry.excludePathPatterns("/swagger-resources/**");
        secureRegistry.excludePathPatterns("/druid/**");
        return secureRegistry;
    }


    作者追问:2023-06-05 11:23

    感谢回复,还有一个问题,所有的服务在同一台服务器上可以只暴露网关端口即可,那如果服务是分开部署,A服务器部署基础模块,B服务器部署biz业务模块,是不是B服务器也需要部署一个网关?前端在调用的时候会自动请求对应的网关吗?

    回答: 2023-06-05 11:28

    分开服务器部署分两种情况

     1. 如果是k8s就不用担心这个。内部通讯自动处理好了

     2. 如果是jar部署,做服务器内网通讯,对外网依旧是一个gateway就行


    所以你也不用担心暴露外网和多个gateway的问题

    0 讨论(0)
提交回复