From 8dd4fca18ec78994c72ca46847e9675e69ac4aa2 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sat, 5 Mar 2022 15:53:47 -0700 Subject: [PATCH] Add some logging --- build/Containerfile | 7 +++++-- cmd/simpleauth/main.go | 10 +++++++++- secret | 1 - 3 files changed, 14 insertions(+), 4 deletions(-) delete mode 100644 secret diff --git a/build/Containerfile b/build/Containerfile index 2ff83cd..3683959 100644 --- a/build/Containerfile +++ b/build/Containerfile @@ -1,4 +1,4 @@ -FROM golang:1 +FROM golang:1-alpine AS builder WORKDIR /go/src/app COPY . . @@ -6,4 +6,7 @@ COPY . . RUN go get -d -v ./... RUN go install -v ./... -CMD ["simpleauth"] \ No newline at end of file +FROM alpine +COPY --from=builder /go/bin/simpleauth /bin +COPY --from=builder /go/src/app/static /static +CMD ["/bin/simpleauth"] diff --git a/cmd/simpleauth/main.go b/cmd/simpleauth/main.go index f0714bf..12026b8 100644 --- a/cmd/simpleauth/main.go +++ b/cmd/simpleauth/main.go @@ -37,11 +37,19 @@ func rootHandler(w http.ResponseWriter, req *http.Request) { } } + // Log the request + clientIP := req.Header.Get("X-Real-IP") + if clientIP == "" { + clientIP = req.RemoteAddr + } + log.Println(clientIP, req.Method, req.URL, "authenticated:", authenticated) + if authenticated { t := token.New(secret, time.Now().Add(lifespan)) http.SetCookie(w, &http.Cookie{ Name: CookieName, Value: t.String(), + Path: "/", Secure: true, SameSite: http.SameSiteStrictMode, }) @@ -112,6 +120,6 @@ func main() { http.HandleFunc("/", rootHandler) - fmt.Println("I am listening on ", *listen) + fmt.Println("listening on", *listen) log.Fatal(http.ListenAndServe(*listen, nil)) } diff --git a/secret b/secret deleted file mode 100644 index 3ee322b..0000000 --- a/secret +++ /dev/null @@ -1 +0,0 @@ -goober