yasithdev commented on code in PR #736:
URL: https://github.com/apache/airavata-custos/pull/736#discussion_r4556717080


##########
api/core.openapi.yaml:
##########
@@ -1232,6 +1282,33 @@ definitions:
       privilege:
         $ref: '#/definitions/PrivilegeKey'
     type: object
+  serviceAccountWithTokenView:

Review Comment:
   can we rename this to createServiceAccountResponse



##########
internal/server/route_policy_test.go:
##########
@@ -34,9 +34,9 @@ func TestNoRequireAuthOnIdScopedRoutes(t *testing.T) {
                t.Fatalf("read server.go: %v", err)
        }
        re := regexp.MustCompile(`RequireAuth(WithoutUserConsent)?\("[A-Z]+ 
([^"]*\{[^"]*)"`)
-       for _, line := range strings.Split(string(src), "\n") {
+       for line := range strings.SplitSeq(string(src), "\n") {
                m := re.FindStringSubmatch(line)
-               if m == nil || (m[1] == "WithoutUserConsent" && 
strings.HasPrefix(m[2], "/me/")) {
+               if m == nil || strings.HasPrefix(m[2], "/me/") {

Review Comment:
        s.router.RequireAuth("GET /projects", s.listProjects)
        s.router.RequireAuth("GET /compute-allocations", 
s.listComputeAllocations)
        s.router.RequireAuthWithoutUserConsent("GET /user/privileges", 
s.getCallerPrivileges)
   
   these routes are user-scoped. but they fail the /me/ check. either they 
should be prefixed with /me/, or we need a more reliable check.



##########
pkg/identity/identity.go:
##########
@@ -31,20 +31,36 @@ import (
 // Caller is the verified identity behind an HTTP request.
 // NeedsOnboarding is set on a first sign-in -- the email matched a PENDING 
user but no sub is stored yet.
 type Caller struct {
-       UserID          string
-       NeedsOnboarding bool
-       ConsentPending  bool
+       UserID            string
+       Email             string
+       NeedsOnboarding   bool
+       ConsentPending    bool
+       ServiceAccountID  string
+       ServiceAccountKey string

Review Comment:
   do we need to carry both ServiceAccountID and ServiceAccountKey here?
   isnt (ServiceAccountID == nil) == (UserID != nil)?



##########
connectors/Signer/internal/handlers.go:
##########
@@ -206,32 +203,40 @@ func (h *Handlers) fetchIfOwned(w http.ResponseWriter, r 
*http.Request) ([]byte,
                signerUnavailable(w)
                return nil, false
        }
-       var certificate struct {
-               UserSub string `json:"user_sub"`
-       }
+       var certificate certificateOwner
        if err := json.Unmarshal(body, &certificate); err != nil {
                signerUnavailable(w)
                return nil, false
        }
-       if certificate.UserSub != claims.Sub {
+       if !owned(certificate) {
                refuse(w, http.StatusNotFound, "not_found", "Certificate not 
found")
                return nil, false
        }
        return body, true
 }
 
-func (h *Handlers) getOwnCertificate(w http.ResponseWriter, r *http.Request) {
-       body, ok := h.fetchIfOwned(w, r)
-       if !ok {
-               return
+func (h *Handlers) fetchUsersCertificate(w http.ResponseWriter, r 
*http.Request) ([]byte, bool) {
+       claims := requireClaims(w, r)
+       if claims == nil {
+               return nil, false
        }
+       return h.fetchIfOwned(w, r, func(c certificateOwner) bool { return 
c.UserSub == claims.Sub })

Review Comment:
   since fetchIfOwned only called here, might be simpler to inline it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to