Skip to content
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14-alpine
FROM golang:1.14-alpine as build

WORKDIR /go/src/github.com/abutaha/aws-es-proxy
COPY . .
Expand All @@ -11,7 +11,7 @@ LABEL name="aws-es-proxy" \

RUN apk --no-cache add ca-certificates
WORKDIR /home/
COPY --from=0 /go/src/github.com/abutaha/aws-es-proxy/aws-es-proxy /usr/local/bin/
COPY --from=build /go/src/github.com/abutaha/aws-es-proxy/aws-es-proxy /usr/local/bin/

ENV PORT_NUM 9200
EXPOSE ${PORT_NUM}
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# ARCHIVED

We do not use AWS ElasticSearch (OpenSearch now) anymore


# aws-es-proxy

[![Docker Pulls](https://img.shields.io/docker/pulls/abutaha/aws-es-proxy.svg)](https://hub.docker.com/r/abutaha/aws-es-proxy/)
Expand Down
19 changes: 17 additions & 2 deletions aws-es-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"runtime"
"strings"
"time"
"encoding/base64"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
Expand Down Expand Up @@ -92,6 +93,10 @@ type proxy struct {
assumeRole string
}

type jwt_header struct {
Email string `json:"email"`
}

func newProxy(args ...interface{}) *proxy {

noRedirect := func(req *http.Request, via []*http.Request) error {
Expand Down Expand Up @@ -373,8 +378,18 @@ func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Println("Body: ")
fmt.Println(string(prettyBody.Bytes()))
} else {
log.Printf(" -> %s; %s; %s; %s; %d; %.3fs\n",
r.Method, r.RemoteAddr,
encoded_header := r.Header.Get("X-Amzn-Oidc-Data")
var jwtHeader jwt_header

if encoded_header != "" {
encoded_header_payload := strings.Split(encoded_header, ".")
// the payload is in the middle
jwt_header_bytes, _ := base64.StdEncoding.DecodeString(encoded_header_payload[1])
_ = json.Unmarshal(jwt_header_bytes, &jwtHeader)
}

log.Printf(" %s -> %s; %s; %s; %s; %d; %.3fs\n",
jwtHeader.Email, r.Method, r.RemoteAddr,
proxied.RequestURI(), query,
resp.StatusCode, requestEnded.Seconds())
}
Expand Down