access

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: BSD-3-Clause Imports: 13 Imported by: 189

Documentation

Overview

This file was auto-generated by the vanadium vdl tool. Package: access Package access defines types and interfaces for dynamic access control. Examples: "allow app to read this photo", "prevent user from modifying this file".

Target Developers

Developers creating functionality to share data or services between multiple users/devices/apps.

Overview

Vanadium objects provide GetPermissions and SetPermissions methods. An AccessList contains the set of blessings that grant principals access to the object. All methods on objects can have "tags" on them and the AccessList used for the method is selected based on that tag (from a Permissions).

An object can have multiple names, so GetPermissions and SetPermissions can be invoked on any of these names, but the object itself has a single AccessList.

SetPermissions completely replaces the Permissions. To perform an atomic read-modify-write of the AccessList, use the version parameter.

Conventions

Service implementors should follow the conventions below to be consistent with other parts of Vanadium and with each other.

All methods that create an object (e.g. Put, Mount, Link) should take an optional AccessList parameter. If the AccessList is not specified, the new object, O, copies its AccessList from the parent. Subsequent changes to the parent AccessList are not automatically propagated to O. Instead, a client library must make recursive AccessList changes.

Resolve access is required on all components of a name, except the last one, in order to access the object referenced by that name. For example, for principal P to access the name "a/b/c", P must have resolve access to "a" and "a/b".

The Resolve tag means that a principal can traverse that component of the name to access the child. It does not give the principal permission to list the children via Glob or a similar method. For example, a server might have an object named "home" with a child for each user of the system. If these users were allowed to list the contents of "home", they could discover the other users of the system. That could be a privacy violation. Without Resolve, every user of the system would need read access to "home" to access "home/<user>". If the user called Glob("home/*"), it would then be up to the server to filter out the names that the user could not access. That could be a very expensive operation if there were a lot of children of "home". Resolve protects these servers against potential denial of service attacks on these large, shared directories.

Blessings allow for sweeping access changes. In particular, a blessing is useful for controlling access to objects that are always accessed together. For example, a document may have embedded images and comments, each with a unique name. When accessing a document, the server would generate a blessing that the client would use to fetch the images and comments; the images and comments would have this blessed identity in their AccessLists. Changes to the document's AccessLists are therefore "propagated" to the images and comments.

In the future, we may add some sort of "groups" mechanism to provide an alternative way to express access control policies.

Some services will want a concept of implicit access control. They are free to implement this as appropriate for their service. However, GetPermissions should respond with the correct Permissions. For example, a corporate file server would allow all employees to create their own directory and have full control within that directory. Employees should not be allowed to modify other employee directories. In other words, within the directory "home", employee E should be allowed to modify only "home/E". The file server doesn't know the list of all employees a priori, so it uses an implementation-specific rule to map employee identities to their home directory.

Examples

client := access.ObjectClient(name)
for {
  perms, version, err := client.GetPermissions()
  if err != nil {
    return err
  }
  perms[newTag] = AccessList{In: []security.BlessingPattern{newPattern}}
  // Use the same version with the modified perms to ensure that no other
  // client has modified the perms since GetPermissions returned.
  if err := client.SetPermissions(perms, version); err != nil {
    if errors.Is(err, verror.ErrBadVersion) {
      // Another client replaced the Permissions after our GetPermissions
      // returned. Try again.
      continue
    }
    return err
  }
}

Index

Constants

View Source
const Admin = Tag("Admin") // Operations that require privileged access for object administration.
View Source
const Debug = Tag("Debug") // Operations that return debugging information (e.g., logs, statistics etc.) about the object.
View Source
const Read = Tag("Read") // Operations that do not mutate the state of the object.
View Source
const Resolve = Tag("Resolve") // Operations involving namespace navigation.
View Source
const Write = Tag("Write") // Operations that mutate the state of the object.

Variables

View Source
var (

	// The AccessList is too big.  Use groups to represent large sets of principals.
	ErrTooBig                    = verror.NewIDAction("v.io/v23/security/access.TooBig", verror.NoRetry)
	ErrNoPermissions             = verror.NewIDAction("v.io/v23/security/access.NoPermissions", verror.NoRetry)
	ErrAccessListMatch           = verror.NewIDAction("v.io/v23/security/access.AccessListMatch", verror.NoRetry)
	ErrUnenforceablePatterns     = verror.NewIDAction("v.io/v23/security/access.UnenforceablePatterns", verror.NoRetry)
	ErrInvalidOpenAccessList     = verror.NewIDAction("v.io/v23/security/access.InvalidOpenAccessList", verror.NoRetry)
	ErrAccessTagCaveatValidation = verror.NewIDAction("v.io/v23/security/access.AccessTagCaveatValidation", verror.NoRetry)
	ErrMultipleTags              = verror.NewIDAction("v.io/v23/security/access.MultipleTags", verror.NoRetry)
	ErrNoTags                    = verror.NewIDAction("v.io/v23/security/access.NoTags", verror.NoRetry)
)
View Source
var AccessTagCaveat = security.CaveatDescriptor{
	Id: uniqueid.Id{
		239,
		205,
		227,
		117,
		20,
		22,
		199,
		59,
		24,
		156,
		232,
		156,
		204,
		147,
		128,
		0,
	},
	ParamType: vdl.TypeOf((*[]Tag)(nil)),
}

AccessTagCaveat represents a caveat that validates iff the method being invoked has at least one of the tags listed in the caveat.

Functions

func AuthorizerFromSpec

func AuthorizerFromSpec(ps PermissionsSpec, name string, tagType *vdl.Type) (security.Authorizer, error)

AuthorizerFromSpec creates an authorizer as specified by the supplied specification. If no permissions are specified then the default, (ie. nil) Authorizer is returned.

func ErrorfAccessListMatch added in v0.1.10

func ErrorfAccessListMatch(ctx *context.T, format string, validBlessings []string, rejectedBlessings []security.RejectedBlessing) error

ErrorfAccessListMatch calls ErrAccessListMatch.Errorf with the supplied arguments.

func ErrorfAccessTagCaveatValidation added in v0.1.10

func ErrorfAccessTagCaveatValidation(ctx *context.T, format string, methodTags []string, caveatTags []Tag) error

ErrorfAccessTagCaveatValidation calls ErrAccessTagCaveatValidation.Errorf with the supplied arguments.

func ErrorfInvalidOpenAccessList added in v0.1.10

func ErrorfInvalidOpenAccessList(ctx *context.T, format string) error

ErrorfInvalidOpenAccessList calls ErrInvalidOpenAccessList.Errorf with the supplied arguments.

func ErrorfMultipleTags added in v0.1.10

func ErrorfMultipleTags(ctx *context.T, format string, suffix string, method string, tag string) error

ErrorfMultipleTags calls ErrMultipleTags.Errorf with the supplied arguments.

func ErrorfNoPermissions added in v0.1.10

func ErrorfNoPermissions(ctx *context.T, format string, validBlessings []string, rejectedBlessings []security.RejectedBlessing, tag string) error

ErrorfNoPermissions calls ErrNoPermissions.Errorf with the supplied arguments.

func ErrorfNoTags added in v0.1.10

func ErrorfNoTags(ctx *context.T, format string, suffix string, method string, tag string) error

ErrorfNoTags calls ErrNoTags.Errorf with the supplied arguments.

func ErrorfTooBig added in v0.1.10

func ErrorfTooBig(ctx *context.T, format string) error

ErrorfTooBig calls ErrTooBig.Errorf with the supplied arguments.

func ErrorfUnenforceablePatterns added in v0.1.10

func ErrorfUnenforceablePatterns(ctx *context.T, format string, rejectedPatterns []security.BlessingPattern) error

ErrorfUnenforceablePatterns calls ErrUnenforceablePatterns.Errorf with the supplied arguments.

func IsUnenforceablePatterns

func IsUnenforceablePatterns(err error) []security.BlessingPattern

UnenforceablePatterns checks if the error has the identifier ErrUnenforceablePatterns.ID, and if so returns the set of unenforceable patterns encapsulated in it. It returns nil otherwise.

func MessageAccessListMatch added in v0.1.10

func MessageAccessListMatch(ctx *context.T, message string, validBlessings []string, rejectedBlessings []security.RejectedBlessing) error

MessageAccessListMatch calls ErrAccessListMatch.Message with the supplied arguments.

func MessageAccessTagCaveatValidation added in v0.1.10

func MessageAccessTagCaveatValidation(ctx *context.T, message string, methodTags []string, caveatTags []Tag) error

MessageAccessTagCaveatValidation calls ErrAccessTagCaveatValidation.Message with the supplied arguments.

func MessageInvalidOpenAccessList added in v0.1.10

func MessageInvalidOpenAccessList(ctx *context.T, message string) error

MessageInvalidOpenAccessList calls ErrInvalidOpenAccessList.Message with the supplied arguments.

func MessageMultipleTags added in v0.1.10

func MessageMultipleTags(ctx *context.T, message string, suffix string, method string, tag string) error

MessageMultipleTags calls ErrMultipleTags.Message with the supplied arguments.

func MessageNoPermissions added in v0.1.10

func MessageNoPermissions(ctx *context.T, message string, validBlessings []string, rejectedBlessings []security.RejectedBlessing, tag string) error

MessageNoPermissions calls ErrNoPermissions.Message with the supplied arguments.

func MessageNoTags added in v0.1.10

func MessageNoTags(ctx *context.T, message string, suffix string, method string, tag string) error

MessageNoTags calls ErrNoTags.Message with the supplied arguments.

func MessageTooBig added in v0.1.10

func MessageTooBig(ctx *context.T, message string) error

MessageTooBig calls ErrTooBig.Message with the supplied arguments.

func MessageUnenforceablePatterns added in v0.1.10

func MessageUnenforceablePatterns(ctx *context.T, message string, rejectedPatterns []security.BlessingPattern) error

MessageUnenforceablePatterns calls ErrUnenforceablePatterns.Message with the supplied arguments.

func NewAccessTagCaveat

func NewAccessTagCaveat(tags ...Tag) (security.Caveat, error)

NewAccessTagCaveat returns a Caveat that will validate iff the intersection of the tags on the method being invoked and those in 'tags' is non-empty.

func ParamsErrAccessListMatch added in v0.1.10

func ParamsErrAccessListMatch(argumentError error) (verrorComponent string, verrorOperation string, validBlessings []string, rejectedBlessings []security.RejectedBlessing, returnErr error)

ParamsErrAccessListMatch extracts the expected parameters from the error's ParameterList.

func ParamsErrInvalidOpenAccessList added in v0.1.10

func ParamsErrInvalidOpenAccessList(argumentError error) (verrorComponent string, verrorOperation string, returnErr error)

ParamsErrInvalidOpenAccessList extracts the expected parameters from the error's ParameterList.

func ParamsErrMultipleTags added in v0.1.10

func ParamsErrMultipleTags(argumentError error) (verrorComponent string, verrorOperation string, suffix string, method string, tag string, returnErr error)

ParamsErrMultipleTags extracts the expected parameters from the error's ParameterList.

func ParamsErrNoPermissions added in v0.1.10

func ParamsErrNoPermissions(argumentError error) (verrorComponent string, verrorOperation string, validBlessings []string, rejectedBlessings []security.RejectedBlessing, tag string, returnErr error)

ParamsErrNoPermissions extracts the expected parameters from the error's ParameterList.

func ParamsErrNoTags added in v0.1.10

func ParamsErrNoTags(argumentError error) (verrorComponent string, verrorOperation string, suffix string, method string, tag string, returnErr error)

ParamsErrNoTags extracts the expected parameters from the error's ParameterList.

func ParamsErrTooBig added in v0.1.10

func ParamsErrTooBig(argumentError error) (verrorComponent string, verrorOperation string, returnErr error)

ParamsErrTooBig extracts the expected parameters from the error's ParameterList.

func ParamsErrUnenforceablePatterns added in v0.1.10

func ParamsErrUnenforceablePatterns(argumentError error) (verrorComponent string, verrorOperation string, rejectedPatterns []security.BlessingPattern, returnErr error)

ParamsErrUnenforceablePatterns extracts the expected parameters from the error's ParameterList.

func PermissionsAuthorizer

func PermissionsAuthorizer(perms Permissions, tagType *vdl.Type) (security.Authorizer, error)

PermissionsAuthorizer implements an authorization policy where access is granted if the remote end presents blessings included in the Access Control Lists (AccessLists) associated with the set of relevant tags.

The set of relevant tags is the subset of tags associated with the method (security.Call.MethodTags) that have the same type as tagType. Currently, tagType.Kind must be reflect.String, i.e., only tags that are named string types are supported.

PermissionsAuthorizer expects exactly one tag of tagType to be associated with the method. If there are multiple, it fails authorization and returns an error. However, if multiple tags become a common occurrence, then this behavior may change.

If the Permissions provided is nil, then a nil authorizer is returned.

Sample usage:

(1) Attach tags to methods in the VDL (eg. myservice.vdl)

package myservice

type MyTag string
const (
  ReadAccess  = MyTag("R")
  WriteAccess = MyTag("W")
)

type MyService interface {
  Get() ([]string, error)       {ReadAccess}
  GetIndex(int) (string, error) {ReadAccess}

  Set([]string) error           {WriteAccess}
  SetIndex(int, string) error   {WriteAccess}
}

(2) Configure the rpc.Dispatcher to use the PermissionsAuthorizer

import (
  "reflect"

  "v.io/v23/rpc"
  "v.io/v23/security"
  "v.io/v23/security/access"
)

type dispatcher struct{}
func (d dispatcher) Lookup(suffix, method) (rpc.Invoker, security.Authorizer, error) {
   perms := access.Permissions{
     "R": access.AccessList{In: []security.BlessingPattern{"alice:friends", "alice:family"} },
     "W": access.AccessList{In: []security.BlessingPattern{"alice:family", "alice:colleagues" } },
   }
   typ := reflect.TypeOf(ReadAccess)  // equivalently, reflect.TypeOf(WriteAccess)
   return newInvoker(), access.PermissionsAuthorizer(perms, typ), nil
}

With the above dispatcher, the server will grant access to a peer with the blessing "alice:friend:bob" access only to the "Get" and "GetIndex" methods. A peer presenting the blessing "alice:colleague:carol" will get access only to the "Set" and "SetIndex" methods. A peer presenting "alice:family:mom" will get access to all methods.

func PermissionsAuthorizerFromFile

func PermissionsAuthorizerFromFile(filename string, tagType *vdl.Type) (security.Authorizer, error)

PermissionsAuthorizerFromFile applies the same authorization policy as PermissionsAuthorizer, with the Permissions to be used sourced from a file named filename.

Changes to the file are monitored and affect subsequent calls to Authorize. Currently, this is achieved by re-reading the file on every call to Authorize. TODO(ashankar,ataly): Use inotify or a similar mechanism to watch for changes.

func TagStrings

func TagStrings(tags ...Tag) []string

TagStrings converts access.Tag values into []string for use with methods on access.Permissions.

func TypicalTagType

func TypicalTagType() *vdl.Type

TypicalTagType returns the type of the predefined tags in this access package.

Typical use of this is to setup an Authorizer that uses these predefined tags:

authorizer, err := PermissionsAuthorizerFromFile(name, TypicalTagType())

For the common case of setting up an Authorizer for a Permissions object with these predefined tags, a convenience function is provided:

authorizer := TypicalTagTypePermissionsAuthorizer(myperms)

func TypicalTagTypePermissionsAuthorizer

func TypicalTagTypePermissionsAuthorizer(perms Permissions) security.Authorizer

TypicalTagTypePermissionsAuthorizer is like PermissionsAuthorizer, but assumes TypicalTagType and thus avoids returning an error.

func WritePermissions

func WritePermissions(w io.Writer, m Permissions) error

WritePermissions writes the JSON-encoded representation of a Permissions to w.

Types

type AccessList

type AccessList struct {
	// In denotes the set of blessings (represented as BlessingPatterns) that
	// should be granted access, unless blacklisted by an entry in NotIn.
	//
	// For example:
	//   In: {"alice:family"}
	// grants access to a principal that presents at least one of
	// "alice:family", "alice:family:friend", "alice:family:friend:spouse" etc.
	// as a blessing.
	In []security.BlessingPattern
	// NotIn denotes the set of blessings (and their delegates) that
	// have been explicitly blacklisted from the In set.
	//
	// For example:
	//   In: {"alice:friend"}, NotIn: {"alice:friend:bob"}
	// grants access to principals that present "alice:friend",
	// "alice:friend:carol" etc. but NOT to a principal that presents
	// "alice:friend:bob" or "alice:friend:bob:spouse" etc.
	NotIn []string
}

Type definitions ================ AccessList represents a set of blessings that should be granted access.

See also: https://vanadium.github.io/glossary.html#access-list

func (AccessList) Authorize

func (acl AccessList) Authorize(ctx *context.T, call security.Call) error

Authorize implements security.Authorizer where the request is authorized only if the remote blessings are included in the AccessList.

func (AccessList) Enforceable

func (acl AccessList) Enforceable(ctx *context.T, p security.Principal) error

Enforceable checks if the AccessList is enforceable by the provided principal.

It returns nil if all blessing patterns in the 'In' list are valid and matched by a blessing name that is recognized by one of the provided principal's roots.

An error with identifier ErrOpenAccessList.ID is returned if the 'In' list contains the pattern "..." along with other patterns in the 'In' or 'NotIn' lists. Otherwise an error with identifier ErrUnenforceablePatterns.ID is returned.

func (AccessList) Includes

func (acl AccessList) Includes(blessings ...string) bool

Includes returns true iff the AccessList grants access to a principal that presents blessings (i.e., if at least one of the blessings matches the AccessList).

func (AccessList) VDLIsZero

func (x AccessList) VDLIsZero() bool

func (*AccessList) VDLRead

func (x *AccessList) VDLRead(dec vdl.Decoder) error

func (AccessList) VDLReflect

func (AccessList) VDLReflect(struct {
	Name string `vdl:"v.io/v23/security/access.AccessList"`
})

func (AccessList) VDLWrite

func (x AccessList) VDLWrite(enc vdl.Encoder) error

type Permissions

type Permissions map[string]AccessList

Permissions maps string tags to access lists specifying the blessings required to invoke methods with that tag.

These tags are meant to add a layer of interposition between the set of users (blessings, specifically) and the set of methods, much like "Roles" do in Role Based Access Control. (http://en.wikipedia.org/wiki/Role-based_access_control)

func ReadPermissions

func ReadPermissions(r io.Reader) (m Permissions, err error)

ReadPermissions reads the JSON-encoded representation of a Permissions from r.

func (Permissions) Add

func (m Permissions) Add(pattern security.BlessingPattern, tags ...string) Permissions

Add updates m to so that blessings matching pattern will be included in the access lists for the provided tags (by adding to the "In" lists). It returns m.

func (Permissions) Blacklist

func (m Permissions) Blacklist(blessing string, tags ...string) Permissions

Blacklist updates m so that the provided blessing will be excluded from the access lists for the provided tags (by adding to the "NotIn" lists). It returns m.

func (Permissions) Clear

func (m Permissions) Clear(blessingOrPattern string, tags ...string) Permissions

Clear removes all references to blessingOrPattern from all the provided tags in the AccessList, or all tags if len(tags) = 0. It returns m.

func (Permissions) Copy

func (m Permissions) Copy() Permissions

Copy returns a new Permissions that is a copy of m.

func (Permissions) Normalize

func (m Permissions) Normalize() Permissions

Normalize re-organizes 'm' so that two equivalent Permissions are comparable via reflection. It returns 'm'.

func (Permissions) VDLIsZero

func (x Permissions) VDLIsZero() bool

func (*Permissions) VDLRead

func (x *Permissions) VDLRead(dec vdl.Decoder) error

func (Permissions) VDLReflect

func (Permissions) VDLReflect(struct {
	Name string `vdl:"v.io/v23/security/access.Permissions"`
})

func (Permissions) VDLWrite

func (x Permissions) VDLWrite(enc vdl.Encoder) error

type PermissionsSpec

type PermissionsSpec struct {
	// ExplicitlySpecified is true if any part of the specification was obtained
	// from an explicitly specified command line flag.
	ExplicitlySpecified bool
	// Files represents a set of named files that contain permissions.
	// The name 'runtime' is reserved for use by the runtime.
	Files map[string]string
	// Literal represents a literal, ie. json, permissions specification.
	Literal string
}

PermissionsSpec represents a specification for permissions derived from command line flags or some other means.

func (*PermissionsSpec) Copy added in v0.1.2

func (ps *PermissionsSpec) Copy() PermissionsSpec

Copy returns a copy of the PermissionSpec.

type Tag

type Tag string

Tag is used to associate methods with an AccessList in a Permissions.

While services can define their own tag type and values, many services should be able to use the type and values defined in this package.

func AllTypicalTags

func AllTypicalTags() []Tag

AllTypicalTags returns all access.Tag values defined in this package.

func ParamsErrAccessTagCaveatValidation added in v0.1.10

func ParamsErrAccessTagCaveatValidation(argumentError error) (verrorComponent string, verrorOperation string, methodTags []string, caveatTags []Tag, returnErr error)

ParamsErrAccessTagCaveatValidation extracts the expected parameters from the error's ParameterList.

func (Tag) VDLIsZero

func (x Tag) VDLIsZero() bool

func (*Tag) VDLRead

func (x *Tag) VDLRead(dec vdl.Decoder) error

func (Tag) VDLReflect

func (Tag) VDLReflect(struct {
	Name string `vdl:"v.io/v23/security/access.Tag"`
})

func (Tag) VDLWrite

func (x Tag) VDLWrite(enc vdl.Encoder) error

Directories

Path Synopsis
This file was auto-generated by the vanadium vdl tool.
This file was auto-generated by the vanadium vdl tool.

Jump to

Keyboard shortcuts

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