PermBAC 🛡️
Easy and flexible permission-based access control for Go applications.
PermBAC simplifies permission management in your Go projects, enabling detailed definition and efficient checking of permissions based on a structure that is configurable and adaptable to your needs.
Installation
To install the PermBAC binary, use the following command:
go install github.com/eduardolat/permbac/cmd/permbac@latest
You can also download precompiled binaries from the GitHub releases.
Getting Started
PermBAC operates through a clear and straightforward workflow, facilitating integration with your project:
-
Initialization: Generate a base configuration file with the command:
permbac --init
-
Permission Definition: Write your permissions in the permission file. For example, in permbac_perms.json
:
[
{
"name": "Example",
"desc": "PermBAC permission example"
},
{
"name": "...",
"desc": "..."
}
]
- name: Permission name. It must be unique and follow the regex
^[A-Z][a-zA-Z0-9-_]*$
.
- desc: Permission description. It is optional and used for documentation purposes.
You can see the detailed schema definition and validation rules here.
-
Permission Generation: Use permbac --generate
to create your permissions. You can specify a custom configuration file with:
permbac --generate --config ./permbac.json
You can also execute permbac --help
to see the available commands and options.
Usage of permbac:
-config string
Path to the configuration file (default "./permbac.json")
-generate
Runs the PermBAC code generator using the configuration file
-init
Initialize a new PermBAC configuration file
Configuration File
The configuration file allows customization of the permission generation process. An example permbac.json
could be:
{
"perms": ["./permbac_perms.json"],
"outdir": "./permbac",
"package": "permbac"
}
-
perms: Array of paths to the permission files to include in the generation process. You can use glob patterns (./perms/*.json
) to include multiple files.
-
outdir: Output directory for the generated files.
-
package: Package name for the generated files.
You can see the detailed schema definition and validation rules here.
Contributions
Contributions are welcome! Feel free to open an issue or pull request on our repository.
License
PermBAC is licensed under the MIT License, allowing its broad use in both commercial and private projects.