Skip to content

Commit

Permalink
Plumb ACL through to state
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Patel committed Jul 30, 2023
1 parent ceba607 commit bcb4ba6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions srepanel/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ type Link struct {
Name string `json:"name"`
URL string `json:"url"`
}

type UserRepoAccess struct {
Repo string
Perm string
}
6 changes: 6 additions & 0 deletions srepanel/ghidra/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const (

const AnonAllowedStr = "=ANONYMOUS_ALLOWED"

var PermStrs = []string{
PermRead: PermReadStr,
PermWrite: PermWriteStr,
PermAdmin: PermAdminStr,
}

// ACL is an in-memory representation of a repo access list.
type ACL struct {
AnonymousAccess bool
Expand Down
2 changes: 2 additions & 0 deletions srepanel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func main() {
dbPath := flag.String("db", "ghidra_panel.db", "path to database file")
listen := flag.String("listen", ":8080", "listen address")
cmdInit := flag.Bool("init", false, "initialize database and exit")
dev := flag.Bool("dev", false, "enable development mode")

flag.Parse()

Expand Down Expand Up @@ -109,6 +110,7 @@ func main() {
webConfig := web.Config{
GhidraEndpoint: &cfg.Ghidra.Endpoint,
Links: cfg.Links,
Dev: *dev,
}
server, err := web.NewServer(&webConfig, db, auth, &issuer, &acls)
if err != nil {
Expand Down
15 changes: 13 additions & 2 deletions srepanel/web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package web

import (
"embed"
"go.mkw.re/ghidra-panel/ghidra"
"html/template"
"net/http"

"go.mkw.re/ghidra-panel/common"
"go.mkw.re/ghidra-panel/database"
"go.mkw.re/ghidra-panel/discord_auth"
"go.mkw.re/ghidra-panel/ghidra"
"go.mkw.re/ghidra-panel/token"
)

Expand Down Expand Up @@ -37,6 +37,7 @@ func init() {
type Config struct {
GhidraEndpoint *common.GhidraEndpoint
Links []common.Link
Dev bool // developer mode
}

type Server struct {
Expand Down Expand Up @@ -83,6 +84,7 @@ type State struct {
Nav []Nav // navigation bar
Links []common.Link // footer links
Ghidra *common.GhidraEndpoint
ACL []common.UserRepoAccess
}

type Nav struct {
Expand Down Expand Up @@ -118,7 +120,16 @@ func (s *Server) authenticateState(wr http.ResponseWriter, req *http.Request, st
http.Error(wr, "failed to get user state, please contact server admin", http.StatusInternalServerError)
return false
}

state.UserState = userState

acl := s.ACLs.Get().QueryUser(ident.Username)
state.ACL = make([]common.UserRepoAccess, len(acl))
for i, v := range acl {
state.ACL[i] = common.UserRepoAccess{
Repo: v.Repo,
Perm: ghidra.PermStrs[v.Perm],
}
}

return true
}

0 comments on commit bcb4ba6

Please sign in to comment.