forked from VantaInc/vanta-agent-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-linux.sh
executable file
·235 lines (200 loc) · 7.33 KB
/
install-linux.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
# Available environment variables:
# VANTA_KEY (the Vanta per-domain secret key)
# VANTA_NOSTART (if true, then don't start the service upon installation.)
# VANTA_EXPERIMENTAL_SELINUX (if true, then also install the SELinux package). Currently Redhat/Centos only.
set -e
DEB_URL="https://vanta-agent-repo.s3.amazonaws.com/targets/versions/2.0.8/vanta-amd64.deb"
RPM_URL="https://vanta-agent-repo.s3.amazonaws.com/targets/versions/2.0.8/vanta-amd64.rpm"
# Checksums need to be updated when PKG_URL is updated.
DEB_CHECKSUM="4fae1b93708d7a6ff1df0b716211ee6a79f8f1e6b25566fb02b6dcdfdaada882"
RPM_CHECKSUM="beb5d2630afde4b96368fe602865f47364ae522595790c0a37f805a0aadc55ff"
DEB_PATH="$(mktemp -d)/vanta.deb"
RPM_PATH="$(mktemp -d)/vanta.rpm"
DEB_INSTALL_CMD="dpkg -Ei"
RPM_INSTALL_CMD="rpm -i"
SELINUX_PATH="$(mktemp -d)/vanta_selinux.rpm"
SELINUX_URL="https://vanta-agent.s3.amazonaws.com/vanta_agent_selinux-1.2-1.el8.noarch.rpm"
UUID_PATH="/sys/class/dmi/id/product_uuid"
# OS/Distro Detection
# Try lsb_release, fallback with /etc/issue then uname command
# Detection code taken from https://github.com/DataDog/datadog-agent/blob/master/cmd/agent/install_script.sh
KNOWN_DISTRIBUTION="(Debian|Ubuntu|RedHat|CentOS|openSUSE|Amazon|Arista|SUSE)"
DISTRIBUTION=$(lsb_release -d 2>/dev/null | grep -Eo $KNOWN_DISTRIBUTION || grep -Eo $KNOWN_DISTRIBUTION /etc/issue 2>/dev/null || grep -Eo $KNOWN_DISTRIBUTION /etc/Eos-release 2>/dev/null || grep -m1 -Eo $KNOWN_DISTRIBUTION /etc/os-release 2>/dev/null || uname -s)
if [ -f /etc/debian_version -o "$DISTRIBUTION" == "Debian" -o "$DISTRIBUTION" == "Ubuntu" ]; then
OS="Debian"
elif [ -f /etc/redhat-release -o "$DISTRIBUTION" == "RedHat" -o "$DISTRIBUTION" == "CentOS" -o "$DISTRIBUTION" == "Amazon" ]; then
OS="RedHat"
# Some newer distros like Amazon may not have a redhat-release file
elif [ -f /etc/system-release -o "$DISTRIBUTION" == "Amazon" ]; then
OS="RedHat"
# Arista is based off of Fedora14/18 but do not have /etc/redhat-release
elif [ -f /etc/Eos-release -o "$DISTRIBUTION" == "Arista" ]; then
OS="RedHat"
# openSUSE and SUSE use /etc/SuSE-release or /etc/os-release
elif [ -f /etc/SuSE-release -o "$DISTRIBUTION" == "SUSE" -o "$DISTRIBUTION" == "openSUSE" ]; then
OS="SUSE"
fi
##
# Vanta needs to be installed as root; use sudo if not already uid 0
##
if [ $(echo "$UID") = "0" ]; then
SUDO=''
else
SUDO='sudo -E'
fi
function get_platform() {
if ! command -v lsb_release &> /dev/null; then
echo "${DISTRIBUTION}"
else
lsb_release -sd
fi
}
if [ "${OS}" == "Debian" ]; then
printf "\033[34m\n* Debian detected \n\033[0m"
PKG_URL=$DEB_URL
PKG_PATH=$DEB_PATH
INSTALL_CMD=$DEB_INSTALL_CMD
CHECKSUM=$DEB_CHECKSUM
elif [ "${OS}" == "RedHat" ]; then
printf "\033[34m\n* RedHat detected \n\033[0m"
PKG_URL=$RPM_URL
PKG_PATH=$RPM_PATH
INSTALL_CMD=$RPM_INSTALL_CMD
CHECKSUM=$RPM_CHECKSUM
else
printf "\033[31m
Cannot install the Vanta agent on unsupported platform $(get_platform).
Please reach out to support@vanta.com for help.
\n\033[0m\n"
exit 1
fi
if [ ! -f "$UUID_PATH" ]; then
printf "\033[31m
Unable to detect hardware UUID – the Vanta Agent is only supported on platforms which provide a value in $UUID_PATH
\n\033[0m\n"
exit 1
fi
hardware_uuid=$($SUDO cat $UUID_PATH)
printf "\033[34m\nHardware UUID: $hardware_uuid\n\033[0m"
bad_uuids=(
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
"ffffffff-ffff-ffff-ffff-ffffffffffff"
"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
"00000000-0000-0000-0000-000000000000"
"11111111-1111-1111-1111-111111111111"
"03000200-0400-0500-0006-000700080009"
"03020100-0504-0706-0809-0a0b0c0d0e0f"
"03020100-0504-0706-0809-0a0b0c0d0e0f"
"10000000-0000-8000-0040-000000000000"
"01234567-8910-1112-1314-151617181920"
)
for uuid in ${bad_uuids[*]}; do
if [ "$uuid" = "$hardware_uuid" ]; then
printf "\033[31m
Invalid hardware UUID – the Vanta Agent is only supported on platforms which provide a unique value in $UUID_PATH
\n\033[0m\n"
exit 1
fi
done
printf "\033[34m\nUUID check passed.\n\033[0m"
if [ -z "$VANTA_KEY" ]; then
printf "\033[31m
You must specify the VANTA_KEY environment variable in order to install the agent.
\n\033[0m\n"
exit 1
fi
if [ ! -z "$VANTA_EXPERIMENTAL_SELINUX" ]; then
if [ -z "$VANTA_NOSTART" ]; then
printf "\033[31m
You must specify the VANTA_NOSTART environment variable when using VANTA_EXPERIMENTAL_SELINUX.
\n\033[0m\n"
exit 1
fi
if [ "${OS}" != "RedHat" ]; then
printf "\033[31m
SELinux support is not available on your OS.
\n\033[0m\n"
exit 1
fi
printf "\033[34m\n* Downloading the SELinux package\n\033[0m"
rm -f $SELINUX_PATH
curl --progress-bar --output $SELINUX_PATH $SELINUX_URL
fi
function onerror() {
printf "\033[31m$ERROR_MESSAGE
Something went wrong while installing the Vanta agent.
If you're having trouble installing, please send an email to support@vanta.com, and we'll help you fix it!
\n\033[0m\n"
}
trap onerror ERR
##
# Download the agent
##
printf "\033[34m\n* Downloading the Vanta Agent\n\033[0m"
rm -f $PKG_PATH
curl --progress-bar --output $PKG_PATH $PKG_URL
##
# Checksum
##
printf "\033[34m\n* Ensuring checksums match\n\033[0m"
if [ -x "$(command -v shasum)" ]; then
downloaded_checksum=$(shasum -a256 $PKG_PATH | cut -d" " -f1)
elif [ -x "$(command -v sha256sum)" ]; then
downloaded_checksum=$(sha256sum $PKG_PATH | cut -d" " -f1)
else
printf "\033[31m shasum is not installed. Not checking binary contents. \033[0m\n"
# For now, don't fail if shasum is not installed. Delete this check if you want to
# ensure that the checksum is always enforced.
CHECKSUM=""
fi
if [ $downloaded_checksum = $CHECKSUM ]; then
printf "\033[34mChecksums match.\n\033[0m"
else
printf "\033[31m Checksums do not match. Please contact support@vanta.com \033[0m\n"
exit 1
fi
##
# Install the agent
##
printf "\033[34m\n* Installing the Vanta Agent. You might be asked for your password...\n\033[0m"
$SUDO $INSTALL_CMD $PKG_PATH
##
# Install the SELinux package
##
if [ ! -z "$VANTA_EXPERIMENTAL_SELINUX" ]; then
printf "\033[34m\n* Installing SELinux support\n\033[0m"
$SUDO $INSTALL_CMD $SELINUX_PATH
fi
##
# Check whether the agent is registered. It may take a couple of seconds,
# so try 5 times with 5-second pauses in between.
##
if [ -z "$VANTA_SKIP_REGISTRATION_CHECK" ] && [ -z "$VANTA_NOSTART" ]; then
printf "\033[34m\n* Checking registration with Vanta\n\033[0m"
registration_success=false
for i in {1..5}
do
# Pause first, as the chances of registration working immediately are low.
sleep 5
echo "Attempt $i/5"
if $SUDO /var/vanta/vanta-cli check-registration; then
registration_success=true
break
fi
done
if [ "$registration_success" = false ] ; then
printf "\033[31m
Could not verify that the agent is registered to a Vanta domain. Are you sure you used the right key?
\n\033[0m\n" >&2
exit 0
fi
else
printf "\033[34m\n* Skipping registration check\n\033[0m"
fi
printf "\033[32m
The Vanta agent has been installed successfully.
It will run in the background and submit data to Vanta.
You can check the agent status using the \"/var/vanta/vanta-cli status\" command.
\033[0m"