Skip to content

Commit

Permalink
segregate kibana index network policy (#2025)
Browse files Browse the repository at this point in the history
* segregate kibana index network policy

* update network policy for kibana index pattern

* fix kibana policy tests

* fix authsidecar tests
  • Loading branch information
pgvishnuram committed Oct 13, 2023
1 parent ad90dc1 commit 69a1b2b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
16 changes: 10 additions & 6 deletions charts/kibana/templates/kibana-networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@ spec:
component: ingress-controller
release: {{ .Release.Name }}
{{- end }}
{{ if .Values.createDefaultIndex }}
ports:
{{- if .Values.global.authSidecar.enabled }}
- protocol: TCP
port: {{ .Values.global.authSidecar.port }}
{{- else }}
- protocol: TCP
port: {{ .Values.ports.http }}
{{- end}}
{{ if .Values.createDefaultIndex }}
- from:
- podSelector:
matchLabels:
component: kibana-default-index
release: {{ .Release.Name }}
tier: logging
{{- end }}
ports:
{{- if .Values.global.authSidecar.enabled }}
- protocol: TCP
port: {{ .Values.global.authSidecar.port }}
{{- else }}
- protocol: TCP
port: {{ .Values.ports.http }}
{{- end}}
Expand Down
13 changes: 2 additions & 11 deletions tests/chart_tests/test_authsidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,9 @@ def test_authSidecar_kibana(self, kube_version):
"namespaceSelector": {
"matchLabels": {"network.openshift.io/policy-group": "ingress"}
}
},
{
"podSelector": {
"matchLabels": {
"component": "kibana-default-index",
"release": "release-name",
"tier": "logging",
}
}
},
}
] == jmespath.search("spec.ingress[0].from", docs[3])
assert [{"port": 8084, "protocol": "TCP"}] == jmespath.search(
assert {"port": 8084, "protocol": "TCP"} in jmespath.search(
"spec.ingress[*].ports[0]", docs[3]
)

Expand Down
27 changes: 27 additions & 0 deletions tests/chart_tests/test_kibana.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,30 @@ def test_kibana_index_disabled(self, kube_version):
)

assert len(docs) == 0

def test_kibana_index_network_policy_enabled(self, kube_version):
"""Test network policy for kibana index service."""
docs = render_chart(
kube_version=kube_version,
values={"kibana": {"createDefaultIndex": True}},
show_only=[
"charts/kibana/templates/kibana-networkpolicy.yaml",
],
)

assert len(docs) == 1
doc = docs[0]
assert "NetworkPolicy" == doc["kind"]
assert [
{
"podSelector": {
"matchLabels": {
"component": "kibana-default-index",
"release": "release-name",
"tier": "logging",
}
},
}
] == [doc["spec"]["ingress"][1]["from"][0]]

assert [{"port": 5601, "protocol": "TCP"}] == doc["spec"]["ingress"][1]["ports"]

0 comments on commit 69a1b2b

Please sign in to comment.