apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
28.94k stars 10.19k forks source link

开启密钥认证后,不生效 #5091

Closed liwei-geng closed 5 months ago

liwei-geng commented 5 months ago

三个组件分别运行分三个容器部署的,访问正常,注册正常,但是在管理密钥中开启密钥后,客户端仍然可以不通过密钥认证获取配置。期待解答。

复现

通过如下步骤可以复现:

  1. 数据修改注册连接
  2. docker运行三个服务,启动系统。
  3. 开启应用的管理密钥
  4. 使用python或者直接get访问url都可以获取配置

期望 期望正常开启密钥验证,防止陌生客户端访问

截图

额外的细节和日志

dosubot[bot] commented 5 months ago

🤖

您遇到的问题可能是由于您试图保护的URL在HttpSecurity配置中没有正确配置。在提供的代码中,有一些URL被从认证过程中绕过。这些URL在BY_PASS_URLS数组中定义:

private static final String[] BY_PASS_URLS = {"/prometheus/**", "/metrics/**", "/openapi/**",
      "/vendor/**", "/styles/**", "/scripts/**", "/views/**", "/img/**", "/i18n/**", "/prefix-path",
      "/health"};

configure(HttpSecurity http)方法中,这些URL对所有用户(无论是否经过认证)都是开放的:

http.authorizeRequests()
    .antMatchers(BY_PASS_URLS).permitAll()
    .antMatchers("/**").authenticated();

如果您试图保护的配置位于这些路径下,那么它们将可以在没有密钥认证的情况下被访问。要解决这个问题,您需要确保您想要保护的配置的路径没有包含在BY_PASS_URLS数组中,并且在configure(HttpSecurity http)方法中正确配置。

源代码:

另外,Apollo 2.2.0的代码库通过不同的方法实现密钥认证,具体取决于激活的配置文件。

  1. 对于"auth"配置文件,它使用Spring Security的JdbcUserDetailsManager进行认证。这个管理器使用SQL查询从数据库中查询用户详细信息和权限。使用的密码编码器是由ApolloPasswordEncoderFactory.createDelegatingPasswordEncoder()创建的。

  2. 对于"ldap"配置文件,它使用Spring Security的LdapAuthenticationProvider进行认证。这个提供者使用BindAuthenticatorDefaultLdapAuthoritiesPopulator从LDAP服务器中认证用户和填充权限。

  3. 对于"oidc"配置文件,它使用Spring Security的OAuth2和OIDC支持进行认证。OidcWebSecurityConfigurerAdapter配置安全过滤链以支持OAuth2登录和OIDC注销。

  4. 如果上述配置文件都没有激活,将使用默认配置,该配置似乎没有实现任何特定的认证机制。

源代码:

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

nisiyong commented 5 months ago

Maybe you missed something, you should provide more details.

liwei-geng commented 5 months ago

抱歉,我对架构的理解出了偏差,以为客户端是要去admin service获取数据,后来看了下架构图,adminservice并不对外开放,仅限内部portal访问,用户都是访问的8080的configservice服务。打扰了。。。