레이블이 iframe인 게시물을 표시합니다. 모든 게시물 표시
레이블이 iframe인 게시물을 표시합니다. 모든 게시물 표시

k8s grafana iframe

k8s grafana 그래프 하나를 share > embed(iframe) 으로 공유할때
브라우저에서 iframe 로딩이 안된다.
이경우 grafana.ini 설정에 다음 설정을 추가해야 한다.
[security]
allow_embedding = true

추가로 로그인 없이 익명사용자로 접근하기 위해서 다음 설정도 필요하다.
요 설정이 없으면 grafana 로그인 화면으로 보인다.
[auth.anonymous]
enabled = true

위 설정으로 grafana 적용(pod재시작)했다.

로컬에 index.html 에
grafana iframe 과
youtube 동영상 하나 공유 링크(iframe) 
로 2개의 iframe을 추가했다.

브라우저로 보면 youtube iframe 은 보이지만 grafana iframe은 보이지 않는다.
x-frame-options 으로 인해 iframe 과 현재 호스트(localhost)가 달라서 콘솔에 다음과 같은 에러가 발생했다.

Refused to display 'http://grafana.ysoftman.test/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

아래와 같은 크롬 익스텐션으로 브라우저에서 x-frame-headers 을 무시하면 되긴 한다.

원인은 k8s grafana ingress 별다른 설정이 없어 ngnix 가 디폴트로 X-Frame-Options: sameorigin 로 처리되기 때문이다.

X-Frame-Options ALLOW-FROM=url 로 특정 url 요청을 허용하도록 하면 될것 같았는데,
ALLOW-FROM 는 obsolete 로 최신브라우저에선 동작하지 않는다.

ingress 설정으로 다음과 같이 X-Frame-Options 헤더를 의미없는 값으로 설정하면 보인다.
하지만 브라우져 콘솔에 invalid 에러가 발생한다.
annotations:
  nginx.ingress.kubernetes.io/configuration-snippet: |
    more_set_headers "X-Frame-Options: _for_ysoftman"

다음과 같이 하면 X-Frame-Options 헤더를 응답에서 제외할 수 있다.
annotations:
  nginx.ingress.kubernetes.io/configuration-snippet: |
    more_clear_headers "X-Frame-Options";


#####


만약 csp(Content-Security-Policy)문제인 경우
csp 의 frame-src 지시자로 iframe url 을 제어한다.
csp는 html 에서 다음과 같이 사용할 수 있지만 서버 응답헤더로 설정을 권장한다.
<meta http-equiv="Content-Security-Policy" content="frame-src http://*">

nginx 응답 헤더 추가를 위해 ingress 에 다음과 같이 설정한다.
annotations:
  nginx.ingress.kubernetes.io/configuration-snippet: |
    more_set_headers "Content-Security-Policy: frame-src http://*;";

참고로 frame-ancestors(iframe 를 호출 하는 상위) 경우는 meta 태그로 명시하지 못한다고 한다.
frame-ancestors specifies the sources that can embed the current page. This directive applies to <frame>, <iframe>, <embed>, and <applet> tags. This directive can't be used in <meta> tags and applies only to non-HTML resources.