The way to create permissions in a custom module is by creating a *.permissions.yml file and adding the definitions in there. Consider the following example:
administer my feature: title: 'Administer my feature' restrict access: true
In this example, administer my feature is the machine name of the permission and actually the most important part. This is what you will use in your code to reference it. Then, we have a title that shows up on the permissions management page we saw earlier. Finally, we have a restrict access key by which we can specify whether we need a warning to be output on the permissions management page regarding the security implications, as follows: Warning: Give to trusted roles only; this permission has security implications:
This is to indicate that our permission is more sensitive and administrators should pay attention...