diff --git a/Dockerfile b/Dockerfile index a4bafe40..9f6b682b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 . . @@ -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} diff --git a/README.md b/README.md index 8e09bf53..a5581cf1 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/aws-es-proxy.go b/aws-es-proxy.go index f1f588ef..6bee45e9 100644 --- a/aws-es-proxy.go +++ b/aws-es-proxy.go @@ -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" @@ -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 { @@ -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()) }