Skip to content

Commit 7c5d0ae

Browse files
committed
Revert "Merge pull request #470 from rkoster/remove-monit-permit-access"
This reverts commit 61e0da3, reversing changes made to 1639545.
1 parent 358c160 commit 7c5d0ae

5 files changed

Lines changed: 59 additions & 3 deletions

File tree

stemcell_builder/stages/bosh_go_agent/assets/runit/agent/run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ set -e
44
export PATH=/var/vcap/bosh/bin:$PATH
55
exec 2>&1
66

7+
source /var/vcap/bosh/etc/monit-access-helper.sh
8+
9+
permit_monit_access
10+
711
cd /var/vcap/bosh
812

913
exec nice -n -15 /var/vcap/bosh/bin/bosh-agent -P $(cat /var/vcap/bosh/etc/operating_system) -C /var/vcap/bosh/agent.json

stemcell_builder/stages/bosh_monit/apply.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ chmod 0700 $chroot/$bosh_dir/etc/monitrc
3030
mkdir -p $chroot/$bosh_app_dir/monit
3131
touch $chroot/$bosh_app_dir/monit/empty.monitrc
3232

33-
cp $dir/assets/monit-access-helper.sh $chroot/$bosh_dir/etc/
33+
# Monit wrapper script:
34+
mv $chroot/$bosh_dir/bin/monit $chroot/$bosh_dir/bin/monit-actual
35+
36+
cp $dir/assets/monit-access-helper.sh $chroot/$bosh_dir/etc/
37+
cp $dir/assets/monit $chroot/$bosh_dir/bin/monit
38+
chmod +x $chroot/$bosh_dir/bin/monit
39+
40+
cp $dir/assets/restrict-monit-api-access $chroot/etc/network/if-up.d/restrict-monit-api-access
41+
chmod +x $chroot/etc/network/if-up.d/restrict-monit-api-access
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source /var/vcap/bosh/etc/monit-access-helper.sh
6+
7+
permit_monit_access
8+
9+
exec /var/vcap/bosh/bin/monit-actual "$@"
Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# This is the integer value of the argument "0xb0540001", which is
2+
# b054:0001 . The major number (the left-hand side) is "BOSH", leet-ified.
3+
# The minor number (the right-hand side) is 1, indicating that this is the
4+
# first thing in our "BOSH" classid namespace.
5+
#
6+
# _Hopefully_ noone uses a major number of "b054", and we avoid collisions _forever_!
7+
# If you need to select new classids for firewall rules or traffic control rules, keep
8+
# the major number "b054" for bosh stuff, unless there's a good reason to not.
9+
#
10+
# The net_cls.classid structure is described in more detail here:
11+
# https://www.kernel.org/doc/Documentation/cgroup-v1/net_cls.txt
12+
13+
monit_isolation_classid=2958295041
14+
115
permit_monit_access() {
2-
/usr/local/sbin/bosh-enable-monit-access
3-
}
16+
net_cls_location="$(cat /proc/self/mounts | grep ^cgroup | grep net_cls | awk '{ print $2 }' )"
17+
net_cls_subproc="$(grep net_cls /proc/self/cgroup | awk -F ":" '{ print $3 }' )"
18+
monit_access_cgroup="${net_cls_location}/${net_cls_subproc}/monit-api-access"
19+
20+
mkdir -p "${monit_access_cgroup}"
21+
echo "${monit_isolation_classid}" > "${monit_access_cgroup}/net_cls.classid"
22+
23+
echo $$ > "${monit_access_cgroup}/tasks"
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
source /var/vcap/bosh/etc/monit-access-helper.sh
4+
5+
if iptables -t mangle -C POSTROUTING -d 127.0.0.1 -p tcp --dport 2822 \
6+
-m cgroup \! --cgroup "${monit_isolation_classid}" -j DROP
7+
then
8+
/bin/true
9+
else
10+
iptables -t mangle -I POSTROUTING -d 127.0.0.1 -p tcp --dport 2822 \
11+
-m cgroup \! --cgroup "${monit_isolation_classid}" -j DROP
12+
iptables -t mangle -I POSTROUTING -d 127.0.0.1 -p tcp --dport 2822 \
13+
-m state --state ESTABLISHED,RELATED -j ACCEPT
14+
fi

0 commit comments

Comments
 (0)