Skip to content

Commit

Permalink
Setup new auth requirements (#70)
Browse files Browse the repository at this point in the history
* troll

* log

* More troll

* Fxi cherck

* Log access denied case

* Moredata

* Moment

* Logging config

* Remove init()

* Support X-Ripple-Token reading from cookie

* t
  • Loading branch information
cmyui authored Aug 1, 2024
1 parent cba67b3 commit 6b3f42c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/production-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:

- name: Get kubeconfig from github secrets
run: |
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
chmod 600 $HOME/.kube/config
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
chmod 600 $HOME/.kube/config
- name: Install helm
uses: azure/setup-helm@v3
Expand Down
10 changes: 10 additions & 0 deletions app/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func initialCaretaker(c *fasthttp.RequestCtx, f func(md common.MethodData) commo
var token string
var bearerToken bool
switch {
case len(c.Request.Header.CookieBytes([]byte("X-Ripple-Token"))) > 0:
token = string(c.Request.Header.CookieBytes([]byte("X-Ripple-Token")))
case len(c.Request.Header.Peek("X-Ripple-Token")) > 0:
token = string(c.Request.Header.Peek("X-Ripple-Token"))
case strings.HasPrefix(string(c.Request.Header.Peek("Authorization")), "Bearer "):
Expand Down Expand Up @@ -65,6 +67,14 @@ func initialCaretaker(c *fasthttp.RequestCtx, f func(md common.MethodData) commo
}
}
if missingPrivileges != 0 {
slog.Error(
"Denied access due to missing privileges",
"tokenHas", md.User.TokenPrivileges,
"userHas", md.User.UserPrivileges,
"missing", missingPrivileges,
"userID", md.User.UserID,
"route", string(c.Request.URI().Path()),
)
c.SetStatusCode(401)
mkjson(c, common.SimpleResponse(401, "Unauthorized."))
return
Expand Down
12 changes: 5 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package main

import (
"fmt"
"log"
"syscall"
"os"

"golang.org/x/exp/slog"

Expand All @@ -17,12 +16,11 @@ import (
"github.com/serenize/snaker"
)

func init() {
log.SetFlags(log.Ltime)
log.SetPrefix(fmt.Sprintf("%d|", syscall.Getpid()))
}

func main() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))

slog.SetDefault(logger)

slog.Info("Akatsuki API")

settings := common.LoadSettings()
Expand Down

0 comments on commit 6b3f42c

Please sign in to comment.