Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block-deletes #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ For a full list of available options, use `-h`:
```sh
./aws-es-proxy -h
Usage of ./aws-es-proxy:
-assume string
Optionally specify role to assume
Comment on lines +127 to +128
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: I re-ran the proxy with -h and I guess this option had not been documented yet either.

-auth
Require HTTP Basic Auth
-block-deletes
Block delete requests, defaults to false
-debug
Print debug messages
-endpoint string
Expand Down
14 changes: 14 additions & 0 deletions aws-es-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type proxy struct {
realm string
remoteTerminate bool
assumeRole string
blockDeletes bool
}

func newProxy(args ...interface{}) *proxy {
Expand All @@ -114,6 +115,7 @@ func newProxy(args ...interface{}) *proxy {
realm: args[9].(string),
remoteTerminate: args[10].(bool),
assumeRole: args[11].(string),
blockDeletes: args[12].(bool),
}
}

Expand Down Expand Up @@ -225,12 +227,21 @@ func (p *proxy) getSigner() *v4.Signer {
return v4.NewSigner(p.credentials)
}

func isDeletePath(path string) bool {
return strings.Contains(path, "_delete_by_query")
}

func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if p.remoteTerminate && r.URL.Path == "/terminate-proxy" && r.Method == http.MethodPost {
logrus.Infoln("Terminate Signal")
os.Exit(0)
}

if p.blockDeletes && (r.Method == http.MethodDelete || isDeletePath(r.URL.Path)) {
logrus.Warningln("Blocked Delete Request")
os.Exit(0)
}

if p.auth {
user, pass, ok := r.BasicAuth()

Expand Down Expand Up @@ -464,6 +475,7 @@ func main() {
timeout int
remoteTerminate bool
assumeRole string
blockDeletes bool
)

flag.StringVar(&endpoint, "endpoint", "", "Amazon ElasticSearch Endpoint (e.g: https://dummy-host.eu-west-1.es.amazonaws.com)")
Expand All @@ -481,6 +493,7 @@ func main() {
flag.StringVar(&realm, "realm", "", "Authentication Required")
flag.BoolVar(&remoteTerminate, "remote-terminate", false, "Allow HTTP remote termination")
flag.StringVar(&assumeRole, "assume", "", "Optionally specify role to assume")
flag.BoolVar(&blockDeletes, "block-deletes", false, "Block delete requests, defaults to false")
flag.Parse()

if endpoint == "" {
Expand Down Expand Up @@ -528,6 +541,7 @@ func main() {
realm,
remoteTerminate,
assumeRole,
blockDeletes,
)

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