Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
postgresql-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PostgreSQL
postgresql-common
Commits
213f34dd
Commit
213f34dd
authored
9 years ago
by
Christoph Berg
Browse files
Options
Downloads
Patches
Plain Diff
Redirect non-root requests through sudo
parent
f2b58285
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pg_ctlcluster
+3
-7
3 additions, 7 deletions
pg_ctlcluster
systemd/Makefile
+5
-0
5 additions, 0 deletions
systemd/Makefile
systemd/pg_ctlcluster.sudo
+48
-0
48 additions, 0 deletions
systemd/pg_ctlcluster.sudo
systemd/postgresql-common.sudoers
+2
-0
2 additions, 0 deletions
systemd/postgresql-common.sudoers
with
58 additions
and
7 deletions
pg_ctlcluster
+
3
−
7
View file @
213f34dd
...
@@ -420,13 +420,9 @@ if (not $skip_systemctl_redirect and getppid() != 1 and # not run from init
...
@@ -420,13 +420,9 @@ if (not $skip_systemctl_redirect and getppid() != 1 and # not run from init
error
"
cluster is running from systemd, can only restart it as root. Try instead:
\n
sudo systemctl
$action
postgresql
\@
$version
-
$cluster
";
error
"
cluster is running from systemd, can only restart it as root. Try instead:
\n
sudo systemctl
$action
postgresql
\@
$version
-
$cluster
";
# program end
# program end
# otherwise just raise a warning on start and restart as non-root
# otherwise just raise a warning on start and restart as non-root
}
elsif
(
-
t
1
)
{
}
else
{
if
(
$action
=~
/start/
)
{
print
"
Redirecting $1 request to sudo
\n
"
if
(
-
t
1
);
print
"
Warning: the cluster will not be running as a systemd service. Consider using systemctl:
\n
";
system
('
sudo
',
'
/usr/share/postgresql-common/pg_ctlcluster.sudo
',
$version
,
$cluster
,
$action
);
}
elsif
(
$unit_active
)
{
# on stop, warn when running from systemd
print
"
Warning: stopping the cluster using pg_ctlcluster will mark the systemd unit as failed. Consider using systemctl:
\n
";
}
print
"
sudo systemctl
$action
postgresql
\@
$version
-
$cluster
\n
";
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
systemd/Makefile
+
5
−
0
View file @
213f34dd
...
@@ -2,6 +2,11 @@ install:
...
@@ -2,6 +2,11 @@ install:
install
-d
$(
DESTDIR
)
/lib/systemd/system-generators/
$(
DESTDIR
)
/lib/systemd/system/
install
-d
$(
DESTDIR
)
/lib/systemd/system-generators/
$(
DESTDIR
)
/lib/systemd/system/
install
postgresql-generator
$(
DESTDIR
)
/lib/systemd/system-generators/
install
postgresql-generator
$(
DESTDIR
)
/lib/systemd/system-generators/
install
-m644
postgresql
*
.service
$(
DESTDIR
)
/lib/systemd/system/
install
-m644
postgresql
*
.service
$(
DESTDIR
)
/lib/systemd/system/
install
-d
$(
DESTDIR
)
/usr/share/postgresql-common/
install
pg_ctlcluster.sudo
$(
DESTDIR
)
/usr/share/postgresql-common/
install
-d
$(
DESTDIR
)
/etc/sudoers.d/
install
-m400
postgresql-common.sudoers
$(
DESTDIR
)
/etc/sudoers.d/postgresql-common
reload
:
install
reload
:
install
systemctl daemon-reload
systemctl daemon-reload
This diff is collapsed.
Click to expand it.
systemd/pg_ctlcluster.sudo
0 → 100755
+
48
−
0
View file @
213f34dd
#!/usr/bin/perl -wT
# pg_ctlcluster to sudo-systemctl wrapper
#
# (C) 2015 Christoph Berg <myon@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
use
strict
;
use
warnings
;
use
PgCommon
;
# sudo sanity checking
exists
(
$ENV
{
SUDO_UID
})
or
error
"
SUDO_UID is unset, pg_ctlcluster.sudo must be invoked through sudo
";
my
(
$sudo_uid
)
=
$ENV
{
SUDO_UID
}
=~
/^(\d+)$/
;
# wipe environment
%ENV
=
(
PATH
=>
'
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
',
);
# argument handling
@ARGV
==
3
or
error
"
pg_ctlcluster.sudo must be invoked with exactly 3 arguments
";
my
(
$version
)
=
$ARGV
[
0
]
=~
/^(\d+\.\d+)$/
or
error
"
malformatted version number
";
my
(
$cluster
)
=
$ARGV
[
1
]
=~
/^([^'"\s]+)$/
or
error
"
malformatted cluster name
";
my
(
$action
)
=
$ARGV
[
2
]
=~
/^(start|stop|restart|reload)$/
or
error
"
malformatted action
";
cluster_exists
(
$version
,
$cluster
)
or
error
"
specified cluster does not exist
";
# cluster owner checking
my
%info
=
cluster_info
(
$version
,
$cluster
);
exists
(
$info
{
owneruid
})
or
error
"
could not determine cluster owner UID
";
exists
(
$info
{
configuid
})
or
error
"
could not determine cluster config UID
";
$info
{
owneruid
}
==
$sudo_uid
or
error
"
user does not own cluster data directory
";
if
(
$info
{
configuid
}
!=
0
)
{
$info
{
configuid
}
==
$sudo_uid
or
error
"
user does not own cluster config
";
}
# forward action to systemctl
system
"
/bin/systemctl
",
$action
,
"
postgresql
\@
$version
-
$cluster
";
exit
$?
>>
8
;
This diff is collapsed.
Click to expand it.
systemd/postgresql-common.sudoers
0 → 100644
+
2
−
0
View file @
213f34dd
# Allow postgres to manage database clusters
postgres ALL=(root) NOPASSWD: /usr/share/postgresql-common/pg_ctlcluster.sudo
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment