Skip to content

Commit 045a587

Browse files
authored
Linux: Add first networking challenge: Firewall management (#9)
1 parent b594449 commit 045a587

30 files changed

Lines changed: 629 additions & 251 deletions

.github/workflows/main.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: main
2+
3+
on:
4+
push:
5+
branches: ['**']
6+
7+
jobs:
8+
main:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Go 1.19+
16+
uses: actions/setup-go@v4
17+
with:
18+
go-version: '>=1.19'
19+
20+
# Linux workshop
21+
- name: CI
22+
run: 'cd ./linux && bash ./scripts/ci.sh'

linux/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
local_team_servers := $(shell vagrant status | grep -E -o 'team[0-9]+')
22

3+
ci:
4+
@bash ./scripts/ci.sh
5+
36
up-local:
4-
@vagrant up db
5-
@vagrant up $(local_team_servers)
7+
# NOTE: --parallel might not work for all providers, but does for libvirt
8+
@vagrant up --parallel
69

710
up-aws:
811
@terraform -chdir=./terraform apply

linux/Vagrantfile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Allows for setting an env var for fewer (or more) team servers, for different
2+
# testing scenarios & hardware
3+
num_team_servers = Integer(ENV["num_team_servers"].nil? ? 2 : ENV["num_team_servers"])
4+
15
Vagrant.configure("2") do |config|
26
box = "debian/bookworm64" # Debian 12
37

@@ -26,27 +30,33 @@ Vagrant.configure("2") do |config|
2630
db.vm.box = box
2731

2832
db.vm.network "private_network", ip: db_addr
29-
db.vm.network "forwarded_port", guest: 5432, host: 5432, protocol: "tcp"
30-
db.vm.network "forwarded_port", guest: 8080, host: 8080, protocol: "tcp"
33+
db.vm.network "forwarded_port", guest: 5432, host: 5432, protocol: "tcp" # DB
34+
db.vm.network "forwarded_port", guest: 8000, host: 8000, protocol: "tcp" # Dummy web app
35+
db.vm.network "forwarded_port", guest: 8080, host: 8080, protocol: "tcp" # Score dashboard
3136

3237
db.vm.synced_folder ".", "/vagrant", disabled: true
3338

3439
db.vm.provision "file", source: "./scripts", destination: "/tmp/scripts"
40+
db.vm.provision "file", source: "./services", destination: "/tmp/services"
3541
db.vm.provision "file", source: "./score-server", destination: "/tmp/score-server"
42+
db.vm.provision "file", source: "./dummy-web-app", destination: "/tmp/dummy-web-app"
3643

3744
db.vm.provision "shell",
3845
inline: <<-SCRIPT
46+
#!/usr/bin/env bash
47+
set -euo pipefail
48+
3949
# Need both running here for Vagrant -- other platforms should ONLY have 2332
40-
sudo sh -c 'grep 2332 /etc/ssh/sshd_config || printf "Port 2332\nPort 22\n" >> /etc/ssh/sshd_config'
50+
sudo sh -c 'grep -q 2332 /etc/ssh/sshd_config || printf "Port 2332\nPort 22\n" >> /etc/ssh/sshd_config'
4151
sudo systemctl restart ssh
4252
43-
rm -rf /root/score-server
44-
sudo cp -r /tmp/score-server /root/score-server
53+
rm -rf /root/{score-server,services,dummy-web-app}
54+
sudo cp -r /tmp/{score-server,services,dummy-web-app} /root/
4555
bash /tmp/scripts/init-db.sh
4656
SCRIPT
4757
end
4858

49-
(1..2).each do |i|
59+
(1..num_team_servers).each do |i|
5060
config.vm.define "team#{i}" do |team|
5161
team.vm.box = box
5262

@@ -63,8 +73,11 @@ Vagrant.configure("2") do |config|
6373

6474
team.vm.provision "shell",
6575
inline: <<-SCRIPT
76+
#!/usr/bin/env bash
77+
set -euo pipefail
78+
6679
# Need both running here for Vagrant -- other platforms should ONLY have 2332
67-
sudo sh -c 'grep 2332 /etc/ssh/sshd_config || printf "Port 2332\nPort 22\n" >> /etc/ssh/sshd_config'
80+
sudo sh -c 'grep -q 2332 /etc/ssh/sshd_config || printf "Port 2332\nPort 22\n" >> /etc/ssh/sshd_config'
6881
sudo systemctl restart ssh
6982
7083
export team_name="Team-#{i}"

linux/dummy-web-app/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dummy-web-app
2+
=============
3+
4+
`dummy-web-app` provides a no-op endpoint for participants in the OSC Linux
5+
Workshop to hit as part of Challenge 5. The server itself is (supposed to be)
6+
always running just fine, but Challenge 5 prevents teams from hitting the server
7+
until they open a client-side firewall ruile.

linux/dummy-web-app/go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/opensourcecorp/workshops/linux/dummy-web-app
2+
3+
go 1.19
4+
5+
require github.com/sirupsen/logrus v1.9.3
6+
7+
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect

linux/dummy-web-app/go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
7+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
8+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
9+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
10+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
11+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
12+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
14+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
15+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

linux/dummy-web-app/main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net/http"
7+
8+
"github.com/sirupsen/logrus"
9+
)
10+
11+
func getRoot(w http.ResponseWriter, r *http.Request) {
12+
log.Println("hit on /")
13+
_, err := fmt.Fprint(w, "You fixed it! But we're busy printing money over here, so... get lost.\n")
14+
if err != nil {
15+
logrus.Fatalf("writing to RepsonseWriter: %v", err)
16+
}
17+
}
18+
19+
func getHealth(w http.ResponseWriter, r *http.Request) {
20+
log.Println("hit on /health")
21+
_, err := fmt.Fprint(w, "ok\n")
22+
if err != nil {
23+
logrus.Fatalf("writing to RepsonseWriter: %v", err)
24+
}
25+
}
26+
27+
func main() {
28+
addr := ":8000"
29+
30+
http.HandleFunc("/", getRoot)
31+
http.HandleFunc("/health", getHealth)
32+
33+
log.Printf("starting server on %s\n", addr)
34+
if err := http.ListenAndServe(addr, nil); err != nil {
35+
logrus.Fatalf("starting server: %v", err)
36+
}
37+
}
File renamed without changes.

linux/instructions/challenge_1.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Challenge 1: Rebuild the app binary
2+
===================================
3+
4+
You hop into the production server and need to figure out why the application
5+
isn't running. Based on the architecture diagram for the app and your knowledge
6+
of your company's deployment pipelines, you know the source code for it should
7+
have been dumped into the directory `/opt/app`. That's probably the best place
8+
to start looking; as a first step, see if you can get the app binary built. Note
9+
that the application is written in Go, so you might need to look up how to build
10+
a Go binary.
11+
12+
Take note of any error messages when trying to build it, and fix any issues you
13+
find.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Step 2: Make binary more accessible
2-
===================================
1+
Challenge 2: Make binary more accessible
2+
========================================
33

44
You got the binary rebuilt, great work! However, the app is in kind of a weird
55
place on the filesystem -- there's nothing *wrong* with apps being under the

0 commit comments

Comments
 (0)