Skip to content

Commit 0735035

Browse files
committed
Move remote termination behind flag
Probably don't want to add the ability to remotely shutdown the proxy to be accessible unless desired and in a safe environment, so moving behind a flag. Also updated the README with latest usage. See Issue #77
1 parent 64771e7 commit 0735035

File tree

3 files changed

+66
-44
lines changed

3 files changed

+66
-44
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ https://github.com/diranged
2424
https://github.com/em0ney
2525
https://github.com/zqben402
2626
https://github.com/dlackty
27+
https://github.com/amcintosh
2728

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ For a full list of available options, use `-h`:
124124
```sh
125125
./aws-es-proxy -h
126126
Usage of ./aws-es-proxy:
127+
-auth
128+
Require HTTP Basic Auth
129+
-debug
130+
Print debug messages
127131
-endpoint string
128132
Amazon ElasticSearch Endpoint (e.g: https://dummy-host.eu-west-1.es.amazonaws.com)
129133
-listen string
@@ -132,10 +136,22 @@ Usage of ./aws-es-proxy:
132136
Log user requests and ElasticSearch responses to files
133137
-no-sign-reqs
134138
Disable AWS Signature v4
139+
-password string
140+
HTTP Basic Auth Password
135141
-pretty
136142
Prettify verbose and file output
143+
-realm string
144+
Authentication Required
145+
-remote-terminate
146+
Allow HTTP remote termination
147+
-timeout int
148+
Set a request timeout to ES. Specify in seconds, defaults to 15 (default 15)
149+
-username string
150+
HTTP Basic Auth Username
137151
-verbose
138152
Print user requests
153+
-version
154+
Print aws-es-proxy version
139155
```
140156

141157

aws-es-proxy.go

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,24 @@ type responseStruct struct {
6969
}
7070

7171
type proxy struct {
72-
scheme string
73-
host string
74-
region string
75-
service string
76-
endpoint string
77-
verbose bool
78-
prettify bool
79-
logtofile bool
80-
nosignreq bool
81-
fileRequest *os.File
82-
fileResponse *os.File
83-
credentials *credentials.Credentials
84-
httpClient *http.Client
85-
auth bool
86-
username string
87-
password string
88-
realm string
72+
scheme string
73+
host string
74+
region string
75+
service string
76+
endpoint string
77+
verbose bool
78+
prettify bool
79+
logtofile bool
80+
nosignreq bool
81+
fileRequest *os.File
82+
fileResponse *os.File
83+
credentials *credentials.Credentials
84+
httpClient *http.Client
85+
auth bool
86+
username string
87+
password string
88+
realm string
89+
remoteTerminate bool
8990
}
9091

9192
func newProxy(args ...interface{}) *proxy {
@@ -100,16 +101,17 @@ func newProxy(args ...interface{}) *proxy {
100101
}
101102

102103
return &proxy{
103-
endpoint: args[0].(string),
104-
verbose: args[1].(bool),
105-
prettify: args[2].(bool),
106-
logtofile: args[3].(bool),
107-
nosignreq: args[4].(bool),
108-
httpClient: &client,
109-
auth: args[6].(bool),
110-
username: args[7].(string),
111-
password: args[8].(string),
112-
realm: args[9].(string),
104+
endpoint: args[0].(string),
105+
verbose: args[1].(bool),
106+
prettify: args[2].(bool),
107+
logtofile: args[3].(bool),
108+
nosignreq: args[4].(bool),
109+
httpClient: &client,
110+
auth: args[6].(bool),
111+
username: args[7].(string),
112+
password: args[8].(string),
113+
realm: args[9].(string),
114+
remoteTerminate: args[10].(bool),
113115
}
114116
}
115117

@@ -210,7 +212,7 @@ func (p *proxy) getSigner() *v4.Signer {
210212
}
211213

212214
func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
213-
if r.URL.Path == "/terminate-proxy" && r.Method == http.MethodPost {
215+
if p.remoteTerminate && r.URL.Path == "/terminate-proxy" && r.Method == http.MethodPost {
214216
logrus.Infoln("Terminate Signal")
215217
os.Exit(0)
216218
}
@@ -424,22 +426,23 @@ func copyHeaders(dst, src http.Header) {
424426
func main() {
425427

426428
var (
427-
debug bool
428-
auth bool
429-
username string
430-
password string
431-
realm string
432-
verbose bool
433-
prettify bool
434-
logtofile bool
435-
nosignreq bool
436-
ver bool
437-
endpoint string
438-
listenAddress string
439-
fileRequest *os.File
440-
fileResponse *os.File
441-
err error
442-
timeout int
429+
debug bool
430+
auth bool
431+
username string
432+
password string
433+
realm string
434+
verbose bool
435+
prettify bool
436+
logtofile bool
437+
nosignreq bool
438+
ver bool
439+
endpoint string
440+
listenAddress string
441+
fileRequest *os.File
442+
fileResponse *os.File
443+
err error
444+
timeout int
445+
remoteTerminate bool
443446
)
444447

445448
flag.StringVar(&endpoint, "endpoint", "", "Amazon ElasticSearch Endpoint (e.g: https://dummy-host.eu-west-1.es.amazonaws.com)")
@@ -455,6 +458,7 @@ func main() {
455458
flag.StringVar(&username, "username", "", "HTTP Basic Auth Username")
456459
flag.StringVar(&password, "password", "", "HTTP Basic Auth Password")
457460
flag.StringVar(&realm, "realm", "", "Authentication Required")
461+
flag.BoolVar(&remoteTerminate, "remote-terminate", false, "Allow HTTP remote termination")
458462
flag.Parse()
459463

460464
if endpoint == "" {
@@ -500,6 +504,7 @@ func main() {
500504
username,
501505
password,
502506
realm,
507+
remoteTerminate,
503508
)
504509

505510
if err = p.parseEndpoint(); err != nil {

0 commit comments

Comments
 (0)