Permission using relationship owner

Hello, I have a relationship to documents called task, the task has task owner aka owned_by_id. How can I make task owner to search and edit the documents?