-
9 votes
-
Google should rotate their email DKIM keys periodically and publish past secret keys, in order to remove the unintended capability for authenticating years-old emails
16 votes -
The old way of handing out corporate hardware doesn’t work anymore
9 votes -
Does Apple really log every app you run? A technical look (The answer? No.)
13 votes -
Installing and analyzing every package in PyPI to look for malicious activity
6 votes -
Researching the potential of using machine learning to predict random number generation
11 votes -
The battle for the soul of digital freedom taking place inside your printer
15 votes -
Chrome will soon have its own dedicated certificate root store
8 votes -
Veronica Mars and NTLM password hashes
7 votes -
How a fake persona laid the groundwork for a Hunter Biden conspiracy deluge
12 votes -
Why the extortion of Vastaamo matters far beyond Finland – and how cyber pros are responding
4 votes -
In which a foolish developer tries DevOps: critique my VPS provisioning script!
I'm attempting to provision two mirror staging and production environments for a future SaaS application that we're close to launching as a company, and I'd like to get some feedback on the...
I'm attempting to provision two mirror staging and production environments for a future SaaS application that we're close to launching as a company, and I'd like to get some feedback on the provisioning script I've created that takes a default VPS from our hosting provider, DigitalOcean, and readies it for being a secure hosting environment for our application instance (which runs inside Docker, and persists data to an unrelated managed database).
I'm sticking with a simple infrastructure architecture at the moment: A single VPS which runs both nginx and the application instance inside a containerised docker service as mentioned earlier. There's no load balancers or server duplication at this point. @Emerald_Knight very kindly provided me in the Tildes Discord with some overall guidance about what to aim for when configuring a server (limit damage as best as possible, limit access when an attack occurs)—so I've tried to be thoughtful and integrate that paradigm where possible (disabling root login, etc).
I’m not a DevOps or sysadmin-oriented person by trade—I stick to programming most of the time—but this role falls to me as the technical person in this business; so the last few days has been a lot of reading and readying. I’ll run through the provisioning flow step by step. Oh, and for reference, Ubuntu 20.04 LTS.
First step is self-explanatory.
#!/bin/sh # Name of the user to create and grant privileges to. USERNAME_OF_ACCOUNT= sudo apt-get -qq update sudo apt install -qq --yes nginx sudo systemctl restart nginx
Next, create my sudo user, add them to the groups needed, require a password change on first login, then copy across any provided authorised keys from the root user which you can configure to be seeded to the VPS in the DigitalOcean management console.
useradd --create-home --shell "/bin/bash" --groups sudo,www-data "${USERNAME_OF_ACCOUNT}" passwd --delete $USERNAME_OF_ACCOUNT chage --lastday 0 $USERNAME_OF_ACCOUNT HOME_DIR="$(eval echo ~${USERNAME_OF_ACCOUNT})" mkdir --parents "${HOME_DIR}/.ssh" cp /root/.ssh/authorized_keys "${HOME_DIR}/.ssh" chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys chown --recursive "${USERNAME_OF_ACCOUNT}":"${USERNAME_OF_ACCOUNT}" "${HOME_DIR}/.ssh" sudo chmod 775 -R /var/www sudo chown -R $USERNAME_OF_ACCOUNT /var/www rm -rf /var/www/html
Installation of docker, and run it as a service, ensure the created user is added to the docker group.
sudo apt-get install -qq --yes \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo apt-key fingerprint 0EBFCD88 sudo add-apt-repository --yes \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" sudo apt-get -qq update sudo apt install -qq --yes docker-ce docker-ce-cli containerd.io # Only add a group if it does not exist sudo getent group docker || sudo groupadd docker sudo usermod -aG docker $USERNAME_OF_ACCOUNT # Enable docker sudo systemctl enable docker sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose docker-compose --version
Disable root logins and any form of password-based authentication by altering
sshd_config
.sed -i '/^PermitRootLogin/s/yes/no/' /etc/ssh/sshd_config sed -i '/^PasswordAuthentication/s/yes/no/' /etc/ssh/sshd_config sed -i '/^ChallengeResponseAuthentication/s/yes/no/' /etc/ssh/sshd_config
Configure the firewall and fail2ban.
sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow ssh sudo ufw allow http sudo ufw allow https sudo ufw reload sudo ufw --force enable && sudo ufw status verbose sudo apt-get -qq install --yes fail2ban sudo systemctl enable fail2ban sudo systemctl start fail2ban
Swapfiles.
sudo fallocate -l 1G /swapfile && ls -lh /swapfile sudo chmod 0600 /swapfile && ls -lh /swapfile sudo mkswap /swapfile sudo swapon /swapfile && sudo swapon --show echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Unattended updates, and restart the ssh daemon.
sudo apt install -qq unattended-upgrades sudo systemctl restart ssh
Some questions
You can assume these questions are cost-benefit focused, i.e. is it worth my time to investigate this, versus something else that may have better gains given my limited time.
- Obviously, any critiques of the above provisioning process are appreciated—both on the micro level of criticising particular lines, or zooming out and saying “well why don’t you do this instead…”. I can’t know what I don’t know.
- Is it worth investigating tools such as
ss
orlynis
(https://github.com/CISOfy/lynis) to perform server auditing? I don’t have to meet any compliance requirements at this point. - Do I get any meaningful increase in security by implementing 2FA on login here using google authenticator? As far as I can see, as long as I'm using best practices to actually
ssh
into our boxes, then the likeliest risk profile for unwanted access probably isn’t via the authentication mechanism I use personally to access my servers. - Am I missing anything here? Beyond the provisioning script itself, I adhere to best practices around storing and generating passwords and ssh keys.
Some notes and comments
- Eventually I'll use the hosting provider's API to spin up and spin down VPS's on the fly via a custom management application, which gives me an opportunity to programmatically execute the provisioning script above and run some over pre- and post-provisioning things, like deployment of the application and so forth.
- Usage alerts and monitoring is configured within DigitalOcean's console, and alerts are sent to our business' Slack for me to action as needed. Currently, I’m settling on the following alerts:
- Server CPU utilisation greater than 80% for 5 minutes.
- Server memory usage greater than 80% for 5 minutes.
- I’m also looking at setting up daily fail2ban status alerts if needed.
9 votes -
Finland's interior minister summoned an emergency meeting after patient records at a private Finnish psychotherapy center were accessed by hackers
5 votes -
Helping people spot the spoofs: A URL experiment
7 votes -
Norway has blamed Russia for a cyberattack on the email system in the parliament in August – Moscow has rejected the claim, calling it a serious and wilful provocation
6 votes -
Hacking Apple for 3 months - 55 vulnerabilities discovered, with $288,500 in bug bounties awarded
10 votes -
Hacking Grindr accounts with copy and paste
21 votes -
EARN IT Act introduced in House of Representatives
37 votes -
Druva introduces software as a service data protection for Kubernetes
4 votes -
Escaping the dark forest - Rescuing over $9.6 million worth of Ethereum from a vulnerable smart contract
8 votes -
Microsoft leaks 6.5TB in Bing search data via unsecured Elastic server
12 votes -
You're going to be using confidential computing sooner rather than later
8 votes -
Ransomware attack at German hospital leads to death of patient
11 votes -
A crash course in CDA Section 230, and a discussion between two lawyers about the EARN IT Act and what it means for free speech and privacy online
5 votes -
When you browse Instagram and find former Australian Prime Minister Tony Abbott's passport number
32 votes -
How police are using 'super recognizers' to track criminals
9 votes -
Beyond the end of the Transban: How to make a 21st-century military
5 votes -
Online voting is much more difficult to do securely, and a fundamental problem with the concept is that most voters won't be able to understand whether it's secure or not
21 votes -
An exploration of Project Zero Issue 2046, a seemingly unexploitable and simple bug in the V8 JavaScript engine that turns out to be exploitable in a very complex manner
7 votes -
A secure operating system
11 votes -
Malware in the wild using DNS-over-HTTPS (DoH) to pull payload
8 votes -
Threat modelling case study: bicycles
7 votes -
Sendgrid under siege from hacked accounts
7 votes -
Denmark suspends Lars Findsen, head of the country's foreign intelligence service – Danish Defense Intelligence Service had initiated operations that were contrary to Danish law
9 votes -
Why and where you should plant your flag
12 votes -
Former Chief Security Officer for Uber charged with obstruction of justice for attempted cover-up of 2016 hack that compromised data from millions of users and drivers
9 votes -
US universities seek ways to protect students and faculty from being prosecuted by Chinese authorities
7 votes -
Mozilla signs fresh Google search deal worth mega-millions as 25% staff cut hits Servo, MDN, security teams
16 votes -
NSA and FBI warn that previously undisclosed Drovorub malware for Linux threatens national security
22 votes -
Achilles: Over 400 vulnerabilities found in Qualcomm’s Snapdragon DSP chip, threatening the security of hundreds of millions of Android devices
17 votes -
Microsoft faces complex technical challenges in TikTok carveout
5 votes -
Reddit moderator accounts compromised in coordinated hack, hundreds of subreddits vandalized
29 votes -
Reversing Lyft’s ride history API to analyze 6 years worth of rides
4 votes -
20GB of Intel's internal source code, schematics, specs, and documents released, allegedly found on an unsecured CDN server
20 votes -
GitLab Support will no longer process MFA resets for free accounts as of August 15th, 2020 - make sure you have a valid backup recovery method set up
14 votes -
US Treasury Secretary Steven Mnuchin confirms TikTok is under review by the Committee on Foreign Investment in the US following national security concerns
11 votes -
Seventeen-year-old in Tampa, Florida arrested and accused of "masterminding" the compromises of prominent Twitter accounts on July 15, charged with thirty felonies
34 votes -
Bitwarden review
11 votes -
More than 1,000 people at Twitter had ability to aid hack of accounts
8 votes -
New ‘Meow’ attack has deleted almost 4000 unsecured databases
14 votes