-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshiny-server.yaml
More file actions
108 lines (102 loc) · 3.34 KB
/
shiny-server.yaml
File metadata and controls
108 lines (102 loc) · 3.34 KB
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
#cloud-config
# Add apt mirror to get the latest version of R necessary for Shiny
apt:
sources:
source1:
source: "deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/"
keyid: E298A3A825C0D65DFD57CBB651716619E084DAB9
package_upgrade: true
packages:
- fail2ban
- curl
# Packages for R
- r-base-dev
- libcurl4-gnutls-dev
- libxml2-dev
- libssl-dev
# Packages for Shiny server
- nginx
- gdebi-core
users:
- name: piet
# Add SSH key
#ssh_authorized_keys:
# - ssh-rsa ... Main computer
sudo: ALL=(ALL) NOPASSWD:ALL
groups: sudo
shell: /bin/bash
write_files:
- path: /etc/fail2ban/jail.local
content: |
[DEFAULT]
# Ban hosts for one hour:
bantime = 3600
#
# Override /etc/fail2ban/jail.d/00-firewalld.conf:
banaction = iptables-multiport
#
[sshd]
enabled = true
port = 4444
logpath = %(sshd_log)s
# Forward ports for Shiny
- path: /etc/nginx/sites-enabled/default
content: |
# Mitigation Slow Read/Loris DDOS attack
limit_conn_zone $binary_remote_addr zone=addr:10m;
# Everything else...
server {
# Mitigation Slow Read/Loris DDOS attack
client_body_timeout 5s;
client_header_timeout 5s;
# Everything else...
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# Mitigation Slow Read/Loris DDOS attack
limit_conn addr 250;
# Everything else...
proxy_pass http://127.0.0.1:3838;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 20d;
}
}
runcmd:
# Configure SSH and fail2ban
- sed -i -e '/^[# ]*Port/s/^.*$/Port 4444/' /etc/ssh/sshd_config
- sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config
- sed -i -e '$aAllowUsers piet' /etc/ssh/sshd_config
- sed -i -e '$aDebianBanner no' /etc/ssh/sshd_config
- service ssh restart
- service fail2ban restart
# Prevent Nginx from showing its version number
- sed -i -e '/^[# ]*server_tokens/s/^.*$/server_tokens off;/' /etc/nginx/nginx.conf
- service nginx restart
# Set up a basic firewall, but allow SSH connections
- ufw allow OpenSSH
- ufw allow 'Nginx HTTP'
# Replace this by the following line if port 443 should also be opened
#- ufw allow 'Nginx Full'
- ufw allow 4444/tcp
- ufw --force enable
# Get rid of message about how to run sudo
- install -m 644 -o piet /dev/null /home/piet/.sudo_as_admin_successful
# ### R stuff ###
# Bigger swap file for R on smaller machines
- /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
- /sbin/mkswap /var/swap.1
- /sbin/swapon /var/swap.1
- sh -c 'echo "/var/swap.1 swap swap defaults 0 0 " >> /etc/fstab'
# Install "shiny" package for R
- R -e 'install.packages(c("shiny", "rmarkdown"), repos="https://cran.rstudio.com/")'
# Download and install Shiny
- wget https://download3.rstudio.org/ubuntu-18.04/x86_64/shiny-server-1.5.18.987-amd64.deb
- gdebi -n shiny-server-1.5.18.987-amd64.deb
# Clean package files
- sudo apt-get clean
- service nginx restart