This repository has been archived by the owner on Jun 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
wizard.go
189 lines (174 loc) · 6.22 KB
/
wizard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package deploy
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
"github.com/oktasecuritylabs/sgt/handlers/helpers"
)
// Wizard walks through setting up an environment config and deploys
func Wizard() error {
config := DeploymentConfig{}
fmt.Print("Enter new environment name. This is typically something like" +
"'Dev' or 'Prod' or 'Testing, but can be anything you want it to be: ")
//envName, err := reader.ReadString('\n')
var envName string
_, err := fmt.Scan(&envName)
if err != nil {
return err
}
err = CreateDeployDirectory(envName)
if err != nil {
return err
}
config.Environment = envName
fmt.Println("Enter the name for the aws profile you'd like to use to deploy this environment \n" +
"if you've never created a profile before, you can read more about how to do this here\n" +
"http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html \n" +
"a 'default' profile is created if you've installed and configured the aws cli: ")
var profile string
_, err = fmt.Scan(&profile)
if err != nil {
return err
}
config.AWSProfile = profile
fmt.Println("Enter the name for the aws region where you want to deploy this environment \n" +
"us-east-1 is recommended: ")
var region string
_, err = fmt.Scan(®ion)
if err != nil {
return err
}
config.AWSRegion = region
fmt.Println("Enter the name for th mail domain for the users of your Kibana dashboard \n" +
"cognito users will be created with email address username@MailDomain: ")
var mail_domain string
_, err = fmt.Scan(&mail_domain)
if err != nil {
return err
}
config.MailDomain = mail_domain
fmt.Println("Enter the desired size of the autoscaling group: \n" +
"This will be the number of instances running in the autoscaling group: ")
var asgsize int
_, err = fmt.Scan(&asgsize)
if err != nil {
return err
}
config.AsgDesiredSize = asgsize
fmt.Println("Enter the comma separated list of users to provision: \n " +
"Example: firstname.lastname,firstname2.lastname2: ")
var cognitousersstring string
_, err = fmt.Scan(&cognitousersstring)
if err != nil {
return err
}
cognitoUsers := strings.Split(cognitousersstring, ",")
config.Users = cognitoUsers
fmt.Println("Enter an ipaddress or cidr block for access to your elasticsearch cluster. \n" +
"Note: This should probably be your current IP address, as you will need to be able to access \n" +
"elasticsearch via API to create the proper indices and mappings when deploying: ")
var ipAddress string
_, err = fmt.Scan(&ipAddress)
if err != nil {
return err
}
config.UserIPAddress = ipAddress
fmt.Println("Enter a name for the s3 bucket that will hold your osquery logs. \n" +
"Remeber; S3 bucket names must be globally unique: ")
var logBucketName string
_, err = fmt.Scan(&logBucketName)
if err != nil {
return err
}
config.SgtOsqueryResultsBucketName = logBucketName
fmt.Println("Enter a name for the s3 bucket that will hold your server configuration \n" +
"Remeber; S3 bucket names must be globally unique: ")
var configBucket string
_, err = fmt.Scan(&configBucket)
if err != nil {
return err
}
config.SgtConfigBucketName = configBucket
fmt.Println("Enter the domain you will be using for your SGT server. \n" +
"Note: This MUST be a domain which you have previously registered or are managing through" +
"aws. \n This will be used to create a subdomain for the SGT TLS endpoint")
var domain string
_, err = fmt.Scan(&domain)
if err != nil {
return err
}
config.Domain = domain
fmt.Println("Enter a subdomain to use as the endpoint. This will be prepended to the \n" +
"domain you provided as a subdomain")
var subdomain string
_, err = fmt.Scan(&subdomain)
if err != nil {
return err
}
config.Subdomain = subdomain
fmt.Println("Enter the name of your aws keypair. This is used to access ec2 instances if" +
"the need \n should ever arise (it shouldn't).\n" +
"NOTE: This is the name of the keypair EXCLUDING the .pem flie name and it must already exist in aws")
var keypair string
_, err = fmt.Scan(&keypair)
if err != nil {
return err
}
config.AwsKeypair = keypair
fmt.Println("Enter the name of the full ssl certificate chain bundle you will be using for \n" +
"your SGT server. EG - full_chain.pem : ")
var fullChain string
_, err = fmt.Scan(&fullChain)
if err != nil {
return err
}
config.FullSslCertchain = fullChain
fmt.Println("Enter the name of the private key for your ssl certificate. Eg - privkey.pem: ")
var privKey string
_, err = fmt.Scan(&privKey)
if err != nil {
return err
}
config.SslPrivateKey = privKey
fmt.Println("Enter the node secret you will use to enroll your endpoints with the SGT server\n" +
"This secret will be used by each endpoint to authenticate to your server: ")
var nodeSecret string
_, err = fmt.Scan(&nodeSecret)
if err != nil {
return err
}
config.SgtNodeSecret = nodeSecret
fmt.Println("Enter the app secret key which will be used to generate session tokens when \n" +
"interacting with the API as an authenticated end-user. Make this long, random and complex: ")
var appSecret string
_, err = fmt.Scan(&appSecret)
if err != nil {
return err
}
config.SgtAppSecret = appSecret
fmt.Println("Enter the s3 bucket name for the bucket you wish to store your terraform state files in. This bucket" +
"should already exists and be accessible via the aws profile you specified earlier")
var backendBucketName string
_, err = fmt.Scan(&backendBucketName)
if err != nil {
return err
}
config.TerraformBackendBucketName = backendBucketName
fmt.Println("Congratulations, you've successfully configured your SGT deployment! \n" +
"That wasn't so bad, was it? \n" +
"You're now ready to do the actual deployment")
fmt.Println("If you'd like to continue and do the actual deployment, you may continue by\n" +
"entering 'Y' at the next prompt. If you'd like to pause, don't worry! \n" +
"next time you're ready to continue, just run ./sgt -deploy -env $your_deployment_name")
d, err := json.MarshalIndent(config, "", " ")
fn := fmt.Sprintf("terraform/%s/%s.json", envName, envName)
err = ioutil.WriteFile(fn, d, 0644)
if err != nil {
return err
}
if helpers.ConfirmAction("Would you like to proceed with deployment?") {
err = AllComponents(config, envName)
}
return err
}