Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opensearch-logs] adding audit user for audit logs, job for alias and dashboard pattern creation #7577

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bf08f39
[opensearch-logs] adding audit user for audit logs
Kuckkuck Dec 18, 2024
7fde4d8
[opensearch-logs] testing new index pattern names
Kuckkuck Dec 20, 2024
f6851df
[opensearch-logs] remove unused config
Kuckkuck Dec 20, 2024
3462217
[opensearch-logs] fix typo in dashboard pattern script
Kuckkuck Dec 20, 2024
5ac07f4
[opensearch-logs] fix alias creation for indexes with more than one dash
Kuckkuck Dec 20, 2024
f4dfa41
[opensearch-logs] remove date from aliases
Kuckkuck Dec 20, 2024
1dfddb3
[opensearch-logs] remove index from alias
Kuckkuck Dec 20, 2024
848addb
[opensearch-logs] mv dashboard/alias script to cron
Kuckkuck Dec 23, 2024
93eac60
[opensearch-logs] fix formatting
Kuckkuck Dec 23, 2024
b74b958
[opensearch-logs] fix formatting
Kuckkuck Dec 23, 2024
73d23d1
[opensearch-logs] testing cron
Kuckkuck Dec 23, 2024
44d1c1e
[opensearch-logs] fix alias creation for indexes with more than one dash
Kuckkuck Dec 23, 2024
43f2815
[opensearch-logs] remove test time from cron
Kuckkuck Dec 23, 2024
47933f7
[opensearch-logs] adding audit user for audit logs, job for alias and…
Kuckkuck Dec 18, 2024
907356d
Merge branch 'opensearch-logs' of https://github.com/sapcc/helm-chart…
Kuckkuck Dec 23, 2024
3fb04bd
[opensearch-logs] fix datastream list
Kuckkuck Jan 2, 2025
fdad687
[opensearch-logs] adding second data user
Kuckkuck Jan 2, 2025
f730ef3
[opensearch-logs] testing index pattern creation
Kuckkuck Jan 2, 2025
fb4d9e1
[opensearch-logs] remove unused cron entry
Kuckkuck Jan 2, 2025
ec861b1
[opensearch-logs] second user for otel
Kuckkuck Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
#!/bin/bash
export BASIC_AUTH_HEADER=${ADMIN_USER}:${ADMIN_PASSWORD}

# 0. Check for index policy
for i in $(curl -s -u ${ADMIN_USER}:${ADMIN_PASSWORD} "${CLUSTER_HOST}/_cat/indices?v"|awk '{ print $3 }'|awk -F- '{ print $1 }'|sort|uniq|grep -v "\."|grep -v "index")
# Creating aliases for all indexes, because logstash-* is also selecting datastreams besides the logstash-2024... indexes.
for i in $(curl -s -u ${BASIC_AUTH_HEADER} "${CLUSTER_HOST}/_cat/indices?v"|awk '{ print $3 }'|grep -v "^\."|sort|sed 's/-[0-9].*\.[0-9].*\.[0-9].*$//'|uniq|grep -v index|grep -v "alerts-other"|grep -v deployments|grep -v maillog|grep -v ss4o|grep -v sample)
do
#Creating an alias for all standard indexes, which are not datastreams to mitigate the issue with indexes, where for example storage-* is selecting the index and also the datastream, which shows up in dashboards as duplicate entries
echo "using index $i from Opensearch-Logs"
echo "setting OpenSearch dashboard index mapping for index $i"
curl --header "content-type: application/JSON" --fail -XGET -u ${ADMIN_USER}:${ADMIN_PASSWORD} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}-*"
if [ $? -eq 0 ]; then
echo "index ${i} already exists in Opensearch dashboard"
export ALIAS_EXISTS=`curl -s -i -u ${BASIC_AUTH_HEADER} "${CLUSTER_HOST}/_cat/aliases/${i}"|grep "content-length"|awk -F: '{ print $2 }'|tr -d '[:space:]'`
echo "Creating for updating alias $i, because alias setting is only valid for indexes, which were created before the alias creation timestamp"
curl -s -XPOST --header "content-type: application/JSON" -u ${BASIC_AUTH_HEADER} "${CLUSTER_HOST}/_aliases" -H "osd-xsrf: true" -d "{ \"actions\": [ { \"add\": { \"index\": \"${i}-2*\", \"alias\": \"${i}\" } } ] }"
echo "Deleting old index pattern based on index-* format"
export DASHBOARD_PATTERN=`curl -s --header "content-type: application/JSON" --fail -XGET -u ${BASIC_AUTH_HEADER} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}-*"|grep "content-length"|awk -F: '{ print $2 }'|tr -d '[:space:]'`
if [[ "$DASHBOARD_PATTERN" -gt 0 ]]
then
echo "Old dashboard pattern exists for for index ${i}, it will be removed"
curl -s -XDELETE -u ${BASIC_AUTH_HEADER} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}-*"
else
echo "No old dashboard pattern for index $i"
fi
done

# Dashboard index pattern for all available aliases, which are not datastreams
for i in $(curl -s -u ${BASIC_AUTH_HEADER} "${CLUSTER_HOST}/_cat/aliases?v"|grep -v "\-ds"|grep -v "^\."|awk '{ print $1 }'|sort|uniq)
do
echo "using alias $i from Opensearch-Logs"
echo "Setting OpenSearch dashboard index mapping for alias $i"
curl -s --fail -XGET -u ${BASIC_AUTH_HEADER} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}"
if [ $? -eq 0 ]
then
echo "index pattern for alias ${i} already exists in Opensearch dashboard, nothing to do"
else
echo "INFO: creating index-pattern in Dashboards for $i logs"
curl -XPOST --header "content-type: application/JSON" -u ${ADMIN_USER}:${ADMIN_PASSWORD} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}-*" -H "osd-xsrf: true" -d "{ \"attributes\": { \"title\": \"${i}-*\", \"timeFieldName\": \"@timestamp\" } }"
echo "INFO: creating index-pattern in Dashboards for datastream alias $i"
curl -s -XPOST --header "content-type: application/JSON" -u ${BASIC_AUTH_HEADER} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}" -H "osd-xsrf: true" -d "{ \"attributes\": { \"title\": \"${i}\", \"timeFieldName\": \"@timestamp\" } }"
fi
done


# Dashboard index pattern for all available datastreams
for i in $(curl -s -u ${ADMIN_USER}:${ADMIN_PASSWORD} "${CLUSTER_HOST}/_cat/aliases?v"|grep "\-ds"|awk '{ print $1 }'|uniq)
for i in $(curl -s -u ${BASIC_AUTH_HEADER} "${CLUSTER_HOST}/_cat/aliases?v"|grep "\-ds"|awk '{ print $1 }'|sort|uniq)
do
echo "using datastream $i from Opensearch-Logs"
echo "setting OpenSearch dashboard index mapping for index $i"
curl --header "content-type: application/JSON" --fail -XGET -u ${ADMIN_USER}:${ADMIN_PASSWORD} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}"
if [ $? -eq 0 ]; then
curl -s --fail -XGET -u ${BASIC_AUTH_HEADER} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}"
if [ $? -eq 0 ]
then
echo "index ${i} already exists in Opensearch dashboard"
else
echo "INFO: creating index-pattern in Dashboards for datastream alias $i"
curl -XPOST --header "content-type: application/JSON" -u ${ADMIN_USER}:${ADMIN_PASSWORD} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}" -H "osd-xsrf: true" -d "{ \"attributes\": { \"title\": \"${i}\", \"timeFieldName\": \"@timestamp\" } }"
curl -s -XPOST --header "content-type: application/JSON" -u ${BASIC_AUTH_HEADER} "${DASHBOARD_HOST}/api/saved_objects/index-pattern/${i}" -H "osd-xsrf: true" -d "{ \"attributes\": { \"title\": \"${i}\", \"timeFieldName\": \"@timestamp\" } }"
fi
done

This file was deleted.

18 changes: 18 additions & 0 deletions system/opensearch-logs/templates/config/_internal_users.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ data:
backend_roles:
- "data"

data2:
hash: "{{ .Values.users.data2.nohash }}"
reserved: true
backend_roles:
- "data"

greenhouse:
hash: "{{ .Values.users.greenhouse.nohash }}"
reserved: true
Expand All @@ -38,6 +44,18 @@ otel:
backend_roles:
- "otel"

otel2:
hash: "{{ .Values.users.otel2.nohash }}"
reserved: true
backend_roles:
- "otel"

audit:
hash: "{{ .Values.users.audit.nohash }}"
reserved: true
backend_roles:
- "audit"

otellogs:
hash: "{{ .Values.users.otellogs.nohash }}"
reserved: true
Expand Down
20 changes: 20 additions & 0 deletions system/opensearch-logs/templates/config/_roles.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,26 @@ compute:
- "indices:admin/create"
- "indices:data/write/bulk*"
- "indices:data/write/index"
audit:
reserved: false
cluster_permissions:
- "cluster_monitor"
- "cluster_composite_ops"
- "cluster:admin/ingest/pipeline/put"
- "cluster:admin/ingest/pipeline/get"
- "indices:admin/template/get"
- "cluster_manage_index_templates"
- "cluster:admin/opensearch/ml/predict"
index_permissions:
- index_patterns:
- "audit-*"
allowed_actions:
- "indices:admin/template/get"
- "indices:admin/template/put"
- "indices:admin/mapping/put"
- "indices:admin/create"
- "indices:data/write/bulk*"
- "indices:data/write/index"
otel:
reserved: false
cluster_permissions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ greenhouse:
users:
- "greenhouse"

audit:
reserved: false
users:
- "audit"

jump:
reserved: false
users:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: "install-dashboard-pattern"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
ccloud/service: logs
ccloud/support-group: observability
spec:
schedule: "30 0,6,8,12,18 * * *"
jobTemplate:
spec:
backoffLimit: 3
template:
spec:
restartPolicy: Never
containers:
- name: install-dashboard-pattern
image: "{{ .Values.global.registry }}/unified-kubernetes-toolbox:latest"
command: ["/bin/bash", "/scripts/install-dashboard-pattern.sh"]
env:
- name: ADMIN_USER
valueFrom:
secretKeyRef:
name: cron-secrets
key: ADMIN_USER
- name: ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: cron-secrets
key: ADMIN_PASSWORD
- name: CLUSTER_HOST
value: "https://opensearch-logs-client.{{ .Values.global.clusterType }}.{{ .Values.global.region }}.{{ .Values.global.tld }}:{{ .Values.httpPort }}"
- name: DASHBOARD_HOST
value: "https://logs.{{ .Values.global.region }}.{{ .Values.global.tld }}"
volumeMounts:
- mountPath: /scripts/install-dashboard-pattern.sh
name: security-config
subPath: install-dashboard-pattern.sh
volumes:
- name: security-config
secret:
defaultMode: 420
secretName: security-config

This file was deleted.

Loading