Post

Spring Actuator 보안 강화: 포트 번호 숨겨서 안전하게 설정하기

Actuator 숨기기


이전에 Grafana, prometheus 에 우리 서비스를 연결하기위해서 spring actuator package 를 추가하고 /actuator/prometheus에 우리 서비스의 정보를 보여줄수 있게 했다. 하지만 이방법은 사람들이 저 endpoint 만 알고있으면 우리 서비스의 상태를 알 수가 있다는 뜻이었다. 따라서 해당 정보를 보여주는 port 를 다르게 하기로 했다.

서비스 포트와 다른 포트로 열기


application.properties 에 다음고 같은 config 를 추가해 주었다.

1
2
3
4
management.endpoints.enabled-by-default=false  # 활성화 기본값 false  
management.endpoint.prometheus.enabled=true # 필요한 prometheus 만 연다  
management.endpoints.web.exposure.include=prometheus  
manate.server.port=3000 # 새로운 임의의 포트

이렇게 설정을 하면 {ip}:{3000}/actuator/prometheus 로 시스템의 정보를 볼 수 있는 Endpoint 를 옮길수있다.

k8s에서 helm 차트에 추가로 해줘야하는 설정


k8s 상에서 우리 서비스가 떠있기 때문에 추가로 helm 차트에 적어주어야 할것이 있다. 우선 prometheus 가 service.yaml 기반으로 metric 을 가져오기 때문에 service.yaml 의 spec.ports 를 조금 추가해준다

1
2
3
4
5
6
spec:  
  ports:  
    - name : metrics  
      port: 3000  
      protocol: TCP  
      targetPort: 3000

그리고 networkpolicy,yaml 을 사용하고있다면 역시 3000 포트를 넣어준다.

1
2
3
4
5
spec:  
  ingress:  
    ports:  
      - port :3000  
        protocal : TCP

다행히도 잘 수집이 됨을 확인 할 수 있었다! 사내에서는 미리 만들어 놓은 helm 차트를 가져와서 values.yaml 만 수정해가면서 그것을 수정하곤 하는데 빨리.. helm 차트를 우리 맘대로 수정 할 수 있는 서비스가 나오면 참 좋을거 같다..

This post is licensed under CC BY 4.0 by the author.

© 병욱. Some rights reserved.