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
- type Authorizer
- type Namespaces
- type OwnerOnly
- type Owners
- type Right
- type RightsMessage
- type Service
- func (this *Service) Access(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, ...) (store.Access, error)
- func (this *Service) Check(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, ...) (bool, error)
- func (this *Service) CheckGranted(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, ...) (bool, error)
- func (this *Service) CheckHub(ctx context.Context, token jwt.Token, networkId string, right Right) (bool, error)
- func (this *Service) EnsureTopics(ctx context.Context, ns model.Namespace) error
- func (this *Service) Grant(ctx context.Context, namespace string, kind model.Kind, id string, ...) error
- func (this *Service) GrantedIds(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, ...) ([]string, error)
- func (this *Service) HandleRightsMessage(ctx context.Context, raw []byte) error
- func (this *Service) HasAdministrate(ctx context.Context, namespace string, kind model.Kind, id string, user string) (bool, error)
- func (this *Service) PublishTo(kafkaTopic string)
- func (this *Service) ReadableHubs(ctx context.Context, token jwt.Token) ([]string, error)
- func (this *Service) Register(ctx context.Context, namespace string, kind model.Kind, id string, ...) error
- func (this *Service) RemoveTopics(ctx context.Context, name string) error
- func (this *Service) RemoveUser(ctx context.Context, userId string, owners Owners) error
- func (this *Service) Rights(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, ...) (map[string]model.Rights, error)
- func (this *Service) Run(ctx context.Context, interval time.Duration)
- func (this *Service) SetNamespaces(namespaces Namespaces)
- func (this *Service) Sync(ctx context.Context) error
Constants ¶
const ( Read = permmodel.Read Write = permmodel.Write Execute = permmodel.Execute Administrate = permmodel.Administrate )
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 OwnerOnly ¶
type OwnerOnly struct{}
OwnerOnly grants access to owners and to the admin role; used without permissions-v2.
type Owners ¶
Owners resolves the owner of a resource of the engine; ok is false if it does not exist.
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) CheckGranted ¶ added in v0.16.0
func (this *Service) CheckGranted(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, id string, right Right) (bool, error)
CheckGranted checks a right in permissions-v2 also where the namespace does not share the kind, for resources of gateways (FOG-11); Check has asked permissions-v2 already where it does.
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 ¶
EnsureTopics writes the three topics of a namespace with their topic-wide default permissions.
func (*Service) Grant ¶ added in v0.16.0
func (this *Service) Grant(ctx context.Context, namespace string, kind model.Kind, id string, owner string, user string, rights model.Rights) error
Grant gives a user other than the owner rights on a resource of a gateway, so that whoever deploys or starts there keeps access to the result (FOG-11). The resource need not exist in the engine yet; the owner gets its administrate with it, as the sync would, because permissions-v2 takes no resource without an administrator.
func (*Service) GrantedIds ¶ added in v0.16.0
func (this *Service) GrantedIds(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, right Right) ([]string, error)
GrantedIds lists the resources of a kind the user holds a right on in permissions-v2 where the namespace does not share the kind, for resources of gateways (FOG-11); Access lists them where it does.
func (*Service) HandleRightsMessage ¶
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 (*Service) PublishTo ¶
PublishTo makes permissions-v2 publish rights changes of the engine topics to a Kafka topic.
func (*Service) ReadableHubs ¶
ReadableHubs lists the gateways the user may read.
func (*Service) Register ¶ added in v0.10.6
func (this *Service) Register(ctx context.Context, namespace string, kind model.Kind, id string, owner string) error
Register makes the owner of a resource administrate it now, as the sync would later, and marks the resource registered; an owner change calls it so that the new owner's rights exist when the call returns (SEC-11). On an error the sync remains, the resource stays pending.
func (*Service) RemoveTopics ¶
func (*Service) RemoveUser ¶
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) Rights ¶ added in v0.33.3
func (this *Service) Rights(ctx context.Context, token jwt.Token, namespace string, kind model.Kind, ids []string) (map[string]model.Rights, error)
Rights lists the rights the token holds through sharing on resources of a kind, as permissions-v2 computes them. Ownership and the admin role are not part of the answer; an id without an entry holds nothing.
func (*Service) SetNamespaces ¶
func (this *Service) SetNamespaces(namespaces Namespaces)