Skip to content

Commit

Permalink
Merge pull request #61 from sdslabs/challengeDeploy
Browse files Browse the repository at this point in the history
Challenge deploy
  • Loading branch information
Bisht13 authored Aug 10, 2023
2 parents 1cc5376 + 42c089d commit 04db0f7
Show file tree
Hide file tree
Showing 69 changed files with 3,354 additions and 2,899 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ katana
test.go
vendor/*
*.log
teams/*
teams/*
teamcreds.txt
lib/harbor/certs/*
22 changes: 10 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ GOBIN := $(PROJECTROOT)/bin
UTILDIR := $(PROJECTROOT)/scripts/utils
SPINNER := $(UTILDIR)/spinner.sh
BUILDIR := $(PROJECTROOT)/scripts/build
CONTROLLER_MANIFEST:= $(PROJECTROOT)/manifests/dev/expose-controller.yml
HELM_MANIFEST:= $(PROJECTROOT)/manifests/templates/helm-values.yml
OPENVPN_MANIFEST:= $(PROJECTROOT)/manifests/templates/helm-values.yml
MANIFEST:= $(PROJECTROOT)/kubernetes/manifests

KEY_NAME := team

Expand All @@ -22,8 +20,6 @@ SERVICE_NAME_COMMAND =$(shell kubectl get svc --namespace $(OPENVPN_NAMESPACE) -
SERVICE_IP_COMMAND=$(shell kubectl get svc --namespace $(OPENVPN_NAMESPACE) -l "app=openvpn,release=openvpn" -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
# CHALLENGE_DEPLOYER_IP := $(shell minikube service nginx-ingress-controller --url -n kube-system)

CREATEBIN := $(shell [ ! -d ./bin ] && mkdir bin)

# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent

Expand Down Expand Up @@ -83,21 +79,24 @@ gen-certificates:
kubectl --namespace $(OPENVPN_NAMESPACE) exec -it $(POD_NAME) cat "/etc/openvpn/certs/pki/$(KEY_NAME)-$$n.ovpn" > $(KEY_NAME)-$$n.ovpn; \
done

gen-vpn: set-env
helm install openvpn -f $(HELM_MANIFEST) stable/openvpn --namespace openvpn
minikube tunnel

set-env: build
minikube start --driver=docker && \
minikube addons enable ingress && \
kubectl apply -f $(CONTROLLER_MANIFEST) && \
sudo -- sh -c "echo \"$(minikube service nginx-ingress-controller --url -n kube-system | awk '{print substr($0,8)}' | awk '{print substr($0, 1, length($0)-6)}' | head -1) katana.local\" >> /etc/hosts" &&\
kubectl apply -f $(MANIFEST) && \
cp config.sample.toml config.toml && \
./bin/katana run

set-env-prod: build
kubectl apply -f $(MANIFEST) && \
cp config.sample.toml config.toml && \
sudo ./bin/katana run

build:
cd cmd && go build -o ../bin/katana

run : build
sudo ./bin/katana run

# Prints help message
help:
@echo "KATANA"
Expand All @@ -109,6 +108,5 @@ help:
@echo "prepare-for-pr - Prepare the code for PR after fmt, lint and checking uncommitted files"
@echo "lint - Lint code using golangci-lint"
@echo "set-env" - Setup Katana environment
@echo "gen-vpn" - Generate VPN configurations
@echo "build" - Build katana binary

Binary file removed cmd/cmd
Binary file not shown.
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"log"

"github.com/spf13/cobra"
)
Expand All @@ -15,7 +15,7 @@ var rootCmd = &cobra.Command{
challenge dispatcher, VM deployer and flag juggler.`,
Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
fmt.Printf("Failed to print cobra help: %s", err)
log.Printf("Failed to print cobra help: %s", err)
}
},
}
Expand Down
38 changes: 15 additions & 23 deletions config.sample.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
kubeconfig = ""
kubehost = "http://localhost"
backendurl = "http://192.168.49.1"
kubehost = "0.0.0.0"
backendurl = "http://52.172.254.231:15528"
rootdirectory = "/opt/katana"
kubenamespace = "default"
verbosity = 3
timeout = 20 # in seconds

[cluster]
deploymentlabel = "katana"
broadcastcount = 2
broadcastlabel = "broadcast"
teamcount = 2
teamlabel = "ctfteam"
manifest_dir = "manifests/templates"
manifests = [
"broadcast.yml",
"broadcast-service.yml",
"ingress.yml",
"openvpn.yml",
templated_manifest_dir = "kubernetes/templates"
templated_manifests = [
"storage-init.yml", # should be first and always present
"gogs.yml",
"mysql.yml",
"logs.yml",
"mongo.yml",
"gogs.yml",
"harbor.yml",
]

[services.api]
host = "localhost"
port = 3000

[services.challengedeployer]
host = "challengedeployer.katana.local"
port = 8002
broadcastport = 3003
teamclientport = 3004
challengeartifactlabel = "challfile"
host = "0.0.0.0"
port = 15528

[teamvm]
teampodname = "katana-team-master-pod"
Expand All @@ -52,7 +41,6 @@ username = "adminuser"
password = "password123"
port = "32000"
mongosh_version = "1.6.1"
cluster_url = "challengedeployer.katana.local"

[mysql]
username = "root"
Expand All @@ -62,3 +50,7 @@ port = "32001"
[admin]
username = "sdslabs"
password = "sdslabs"

[harbor]
username = "admin"
password = "Password12345" # NOTE: Password should be 8-128 characters long with at least 1 uppercase, 1 lowercase and 1 number
4 changes: 2 additions & 2 deletions configs/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ var (

ClusterConfig = KatanaConfig.Cluster

ChallengeDeployerConfig = ServicesConfig.ChallengeDeployer

SSHProviderConfig = ServicesConfig.SSHProvider

AdminConfig = KatanaConfig.AdminConfig
Expand All @@ -38,4 +36,6 @@ var (
MongoConfig = KatanaConfig.Mongo

MySQLConfig = KatanaConfig.MySQL

HarborConfig = KatanaConfig.Harbor
)
33 changes: 15 additions & 18 deletions configs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,11 @@ type API struct {
}

type ClusterCfg struct {
DeploymentLabel string `toml:"deploymentlabel"`
BroadcastCount uint `toml:"broadcastcount"`
BroadcastLabel string `toml:"broadcastlabel"`
TeamCount uint `toml:"teamcount"`
TeamLabel string `toml:"teamlabel"`
ManifestDir string `toml:"manifest_dir"`
Manifests []string `toml:"manifests"`
}

type ChallengeDeployerCfg struct {
Host string `toml:"host"`
Port uint `toml:"port"`
BroadcastPort uint `toml:"broadcastport"`
TeamClientPort uint `toml:"teamclientport"`
ArtifactLabel string `toml:"challengeartifactlabel"`
DeploymentLabel string `toml:"deploymentlabel"`
TeamCount uint `toml:"teamcount"`
TeamLabel string `toml:"teamlabel"`
TemplatedManifestDir string `toml:"templated_manifest_dir"`
TemplatedManifests []string `toml:"templated_manifests"`
}

type AdminCfg struct {
Expand All @@ -29,9 +19,8 @@ type AdminCfg struct {
}

type ServicesCfg struct {
API API `toml:"api"`
ChallengeDeployer ChallengeDeployerCfg `toml:"challengedeployer"`
SSHProvider SSHProviderCfg `toml:"sshprovider"`
API API `toml:"api"`
SSHProvider SSHProviderCfg `toml:"sshprovider"`
}

type TeamChallengeConfig struct {
Expand Down Expand Up @@ -66,6 +55,7 @@ type MySQLCfg struct {
type KatanaCfg struct {
KubeHost string `toml:"kubehost"`
BackendUrl string `toml:"backendurl"`
RootDirectory string `toml:"rootdirectory"`
KubeNameSpace string `toml:"kubenamespace"`
KubeConfig string `toml:"kubeconfig"`
LogFile string `toml:"logfile"`
Expand All @@ -75,4 +65,11 @@ type KatanaCfg struct {
TeamVmConfig TeamChallengeConfig `toml:"teamvm"`
AdminConfig AdminCfg `toml:"admin"`
MySQL MySQLCfg `toml:"mysql"`
Harbor HarborCfg `toml:"harbor"`
TimeOut int `toml:"timeout"`
}

type HarborCfg struct {
Username string `toml:"username"`
Password string `toml:"password"`
}
148 changes: 105 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,53 +1,115 @@
module github.com/sdslabs/katana

go 1.13
go 1.19

require (
github.com/Azure/go-autorest/autorest v0.9.6 // indirect
github.com/BurntSushi/toml v0.3.1
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.2 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v23.0.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 // indirect
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633 // indirect
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/BurntSushi/toml v1.3.2
github.com/gliderlabs/ssh v0.3.5
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-git v4.7.0+incompatible // indirect
github.com/go-git/go-git/v5 v5.6.0 // indirect
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501 // indirect
github.com/go-sql-driver/mysql v1.7.0
github.com/gofiber/fiber/v2 v2.40.1
github.com/go-git/go-git/v5 v5.7.0
github.com/go-sql-driver/mysql v1.7.1
github.com/gofiber/fiber/v2 v2.47.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang-jwt/jwt/v4 v4.4.3
github.com/golang/protobuf v1.5.2
github.com/googleapis/gnostic v0.5.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/mholt/archiver/v3 v3.5.1
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/rivo/uniseg v0.4.2 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
go.mongodb.org/mongo-driver v1.12.0
golang.org/x/crypto v0.11.0
k8s.io/api v0.27.3
k8s.io/apimachinery v0.27.3
k8s.io/client-go v0.27.3
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230710112148-e01326fd72eb // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matryer/is v1.4.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
github.com/onsi/gomega v1.27.8 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.0.0
go.mongodb.org/mongo-driver v1.5.3
golang.org/x/crypto v0.7.0
golang.org/x/tools v0.7.0 // indirect
google.golang.org/grpc v1.33.0
google.golang.org/protobuf v1.28.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/ulikunitz/xz v0.5.9 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.47.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.11.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.26.2
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 04db0f7

Please sign in to comment.