image-renderer-network-policy.yaml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {{- if and (.Values.imageRenderer.enabled) (.Values.imageRenderer.networkPolicy.limitIngress) }}
  2. ---
  3. apiVersion: networking.k8s.io/v1
  4. kind: NetworkPolicy
  5. metadata:
  6. name: {{ template "grafana.fullname" . }}-image-renderer-ingress
  7. namespace: {{ template "grafana.namespace" . }}
  8. annotations:
  9. comment: Limit image-renderer ingress traffic from grafana
  10. spec:
  11. podSelector:
  12. matchLabels:
  13. {{- include "grafana.imageRenderer.selectorLabels" . | nindent 6 }}
  14. {{- if .Values.imageRenderer.podLabels }}
  15. {{ toYaml .Values.imageRenderer.podLabels | nindent 6 }}
  16. {{- end }}
  17. policyTypes:
  18. - Ingress
  19. ingress:
  20. - ports:
  21. - port: {{ .Values.imageRenderer.service.targetPort }}
  22. protocol: TCP
  23. from:
  24. - namespaceSelector:
  25. matchLabels:
  26. name: {{ template "grafana.namespace" . }}
  27. podSelector:
  28. matchLabels:
  29. {{- include "grafana.selectorLabels" . | nindent 14 }}
  30. {{- if .Values.podLabels }}
  31. {{ toYaml .Values.podLabels | nindent 14 }}
  32. {{- end }}
  33. {{ end }}
  34. {{- if and (.Values.imageRenderer.enabled) (.Values.imageRenderer.networkPolicy.limitEgress) }}
  35. ---
  36. apiVersion: networking.k8s.io/v1
  37. kind: NetworkPolicy
  38. metadata:
  39. name: {{ template "grafana.fullname" . }}-image-renderer-egress
  40. namespace: {{ template "grafana.namespace" . }}
  41. annotations:
  42. comment: Limit image-renderer egress traffic to grafana
  43. spec:
  44. podSelector:
  45. matchLabels:
  46. {{- include "grafana.imageRenderer.selectorLabels" . | nindent 6 }}
  47. {{- if .Values.imageRenderer.podLabels }}
  48. {{ toYaml .Values.imageRenderer.podLabels | nindent 6 }}
  49. {{- end }}
  50. policyTypes:
  51. - Egress
  52. egress:
  53. # allow dns resolution
  54. - ports:
  55. - port: 53
  56. protocol: UDP
  57. - port: 53
  58. protocol: TCP
  59. # talk only to grafana
  60. - ports:
  61. - port: {{ .Values.service.port }}
  62. protocol: TCP
  63. to:
  64. - podSelector:
  65. matchLabels:
  66. {{- include "grafana.selectorLabels" . | nindent 14 }}
  67. {{- if .Values.podLabels }}
  68. {{ toYaml .Values.podLabels | nindent 14 }}
  69. {{- end }}
  70. {{ end }}