crossmodel

package
v0.0.0-...-1eb8e40 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const ErrInvalidMacaroon = internalerrors.ConstError("invalid CMR macaroon")

ErrInvalidMacaroon is returned when a macaroon is invalid.

Variables

This section is empty.

Functions

func NewCMRAuthorizer

func NewCMRAuthorizer(logger logger.Logger) bakery.OpsAuthorizer

NewCMRAuthorizer returns a bakery.OpsAuthorizer that authorizes cross model related operations.

Types

type AccessService

type AccessService interface {
	// ReadUserAccessLevelForTarget returns the user access level for the
	// given user on the given target.
	ReadUserAccessLevelForTarget(ctx context.Context, subject user.Name, target permission.ID) (permission.Access, error)
}

AccessService validates access for user permissions.

type AuthContext

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

AuthContext is used to validate macaroons used to access application offers.

func NewAuthContext

func NewAuthContext(
	accessService AccessService,
	bakery OfferBakery,
	offerThirdPartyKey *bakery.KeyPair,
	controllerUUID string,
	modelUUID model.UUID,
	clock clock.Clock,
	logger logger.Logger,
) *AuthContext

NewAuthContext creates a new authentication context for checking macaroons used with application offer requests.

func (*AuthContext) Authenticator

func (a *AuthContext) Authenticator() facade.MacaroonAuthenticator

Authenticator returns an instance used to authenticate macaroons used to access offers.

func (*AuthContext) CheckLocalAccessRequest

func (a *AuthContext) CheckLocalAccessRequest(ctx context.Context, details crossmodelbakery.OfferAccessDetails) ([]checkers.Caveat, error)

CheckLocalAccessRequest checks that the user in the specified permission check details has consume access to the offer in the details. It returns an error with a *bakery.VerificationError cause if the macaroon verification failed. If the macaroon is valid, CheckLocalAccessRequest returns a list of caveats to add to the discharge macaroon.

func (*AuthContext) CheckOfferAccessCaveat

func (a *AuthContext) CheckOfferAccessCaveat(ctx context.Context, caveat string) (crossmodelbakery.OfferAccessDetails, error)

CheckOfferAccessCaveat checks that the specified caveat required to be satisfied to gain access to an offer is valid, and returns the attributes return to check that the caveat is satisfied.

func (*AuthContext) CreateConsumeOfferMacaroon

func (a *AuthContext) CreateConsumeOfferMacaroon(
	ctx context.Context,
	modelUUID model.UUID,
	offerUUID, username string,
	version bakery.Version,
) (*bakery.Macaroon, error)

CreateConsumeOfferMacaroon creates a macaroon that authorizes access to the specified offer.

func (*AuthContext) CreateRemoteRelationMacaroon

func (a *AuthContext) CreateRemoteRelationMacaroon(
	ctx context.Context,
	modelUUID model.UUID,
	offerUUID, username string,
	rel names.RelationTag,
	version bakery.Version,
) (*bakery.Macaroon, error)

CreateRemoteRelationMacaroon creates a macaroon that authorizes access to the specified relation.

func (*AuthContext) OfferThirdPartyKey

func (a *AuthContext) OfferThirdPartyKey() *bakery.KeyPair

OfferThirdPartyKey returns the key used to discharge offer macaroons.

type Authenticator

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

Authenticator is used to authenticate macaroons used to access application offers.

func (*Authenticator) CheckOfferMacaroons

func (a *Authenticator) CheckOfferMacaroons(ctx context.Context, offeringModelUUID, offerUUID string, mac macaroon.Slice, version bakery.Version) (map[string]string, error)

CheckOfferMacaroons verifies that the specified macaroons allow access to the offer.

func (*Authenticator) CheckRelationMacaroons

func (a *Authenticator) CheckRelationMacaroons(ctx context.Context, sourceModelUUID, offerUUID string, relationTag names.RelationTag, mac macaroon.Slice, version bakery.Version) error

CheckRelationMacaroons verifies that the specified macaroons allow access to the relation.

type OfferBakery

type OfferBakery interface {
	// ParseCaveat parses the specified caveat and returns the offer access details
	// it contains.
	ParseCaveat(caveat string) (crossmodelbakery.OfferAccessDetails, error)
	// GetConsumeOfferCaveats returns the caveats for consuming an offer.
	GetConsumeOfferCaveats(offerUUID, sourceModelUUID, username, relation string) []checkers.Caveat
	// GetRemoteRelationCaveats returns the caveats for accessing a remote relation.
	GetRemoteRelationCaveats(offerUUID, sourceModelUUID, username, relation string) []checkers.Caveat
	// InferDeclaredFromMacaroon retrieves any declared information from
	// the given macaroons and returns it as a key-value map.
	InferDeclaredFromMacaroon(macaroon.Slice, map[string]string) crossmodelbakery.DeclaredValues
	// NewMacaroon creates a new macaroon for the given version, caveats and ops.
	NewMacaroon(context.Context, bakery.Version, []checkers.Caveat, ...bakery.Op) (*bakery.Macaroon, error)
	// CreateDischargeMacaroon creates a discharge macaroon.
	CreateDischargeMacaroon(
		ctx context.Context,
		username string,
		requiredValues map[string]string,
		declaredValues crossmodelbakery.DeclaredValues,
		op bakery.Op,
		version bakery.Version,
	) (*bakery.Macaroon, error)
	// GetOfferRequiredValues returns the required values for the specified
	// offer access.
	GetOfferRequiredValues(sourceModelUUID, offerUUID string) (map[string]string, error)
	// GetRelationRequiredValues returns the required values for the specified
	// relation access.
	GetRelationRequiredValues(sourceModelUUID, offerUUID, relation string) (map[string]string, error)
	// AllowedAuth checks the specified macaroon is valid for the operation
	// and returns the associated AuthInfo.
	AllowedAuth(ctx context.Context, op bakery.Op, mac macaroon.Slice) ([]string, error)
}

OfferBakery is used to create and inspect macaroons used to access application offers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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