1. 역할 이름 수정
elasticbeanstalk이 아니라 elaticbeanstalk
2. Elastic Beanstalk 다시 생성
변경된 역할로 다시 생성
잘 생성이 되었다~~
3. application.yml 파일의 환경 변수도 elastic beanstalk 환경 속성에 추가하기
JWT_SECRET 추가!
헬스 체크 요청을 위한 API URL이 /health 인데, 시큐리티로 인해 막혀있는 상황이라 요청 허가로 변경
SecurityConfig.java
@RequiredArgsConstructor
@Configuration
@EnableWebSecurity
public class SecurityConfig {
private final JwtTokenProvider jwtTokenProvider;
@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
return httpSecurity
// basic auth 및 csrf 보안 사용하지 않음
.httpBasic(http -> http.disable())
.csrf(csrf -> csrf.disable())
// JWT 사용하기 때문에 세션 사용하지 않음
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(authorize -> authorize
// 해당 API에 대해서는 모든 요청을 허가
.requestMatchers("/members/sign-in",
"/members/sign-up",
"/swagger-ui/**",
"/swagger-resources/**",
"/v3/api-docs/**",
"/health").permitAll()
// USER 권한이 있어야 요청할 수 있음
.requestMatchers("/members/test").hasRole("USER")
// 이 밖에 모든 요청에 대해서 인증 필요
.anyRequest().authenticated()
)
// JWT 인증을 위해 직접 구현한 필터를 UsernamePasswordAuthenticationFilter 전에 실행
.addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider),
UsernamePasswordAuthenticationFilter.class).build();
}
}
에러 로그 확인
Aug 10 15:24:57 ip-10-0-1-109 web[2107]: 2024-08-10T15:24:57.325+09:00 WARN 2107 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 08S01
Aug 10 15:24:57 ip-10-0-1-109 web[2107]: 2024-08-10T15:24:57.325+09:00 ERROR 2107 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Communications link failure
Aug 10 15:24:57 ip-10-0-1-109 web[2107]: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Aug 10 15:24:57 ip-10-0-1-109 web[2107]: 2024-08-10T15:24:57.332+09:00 ERROR 2107 --- [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution [Communications link failure
Communications link failure 오류가 발생한다
mysql 서버는 실행중인데 계속 같은 오류가 발생해서 찾아보니
MySQL root 사용자가 모든 호스트 ('%') 에서 접근가능하도록 설정되어있어야 한다고 한다.
확인해보니 'localhost'에서만 접근 가능하도록 되어있었음ㅜㅜ
아래 명령어로 모든 호스트에 대한 접근 권한이 있는 root 사용자를 만들었다
CREATE USER 'root'@'%' IDENTIFIED BY 'your_password';
그리고 새로 추가한 사용자에게 모든 권한을 부여했다
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
권한을 적용한다
FLUSH PRIVILEGES;
---
로컬 DB -> RDS로 변경해서 배포하니 성공ㅜㅜ
'인프라 & 배포' 카테고리의 다른 글
무중단 CI/CD (Github Action + Elastic Beanstalk) (0) | 2024.07.09 |
---|---|
[docker] MySQL 컨테이너 포트 변경, IntelliJ database 연결 오류 (0) | 2023.11.24 |
[Docker] 컨테이너 생성 오류 (4) | 2023.11.24 |