/
make-docker.sh
205 lines (173 loc) · 7.79 KB
/
make-docker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
#
# Created: 27-July-2016
# Author: EJK
# Description:
#
# A short post installation utility script to set up a Web Service server on a private
# network within SoftLayer. This file can be executed standalone or implemented as part
# of a post installation script. The script itself does the following:
#
# - creates a logfile so we can debug;
# - sets the timezone correctly;
# - sets up the IPtables implementation;
# - carries out a yum update;
# - yum installs the EPEL release;
# - yum installs fail2ban;
# - configures fail2ban;
# - adds a 'sysadm' user;
# - adds the 'sysadm' user to sudoers file;
# - adds the 'sysadm' ssh keys;
# - restarts ssh daemon;
# - installs the docker-engine package; and
# - starts Docker.
#
# Note: There have been issues with connectivity from a private only network implementation
# and the Docker repo. So this script has failed where firewall and proxy services are not
# enabling the repo to be downloaded and installed. At present this works only when a machine
# has public network access.
#
# Dependencies:
# 1) A SoftLayer account;
# 2) Assumes CentOS 7 operating system (recommended by Docker);
# 3) Assumes a minimum kernel version of 3.10;
# 4) Assumes the latest Docker tarball exists on your internal web server; and
# 4) Assumes a minimal build.
#
# License: MIT License
# Copyright (c)2016, SaaSify Limited, EJK
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# ----------------------------------------------------------------------------------------
#
# SCRIPT STARTS
#
# ----------------------------------------------------------------------------------------
#
# Script Variables
#
# From a change control perspective this script is set up in such a way that simply changing
# these variables will deliver the changes without having to change the structure of the
# bash script itself.
#
LOGFILE="logs/make-docker.log"
sysadmuid="968"
sysadmuser="sysadm"
#
# Lets create a log of the install
#
mkdir logs
exec > >(tee -i $LOGFILE)
exec 2>&1
echo "********************************************************************************"
echo "* setting the timezone *"
echo "********************************************************************************"
#
# Link the timezone correctly
#
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
echo "********************************************************************************"
echo "* executing Yum update *"
echo "********************************************************************************"
#
# Now the yum update
#
yum -y update
#
# Lets quickly add fail2ban if you wish to use it!
#
echo "********************************************************************************"
echo "* executing Fail2Ban Install *"
echo "********************************************************************************"
yum -y install epel-release
yum -y install fail2ban
chkconfig --levels 235 fail2ban on
echo "[sshd]" >> /etc/fail2ban/jail.local
echo "enabled = true" >> /etc/fail2ban/jail.local
echo "filter = sshd" >> /etc/fail2ban/jail.local
echo "action = iptables[name=SSH, port=ssh, protocol=tcp]" >> /etc/fail2ban/jail.local
echo "logpath = /var/log/secure" >> /etc/fail2ban/jail.local
echo "bantime = 3600" >> /etc/fail2ban/jail.local
echo "maxretry = 3" >> /etc/fail2ban/jail.local
service fail2ban restart
#
# Add the standard administration user for your machines on SoftLayer. Given we're using
# images as part of the build we need to be sure we maintain consistency over the uid and
# trusted keys that get implemented on new machines. To do this we need to eradicate any
# existing standard Systems Administration user that may be contained in the image file.
#
echo "********************************************************************************"
echo "* adding 'sysadm' user *"
echo "********************************************************************************"
id -u $sysadmuser > /dev/null
if [ $? == 1 ]; then
useradd $sysadmuser -u $sysadmuid -c "Standard Systems Administration User" -m
else
userdel -r $sysadmuser
useradd $sysadmuser -u $sysadmuid -c "Standard Systems Administration User" -m
fi
#
# Add a password for the administration user - clearly this is suboptimal and the future
# trajectory for this aspect is to add a standard administrative user to LDAP and to
# manage the password distribution through that mechanism. For expediency in the POC
# the password is set here. That said this script is removing the ability to SSH into
# accounts using passwords so security integrity is maintained. Only access to the console
# would enable the use of this password.
#
passwd sysadm <<EOT
t5QMF;{/rP>aW/c6
t5QMF;{/rP>aW/c6
EOT
#
# We need to add the standard Systems Administrator account to the sudoers file
#
echo "sysadm ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
#
# We need to add the trusted keys file into the .ssh directory of the standard Syatems
# Administration users home directory.
#
mkdir /home/sysadm/.ssh
chown sysadm /home/sysadm/.ssh
chmod 700 /home/sysadm/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJApotnI8z+jw8qIlfmE6HdKrb1SjvXsenAlvhM73DtuQtXnM2Wc3nxi3pAmdWQPsXBmsWaohKu6rXqY8KMEH8eRxEjaVxyi8qOgWVwtXRHvo+l5BHrzETDQSjxAHi98DYAnOx4tx6qhpXNfACepbBh0vzTfhZ6UPff6hpNk9jnm9NS9EC7BRhxz7CJmCdPYfcq0xLV+mnLNemG9z2evEXQytXMvhGw1ekeUViCsgt6ceKbVkKSHRWcIL2De4EE8pCnZyK2Ac33nm4HCF65QJP0QUHrE+9Ga+KJrqfXqLylg17WS70Qk5u6d1jf23gsEltMmH5ckCjfPzsHzaC06SJ saasify@Eamonns-iMac.local" > /home/sysadm/.ssh/authorized_keys
chown sysadm /home/sysadm/.ssh/authorized_keys
chmod 600 /home/sysadm/.ssh/authorized_keys
#
# Restart the ssh service
#
service sshd restart
#
# Lets quickly add the Docker repo
#
echo "********************************************************************************"
echo "* executing Docker installation *"
echo "********************************************************************************"
echo "[dockerrepo]" > /etc/yum.repos.d/docker.repos
echo "name=Docker Repository" >> /etc/yum.repos.d/docker.repos
echo "baseurl=https://yum.dockerproject.org/repo/main/centos/7/" >> /etc/yum.repos.d/docker.repos
echo "enabled=1" >> /etc/yum.repos.d/docker.repos
echo "gpgcheck=1" >> /etc/yum.repos.d/docker.repos
echo "gpgkey=https://yum.dockerproject.org/gpg" >> /etc/yum.repos.d/docker.repos
yum -y install docker-engine
/bin/systemctl start docker.service
exit 0
# ----------------------------------------------------------------------------------------
#
# SCRIPT FINISHES
#
# ----------------------------------------------------------------------------------------