loop MTD, checks before doing mtd to service
This commit is contained in:
parent
e8962c3cba
commit
143e839e78
7
main.go
7
main.go
@ -28,11 +28,18 @@ func main() {
|
||||
config = indexAllInstances(config)
|
||||
state.SaveConf(ConfigPath, config)
|
||||
|
||||
// START DOING MTD
|
||||
mtdLoop(config)
|
||||
}
|
||||
|
||||
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{
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"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/types"
|
||||
"github.com/google/uuid"
|
||||
"github.com/thefeli73/polemos/state"
|
||||
)
|
||||
@ -37,6 +38,12 @@ func AWSUpdateService(config state.Config, region string, service state.CustomUU
|
||||
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
|
||||
func AWSMoveInstance(config state.Config) (state.Config) {
|
||||
|
||||
@ -61,6 +68,19 @@ func AWSMoveInstance(config state.Config) (state.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)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating image:\t", err)
|
||||
|
@ -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
|
||||
type Service struct {
|
||||
CloudID string `yaml:"cloud_id"`
|
||||
AdminDisabled bool `yaml:"admin_disabled"`
|
||||
Inactive bool `yaml:"inactive"`
|
||||
EntryIP netip.Addr `yaml:"entry_ip"`
|
||||
EntryPort uint16 `yaml:"entry_port"`
|
||||
ServiceIP netip.Addr `yaml:"service_ip"`
|
||||
|
Loading…
Reference in New Issue
Block a user