Skip to content

Commit

Permalink
[PLAT-14974][PLAT-15045] Added prometheus user as part of yugabyte group
Browse files Browse the repository at this point in the history
Summary: Added prometheus user as part of yugabyte group, & changed the permission of yb_home_dir to 750, so as to remove world executable permission.

Test Plan:
Manually created universe.
Verified that the metrics are working as expected.

Reviewers: amalyshev, anijhawan

Reviewed By: amalyshev, anijhawan

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D37533
  • Loading branch information
Vars-07 committed Aug 28, 2024
1 parent 4ea354b commit b80999d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
failed_when: False

- set_fact:
node_exporter_group: "prometheus"
node_exporter_group: "yugabyte"
when: user_group.rc != 0

- set_fact:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
- name: Grant traverse permission on yb_home directory
file:
path: "{{ yb_home_dir }}"
mode: '0711'
mode: '0750'
become: yes
become_method: sudo
when: (install_node_exporter is defined and install_node_exporter|bool) or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ fi

# Check if the user "prometheus" already exists
if ! id -u prometheus >/dev/null 2>&1; then
adduser --shell /bin/bash prometheus
os_type=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
case "$os_type" in
ubuntu|debian)
adduser --no-create-home --disabled-password --shell /bin/bash --ingroup {{ yb_user }} \
--gecos "" prometheus
;;
rhel|centos|fedora|rocky|alma)
useradd --shell /bin/bash --no-create-home -g {{ yb_user }} prometheus
;;
*)
echo "Unsupported OS: $os_type"
exit 1
;;
esac
else
echo "User 'prometheus' already exists."
fi

# Set ownership and permissions
Expand Down Expand Up @@ -51,7 +66,9 @@ Restart=on-failure
User=prometheus
Group=prometheus

ExecStart=/opt/prometheus/node_exporter-1.7.0.linux-amd64/node_exporter --web.listen-address=:9300 --collector.textfile.directory={{ yb_home_dir }}/metrics
ExecStart=/opt/prometheus/node_exporter-1.7.0.linux-amd64/node_exporter \
--web.listen-address=:9300 \
--collector.textfile.directory={{ yb_home_dir }}/metrics
EOL

# Enable and start the node_exporter service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ if [ -z {{ public_key_filepath }} ]; then
fi
fi

# Ensure the permissions for yb_home_dir are 711
chmod -R 711 "{{ yb_home_dir }}"
# Ensure the permissions for yb_home_dir are 750
chmod 750 "{{ yb_home_dir }}"

0 comments on commit b80999d

Please sign in to comment.