From 95f4c1666574e286d7c9f88cf2bcaeb67102236a Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Tue, 23 Sep 2025 02:51:41 +0530 Subject: [PATCH 1/4] chore: remove purely sidecar related files Signed-off-by: vibhatsu --- cmd/agents/mongo/main.go | 127 ------------- cmd/agents/mysql/main.go | 122 ------------- core/manager/sidecar.go | 104 ----------- core/sidecar/agent.go | 24 --- core/sidecar/constants.go | 5 - core/sidecar/mongo/agent.go | 102 ----------- core/sidecar/mysql/agent.go | 102 ----------- core/sidecar/protos/mongo/mongo.pb.go | 251 -------------------------- core/sidecar/protos/mongo/mongo.proto | 27 --- core/sidecar/protos/mysql/mysql.pb.go | 251 -------------------------- core/sidecar/protos/mysql/mysql.proto | 27 --- 11 files changed, 1142 deletions(-) delete mode 100644 cmd/agents/mongo/main.go delete mode 100644 cmd/agents/mysql/main.go delete mode 100644 core/manager/sidecar.go delete mode 100644 core/sidecar/agent.go delete mode 100644 core/sidecar/constants.go delete mode 100644 core/sidecar/mongo/agent.go delete mode 100644 core/sidecar/mysql/agent.go delete mode 100644 core/sidecar/protos/mongo/mongo.pb.go delete mode 100644 core/sidecar/protos/mongo/mongo.proto delete mode 100644 core/sidecar/protos/mysql/mysql.pb.go delete mode 100644 core/sidecar/protos/mysql/mysql.proto diff --git a/cmd/agents/mongo/main.go b/cmd/agents/mongo/main.go deleted file mode 100644 index ec3e4478..00000000 --- a/cmd/agents/mongo/main.go +++ /dev/null @@ -1,127 +0,0 @@ -package main - -import ( - "bytes" - "context" - "fmt" - "math/rand" - "net" - "os" - "os/exec" - "text/template" - "time" - - "google.golang.org/grpc" - - "log" - - pb "github.com/sdslabs/beastv4/core/sidecar/protos/mongo" -) - -const MONGO_AGENT_PORT uint32 = 9501 - -var mongoScript = ` -use {{.Database}} -db.createUser( - { - user: "{{.Username}}", - pwd: "{{.Password}}", - roles: - [ - { - role: "readWrite", - db: "{{.Database}}" - } - ] - } -) -db.createCollection("test"); -` - -// Root user credentials for mongo sidecar. -var dbUser = os.Getenv("MONGO_INITDB_ROOT_USERNAME") -var dbPass = os.Getenv("MONGO_INITDB_ROOT_PASSWORD") -var createCommand = fmt.Sprintf("mongo admin -u %s -p %s < /tmp/createUser.js", dbUser, dbPass) - -type mongoAgentServer struct{} - -func init() { - rand.Seed(time.Now().UnixNano()) -} - -var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") - -func randString(n int) string { - b := make([]rune, n) - for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] - } - return string(b) -} - -func (s *mongoAgentServer) CreateMongoInstance(ctx context.Context, none *pb.None) (*pb.MongoInstance, error) { - log.Println("Creating mongo database and user instance") - database := randString(16) - username := randString(16) - password := randString(16) - - instance := &pb.MongoInstance{ - Username: username, - Database: database, - Password: password, - } - file, err := os.OpenFile("/tmp/createUser.js", os.O_CREATE|os.O_WRONLY, 0644) - - var buff bytes.Buffer - mongoTemplate, err := template.New("mongoscript").Parse(mongoScript) - if err != nil { - file.Close() - return instance, fmt.Errorf("Error while parsing template :: %s", err) - } - - err = mongoTemplate.Execute(&buff, instance) - if err != nil { - file.Close() - return instance, fmt.Errorf("Error while executing template :: %s", err) - } - - _, err = file.WriteString(buff.String()) - if err != nil { - file.Close() - return instance, fmt.Errorf("Error while writing to file :: %s", err) - } - - file.Close() - err = exec.Command("bash", "-c", createCommand).Run() - if err != nil { - return instance, fmt.Errorf("Error while running command: %v", err) - } - - return instance, nil -} - -func (s *mongoAgentServer) DeleteMongoInstance(ctx context.Context, instance *pb.MongoInstance) (*pb.None, error) { - none := &pb.None{} - - err := exec.Command("sh", "-c", fmt.Sprintf("mongo admin -u %s -p %s --eval \"db=db.getSiblingDB('%s');db.dropDatabase();\"", dbUser, dbPass, instance.Database)).Run() - if err != nil { - return none, fmt.Errorf("Error while deleting the database : %s", err) - } - - return none, nil -} - -func main() { - listener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", MONGO_AGENT_PORT)) - if err != nil { - fmt.Println("Error while starting listener : %s", err) - os.Exit(1) - } - - grpcServer := grpc.NewServer() - server := mongoAgentServer{} - pb.RegisterMongoServiceServer(grpcServer, &server) - - fmt.Printf("Starting new server at port : %d", MONGO_AGENT_PORT) - grpcServer.Serve(listener) -} diff --git a/cmd/agents/mysql/main.go b/cmd/agents/mysql/main.go deleted file mode 100644 index 76664ad2..00000000 --- a/cmd/agents/mysql/main.go +++ /dev/null @@ -1,122 +0,0 @@ -package main - -import ( - "context" - "database/sql" - "fmt" - "math/rand" - "net" - "os" - "time" - - "google.golang.org/grpc" - - "log" - - _ "github.com/go-sql-driver/mysql" - pb "github.com/sdslabs/beastv4/core/sidecar/protos/mysql" -) - -const MYSQL_AGENT_PORT uint32 = 9500 - -// Root user credentials for mysql sidecar. -var dbHost = `%` -var dbUser = "root" -var dbPass = os.Getenv("MYSQL_ROOT_PASSWORD") - -type mysqlAgentServer struct{} - -func init() { - rand.Seed(time.Now().UnixNano()) -} - -var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") - -func randString(n int) string { - b := make([]rune, n) - for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] - } - return string(b) -} - -func (s *mysqlAgentServer) CreateMySQLInstance(ctx context.Context, none *pb.None) (*pb.MySQLInstance, error) { - log.Println("Creating mysql database and user instance") - connection := fmt.Sprintf("%s:%s@/", dbUser, dbPass) - database := randString(16) - username := randString(16) - password := randString(16) - - instance := &pb.MySQLInstance{ - Username: username, - Database: database, - Password: password, - } - - db, err := sql.Open("mysql", connection) - if err != nil { - return instance, fmt.Errorf("Error while connecting to database.") - } - defer db.Close() - - _, err = db.Exec("CREATE DATABASE " + database) - if err != nil { - return instance, fmt.Errorf("Error while creating the database : %s", err) - } - - query := fmt.Sprintf("CREATE USER '%s'@'%s' IDENTIFIED BY '%s'", username, dbHost, password) - _, err = db.Exec(query) - if err != nil { - return instance, fmt.Errorf("Error while creating user : %s", err) - } - - query = fmt.Sprintf("GRANT ALL ON %s.* TO '%s'@'%s'", database, username, dbHost) - _, err = db.Exec(query) - if err != nil { - return instance, fmt.Errorf("Error granting permissions to user : %s", err) - } - - _, err = db.Exec("FLUSH PRIVILEGES") - if err != nil { - return instance, fmt.Errorf("Error while flushing user priviliges : %s", err) - } - - return instance, nil -} - -func (s *mysqlAgentServer) DeleteMySQLInstance(ctx context.Context, instance *pb.MySQLInstance) (*pb.None, error) { - none := &pb.None{} - connection := fmt.Sprintf("%s:%s@/", dbUser, dbPass) - - db, err := sql.Open("mysql", connection) - if err != nil { - return none, fmt.Errorf("Error while connecting to database.") - } - defer db.Close() - - _, err = db.Exec("DROP DATABASE " + instance.Database) - if err != nil { - return none, fmt.Errorf("Error while deleting the database : %s", err) - } - - _, err = db.Exec(fmt.Sprintf("DROP USER '%s'@'%s'", instance.Username, dbHost)) - if err != nil { - return none, fmt.Errorf("Error while deleting the user : %s", err) - } - return none, nil -} - -func main() { - listner, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", MYSQL_AGENT_PORT)) - if err != nil { - fmt.Println("Error while starting listener : %s", err) - os.Exit(1) - } - - grpcServer := grpc.NewServer() - server := mysqlAgentServer{} - pb.RegisterMySQLServiceServer(grpcServer, &server) - - fmt.Printf("Starting new server at port : %d", MYSQL_AGENT_PORT) - grpcServer.Serve(listner) -} diff --git a/core/manager/sidecar.go b/core/manager/sidecar.go deleted file mode 100644 index 3c375574..00000000 --- a/core/manager/sidecar.go +++ /dev/null @@ -1,104 +0,0 @@ -package manager - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "path/filepath" - - "github.com/sdslabs/beastv4/core" - cfg "github.com/sdslabs/beastv4/core/config" - "github.com/sdslabs/beastv4/core/sidecar" - "github.com/sdslabs/beastv4/utils" - log "github.com/sirupsen/logrus" -) - -func configureSidecar(config *cfg.BeastChallengeConfig) error { - log.Infof("Configuring sidecar for challenge : %s", config.Challenge.Metadata.Name) - - sidecarAgent, err := sidecar.GetSidecarAgent(config.Challenge.Metadata.Sidecar) - if err != nil { - return err - } - - stagingDir := filepath.Join(core.BEAST_GLOBAL_DIR, core.BEAST_STAGING_DIR, config.Challenge.Metadata.Name) - configPath := filepath.Join(stagingDir, fmt.Sprintf(".%s.env", config.Challenge.Metadata.Sidecar)) - err = utils.ValidateFileExists(configPath) - if err == nil { - log.Infof("Sidecar configuration file already exists, not creating a new.") - return nil - } - - err = sidecarAgent.Bootstrap(configPath) - if err != nil { - return fmt.Errorf("error while bootstrapping sidecar configuration: %s", err) - } - - log.Infof("Sidecar configuration bootstrap complete.") - return nil -} - -func cleanSidecar(config *cfg.BeastChallengeConfig) error { - - if config.Challenge.Metadata.Sidecar == "" { - return nil - } - - log.Infof("Destroying the sidecar configuration for challenge: %s", config.Challenge.Metadata.Name) - - sidecarAgent, err := sidecar.GetSidecarAgent(config.Challenge.Metadata.Sidecar) - if err != nil { - return err - } - - stagingDir := filepath.Join(core.BEAST_GLOBAL_DIR, core.BEAST_STAGING_DIR, config.Challenge.Metadata.Name) - configPath := filepath.Join(stagingDir, fmt.Sprintf(".%s.env", config.Challenge.Metadata.Sidecar)) - err = utils.ValidateFileExists(configPath) - if err != nil { - log.Warnf("Sidecar configuration does not exist, nothing to wipe.") - return nil - } - - err = sidecarAgent.Destroy(configPath) - if err != nil { - return fmt.Errorf("error while destroying sidecar configuration: %s", err) - } - - log.Infof("Sidecar configuration cleanup complete.") - return nil -} - -// Read the environment variables from the challenge sidecar environment -// file and return a list of the same. -func getSidecarEnv(config *cfg.BeastChallengeConfig) []string { - var env []string - stagingDir := filepath.Join(core.BEAST_GLOBAL_DIR, core.BEAST_STAGING_DIR, config.Challenge.Metadata.Name) - envFile := filepath.Join(stagingDir, fmt.Sprintf(".%s.env", config.Challenge.Metadata.Sidecar)) - - cont := make(map[string]interface{}) - file, err := os.Open(envFile) - if err != nil { - log.Warnf("Error while reading env file %s : %s", envFile, err) - return env - } - defer file.Close() - - byteValue, _ := ioutil.ReadAll(file) - err = json.Unmarshal([]byte(byteValue), &cont) - if err != nil { - log.Warnf("Error while reading json env: %s", err) - return env - } - - for key, val := range cont { - env = append(env, fmt.Sprintf("%s_%s=%s", core.SIDECAR_ENV_PREFIX[config.Challenge.Metadata.Sidecar], key, val)) - } - - log.Debugf("Generated environment variables for container are : %v", env) - return env -} - -func getSidecarNetwork(sidecar string) string { - return core.SIDECAR_NETWORK_MAP[sidecar] -} diff --git a/core/sidecar/agent.go b/core/sidecar/agent.go deleted file mode 100644 index 7b1cd373..00000000 --- a/core/sidecar/agent.go +++ /dev/null @@ -1,24 +0,0 @@ -package sidecar - -import ( - "fmt" - - "github.com/sdslabs/beastv4/core/sidecar/mongo" - "github.com/sdslabs/beastv4/core/sidecar/mysql" -) - -type SidecarAgent interface { - Bootstrap(configPath string) error - Destroy(configPath string) error -} - -func GetSidecarAgent(sidecar string) (SidecarAgent, error) { - switch sidecar { - case "mysql": - return &mysql.MySQLAgent{}, nil - case "mongo": - return &mongo.MongoAgent{}, nil - default: - return nil, fmt.Errorf("Not a valid sidecar name: %s", sidecar) - } -} diff --git a/core/sidecar/constants.go b/core/sidecar/constants.go deleted file mode 100644 index 0f74873b..00000000 --- a/core/sidecar/constants.go +++ /dev/null @@ -1,5 +0,0 @@ -package sidecar - -var ( - AVAILBLE_SIDECAR_AGENTS []string = []string{"mysql", "mongo"} -) diff --git a/core/sidecar/mongo/agent.go b/core/sidecar/mongo/agent.go deleted file mode 100644 index c7ddd229..00000000 --- a/core/sidecar/mongo/agent.go +++ /dev/null @@ -1,102 +0,0 @@ -package mongo - -import ( - "bufio" - "context" - "encoding/json" - "fmt" - "io/ioutil" - "os" - "time" - - "google.golang.org/grpc" - - pb "github.com/sdslabs/beastv4/core/sidecar/protos/mongo" - log "github.com/sirupsen/logrus" -) - -type MongoAgent struct{} - -const MONGO_AGENT_PORT uint32 = 9501 - -var serverAddr string = fmt.Sprintf("127.0.0.1:%d", MONGO_AGENT_PORT) -var opts = []grpc.DialOption{grpc.WithInsecure()} - -// This function assumes that store path is the path of the file in which the instance -// values should be store, it assumes that the directory containing the file exist and -// the file represented by configPath does not exists. This function will create the file -// and will write the configuration to the file in json format. -func (a *MongoAgent) Bootstrap(configPath string) error { - conn, err := grpc.Dial(serverAddr, opts...) - if err != nil { - return fmt.Errorf("ERROR while dailing RPC : %s", err) - } - defer conn.Close() - - client := pb.NewMongoServiceClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - instance, err := client.CreateMongoInstance(ctx, &pb.None{}) - if err != nil { - return err - } - log.Debugf("Created instance in Mongo sidecar with details : %v", instance) - // Save instance details here in a file or a database, so it can be used later for - // destroying context through agent. - instStr, err := json.Marshal(instance) - if err != nil { - return fmt.Errorf("Error while marshalling instance for storing: %s", err) - } - - file, err := os.Create(configPath) - defer file.Close() - if err != nil { - return fmt.Errorf("Error while creating sidecar configuration file: %s", err) - } - - w := bufio.NewWriter(file) - _, err = w.WriteString(string(instStr)) - if err != nil { - return fmt.Errorf("Error while writing sidecar configuration to file: %s", err) - } - w.Flush() - - return nil -} - -func (a *MongoAgent) Destroy(configPath string) error { - file, err := os.Open(configPath) - if err != nil { - return fmt.Errorf("Error while opening sidecar configuration file: %s", err) - } - defer file.Close() - - byteValue, _ := ioutil.ReadAll(file) - - var instance pb.MongoInstance - json.Unmarshal([]byte(byteValue), &instance) - - conn, err := grpc.Dial(serverAddr, opts...) - if err != nil { - return fmt.Errorf("ERROR while dailing RPC : %s", err) - } - defer conn.Close() - - client := pb.NewMongoServiceClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - log.Debugf("Deleting instance in Mongo sidecar with details : %v", instance) - _, err = client.DeleteMongoInstance(ctx, &instance) - if err != nil { - return err - } - - err = os.Remove(configPath) - if err != nil { - return fmt.Errorf("Error while removing undesired sidecar configuration: %s", err) - } - - return nil -} diff --git a/core/sidecar/mysql/agent.go b/core/sidecar/mysql/agent.go deleted file mode 100644 index 5b3dbef8..00000000 --- a/core/sidecar/mysql/agent.go +++ /dev/null @@ -1,102 +0,0 @@ -package mysql - -import ( - "bufio" - "context" - "encoding/json" - "fmt" - "io/ioutil" - "os" - "time" - - "google.golang.org/grpc" - - pb "github.com/sdslabs/beastv4/core/sidecar/protos/mysql" - log "github.com/sirupsen/logrus" -) - -type MySQLAgent struct{} - -const MYSQL_AGENT_PORT uint32 = 9500 - -var serverAddr string = fmt.Sprintf("127.0.0.1:%d", MYSQL_AGENT_PORT) -var opts = []grpc.DialOption{grpc.WithInsecure()} - -// This function assumes that store path is the path of the file in which the instance -// values should be store, it assumes that the directory containing the file exist and -// the file represented by configPath does not exists. This function will create the file -// and will write the configuration to the file in json format. -func (a *MySQLAgent) Bootstrap(configPath string) error { - conn, err := grpc.Dial(serverAddr, opts...) - if err != nil { - return fmt.Errorf("ERROR while dailing RPC : %s", err) - } - defer conn.Close() - - client := pb.NewMySQLServiceClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - instance, err := client.CreateMySQLInstance(ctx, &pb.None{}) - if err != nil { - return err - } - log.Debugf("Created instance in MYSQL sidecar with details : %v", instance) - // Save instance details here in a file or a database, so it can be used later for - // destroying context through agent. - instStr, err := json.Marshal(instance) - if err != nil { - return fmt.Errorf("Error while marshalling instance for storing: %s", err) - } - - file, err := os.Create(configPath) - defer file.Close() - if err != nil { - return fmt.Errorf("Error while creating sidecar configuration file: %s", err) - } - - w := bufio.NewWriter(file) - _, err = w.WriteString(string(instStr)) - if err != nil { - return fmt.Errorf("Error while writing sidecar configuration to file: %s", err) - } - w.Flush() - - return nil -} - -func (a *MySQLAgent) Destroy(configPath string) error { - file, err := os.Open(configPath) - if err != nil { - return fmt.Errorf("Error while opening sidecar configuration file: %s", err) - } - defer file.Close() - - byteValue, _ := ioutil.ReadAll(file) - - var instance pb.MySQLInstance - json.Unmarshal([]byte(byteValue), &instance) - - conn, err := grpc.Dial(serverAddr, opts...) - if err != nil { - return fmt.Errorf("ERROR while dailing RPC : %s", err) - } - defer conn.Close() - - client := pb.NewMySQLServiceClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - log.Debugf("Deleting instance in MYSQL sidecar with details : %v", instance) - _, err = client.DeleteMySQLInstance(ctx, &instance) - if err != nil { - return err - } - - err = os.Remove(configPath) - if err != nil { - return fmt.Errorf("Error while removing undesired sidecar configuration: %s", err) - } - - return nil -} diff --git a/core/sidecar/protos/mongo/mongo.pb.go b/core/sidecar/protos/mongo/mongo.pb.go deleted file mode 100644 index 32b6274f..00000000 --- a/core/sidecar/protos/mongo/mongo.pb.go +++ /dev/null @@ -1,251 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: mongo.proto - -package protobuf - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -import ( - context "golang.org/x/net/context" - grpc "google.golang.org/grpc" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type None struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *None) Reset() { *m = None{} } -func (m *None) String() string { return proto.CompactTextString(m) } -func (*None) ProtoMessage() {} -func (*None) Descriptor() ([]byte, []int) { - return fileDescriptor_mongo_915eadb25bd14b1e, []int{0} -} -func (m *None) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_None.Unmarshal(m, b) -} -func (m *None) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_None.Marshal(b, m, deterministic) -} -func (dst *None) XXX_Merge(src proto.Message) { - xxx_messageInfo_None.Merge(dst, src) -} -func (m *None) XXX_Size() int { - return xxx_messageInfo_None.Size(m) -} -func (m *None) XXX_DiscardUnknown() { - xxx_messageInfo_None.DiscardUnknown(m) -} - -var xxx_messageInfo_None proto.InternalMessageInfo - -// Message respresenting a Mongo instance -type MongoInstance struct { - Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` - Database string `protobuf:"bytes,2,opt,name=database,proto3" json:"database,omitempty"` - Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *MongoInstance) Reset() { *m = MongoInstance{} } -func (m *MongoInstance) String() string { return proto.CompactTextString(m) } -func (*MongoInstance) ProtoMessage() {} -func (*MongoInstance) Descriptor() ([]byte, []int) { - return fileDescriptor_mongo_915eadb25bd14b1e, []int{1} -} -func (m *MongoInstance) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_MongoInstance.Unmarshal(m, b) -} -func (m *MongoInstance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_MongoInstance.Marshal(b, m, deterministic) -} -func (dst *MongoInstance) XXX_Merge(src proto.Message) { - xxx_messageInfo_MongoInstance.Merge(dst, src) -} -func (m *MongoInstance) XXX_Size() int { - return xxx_messageInfo_MongoInstance.Size(m) -} -func (m *MongoInstance) XXX_DiscardUnknown() { - xxx_messageInfo_MongoInstance.DiscardUnknown(m) -} - -var xxx_messageInfo_MongoInstance proto.InternalMessageInfo - -func (m *MongoInstance) GetUsername() string { - if m != nil { - return m.Username - } - return "" -} - -func (m *MongoInstance) GetDatabase() string { - if m != nil { - return m.Database - } - return "" -} - -func (m *MongoInstance) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -func init() { - proto.RegisterType((*None)(nil), "protobuf.None") - proto.RegisterType((*MongoInstance)(nil), "protobuf.MongoInstance") -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// MongoServiceClient is the client API for MongoService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type MongoServiceClient interface { - // RPC to create a new Mongo instance, an instance is represented by a - // user and a database. So this RPC creates a new user along with a database - // which the user owns. After creating the database it returns the instance - // created. - CreateMongoInstance(ctx context.Context, in *None, opts ...grpc.CallOption) (*MongoInstance, error) - // This RPC deletes an existing Mongo instance, it deletes the user and the database - // user is associated with. As a return value it results RPCResult depicting if the - // operation was successful or not. - DeleteMongoInstance(ctx context.Context, in *MongoInstance, opts ...grpc.CallOption) (*None, error) -} - -type mongoServiceClient struct { - cc *grpc.ClientConn -} - -func NewMongoServiceClient(cc *grpc.ClientConn) MongoServiceClient { - return &mongoServiceClient{cc} -} - -func (c *mongoServiceClient) CreateMongoInstance(ctx context.Context, in *None, opts ...grpc.CallOption) (*MongoInstance, error) { - out := new(MongoInstance) - err := c.cc.Invoke(ctx, "/protobuf.MongoService/CreateMongoInstance", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *mongoServiceClient) DeleteMongoInstance(ctx context.Context, in *MongoInstance, opts ...grpc.CallOption) (*None, error) { - out := new(None) - err := c.cc.Invoke(ctx, "/protobuf.MongoService/DeleteMongoInstance", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MongoServiceServer is the server API for MongoService service. -type MongoServiceServer interface { - // RPC to create a new Mongo instance, an instance is represented by a - // user and a database. So this RPC creates a new user along with a database - // which the user owns. After creating the database it returns the instance - // created. - CreateMongoInstance(context.Context, *None) (*MongoInstance, error) - // This RPC deletes an existing Mongo instance, it deletes the user and the database - // user is associated with. As a return value it results RPCResult depicting if the - // operation was successful or not. - DeleteMongoInstance(context.Context, *MongoInstance) (*None, error) -} - -func RegisterMongoServiceServer(s *grpc.Server, srv MongoServiceServer) { - s.RegisterService(&_MongoService_serviceDesc, srv) -} - -func _MongoService_CreateMongoInstance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(None) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MongoServiceServer).CreateMongoInstance(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/protobuf.MongoService/CreateMongoInstance", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MongoServiceServer).CreateMongoInstance(ctx, req.(*None)) - } - return interceptor(ctx, in, info, handler) -} - -func _MongoService_DeleteMongoInstance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MongoInstance) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MongoServiceServer).DeleteMongoInstance(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/protobuf.MongoService/DeleteMongoInstance", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MongoServiceServer).DeleteMongoInstance(ctx, req.(*MongoInstance)) - } - return interceptor(ctx, in, info, handler) -} - -var _MongoService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "protobuf.MongoService", - HandlerType: (*MongoServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "CreateMongoInstance", - Handler: _MongoService_CreateMongoInstance_Handler, - }, - { - MethodName: "DeleteMongoInstance", - Handler: _MongoService_DeleteMongoInstance_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "mongo.proto", -} - -func init() { proto.RegisterFile("mongo.proto", fileDescriptor_mongo_915eadb25bd14b1e) } - -var fileDescriptor_mongo_915eadb25bd14b1e = []byte{ - // 181 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xce, 0xcd, 0xcf, 0x4b, - 0xcf, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x00, 0x53, 0x49, 0xa5, 0x69, 0x4a, 0x6c, - 0x5c, 0x2c, 0x7e, 0xf9, 0x79, 0xa9, 0x4a, 0xc9, 0x5c, 0xbc, 0xbe, 0x20, 0x05, 0x9e, 0x79, 0xc5, - 0x25, 0x89, 0x79, 0xc9, 0xa9, 0x42, 0x52, 0x5c, 0x1c, 0xa5, 0xc5, 0xa9, 0x45, 0x79, 0x89, 0xb9, - 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x70, 0x3e, 0x48, 0x2e, 0x25, 0xb1, 0x24, 0x31, - 0x29, 0xb1, 0x38, 0x55, 0x82, 0x09, 0x22, 0x07, 0xe3, 0x83, 0xe4, 0x0a, 0x12, 0x8b, 0x8b, 0xcb, - 0xf3, 0x8b, 0x52, 0x24, 0x98, 0x21, 0x72, 0x30, 0xbe, 0xd1, 0x24, 0x46, 0x2e, 0x1e, 0xb0, 0x2d, - 0xc1, 0xa9, 0x45, 0x65, 0x99, 0xc9, 0xa9, 0x42, 0x0e, 0x5c, 0xc2, 0xce, 0x45, 0xa9, 0x89, 0x25, - 0xa9, 0xa8, 0x76, 0xf3, 0xe9, 0xc1, 0xdc, 0xa7, 0x07, 0x72, 0x9c, 0x94, 0x38, 0x82, 0x8f, 0xa2, - 0x50, 0x89, 0x01, 0x64, 0x82, 0x4b, 0x6a, 0x4e, 0x2a, 0xba, 0x09, 0xb8, 0x74, 0x48, 0xa1, 0x19, - 0xad, 0xc4, 0x90, 0xc4, 0x06, 0x16, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x17, 0x4a, 0x00, - 0xa8, 0x21, 0x01, 0x00, 0x00, -} diff --git a/core/sidecar/protos/mongo/mongo.proto b/core/sidecar/protos/mongo/mongo.proto deleted file mode 100644 index 78bd0ce3..00000000 --- a/core/sidecar/protos/mongo/mongo.proto +++ /dev/null @@ -1,27 +0,0 @@ -syntax = "proto3"; - -package protobuf; - - -// Interface for the mongo service. -service MongoService { - // RPC to create a new Mongo instance, an instance is represented by a - // user and a database. So this RPC creates a new user along with a database - // which the user owns. After creating the database it returns the instance - // created. - rpc CreateMongoInstance(None) returns (MongoInstance) {} - - // This RPC deletes an existing Mongo instance, it deletes the user and the database - // user is associated with. As a return value it results RPCResult depicting if the - // operation was successful or not. - rpc DeleteMongoInstance(MongoInstance) returns (None) {} -} - -message None {} - -// Message respresenting a Mongo instance -message MongoInstance { - string username = 1; - string database = 2; - string password = 3; -} diff --git a/core/sidecar/protos/mysql/mysql.pb.go b/core/sidecar/protos/mysql/mysql.pb.go deleted file mode 100644 index 2ca928de..00000000 --- a/core/sidecar/protos/mysql/mysql.pb.go +++ /dev/null @@ -1,251 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: mysql.proto - -package protobuf - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -import ( - context "golang.org/x/net/context" - grpc "google.golang.org/grpc" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type None struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *None) Reset() { *m = None{} } -func (m *None) String() string { return proto.CompactTextString(m) } -func (*None) ProtoMessage() {} -func (*None) Descriptor() ([]byte, []int) { - return fileDescriptor_mysql_40a914aca32fed04, []int{0} -} -func (m *None) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_None.Unmarshal(m, b) -} -func (m *None) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_None.Marshal(b, m, deterministic) -} -func (dst *None) XXX_Merge(src proto.Message) { - xxx_messageInfo_None.Merge(dst, src) -} -func (m *None) XXX_Size() int { - return xxx_messageInfo_None.Size(m) -} -func (m *None) XXX_DiscardUnknown() { - xxx_messageInfo_None.DiscardUnknown(m) -} - -var xxx_messageInfo_None proto.InternalMessageInfo - -// Message respresenting a MySQL instance -type MySQLInstance struct { - Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` - Database string `protobuf:"bytes,2,opt,name=database,proto3" json:"database,omitempty"` - Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *MySQLInstance) Reset() { *m = MySQLInstance{} } -func (m *MySQLInstance) String() string { return proto.CompactTextString(m) } -func (*MySQLInstance) ProtoMessage() {} -func (*MySQLInstance) Descriptor() ([]byte, []int) { - return fileDescriptor_mysql_40a914aca32fed04, []int{1} -} -func (m *MySQLInstance) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_MySQLInstance.Unmarshal(m, b) -} -func (m *MySQLInstance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_MySQLInstance.Marshal(b, m, deterministic) -} -func (dst *MySQLInstance) XXX_Merge(src proto.Message) { - xxx_messageInfo_MySQLInstance.Merge(dst, src) -} -func (m *MySQLInstance) XXX_Size() int { - return xxx_messageInfo_MySQLInstance.Size(m) -} -func (m *MySQLInstance) XXX_DiscardUnknown() { - xxx_messageInfo_MySQLInstance.DiscardUnknown(m) -} - -var xxx_messageInfo_MySQLInstance proto.InternalMessageInfo - -func (m *MySQLInstance) GetUsername() string { - if m != nil { - return m.Username - } - return "" -} - -func (m *MySQLInstance) GetDatabase() string { - if m != nil { - return m.Database - } - return "" -} - -func (m *MySQLInstance) GetPassword() string { - if m != nil { - return m.Password - } - return "" -} - -func init() { - proto.RegisterType((*None)(nil), "protobuf.None") - proto.RegisterType((*MySQLInstance)(nil), "protobuf.MySQLInstance") -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// MySQLServiceClient is the client API for MySQLService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type MySQLServiceClient interface { - // RPC to create a new MySQL instance, an instance is represented by a - // user and a database. So this RPC creates a new user along with a database - // which the user owns. After creating the database it returns the instance - // created. - CreateMySQLInstance(ctx context.Context, in *None, opts ...grpc.CallOption) (*MySQLInstance, error) - // This RPC deletes an existing MySQL instance, it deletes the user and the database - // user is associated with. As a return value it results RPCResult depicting if the - // operation was successful or not. - DeleteMySQLInstance(ctx context.Context, in *MySQLInstance, opts ...grpc.CallOption) (*None, error) -} - -type mySQLServiceClient struct { - cc *grpc.ClientConn -} - -func NewMySQLServiceClient(cc *grpc.ClientConn) MySQLServiceClient { - return &mySQLServiceClient{cc} -} - -func (c *mySQLServiceClient) CreateMySQLInstance(ctx context.Context, in *None, opts ...grpc.CallOption) (*MySQLInstance, error) { - out := new(MySQLInstance) - err := c.cc.Invoke(ctx, "/protobuf.MySQLService/CreateMySQLInstance", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *mySQLServiceClient) DeleteMySQLInstance(ctx context.Context, in *MySQLInstance, opts ...grpc.CallOption) (*None, error) { - out := new(None) - err := c.cc.Invoke(ctx, "/protobuf.MySQLService/DeleteMySQLInstance", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MySQLServiceServer is the server API for MySQLService service. -type MySQLServiceServer interface { - // RPC to create a new MySQL instance, an instance is represented by a - // user and a database. So this RPC creates a new user along with a database - // which the user owns. After creating the database it returns the instance - // created. - CreateMySQLInstance(context.Context, *None) (*MySQLInstance, error) - // This RPC deletes an existing MySQL instance, it deletes the user and the database - // user is associated with. As a return value it results RPCResult depicting if the - // operation was successful or not. - DeleteMySQLInstance(context.Context, *MySQLInstance) (*None, error) -} - -func RegisterMySQLServiceServer(s *grpc.Server, srv MySQLServiceServer) { - s.RegisterService(&_MySQLService_serviceDesc, srv) -} - -func _MySQLService_CreateMySQLInstance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(None) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MySQLServiceServer).CreateMySQLInstance(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/protobuf.MySQLService/CreateMySQLInstance", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MySQLServiceServer).CreateMySQLInstance(ctx, req.(*None)) - } - return interceptor(ctx, in, info, handler) -} - -func _MySQLService_DeleteMySQLInstance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MySQLInstance) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MySQLServiceServer).DeleteMySQLInstance(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/protobuf.MySQLService/DeleteMySQLInstance", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MySQLServiceServer).DeleteMySQLInstance(ctx, req.(*MySQLInstance)) - } - return interceptor(ctx, in, info, handler) -} - -var _MySQLService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "protobuf.MySQLService", - HandlerType: (*MySQLServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "CreateMySQLInstance", - Handler: _MySQLService_CreateMySQLInstance_Handler, - }, - { - MethodName: "DeleteMySQLInstance", - Handler: _MySQLService_DeleteMySQLInstance_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "mysql.proto", -} - -func init() { proto.RegisterFile("mysql.proto", fileDescriptor_mysql_40a914aca32fed04) } - -var fileDescriptor_mysql_40a914aca32fed04 = []byte{ - // 183 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xce, 0xad, 0x2c, 0x2e, - 0xcc, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x00, 0x53, 0x49, 0xa5, 0x69, 0x4a, 0x6c, - 0x5c, 0x2c, 0x7e, 0xf9, 0x79, 0xa9, 0x4a, 0xc9, 0x5c, 0xbc, 0xbe, 0x95, 0xc1, 0x81, 0x3e, 0x9e, - 0x79, 0xc5, 0x25, 0x89, 0x79, 0xc9, 0xa9, 0x42, 0x52, 0x5c, 0x1c, 0xa5, 0xc5, 0xa9, 0x45, 0x79, - 0x89, 0xb9, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x70, 0x3e, 0x48, 0x2e, 0x25, 0xb1, - 0x24, 0x31, 0x29, 0xb1, 0x38, 0x55, 0x82, 0x09, 0x22, 0x07, 0xe3, 0x83, 0xe4, 0x0a, 0x12, 0x8b, - 0x8b, 0xcb, 0xf3, 0x8b, 0x52, 0x24, 0x98, 0x21, 0x72, 0x30, 0xbe, 0xd1, 0x24, 0x46, 0x2e, 0x1e, - 0xb0, 0x2d, 0xc1, 0xa9, 0x45, 0x65, 0x99, 0xc9, 0xa9, 0x42, 0x0e, 0x5c, 0xc2, 0xce, 0x45, 0xa9, - 0x89, 0x25, 0xa9, 0xa8, 0x76, 0xf3, 0xe9, 0xc1, 0xdc, 0xa7, 0x07, 0x72, 0x9c, 0x94, 0x38, 0x82, - 0x8f, 0xa2, 0x50, 0x89, 0x01, 0x64, 0x82, 0x4b, 0x6a, 0x4e, 0x2a, 0xba, 0x09, 0xb8, 0x74, 0x48, - 0xa1, 0x19, 0xad, 0xc4, 0x90, 0xc4, 0x06, 0x16, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8f, - 0x87, 0xbc, 0x06, 0x21, 0x01, 0x00, 0x00, -} diff --git a/core/sidecar/protos/mysql/mysql.proto b/core/sidecar/protos/mysql/mysql.proto deleted file mode 100644 index 3d622429..00000000 --- a/core/sidecar/protos/mysql/mysql.proto +++ /dev/null @@ -1,27 +0,0 @@ -syntax = "proto3"; - -package protobuf; - - -// Interface for the mysql service. -service MySQLService { - // RPC to create a new MySQL instance, an instance is represented by a - // user and a database. So this RPC creates a new user along with a database - // which the user owns. After creating the database it returns the instance - // created. - rpc CreateMySQLInstance(None) returns (MySQLInstance) {} - - // This RPC deletes an existing MySQL instance, it deletes the user and the database - // user is associated with. As a return value it results RPCResult depicting if the - // operation was successful or not. - rpc DeleteMySQLInstance(MySQLInstance) returns (None) {} -} - -message None {} - -// Message respresenting a MySQL instance -message MySQLInstance { - string username = 1; - string database = 2; - string password = 3; -} From ef4a0fbf90997f758a906d276c49d234b09ae99b Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Tue, 23 Sep 2025 02:53:07 +0530 Subject: [PATCH 2/4] refactor: remove sidecar references and related code Signed-off-by: vibhatsu --- _examples/example.config.toml | 3 +- core/config/challenge.go | 10 ++--- core/config/config.go | 2 +- core/constants.go | 30 ++++++------- core/database/challenges.go | 2 +- core/manager/challenge.go | 3 +- core/manager/pipeline.go | 38 ++++++++-------- core/manager/utils.go | 2 +- scripts/build/build.sh | 6 +-- scripts/build/extras.sh | 82 +++++++++++++++++------------------ templates/templates.go | 1 - 11 files changed, 91 insertions(+), 88 deletions(-) diff --git a/_examples/example.config.toml b/_examples/example.config.toml index fb6d97d5..1164f160 100644 --- a/_examples/example.config.toml +++ b/_examples/example.config.toml @@ -11,9 +11,10 @@ scripts_dir = "$HOME/.beast/scripts" # Base OS image that beast allows the challenges to use. allowed_base_images = ["ubuntu:18.04", "ubuntu:16.04", "debian:jessie"] +# DEPRECATED # The sidecar that we support with beast, currently we only support two MySQL and # MongoDB. -available_sidecars = ["mysql", "mongodb"] +# available_sidecars = ["mysql", "mongodb"] # For authentication purposes beast uses JWT based authentication, this is the # key used for encrypting the claims of a user. Keep this strong. diff --git a/core/config/challenge.go b/core/config/challenge.go index 33c93ee4..91c3f34e 100644 --- a/core/config/challenge.go +++ b/core/config/challenge.go @@ -46,7 +46,7 @@ func (Metadata *ChallengeMetadata) PopulateChallengeMetadata() { Metadata.Type = "ChallengeType" Metadata.DynamicFlag = false Metadata.Flag = "ChallengeFlag" - Metadata.Sidecar = "SidecarHelper" + // Metadata.Sidecar = "SidecarHelper" } func (Env *ChallengeEnv) PopulateChallengeEnv() { @@ -134,7 +134,7 @@ type ChallengeMetadata struct { Name string `toml:"name"` Type string `toml:"type"` Tags []string `toml:"tags"` - Sidecar string `toml:"sidecar"` + // Sidecar string `toml:"sidecar"` Description string `toml:"description"` Hints []struct { Text string `toml:"text"` @@ -167,9 +167,9 @@ func (config *ChallengeMetadata) ValidateRequiredFields() (error, bool) { config.MaxAttemptLimit = -1 } - if !(utils.StringInSlice(config.Sidecar, Cfg.AvailableSidecars) || config.Sidecar == "") { - return fmt.Errorf("sidecar provided is not an available sidecar"), false - } + // if !(utils.StringInSlice(config.Sidecar, Cfg.AvailableSidecars) || config.Sidecar == "") { + // return fmt.Errorf("sidecar provided is not an available sidecar"), false + // } // Check if the config type is static here and if it is // then return an indication for that, so that caller knows if it need diff --git a/core/config/config.go b/core/config/config.go index 85bd087a..623726d2 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -118,7 +118,7 @@ type BeastConfig struct { AuthorizedKeysFile string `toml:"authorized_keys_file"` BeastScriptsDir string `toml:"scripts_dir"` AllowedBaseImages []string `toml:"allowed_base_images"` - AvailableSidecars []string `toml:"available_sidecars"` + // AvailableSidecars []string `toml:"available_sidecars"` AvailableServers map[string]AvailableServer `toml:"available_servers"` GitRemotes []GitRemote `toml:"remote"` PsqlConf PsqlConfig `toml:"psql_config"` diff --git a/core/constants.go b/core/constants.go index 89d7732d..26ca1200 100644 --- a/core/constants.go +++ b/core/constants.go @@ -119,23 +119,23 @@ var USER_ROLES = map[string]string{ "maintainer": "maintainer", } -const MYSQL_SIDECAR_HOST = "mysql" -const MONGO_SIDECAR_HOST = "mongo" +// const MYSQL_SIDECAR_HOST = "mysql" +// const MONGO_SIDECAR_HOST = "mongo" -var SIDECAR_CONTAINER_MAP = map[string]string{ - "mysql": "mysql", - "mongo": "mongo", -} +// var SIDECAR_CONTAINER_MAP = map[string]string{ +// "mysql": "mysql", +// "mongo": "mongo", +// } -var SIDECAR_NETWORK_MAP = map[string]string{ - "mysql": "beast-mysql", - "mongo": "beast-mongo", -} +// var SIDECAR_NETWORK_MAP = map[string]string{ +// "mysql": "beast-mysql", +// "mongo": "beast-mongo", +// } -var SIDECAR_ENV_PREFIX = map[string]string{ - "mysql": "MYSQL", - "mongo": "MONGO", -} +// var SIDECAR_ENV_PREFIX = map[string]string{ +// "mysql": "MYSQL", +// "mongo": "MONGO", +// } // Available challenge types var AVAILABLE_CHALLENGE_TYPES = []string{STATIC_CHALLENGE_TYPE_NAME, SERVICE_CHALLENGE_TYPE_NAME, BARE_CHALLENGE_TYPE_NAME, WEB_CHALLENGE_TYPE_NAME} @@ -208,4 +208,4 @@ var USER_STATUS = map[string]string{ const ( LEADERBOARD_SIZE = 25 LEADERBOARD_GRAPH_SIZE = 12 -) \ No newline at end of file +) diff --git a/core/database/challenges.go b/core/database/challenges.go index dda0a300..e1c5bb03 100644 --- a/core/database/challenges.go +++ b/core/database/challenges.go @@ -53,7 +53,7 @@ type Challenge struct { Difficulty string `gorm:"not null;default:'medium'"` MaxAttemptLimit int `gorm:"default:-1"` PreReqs string `gorm:"type:text"` - Sidecar string `gorm:"type:varchar(64)"` + // Sidecar string `gorm:"type:varchar(64)"` TODO: remove sidecars completely Assets string `gorm:"type:text"` AdditionalLinks string `gorm:"type:text"` Description string `gorm:"type:text"` diff --git a/core/manager/challenge.go b/core/manager/challenge.go index ed40201a..ac707022 100644 --- a/core/manager/challenge.go +++ b/core/manager/challenge.go @@ -681,7 +681,8 @@ func undeployChallenge(challengeName string, purge bool) error { if err != nil { return err } - err = cleanSidecar(&cfg) + // TODO: remove sidecars completely + // err = cleanSidecar(&cfg) if err != nil { return err } diff --git a/core/manager/pipeline.go b/core/manager/pipeline.go index a9ae2d22..662aedda 100644 --- a/core/manager/pipeline.go +++ b/core/manager/pipeline.go @@ -194,16 +194,17 @@ func commitChallenge(challenge *database.Challenge, config cfg.BeastChallengeCon log.Infof("Image build for `%s` done", challengeName) - if config.Challenge.Metadata.Sidecar != "" { - // Need to configure the sidecar container, so we can use the configuration - // during deployment. We don't want sidecar configuration to change each time we - // make a deployment, so we are doing it in commit phase, so unless the challenge is purged - // we can use the same sidecar configuration. - err = configureSidecar(&config) - if err != nil { - return err - } - } + // TODO: remove sidecars completely + // if config.Challenge.Metadata.Sidecar != "" { + // // Need to configure the sidecar container, so we can use the configuration + // // during deployment. We don't want sidecar configuration to change each time we + // // make a deployment, so we are doing it in commit phase, so unless the challenge is purged + // // we can use the same sidecar configuration. + // err = configureSidecar(&config) + // if err != nil { + // return err + // } + // } return nil } @@ -234,14 +235,15 @@ func deployChallenge(challenge *database.Challenge, config cfg.BeastChallengeCon var containerEnv []string var containerNetwork string - if config.Challenge.Metadata.Sidecar != "" { - // We need to configure the sidecar for the challenge container. - // Push the environment variables to the container and link to the sidecar. - env := getSidecarEnv(&config) - containerEnv = append(containerEnv, env...) - - containerNetwork = getSidecarNetwork(config.Challenge.Metadata.Sidecar) - } + // TODO: remove sidecars completely + // if config.Challenge.Metadata.Sidecar != "" { + // // We need to configure the sidecar for the challenge container. + // // Push the environment variables to the container and link to the sidecar. + // env := getSidecarEnv(&config) + // containerEnv = append(containerEnv, env...) + + // containerNetwork = getSidecarNetwork(config.Challenge.Metadata.Sidecar) + // } for _, env := range config.Challenge.Env.EnvironmentVars { containerEnv = append(containerEnv, fmt.Sprintf("%s=%s", env.Key, filepath.Join(core.BEAST_DOCKER_CHALLENGE_DIR, env.Value))) diff --git a/core/manager/utils.go b/core/manager/utils.go index 83ff5f17..967f7428 100644 --- a/core/manager/utils.go +++ b/core/manager/utils.go @@ -509,7 +509,7 @@ func UpdateOrCreateChallengeDbEntry(challEntry *database.Challenge, config cfg.B DynamicFlag: config.Challenge.Metadata.DynamicFlag, Flag: config.Challenge.Metadata.Flag, Type: config.Challenge.Metadata.Type, - Sidecar: config.Challenge.Metadata.Sidecar, + // Sidecar: config.Challenge.Metadata.Sidecar, Description: config.Challenge.Metadata.Description, Assets: strings.Join(assetsURL, core.DELIMITER), AdditionalLinks: strings.Join(config.Challenge.Metadata.AdditionalLinks, core.DELIMITER), diff --git a/scripts/build/build.sh b/scripts/build/build.sh index 51125e1c..7a170fb1 100755 --- a/scripts/build/build.sh +++ b/scripts/build/build.sh @@ -51,9 +51,9 @@ fi GOBIN=$PWD go "${GO_CMD}" -o "${GOPATH}/bin/beast" ${GO_FLAGS} -ldflags "${ldflags}" "${main_package}" -echo ">>> Build beast sidecar agents..." -GOBIN=$PWD go "${GO_CMD}" -o "${CWD}/extras/sidecars/mysql/beast_agent" ${GO_FLAGS} "${mysql_agent}" -GOBIN=$PWD go "${GO_CMD}" -o "${CWD}/extras/sidecars/mongo/beast_agent" ${GO_FLAGS} "${mongo_agent}" +# echo ">>> Build beast sidecar agents..." +# GOBIN=$PWD go "${GO_CMD}" -o "${CWD}/extras/sidecars/mysql/beast_agent" ${GO_FLAGS} "${mysql_agent}" +# GOBIN=$PWD go "${GO_CMD}" -o "${CWD}/extras/sidecars/mongo/beast_agent" ${GO_FLAGS} "${mongo_agent}" echo "[*] Build Complete." exit 0 diff --git a/scripts/build/extras.sh b/scripts/build/extras.sh index 99bb7fe0..72b2d2c9 100755 --- a/scripts/build/extras.sh +++ b/scripts/build/extras.sh @@ -24,51 +24,51 @@ else beast-static fi -echo -e "\n\nBuilding beast extras sidecar images: MYSQL\n" -cd "${CWD}/extras/sidecars/mysql" +# echo -e "\n\nBuilding beast extras sidecar images: MYSQL\n" +# cd "${CWD}/extras/sidecars/mysql" -if docker images | grep -q 'beast-mysql'; then - echo "Image for beast-mysql container already exists." -else - docker build . --tag beast-mysql:latest -fi +# if docker images | grep -q 'beast-mysql'; then +# echo "Image for beast-mysql container already exists." +# else +# docker build . --tag beast-mysql:latest +# fi -if docker network ls | grep -q 'beast-mysql'; then - echo "Network for beast-mysql sidecar already exists." -else - docker network create beast-mysql -fi +# if docker network ls | grep -q 'beast-mysql'; then +# echo "Network for beast-mysql sidecar already exists." +# else +# docker network create beast-mysql +# fi -if docker ps -a | grep -q 'mysql'; then - echo "Container for mysql sidecar with name mysql already exists." -else - docker run -d -p 127.0.0.1:9500:9500 \ - --name mysql --network beast-mysql \ - --env MYSQL_ROOT_PASSWORD=$(openssl rand -hex 20) \ - beast-mysql -fi +# if docker ps -a | grep -q 'mysql'; then +# echo "Container for mysql sidecar with name mysql already exists." +# else +# docker run -d -p 127.0.0.1:9500:9500 \ +# --name mysql --network beast-mysql \ +# --env MYSQL_ROOT_PASSWORD=$(openssl rand -hex 20) \ +# beast-mysql +# fi -echo -e "\n\nBuilding beast extras sidecar images: MONGO\n" -cd "${CWD}/extras/sidecars/mongo" +# echo -e "\n\nBuilding beast extras sidecar images: MONGO\n" +# cd "${CWD}/extras/sidecars/mongo" -if docker images | grep -q 'beast-mongo'; then - echo "Image for beast-mongo container already exists." -else - docker build . --tag beast-mongo:latest -fi +# if docker images | grep -q 'beast-mongo'; then +# echo "Image for beast-mongo container already exists." +# else +# docker build . --tag beast-mongo:latest +# fi -if docker network ls | grep -q 'beast-mongo'; then - echo "Network for beast-mongo sidecar already exists." -else - docker network create beast-mongo -fi +# if docker network ls | grep -q 'beast-mongo'; then +# echo "Network for beast-mongo sidecar already exists." +# else +# docker network create beast-mongo +# fi -if docker ps -a | grep -q 'mongo'; then - echo "Container for mongo sidecar with name mongo already exists." -else - docker run -d -p 127.0.0.1:9501:9501 \ - --name mongo --network beast-mongo \ - -e MONGO_INITDB_ROOT_USERNAME=$(openssl rand -hex 20) \ - -e MONGO_INITDB_ROOT_PASSWORD=$(openssl rand -hex 20) \ - beast-mongo -fi +# if docker ps -a | grep -q 'mongo'; then +# echo "Container for mongo sidecar with name mongo already exists." +# else +# docker run -d -p 127.0.0.1:9501:9501 \ +# --name mongo --network beast-mongo \ +# -e MONGO_INITDB_ROOT_USERNAME=$(openssl rand -hex 20) \ +# -e MONGO_INITDB_ROOT_PASSWORD=$(openssl rand -hex 20) \ +# beast-mongo +# fi diff --git a/templates/templates.go b/templates/templates.go index 6c6a9fe9..3e15471c 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -11,7 +11,6 @@ name = {{.Challenge.Metadata.Name}} # Required: Name of the c type = {{.Challenge.Metadata.Type}} # Required: Type of challenge -> [web::: static service] dynamicFlag = {{.Challenge.Metadata.DynamicFlag}} # Required: Dynamic flag or not -> [true/false] flag = {{.Challenge.Metadata.Flag}} # Challenge Flag if dynamicFlag is false -sidecar = {{.Challenge.Metadata.Sidecar}} # Specify helper sidecar container for example mysql difficulty = {{.Challenge.Metadata.Difficulty}} # Specify the difficulty of the challenge [challenge.env] From 2fe7a6c5da92bbd16a74590e077d9aca3f5e5e80 Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Tue, 23 Sep 2025 02:53:42 +0530 Subject: [PATCH 3/4] docs: mark sidecar references as deprecated in documentation Signed-off-by: vibhatsu --- README.md | 2 +- docs/ChallConfig.md | 1 - docs/ChallTypes.md | 2 +- docs/Documentation.md | 2 +- docs/Features.md | 2 +- docs/README.md | 2 +- docs/SampleChallenges.md | 2 +- docs/Setup.md | 3 ++- docs/Sidecars.md | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7bfa0b4b..6f745c90 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ If you're looking for the source code of playCTF, the frontend powered by Beast, - An optional automated health check service to periodically check the status of challenges and report if there is some sort of problem with one. - Single source of truth for all the static content related to all the challenges making it easy to debug, monitor and manage static content through a single interface. -- Use of sidecar mechanism for stateful workloads which can be shared by multiple challenges at once, MySQL for example. +- **[DEPRECATED]** Use of sidecar mechanism for stateful workloads which can be shared by multiple challenges at once, MySQL for example. - Support for various notification channels like slack, discord. - Everything embedded to a single go binary which can be easily used anywhere. diff --git a/docs/ChallConfig.md b/docs/ChallConfig.md index 1907a8e7..cc2bea22 100644 --- a/docs/ChallConfig.md +++ b/docs/ChallConfig.md @@ -74,7 +74,6 @@ description = "" # Descritption for the challenge. # Optional fields. tags = ["", ""] # Tags that the challenge might belong to, used to do bulk query and handling eg. binary, misc etc. hints = ["", ""] -sidecar = "" # Name of the sidecar if any used by the challenge. minPoints = 0 # Minimum points given to the player for correct flag submission. Beast has dynamic scoring, so a range of points is specified maxPoints = 0 # Maximum points given to the player for correct flag submission. Beast has dynamic scoring, so a range of points is specified assets = ["", ""] # Name of assets to be provided which are included in the ./static folder diff --git a/docs/ChallTypes.md b/docs/ChallTypes.md index 6816ee7a..ac21a311 100644 --- a/docs/ChallTypes.md +++ b/docs/ChallTypes.md @@ -35,7 +35,7 @@ All the challenges which requires the hackers to only have static files comes un ## Bare Challenge -A challenge which requires high level of customization can be hosted using `bare` challenge. In these case, a bare base image is provided with access to mentioned sidecars, and exposed ports. +A challenge which requires high level of customization can be hosted using `bare` challenge. In these case, a bare base image is provided ~~with access to mentioned sidecars~~, and exposed ports. ###Primary Requirements diff --git a/docs/Documentation.md b/docs/Documentation.md index ade76f9c..f41c8048 100644 --- a/docs/Documentation.md +++ b/docs/Documentation.md @@ -14,4 +14,4 @@ Move over to any of the below pages to know more about beast. * [Authentication Flow](./APIAuth.md) * [Challenge Configuration](./ChallConfig.md) * [Deployment](./Deployment.md) -* [Sidecars](./Sidecars.md) +* **[DEPRECATED]** [Sidecars](./Sidecars.md) diff --git a/docs/Features.md b/docs/Features.md index 00111e2a..9fe9aba1 100644 --- a/docs/Features.md +++ b/docs/Features.md @@ -60,7 +60,7 @@ environments. - Single source of truth for all the static content related to all the challenges making it easy to debug, monitor and manage static content through a single interface. -- Use of sidecar mechanism for stateful workloads which can be shared by multiple challenges at once, MySQL for example. +~~- Use of sidecar mechanism for stateful workloads which can be shared by multiple challenges at once, MySQL for example.~~ - Support for various notification channels like slack, discord. diff --git a/docs/README.md b/docs/README.md index ed234710..ae6a2e3d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -14,7 +14,7 @@ This directory contains documentation related to beast and will guide you throug * [Challenge Configuration](ChallConfig.md) * [Sample Challenges](SampleChallenges.md) * [Deployment](Deployment.md) -* [Sidecars](Sidecars.md) +* **[DEPRECATED]** [Sidecars](Sidecars.md) ## Intro diff --git a/docs/SampleChallenges.md b/docs/SampleChallenges.md index 9c469e4b..aed5ef2a 100644 --- a/docs/SampleChallenges.md +++ b/docs/SampleChallenges.md @@ -180,7 +180,7 @@ The `web_root` is the base directory for the php server to locate the files. The type of challenge consist of the following format - `web:php::` -### PHP challenge with MySQL database +### PHP challenge with MySQL database [DEPRECATED] For deploying a challenge with database requirement beast sidecars needs to be used. diff --git a/docs/Setup.md b/docs/Setup.md index 216a7e19..c61985f7 100644 --- a/docs/Setup.md +++ b/docs/Setup.md @@ -88,9 +88,10 @@ service_name = "discord" # If it is false then notification will not be sent on this URL active = true +# DEPRECATED # The sidecar that we support with beast, currently we only support two MySQL and # MongoDB. -available_sidecars = ["mysql", "mongodb"] +# available_sidecars = ["mysql", "mongodb"] # The frequency for any periodic event in beast, the value is provided in seconds. diff --git a/docs/Sidecars.md b/docs/Sidecars.md index d375af4f..dbd890d7 100644 --- a/docs/Sidecars.md +++ b/docs/Sidecars.md @@ -1,4 +1,4 @@ -# Sidecars +# Sidecars [DEPRECATED] Sidecar container in beast are the container that provide additional functionality to existing challenge containers. For a challenge you can specify one or more sidecar containers, which your container can then access with the variables injected in container Environment Variables. As a example let's take MySQL sidecar for web challenges as an instance. From bd2c459215b445c4bd99a293e6554c01d2b4ef50 Mon Sep 17 00:00:00 2001 From: vibhatsu Date: Tue, 23 Sep 2025 02:54:11 +0530 Subject: [PATCH 4/4] fix: update mod file Signed-off-by: vibhatsu --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2299d231..04e1a257 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/gin-contrib/cors v1.3.1 github.com/gin-contrib/static v0.0.0-20200916080430-d45d9a37d28e github.com/gin-gonic/gin v1.7.0 - github.com/go-sql-driver/mysql v1.4.0 github.com/golang/protobuf v1.3.3 github.com/jinzhu/gorm v1.9.1 github.com/mohae/struct2csv v0.0.0-20151122200941-e72239694eae @@ -48,6 +47,7 @@ require ( github.com/go-playground/locales v0.13.0 // indirect github.com/go-playground/universal-translator v0.17.0 // indirect github.com/go-playground/validator/v10 v10.4.1 // indirect + github.com/go-sql-driver/mysql v1.4.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect