forked from GSA-TTS/identity-idva-aws-sigv4-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alexander Tanton <[email protected]>
- Loading branch information
Tanton
committed
Oct 22, 2018
1 parent
9539b38
commit 2730dc8
Showing
494 changed files
with
223,798 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.11-alpine3.8 as build | ||
|
||
RUN apk add -U --no-cache ca-certificates git bash | ||
|
||
COPY ./ /go/src/github.com/tantona/aws-sigv4-proxy | ||
WORKDIR /go/src/github.com/tantona/aws-sigv4-proxy | ||
|
||
RUN go build -o app github.com/tantona/aws-sigv4-proxy && \ | ||
mv ./app /go/bin | ||
|
||
FROM alpine:3.8 | ||
|
||
WORKDIR /opt/ | ||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=build /go/bin/app /opt/ | ||
|
||
ENTRYPOINT [ "/opt/app" ] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/aws/aws-sdk-go" | ||
version = "1.15.27" | ||
|
||
[[constraint]] | ||
name = "github.com/coreos/pkg" | ||
version = "4.0.0" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
approvers: | ||
- tantona | ||
reviewers: | ||
- tantona |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package handler | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
) | ||
|
||
var services = map[string]endpoints.ResolvedEndpoint{} | ||
|
||
func init() { | ||
// Triple nested loop - 😭 | ||
for _, partition := range endpoints.DefaultPartitions() { | ||
|
||
for _, service := range partition.Services() { | ||
for _, endpoint := range service.Endpoints() { | ||
resolvedEndpoint, _ := endpoint.ResolveEndpoint() | ||
host := strings.Replace(resolvedEndpoint.URL, "https://", "", 1) | ||
services[host] = resolvedEndpoint | ||
} | ||
} | ||
} | ||
|
||
// Add api gateway endpoints | ||
for region := range endpoints.AwsPartition().Regions() { | ||
host := fmt.Sprintf("execute-api.%s.amazonaws.com", region) | ||
services[host] = endpoints.ResolvedEndpoint{URL: fmt.Sprintf("https://%s", host), SigningMethod: "v4", SigningRegion: region, SigningName: "execute-api"} | ||
} | ||
} | ||
|
||
func determineAWSServiceFromHost(host string) *endpoints.ResolvedEndpoint { | ||
for endpoint, service := range services { | ||
if strings.Contains(host, endpoint) { | ||
return &service | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package handler | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"net/http" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type Handler struct { | ||
ProxyClient Client | ||
} | ||
|
||
func (h *Handler) write(w http.ResponseWriter, status int, body []byte) { | ||
w.WriteHeader(status) | ||
w.Write(body) | ||
} | ||
|
||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
resp, err := h.ProxyClient.Do(r) | ||
if err != nil { | ||
log.WithError(err).Error("unable to proxy request") | ||
h.write(w, http.StatusBadRequest, []byte(err.Error())) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
// read response body | ||
buf := bytes.Buffer{} | ||
if _, err := io.Copy(&buf, resp.Body); err != nil { | ||
log.WithError(err).Error("unable to proxy request") | ||
h.write(w, http.StatusInternalServerError, []byte(err.Error())) | ||
return | ||
} | ||
|
||
// copy headers | ||
for k, vals := range resp.Header { | ||
for _, v := range vals { | ||
w.Header().Add(k, v) | ||
} | ||
} | ||
|
||
h.write(w, resp.StatusCode, buf.Bytes()) | ||
} |
Oops, something went wrong.