Skip to content
Merged
Changes from 2 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
48 changes: 28 additions & 20 deletions entfga/templates/authzChecks.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,18 @@ func newOrganizationContextKey(e string) *map[string]any {
return privacy.Skipf("not a graphql request, no context to check")
}

objectID, ok := gCtx.Args["id"].(string)
if !ok {
var ids []string

if id, ok := gCtx.Args["id"].(string); ok {
ids = append(ids, id)
} else if bulkIDs, ok := gCtx.Args["ids"].([]string); ok {
ids = bulkIDs
}

if len(ids) == 0 {
log.Info().Msg("no id found in args, skipping auth check, will be filtered in hooks")

return privacy.Allowf("nil request, bypassing auth check")
return privacy.Skipf("nil request, bypassing auth check")
}

caller, ok := auth.CallerFromContext(ctx)
Expand All @@ -257,27 +264,28 @@ func newOrganizationContextKey(e string) *map[string]any {
return privacy.Skipf("unable to get caller from context")
}

ac := fgax.AccessCheck{
Relation: fgax.CanDelete,
ObjectType: "{{ $objectType | ToLower }}",
ObjectID: objectID,
SubjectType: caller.SubjectType(),
SubjectID: caller.SubjectID,
Context: newOrganizationContextKey(caller.SubjectEmail),
}
for _, objectID := range ids {
ac := fgax.AccessCheck{
Relation: fgax.CanDelete,
ObjectType: "{{ $objectType | ToLower }}",
ObjectID: objectID,
SubjectType: caller.SubjectType(),
SubjectID: caller.SubjectID,
Context: newOrganizationContextKey(caller.SubjectEmail),
}

log.Debug().Interface("access_check", ac).Msg("checking relationship tuples")
log.Debug().Interface("access_check", ac).Msg("checking relationship tuples")

access, err := m.Authz.CheckAccess(ctx, ac)
if err == nil && access {
return privacy.Allow
}
access, err := m.Authz.CheckAccess(ctx, ac)
if err != nil || !access {
log.Error().Interface("access_check", ac).Bool("access_result", access).Msg("access denied")

log.Error().Interface("access_check", ac).Bool("access_result", access).Msg("access denied")
return ErrPermissionDenied
}
}

// return error if the action is not allowed
return ErrPermissionDenied
return privacy.Allow
}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Loading