permissions

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package permissions connects the engine to permissions-v2 (NS-05, SEC-01, SEC-07, SEC-10).

The owner of a resource is kept by the engine and always has every right, independent of permissions-v2. Rights of others count only on shareable levels. Resources are registered in permissions-v2 asynchronously: a new resource is marked unregistered in its transaction, and Sync writes it; deletions queue a removal in their transaction. permissions-v2 being unavailable therefore delays sharing but blocks nothing, and no HTTP call runs inside a database transaction.

Index

Constants

View Source
const (
	Read         = permmodel.Read
	Write        = permmodel.Write
	Execute      = permmodel.Execute
	Administrate = permmodel.Administrate
)
View Source
const HubsTopic = "hubs"

HasAdministrate reports whether user holds administrate on a resource in permissions-v2, directly or through a group or role (SEC-11). permissions-v2 evaluates the rights with a token of that user. HubsTopic is the permissions-v2 topic of gateways, written by device-repository (SEC-05).

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorizer

type Authorizer interface {
	Check(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, id string, owner string, right Right) (bool, error)
	// Access restricts list queries to what the token may see
	Access(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, right Right) (store.Access, error)
}

Authorizer decides access to resources of the engine.

type Namespaces

type Namespaces interface {
	Get(name string) (model.Namespace, bool)
	List() []model.Namespace
}

type OwnerOnly

type OwnerOnly struct{}

OwnerOnly grants access to owners and to the admin role; used without permissions-v2.

func (OwnerOnly) Access

func (OwnerOnly) Access(_ context.Context, token jwt.Token, _ string, _ model.Kind, _ Right) (store.Access, error)

func (OwnerOnly) Check

func (OwnerOnly) Check(_ context.Context, token jwt.Token, _ string, _ model.Kind, _ string, owner string, _ Right) (bool, error)

type Owners

type Owners func(kind model.Kind, id string) (owner string, ok bool, err error)

Owners resolves the owner of a resource of the engine; ok is false if it does not exist.

type Right = permmodel.Permission

Right follows permissions-v2.

type RightsMessage

type RightsMessage struct {
	Command string `json:"command"`
	Id      string `json:"id"`
	Rights  struct {
		UserRights map[string]permmodel.PermissionsMap `json:"user_rights"`
	} `json:"rights"`
}

RightsMessage is what permissions-v2 publishes on a rights change

type Service

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

func New

func New(client permclient.Client, adminToken auth.TokenSource, userToken auth.UserTokenSource, namespaces Namespaces, s *store.Store, logger *slog.Logger) *Service

func (*Service) Access

func (this *Service) Access(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, right Right) (store.Access, error)

func (*Service) Check

func (this *Service) Check(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, id string, owner string, right Right) (bool, error)

func (*Service) CheckHub

func (this *Service) CheckHub(ctx context.Context, token jwt.Token, networkId string, right Right) (bool, error)

CheckHub checks a right of the user on a gateway: rx to read and start, a to deploy and delete (SEC-05).

func (*Service) EnsureTopics

func (this *Service) EnsureTopics(ctx context.Context, ns model.Namespace) error

EnsureTopics writes the three topics of a namespace with their topic-wide default permissions.

func (*Service) HandleRightsMessage

func (this *Service) HandleRightsMessage(ctx context.Context, raw []byte) error

HandleRightsMessage restores the owner's administrate right when it was withdrawn directly in permissions-v2 (SEC-10): the resource is registered again, which adds the owner.

func (*Service) HasAdministrate

func (this *Service) HasAdministrate(ctx context.Context, namespace string, kind model.Kind, id string, user string) (bool, error)

func (*Service) PublishTo

func (this *Service) PublishTo(kafkaTopic string)

PublishTo makes permissions-v2 publish rights changes of the engine topics to a Kafka topic.

func (*Service) ReadableHubs

func (this *Service) ReadableHubs(ctx context.Context, token jwt.Token) ([]string, error)

ReadableHubs lists the gateways the user may read.

func (*Service) RemoveTopics

func (this *Service) RemoveTopics(ctx context.Context, name string) error

func (*Service) RemoveUser

func (this *Service) RemoveUser(ctx context.Context, userId string, owners Owners) error

RemoveUser removes the rights a user holds on resources of others in every topic of the engine (SEC-08). Resources the user owns are skipped, they are deleted with their removal. The user's resources are listed with an unsigned token of the user, which permissions-v2 accepts because it does not verify signatures; device-repository deletes users the same way.

func (*Service) Run

func (this *Service) Run(ctx context.Context, interval time.Duration)

Run calls Sync until ctx is done.

func (*Service) SetNamespaces

func (this *Service) SetNamespaces(namespaces Namespaces)

func (*Service) Sync

func (this *Service) Sync(ctx context.Context) error

Sync registers pending resources and processes queued removals, a batch per call.

Jump to

Keyboard shortcuts

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