Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_apis_create_api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func (h *Handler) Path() string {
}

func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -49,7 +50,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
return err
}

err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: "*",
Expand Down
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_apis_delete_api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (h *Handler) Path() string {

// Handle processes the HTTP request
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -54,7 +55,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
if err != nil {
return err
}
err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: "*",
Expand Down
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_apis_get_api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func (h *Handler) Path() string {
// Handle processes the HTTP request
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
h.Logger.Debug("handling request", "requestId", s.RequestID(), "path", "/v2/apis.getApi")
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -48,7 +49,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
return err
}

err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: "*",
Expand Down
7 changes: 4 additions & 3 deletions go/apps/api/routes/v2_apis_list_keys/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (h *Handler) Path() string {
// The current implementation queries the database directly without caching, which may impact performance.
// Consider implementing cache with optional bypass via revalidateKeysCache parameter.
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -54,7 +55,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
if err != nil {
return err
}
err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.And(
rbac.Or(
rbac.T(rbac.Tuple{
Expand Down Expand Up @@ -147,7 +148,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
)
}

err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: "*",
Expand Down
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_identities_create_identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (h *Handler) Path() string {

// Handle processes the HTTP request
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -61,7 +62,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
return err
}

err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Identity,
ResourceID: "*",
Expand Down
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_identities_delete_identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func (h *Handler) Path() string {

// Handle processes the HTTP request
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -53,7 +54,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
return err
}

err = auth.Verify(ctx, keys.WithPermissions(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(
rbac.Or(
rbac.T(
rbac.Tuple{
Expand Down
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_identities_get_identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func (h *Handler) Path() string {

// Handle processes the HTTP request
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand Down Expand Up @@ -100,7 +101,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
ratelimits := result.Ratelimits

// Check permissions using either wildcard or the specific identity ID
err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Identity,
ResourceID: "*",
Expand Down
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_identities_list_identities/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func (h *Handler) Path() string {

// Handle processes the HTTP request
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand Down Expand Up @@ -93,7 +94,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
}),
)

err = auth.Verify(ctx, keys.WithPermissions(permissionCheck))
err = auth.VerifyRootKey(ctx, keys.WithPermissions(permissionCheck))
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_identities_update_identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func (h *Handler) Path() string {

// Handle processes the HTTP request
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -61,7 +62,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
return err
}

err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Identity,
ResourceID: "*",
Expand Down
18 changes: 12 additions & 6 deletions go/apps/api/routes/v2_keys_add_permissions/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (h *Handler) Path() string {

// Handle processes the HTTP request
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -55,6 +56,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
return err
}

// 4. Validate key exists and belongs to workspace
key, err := db.Query.FindKeyByIdOrHash(ctx,
h.DB.RO(),
db.FindKeyByIdOrHashParams{
Expand All @@ -66,23 +68,27 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
if db.IsNotFound(err) {
return fault.New("key not found",
fault.Code(codes.Data.Key.NotFound.URN()),
fault.Internal("key not found"), fault.Public("The specified key was not found."),
fault.Internal("key not found"),
fault.Public("The specified key was not found."),
)
}

return fault.Wrap(err,
fault.Code(codes.App.Internal.ServiceUnavailable.URN()),
fault.Internal("database error"), fault.Public("Failed to retrieve key."),
fault.Internal("database error"),
fault.Public("Failed to retrieve key."),
)
}

if key.WorkspaceID != auth.AuthorizedWorkspaceID {
return fault.New("key not found",
fault.Code(codes.Data.Key.NotFound.URN()),
fault.Internal("key belongs to different workspace"), fault.Public("The specified key was not found."),
fault.Internal("key belongs to different workspace"),
fault.Public("The specified key was not found."),
)
}

err = auth.Verify(ctx, keys.WithPermissions(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(
rbac.And(
rbac.Or(
rbac.T(rbac.Tuple{
Expand Down Expand Up @@ -156,7 +162,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
}

for perm := range missingPermissions {
err = auth.Verify(ctx, keys.WithPermissions(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(
rbac.T(rbac.Tuple{
ResourceType: rbac.Rbac,
ResourceID: "*",
Expand Down
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_keys_add_roles/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func (h *Handler) Path() string {
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
h.Logger.Debug("handling request", "requestId", s.RequestID(), "path", "/v2/keys.addRoles")

auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand Down Expand Up @@ -84,7 +85,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
)
}

err = auth.Verify(ctx, keys.WithPermissions(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(
rbac.And(
rbac.Or(
rbac.T(rbac.Tuple{
Expand Down
7 changes: 4 additions & 3 deletions go/apps/api/routes/v2_keys_create_key/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
h.Logger.Debug("handling request", "requestId", s.RequestID(), "path", "/v2/keys.createKey")

// 1. Authentication
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -65,7 +66,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
}

// 3. Permission check
err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: req.ApiId,
Expand Down Expand Up @@ -138,7 +139,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
)
}

err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: "*",
Expand Down
5 changes: 3 additions & 2 deletions go/apps/api/routes/v2_keys_delete_key/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
h.Logger.Debug("handling request", "requestId", s.RequestID(), "path", "/v2/keys.deleteKey")

// Authentication
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand Down Expand Up @@ -92,7 +93,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
}

// Permission check
err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: "*",
Expand Down
7 changes: 4 additions & 3 deletions go/apps/api/routes/v2_keys_get_key/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
h.Logger.Debug("handling request", "requestId", s.RequestID(), "path", "/v2/keys.getKey")

// Authentication
auth, err := h.Keys.GetRootKey(ctx, s)
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand Down Expand Up @@ -92,7 +93,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
}

// Permission check
err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: "*",
Expand Down Expand Up @@ -133,7 +134,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
}

// Permission check
err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: "*",
Expand Down
7 changes: 5 additions & 2 deletions go/apps/api/routes/v2_keys_remove_permissions/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func (h *Handler) Path() string {
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
h.Logger.Debug("handling request", "requestId", s.RequestID(), "path", "/v2/keys.removePermissions")

auth, err := h.Keys.GetRootKey(ctx, s)
// 1. Authentication
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand All @@ -56,6 +58,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
return err
}

// 4. Validate key exists and belongs to workspace
key, err := db.Query.FindKeyByIdOrHash(ctx,
h.DB.RO(),
db.FindKeyByIdOrHashParams{
Expand Down Expand Up @@ -85,7 +88,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
)
}

err = auth.Verify(ctx, keys.WithPermissions(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(
rbac.And(
rbac.Or(
rbac.T(rbac.Tuple{
Expand Down
6 changes: 4 additions & 2 deletions go/apps/api/routes/v2_keys_remove_roles/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func (h *Handler) Path() string {
func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
h.Logger.Debug("handling request", "requestId", s.RequestID(), "path", "/v2/keys.removeRoles")

auth, err := h.Keys.GetRootKey(ctx, s)
// 1. Authentication
auth, emit, err := h.Keys.GetRootKey(ctx, s)
defer emit()
if err != nil {
return err
}
Expand Down Expand Up @@ -83,7 +85,7 @@ func (h *Handler) Handle(ctx context.Context, s *zen.Session) error {
)
}

err = auth.Verify(ctx, keys.WithPermissions(rbac.Or(
err = auth.VerifyRootKey(ctx, keys.WithPermissions(rbac.Or(
rbac.T(rbac.Tuple{
ResourceType: rbac.Api,
ResourceID: "*",
Expand Down
Loading
Loading