auth

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyAuthenticatedUser = "enclave/authenticatedUser"
	UnauthenticatedUser         = "__unauthenticated__"
)

Variables

This section is empty.

Functions

func AddPolicy

func AddPolicy(userGroup, resourceGroup, method string) error

AddPolicy adds a policy to the enforcer if it does not already exist.

It checks if the user group and resource group exist before adding the policy and throws if they do not.

func AddResourceToGroup

func AddResourceToGroup(resourceName string, groupName ...string) error

AddResourceToGroup adds a resource to one or more groups. It validates that all specified groups exist before adding the resource.

func AddUserToGroup

func AddUserToGroup(userName string, groupName ...string) error

AddUserToGroup adds a user to one or more groups. It validates that all specified groups exist before adding the user.

func CreateResourceGroup

func CreateResourceGroup(groupName string) error

CreateResourceGroup creates a new resource group with the specified name. If the group already exists, the function returns without error.

func CreateUserGroup

func CreateUserGroup(groupName string) error

CreateUserGroup creates a new user group with the specified name. If the group already exists, the function returns without error.

func GetGroupsForResource

func GetGroupsForResource(resourceName string) ([]string, error)

GetGroupsForResource returns all groups that a specific resource belongs to.

func GetGroupsForUser

func GetGroupsForUser(userName string) ([]string, error)

GetGroupsForUser returns all groups that a specific user belongs to.

func GetResourceGroup

func GetResourceGroup(groupName string) ([]string, error)

GetResourceGroup returns all resources that belong to a specific group.

func GetUserGroup

func GetUserGroup(groupName string) ([]string, error)

GetUserGroup returns all users that belong to a specific group.

func InitAuth

func InitAuth(adapter persist.Adapter) *casbin.Enforcer

InitAuth initializes the casbin enforcer with the provided adapter and sets up default policies. It creates the casbin model, loads policies, and ensures the enclaveAdmin group and policy exist.

func InsertAuthenticatedUser added in v0.4.1

func InsertAuthenticatedUser(c *gin.Context, user string)

func RemovePolicy

func RemovePolicy(userGroup, resourceGroup, method string) error

RemovePolicy removes a policy from the enforcer.

It prevents the removal of the enclaveAdmin policy to ensure that enclaveAdmins always have full access.

func RemoveResource

func RemoveResource(resourceName string) error

RemoveResource removes a resource from all groups it belongs to.

func RemoveResourceFromGroup

func RemoveResourceFromGroup(resourceName string, groupName ...string) error

RemoveResourceFromGroup removes a resource from one or more groups. It validates that all specified groups exist before removing the resource.

func RemoveResourceGroup

func RemoveResourceGroup(groupName string) error

RemoveResourceGroup removes a resource group and all associated policies. It prevents removal of the enclaveAdmin group to maintain system security.

func RemoveUser

func RemoveUser(userName string) error

RemoveUser removes a user from all groups they belong to.

func RemoveUserFromGroup

func RemoveUserFromGroup(userName string, groupName ...string) error

RemoveUserFromGroup removes a user from one or more groups. It validates that all specified groups exist before removing the user.

func RemoveUserGroup

func RemoveUserGroup(groupName string) error

RemoveUserGroup removes a user group and all associated policies. It prevents removal of the enclaveAdmin group to maintain system security.

func ResourceGroupExists

func ResourceGroupExists(groupName string) (bool, error)

ResourceGroupExists checks if a resource group with the specified name exists.

func RetrieveAuthenticatedUser added in v0.4.1

func RetrieveAuthenticatedUser(ctx context.Context) string

func UserGroupExists

func UserGroupExists(groupName string) (bool, error)

UserGroupExists checks if a user group with the specified name exists.

Types

type CasbinError added in v0.4.1

type CasbinError struct {
	Action string
	Err    error
}

func (*CasbinError) Error added in v0.4.1

func (e *CasbinError) Error() string

func (*CasbinError) Unwrap added in v0.4.1

func (e *CasbinError) Unwrap() error

type ConflictError added in v0.4.1

type ConflictError struct {
	Reason string
}

func (*ConflictError) Error added in v0.4.1

func (e *ConflictError) Error() string

type GroupType

type GroupType string

GroupType represents the policy type for different group kinds

const (
	UserGroupType     GroupType = "g"
	ResourceGroupType GroupType = "g2"
)

type NotFoundError added in v0.4.1

type NotFoundError struct {
	ResourceType string
	Name         string
}

func (*NotFoundError) Error added in v0.4.1

func (e *NotFoundError) Error() string

type Policy added in v0.4.1

type Policy struct {
	UserGroup     string
	ResourceGroup string
	Permission    string
}

func ListPolicies added in v0.4.1

func ListPolicies() ([]Policy, error)

type ResourceGroup

type ResourceGroup struct {
	ResourceName string
	GroupName    string
}

func GetResourceGroups

func GetResourceGroups() ([]ResourceGroup, error)

GetResourceGroups returns all resource groups as a slice of ResourceGroup structs.

func (ResourceGroup) GetGroupName

func (rg ResourceGroup) GetGroupName() string

func (ResourceGroup) GetName

func (rg ResourceGroup) GetName() string

Implement group interface for ResourceGroup

type UserGroup

type UserGroup struct {
	UserName  string
	GroupName string
}

func GetUserGroups

func GetUserGroups() ([]UserGroup, error)

GetUserGroups returns all user groups as a slice of UserGroup structs.

func (UserGroup) GetGroupName

func (ug UserGroup) GetGroupName() string

func (UserGroup) GetName

func (ug UserGroup) GetName() string

Implement group interface for UserGroup

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL