loop MTD, checks before doing mtd to service

This commit is contained in:
schulze 2023-04-18 11:08:31 +02:00
parent e8962c3cba
commit 143e839e78
3 changed files with 33 additions and 4 deletions

15
main.go
View File

@ -28,11 +28,18 @@ func main() {
config = indexAllInstances(config) config = indexAllInstances(config)
state.SaveConf(ConfigPath, config) state.SaveConf(ConfigPath, config)
//TODO: figure out migration (MTD) // START DOING MTD
config = movingTargetDefense(config) mtdLoop(config)
state.SaveConf(ConfigPath, config) }
//TODO: proxy commands func mtdLoop(config state.Config) {
for true {
//TODO: figure out migration (MTD)
config = movingTargetDefense(config)
state.SaveConf(ConfigPath, config)
//TODO: proxy commands
}
} }
func movingTargetDefense(config state.Config) state.Config{ func movingTargetDefense(config state.Config) state.Config{

View File

@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/thefeli73/polemos/state" "github.com/thefeli73/polemos/state"
) )
@ -37,6 +38,12 @@ func AWSUpdateService(config state.Config, region string, service state.CustomUU
return config return config
} }
// isInstanceRunning returns if an instance is running (true=running)
func isInstanceRunning(instance *types.Instance) bool {
return instance.State.Name == types.InstanceStateNameRunning
}
// AWSMoveInstance moves a specified instance to a new availability region // AWSMoveInstance moves a specified instance to a new availability region
func AWSMoveInstance(config state.Config) (state.Config) { func AWSMoveInstance(config state.Config) (state.Config) {
@ -61,6 +68,19 @@ func AWSMoveInstance(config state.Config) (state.Config) {
return config return config
} }
if !isInstanceRunning(realInstance) {
fmt.Println("Error, Instance is not running!")
return config
}
if instance.AdminDisabled {
fmt.Println("Error, Service is Disabled!")
return config
}
if instance.Inactive {
fmt.Println("Error, Service is Inactive!")
return config
}
imageName, err := createImage(svc, instanceID) imageName, err := createImage(svc, instanceID)
if err != nil { if err != nil {
fmt.Println("Error creating image:\t", err) fmt.Println("Error creating image:\t", err)

View File

@ -24,6 +24,8 @@ type mtdconf struct {
// Service contains all necessary information about a service to identify it in the cloud as well as configuring a proxy for it // Service contains all necessary information about a service to identify it in the cloud as well as configuring a proxy for it
type Service struct { type Service struct {
CloudID string `yaml:"cloud_id"` CloudID string `yaml:"cloud_id"`
AdminDisabled bool `yaml:"admin_disabled"`
Inactive bool `yaml:"inactive"`
EntryIP netip.Addr `yaml:"entry_ip"` EntryIP netip.Addr `yaml:"entry_ip"`
EntryPort uint16 `yaml:"entry_port"` EntryPort uint16 `yaml:"entry_port"`
ServiceIP netip.Addr `yaml:"service_ip"` ServiceIP netip.Addr `yaml:"service_ip"`