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

PMM-12529 Run pmm-agent as non root #2590

Merged
merged 22 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
08116ea
PMM-12529 run pmm-agent as non-root
ademidoff Nov 3, 2023
c1b14d3
PMM-12529 update the spec and package files to leverage user pmm
ademidoff Nov 3, 2023
b68b5fb
PMM-12529 fix the changelog
ademidoff Nov 3, 2023
2f0bf7f
PMM-12529 see if disabling parallel fixes the tests
ademidoff Nov 3, 2023
1b5bae4
PMM-12529 leave a todo for re-enabling parallel runs
ademidoff Nov 3, 2023
c618a8d
PMM-12529 do not create pmm-agent user
ademidoff Nov 9, 2023
a5893c9
Merge branch 'v3' into PMM-12529-run-pmm-agent-as-non-root
ademidoff Nov 9, 2023
665fbda
PMM-12529 add PostgreSQL to deb description
ademidoff Nov 10, 2023
44ebb77
PMM-12529 restore some changes
ademidoff Nov 14, 2023
fdfb135
Merge branch 'PMM-12529-run-pmm-agent-as-non-root' of github.com:perc…
ademidoff Nov 14, 2023
c2dc73e
PMM-12529 provide a playbook to install pmm-client
ademidoff Nov 17, 2023
c866368
PMM-12529 fix a typo
ademidoff Nov 19, 2023
9ce2a1b
PMM-12529 Move the agent role to build roles
ademidoff Nov 19, 2023
1e1be00
PMM-12529 fix the tax syntax
ademidoff Nov 20, 2023
6c98cd6
PMM-12529 create an empty dir
ademidoff Nov 20, 2023
94431f8
PMM-12529 pass the client to PMM Server docker
ademidoff Nov 20, 2023
5d525e8
PMM-12529 fix the tabulation
ademidoff Nov 20, 2023
0af13d7
Merge branch 'v3' into PMM-12529-run-pmm-agent-as-non-root
ademidoff Nov 20, 2023
119bdd6
PMM-12529 remove v2 from paths
ademidoff Nov 20, 2023
b786fbf
Merge branch 'v3' into PMM-12529-run-pmm-agent-as-non-root
ademidoff Nov 21, 2023
b83c76c
PMM-12529 update the agent installation path
ademidoff Nov 22, 2023
896b4ed
Merge branch 'v3' into PMM-12529-run-pmm-agent-as-non-root
ademidoff Nov 30, 2023
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
2 changes: 0 additions & 2 deletions build/ansible/roles/pmm2-images/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
- { name: nginx, gid: 999 }
- { name: grafana, gid: 998 }
- { name: clickhouse, gid: 997 }
- { name: pmm-agent, gid: 996 }

- name: Create users | Create users
user:
Expand All @@ -119,7 +118,6 @@
- { name: nginx, uid: 999, comment: "nginx user", shell: "/sbin/nologin", home: "/var/cache/nginx", group: nginx, }
- { name: grafana, uid: 998, comment: "Grafana Dashboard", shell: "/sbin/nologin", home: "/etc/grafana", group: grafana, }
- { name: clickhouse, uid: 997, comment: "Clickhouse server", shell: "/sbin/nologin", home: "/var/lib/clickhouse", group: clickhouse, }
- { name: pmm-agent, uid: 996, comment: "pmm-agent", shell: "/bin/false", home: "/usr/local/percona/", group: pmm-agent, }
when: ansible_virtualization_type == "docker"

- name: Create directories | Create dirs
Expand Down
1 change: 0 additions & 1 deletion build/docker/server/create_users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ users=(
"nginx:999:/sbin/nologin:/var/cache/nginx:nginx"
"grafana:998:/sbin/nologin:/etc/grafana:grafana"
"clickhouse:997:/sbin/nologin:/var/lib/clickhouse:clickhouse"
"pmm-agent:996:/bin/false:/usr/local/percona/:pmm-agent"
)

for user in "${users[@]}"; do
Expand Down
4 changes: 2 additions & 2 deletions build/packages/deb/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ fi

case "$1" in
configure)
chown -R pmm-agent:pmm-agent /usr/local/percona/pmm2
chown -R pmm:pmm /usr/local/percona/pmm2
if [ ! -f /usr/local/percona/pmm2/config/pmm-agent.yaml ]; then
install -d -m 0755 /usr/local/percona/pmm2/config
install -m 0660 -o pmm-agent -g pmm-agent /dev/null /usr/local/percona/pmm2/config/pmm-agent.yaml
install -m 0660 -o pmm -g pmm /dev/null /usr/local/percona/pmm2/config/pmm-agent.yaml
fi
;;

Expand Down
2 changes: 1 addition & 1 deletion build/packages/deb/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ case "$1" in
esac

if [ "$1" = "purge" ]; then
userdel pmm-agent || true
userdel pmm || true
if [ -f /usr/local/percona/pmm2/config/pmm-agent.yaml ]; then
rm -f /usr/local/percona/pmm2/config/pmm-agent.yaml
fi
Expand Down
4 changes: 2 additions & 2 deletions build/packages/deb/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# create group and user

if ! getent passwd pmm-agent >/dev/null 2>&1; then
adduser --system --home /usr/local/percona --group pmm-agent
if ! getent passwd pmm >/dev/null 2>&1; then
adduser --system --home /usr/local/percona --group pmm
fi

#DEBHELPER#
Expand Down
25 changes: 14 additions & 11 deletions build/packages/rpm/client/pmm2-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ rm -rf $RPM_BUILD_ROOT

%pre
if [ $1 == 1 ]; then
if ! getent passwd pmm-agent > /dev/null 2>&1; then
/usr/sbin/groupadd -r pmm-agent
/usr/sbin/useradd -M -r -g pmm-agent -d /usr/local/percona/ -s /bin/false -c pmm-agent pmm-agent > /dev/null 2>&1
if ! getent passwd pmm > /dev/null 2>&1; then
/usr/sbin/groupadd -r pmm
/usr/sbin/useradd -M -r -g pmm -d /usr/local/percona/ -s /bin/false -c pmm pmm > /dev/null 2>&1
fi
fi
if [ $1 -eq 2 ]; then
Expand All @@ -117,7 +117,7 @@ done
if [ $1 == 1 ]; then
if [ ! -f /usr/local/percona/pmm2/config/pmm-agent.yaml ]; then
install -d -m 0755 /usr/local/percona/pmm2/config
install -m 0660 -o pmm-agent -g pmm-agent /dev/null /usr/local/percona/pmm2/config/pmm-agent.yaml
install -m 0660 -o pmm -g pmm /dev/null /usr/local/percona/pmm2/config/pmm-agent.yaml
fi
/usr/bin/systemctl enable pmm-agent >/dev/null 2>&1 || :
/usr/bin/systemctl daemon-reload
Expand All @@ -135,17 +135,17 @@ fi
%postun
case "$1" in
0) # This is a yum remove.
/usr/sbin/userdel pmm-agent
/usr/sbin/userdel pmm
%systemd_postun_with_restart pmm-agent.service
;;
1) # This is a yum upgrade.
%systemd_postun_with_restart pmm-agent.service
;;
esac
if [ $1 == 0 ]; then
if /usr/bin/id -g pmm-agent > /dev/null 2>&1; then
/usr/sbin/userdel pmm-agent > /dev/null 2>&1
/usr/sbin/groupdel pmm-agent > /dev/null 2>&1 || true
if /usr/bin/id -g pmm > /dev/null 2>&1; then
/usr/sbin/userdel pmm > /dev/null 2>&1
/usr/sbin/groupdel pmm > /dev/null 2>&1 || true
if [ -f /usr/local/percona/pmm2/config/pmm-agent.yaml ]; then
rm -r /usr/local/percona/pmm2/config/pmm-agent.yaml
fi
Expand All @@ -164,12 +164,15 @@ fi

%files
%config %{_unitdir}/pmm-agent.service
%attr(0660,pmm-agent,pmm-agent) %ghost /usr/local/percona/pmm2/config/pmm-agent.yaml
%attr(-,pmm-agent,pmm-agent) /usr/local/percona/pmm2
%attr(0660,pmm,pmm) %ghost /usr/local/percona/pmm2/config/pmm-agent.yaml
%attr(-,pmm,pmm) /usr/local/percona/pmm2

%changelog
* Fri Nov 3 2023 Alex Demidoff <[email protected]>
- PMM-12529 run pmm-agent as non-root pmm user.

* Tue Jun 21 2022 Nikita Beletskii <[email protected]>
- PMM-7 remove support for RHEL older then 7
- PMM-7 remove support for RHEL older then 7.

* Tue Aug 24 2021 Vadim Yalovets <[email protected]>
- PMM-8618 ship default PG queries in PMM.
Expand Down
1 change: 1 addition & 0 deletions managed/services/supervisord/pmm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ redirect_stderr = true
[program:pmm-agent]
priority = 15
command = /usr/sbin/pmm-agent --config-file=/usr/local/percona/pmm2/config/pmm-agent.yaml
user = pmm
autorestart = true
autostart = true
startretries = 1000
Expand Down
1 change: 1 addition & 0 deletions managed/testdata/supervisord.d/pmm-db_disabled.ini
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ redirect_stderr = true
[program:pmm-agent]
priority = 15
command = /usr/sbin/pmm-agent --config-file=/usr/local/percona/pmm2/config/pmm-agent.yaml
user = pmm
autorestart = true
autostart = true
startretries = 1000
Expand Down
1 change: 1 addition & 0 deletions managed/testdata/supervisord.d/pmm-db_enabled.ini
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ redirect_stderr = true
[program:pmm-agent]
priority = 15
command = /usr/sbin/pmm-agent --config-file=/usr/local/percona/pmm2/config/pmm-agent.yaml
user = pmm
autorestart = true
autostart = true
startretries = 1000
Expand Down