Documentation
¶
Index ¶
- Constants
- Variables
- func IsOrgRole(roleName string) (string, bool)
- func RoleAdmin() string
- func RoleMember() string
- func RoleOrgAdmin(organizationID uuid.UUID) string
- func RoleOrgMember(organizationID uuid.UUID) string
- type Action
- type Object
- type Permission
- type RegoAuthorizer
- type Role
- type UnauthorizedError
Constants ¶
const ( ActionCreate = "create" ActionRead = "read" ActionUpdate = "update" ActionDelete = "delete" )
const WildcardSymbol = "*"
Variables ¶
var ( ResourceWorkspace = Object{ Type: "workspace", } ResourceTemplate = Object{ Type: "template", } // ResourceWildcard represents all resource types ResourceWildcard = Object{ Type: WildcardSymbol, } )
Resources are just typed objects. Making resources this way allows directly passing them into an Authorize function and use the chaining api.
Functions ¶
func RoleMember ¶
func RoleMember() string
func RoleOrgAdmin ¶
func RoleOrgMember ¶
Types ¶
type Object ¶
type Object struct { ResourceID string `json:"id"` Owner string `json:"owner"` // OrgID specifies which org the object is a part of. OrgID string `json:"org_owner"` // Type is "workspace", "project", "devurl", etc Type string `json:"type"` }
Object is used to create objects for authz checks when you have none in hand to run the check on. An example is if you want to list all workspaces, you can create a Object that represents the set of workspaces you are trying to get access too. Do not export this type, as it can be created from a resource type constant.
type Permission ¶
type Permission struct { // Negate makes this a negative permission Negate bool `json:"negate"` ResourceType string `json:"resource_type"` ResourceID string `json:"resource_id"` Action Action `json:"action"` }
Permission is the format passed into the rego.
type RegoAuthorizer ¶
type RegoAuthorizer struct {
// contains filtered or unexported fields
}
RegoAuthorizer will use a prepared rego query for performing authorize()
func NewAuthorizer ¶
func NewAuthorizer() (*RegoAuthorizer, error)
func (RegoAuthorizer) Authorize ¶
func (a RegoAuthorizer) Authorize(ctx context.Context, subjectID string, roles []Role, action Action, object Object) error
Authorize allows passing in custom Roles. This is really helpful for unit testing, as we can create custom roles to exercise edge cases.
func (RegoAuthorizer) AuthorizeByRoleName ¶ added in v0.5.2
func (a RegoAuthorizer) AuthorizeByRoleName(ctx context.Context, subjectID string, roleNames []string, action Action, object Object) error
AuthorizeByRoleName will expand all roleNames into roles before calling Authorize(). This is the function intended to be used outside this package. The role is fetched from the builtin map located in memory.
type Role ¶
type Role struct { Name string `json:"name"` Site []Permission `json:"site"` // Org is a map of orgid to permissions. We represent orgid as a string. // We scope the organizations in the role so we can easily combine all the // roles. Org map[string][]Permission `json:"org"` User []Permission `json:"user"` }
Role is a set of permissions at multiple levels: - Site level permissions apply EVERYWHERE - Org level permissions apply to EVERYTHING in a given ORG - User level permissions are the lowest This is the type passed into the rego as a json payload. Users of this package should instead **only** use the role names, and this package will expand the role names into their json payloads.
func RoleByName ¶ added in v0.5.2
RoleByName returns the permissions associated with a given role name. This allows just the role names to be stored and expanded when required.
type UnauthorizedError ¶
type UnauthorizedError struct {
// contains filtered or unexported fields
}
UnauthorizedError is the error type for authorization errors
func ForbiddenWithInternal ¶
func ForbiddenWithInternal(internal error, input map[string]interface{}, output rego.ResultSet) *UnauthorizedError
ForbiddenWithInternal creates a new error that will return a simple "forbidden" to the client, logging internally the more detailed message provided.
func (UnauthorizedError) Error ¶
func (UnauthorizedError) Error() string
Error implements the error interface.
func (*UnauthorizedError) Input ¶
func (e *UnauthorizedError) Input() map[string]interface{}
func (*UnauthorizedError) Internal ¶
func (e *UnauthorizedError) Internal() error
Internal allows the internal error message to be logged.
func (*UnauthorizedError) Output ¶
func (e *UnauthorizedError) Output() rego.ResultSet
Output contains the results of the Rego query for debugging.