질문&답변
도커 컨테이너로 동작할 때 user-service에서 403 forbidden 오류 관련
저는 도커로 배포할때 도커 내부 네트워크 ip 지정 안해주니까 게이트웨이에서 user-service 로 로드 밸런싱이 안되더라구요 아래 코드처럼 내부 아이피도 추가 해주니까 도커에서 정상동작하기 시작했습니다! 이틀만에 해결한거라,, 처음으로 q&n올려봅니다! @Bean protected SecurityFilterChain configure(HttpSecurity http) throws Exception {// 권한 관련 메소드 // Configure AuthenticationManagerBuilder AuthenticationManagerBuilder authenticationManagerBuilder = http.getSharedObject(AuthenticationManagerBuilder.class); authenticationManagerBuilder.userDetailsService(userService).passwordEncoder(bCryptPasswordEncoder); AuthenticationManager authenticationManager = authenticationManagerBuilder.build(); http.csrf( (csrf) -> csrf.disable()); http.authorizeHttpRequests((authz) -> authz .requestMatchers(new AntPathRequestMatcher("/actuator/**")).permitAll() .requestMatchers(new AntPathRequestMatcher("/actuator/**")).permitAll() .requestMatchers(new AntPathRequestMatcher("/h2-console/**")).permitAll() .requestMatchers(new AntPathRequestMatcher("/users", "POST")).permitAll() .requestMatchers(new AntPathRequestMatcher("/welcome")).permitAll() .requestMatchers(new AntPathRequestMatcher("/health-check")).permitAll() .requestMatchers(new AntPathRequestMatcher("/swagger-ui/**")).permitAll() .requestMatchers(new AntPathRequestMatcher("/swagger-resources/**")).permitAll() .requestMatchers(new AntPathRequestMatcher("/v3/api-docs/**")).permitAll() // .requestMatchers("/**").access(this::hasIpAddress) // .requestMatchers("/**").access( // new WebExpressionAuthorizationManager( // "hasIpAddress('127.0.0.1') " + // "or hasIpAddress('192.168.45.83')"+ // "or hasIpAddress('172.17.0.0/32')")) // host pc ip address // .anyRequest().authenticated() // IP 주소 체크와 로그 찍기 .requestMatchers("/**").access((authentication, httpServletRequest) -> { // 클라이언트 IP 주소 가져오기 String clientIp = httpServletRequest.getRequest().getRemoteAddr(); log.info("Request from IP: {}", clientIp); // 로그 출력 // IP 주소가 허용된 범위 내인지 확인 if (clientIp.equals("127.0.0.1") || clientIp.equals("192.168.45.83") || clientIp.startsWith("172.18.")) { log.info("Access granted for IP: {}", clientIp); // 허용된 IP에 대한 로그 return new AuthorizationDecision(true); // 인증 통과 } else { log.warn("Access denied for IP: {}", clientIp); // 허용되지 않은 IP에 대한 로그 return new AuthorizationDecision(false); // 인증 실패 } }) .anyRequest().authenticated() ) .formLogin(Customizer.withDefaults()) .authenticationManager(authenticationManager); // .sessionManagement((session) -> session // .sessionCreationPolicy(SessionCreationPolicy.STATELESS)); http.addFilter(getAuthenticationFilter(authenticationManager)); http.headers((headers) -> headers.frameOptions((frameOptions) -> frameOptions.sameOrigin())); return http.build(); }
- 좋아요수
- 1
- 댓글수
- 2
- 조회수
- 347





