게시글
질문&답변
도커 컨테이너로 동작할 때 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
- 151
질문&답변
login 요청하면 404 에러가 발생합니다.
저도 이부분 궁금해서 찾아보았는데요... 다른 userservice url은 동작하기 때문에 gateway설정 문제는 아닌 것 같긴합니다..(복붙해서 동일하게 사용했기 때문에)전, user-service 포트로 login 연결하면 200으로 응답오고, 게이트 웨이 통해서 login 연결하면 404가 떳는데 gateway filter - RemoveRequestHeader=Cookie를 주석처리하니 동일하게 200으로 응답이 오더라구요... 왜 그런지는 정확히 잘 모르겠어서 혹시 아시분있나 해서 댓글 달아봅니다..
- 0
- 2
- 1K
질문&답변
Deploy를 계속 실패합니다.
여러분들!! 로그에 있는 것처럼 eb-engine.log 다운받아서 확인해보세요! 전 docker-compose.yml 파일에 ports 띄어쓰기 안했다고 나와서 수정했더니 됬습니다!(사진)(사진)
- 3
- 4
- 1.2K