auth

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnauthenticatedUser = "__unauthenticated__"
)

Variables

This section is empty.

Functions

func GetAuthenticatedUser added in v0.9.0

func GetAuthenticatedUser(ctx context.Context) string

func SetAuthenticatedUser added in v0.9.0

func SetAuthenticatedUser(ctx context.Context, user string) context.Context

Types

type AuthModule added in v0.9.0

type AuthModule struct {
	// contains filtered or unexported fields
}

func NewModule added in v0.9.0

func NewModule(adapter persist.Adapter) AuthModule

NewModule 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 (*AuthModule) AddPolicy added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) AddResourceToGroup added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) AddUserToGroup added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) CreateResourceGroup added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) CreateUserGroup added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) GetGroupsForResource added in v0.9.0

func (auth *AuthModule) GetGroupsForResource(
	resourceName string,
) ([]string, error)

GetGroupsForResource returns all groups that a specific resource belongs to.

func (*AuthModule) GetGroupsForUser added in v0.9.0

func (auth *AuthModule) GetGroupsForUser(userName string) ([]string, error)

GetGroupsForUser returns all groups that a specific user belongs to.

func (*AuthModule) GetResourceGroup added in v0.9.0

func (auth *AuthModule) GetResourceGroup(groupName string) ([]string, error)

GetResourceGroup returns all resources that belong to a specific group.

func (*AuthModule) GetResourceGroups added in v0.9.0

func (auth *AuthModule) GetResourceGroups() ([]ResourceGroup, error)

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

func (*AuthModule) GetUserGroup added in v0.9.0

func (auth *AuthModule) GetUserGroup(groupName string) ([]string, error)

GetUserGroup returns all users that belong to a specific group.

func (*AuthModule) GetUserGroups added in v0.9.0

func (auth *AuthModule) GetUserGroups() ([]UserGroup, error)

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

func (*AuthModule) ListPolicies added in v0.9.0

func (auth *AuthModule) ListPolicies() ([]Policy, error)

func (*AuthModule) Middleware added in v0.9.0

func (auth *AuthModule) Middleware() gin.HandlerFunc

func (*AuthModule) RemovePolicy added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) RemoveResource added in v0.9.0

func (auth *AuthModule) RemoveResource(resourceName string) error

RemoveResource removes a resource from all groups it belongs to.

func (*AuthModule) RemoveResourceFromGroup added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) RemoveResourceGroup added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) RemoveUser added in v0.9.0

func (auth *AuthModule) RemoveUser(userName string) error

RemoveUser removes a user from all groups they belong to.

func (*AuthModule) RemoveUserFromGroup added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) RemoveUserGroup added in v0.9.0

func (auth *AuthModule) 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 (*AuthModule) ResourceGroupExists added in v0.9.0

func (auth *AuthModule) ResourceGroupExists(groupName string) (bool, error)

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

func (*AuthModule) UserGroupExists added in v0.9.0

func (auth *AuthModule) UserGroupExists(groupName string) (bool, error)

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

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
}

type ResourceGroup

type ResourceGroup struct {
	ResourceName string
	GroupName    string
}

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 (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