Documentation ¶
Index ¶
- Variables
- func AddConstraints(mac *macaroon.Macaroon, cs ...Constraint) (*macaroon.Macaroon, error)
- func ContextWithRootKeyID(ctx context.Context, value interface{}) context.Context
- func IPLockChecker() (string, checkers.Func)
- func IPLockConstraint(ipAddr string) func(*macaroon.Macaroon) error
- func NewMemRootKeyStore(rootKey []byte) (bakery.RootKeyStore, error)
- func RootKeyIDFromContext(ctx context.Context) ([]byte, error)
- func TimeoutConstraint(seconds int64) func(*macaroon.Macaroon) error
- type AuthGenerator
- type AuthValidator
- type Checker
- type Constraint
- type MacaroonCredential
- type MacaroonValidator
- type Service
- func (svc *Service) NewMacaroon(ctx context.Context, rootKeyID []byte, ops ...bakery.Op) (*bakery.Macaroon, error)
- func (svc *Service) RegisterExternalValidator(fullMethod string, validator MacaroonValidator) error
- func (svc *Service) ValidateMacaroon(ctx context.Context, requiredPermissions []bakery.Op, fullMethod string) error
Constants ¶
This section is empty.
Variables ¶
var ( // RootKeyIDContextKey is the key to get rootKeyID from context. RootKeyIDContextKey = contextKey{"rootkeyid"} // ErrContextRootKeyID is used when the supplied context doesn't have // a root key ID. ErrContextRootKeyID = fmt.Errorf( "failed to read root key ID from context", ) )
var ( // ErrMissingRootKeyID specifies the root key ID is missing. ErrMissingRootKeyID = fmt.Errorf("missing root key ID") // ErrDeletionForbidden is used when attempting to delete the // DefaultRootKeyID or the encryptedKeyID. ErrDeletionForbidden = fmt.Errorf("the specified ID cannot be deleted") // PermissionEntityCustomURI is a special entity name for a permission // that does not describe an entity:action pair but instead specifies a // specific URI that needs to be granted access to. This can be used for // more fine-grained permissions where a macaroon only grants access to // certain methods instead of a whole list of methods that define the // same entity:action pairs. PermissionEntityCustomURI = "uri" )
var ( ErrRootKeyNotFound = errgo.New("root key not found") ErrMissingRootKey = errgo.New("missing root key") DefaultRootKeyID = []byte("rootkeyid") )
Functions ¶
func AddConstraints ¶
AddConstraints returns new derived macaroon by applying every passed constraint and tightening its restrictions.
func ContextWithRootKeyID ¶
ContextWithRootKeyID passes the root key ID value to context.
func IPLockChecker ¶
IPLockChecker accepts client IP from the validation context and compares it with IP locked in the macaroon. It is of the `Checker` type.
func IPLockConstraint ¶
IPLockConstraint locks macaroon to a specific IP address. If address is an empty string, this constraint does nothing to accommodate default value's desired behavior.
func NewMemRootKeyStore ¶
func NewMemRootKeyStore(rootKey []byte) (bakery.RootKeyStore, error)
func RootKeyIDFromContext ¶
RootKeyIDFromContext retrieves the root key ID from context using the key RootKeyIDContextKey.
Types ¶
type AuthGenerator ¶
type AuthGenerator struct {
// contains filtered or unexported fields
}
func NewAuthGenerator ¶
func NewAuthGenerator( secret string, supportedServices []string, ) (*AuthGenerator, error)
func (*AuthGenerator) NewToken ¶
func (s *AuthGenerator) NewToken( pubkey string, services []string, ) (string, error)
func (*AuthGenerator) SupportedServices ¶
func (s *AuthGenerator) SupportedServices() ([]string, error)
type AuthValidator ¶
type AuthValidator struct {
// contains filtered or unexported fields
}
func NewAuthValidator ¶
func (*AuthValidator) PubkeyFromToken ¶
func (s *AuthValidator) PubkeyFromToken(token string) (string, error)
func (*AuthValidator) ValidateToken ¶
func (s *AuthValidator) ValidateToken(token, method string) error
type Checker ¶
Checker type adds a layer of indirection over macaroon checkers. A Checker returns the name of the checker and the checker function; these are used to register the function with the bakery service's compound checker.
type Constraint ¶
Constraint type adds a layer of indirection over macaroon caveats.
type MacaroonCredential ¶
MacaroonCredential wraps a macaroon to implement the credentials.PerRPCCredentials interface.
func NewMacaroonCredential ¶
func NewMacaroonCredential(m *macaroon.Macaroon, withTLS bool) MacaroonCredential
NewMacaroonCredential returns a copy of the passed macaroon wrapped in a MacaroonCredential struct which implements PerRPCCredentials.
func (MacaroonCredential) GetRequestMetadata ¶
func (m MacaroonCredential) GetRequestMetadata( ctx context.Context, uri ...string, ) (map[string]string, error)
GetRequestMetadata implements the PerRPCCredentials interface. This method is required in order to pass the wrapped macaroon into the gRPC context. With this, the macaroon will be available within the request handling scope of the ultimate gRPC server implementation.
func (MacaroonCredential) RequireTransportSecurity ¶
func (m MacaroonCredential) RequireTransportSecurity() bool
RequireTransportSecurity implements the PerRPCCredentials interface.
type MacaroonValidator ¶
type MacaroonValidator interface { // ValidateMacaroon extracts the macaroon from the context's gRPC // metadata, checks its signature, makes sure all specified permissions // for the called method are contained within and finally ensures all // caveat conditions are met. A non-nil error is returned if any of the // checks fail. ValidateMacaroon(ctx context.Context, requiredPermissions []bakery.Op, fullMethod string) error }
MacaroonValidator is an interface type that can check if macaroons are valid.
type Service ¶
type Service struct { bakery.Bakery // ExternalValidators is a map between an absolute gRPC URIs and the // corresponding external macaroon validator to be used for that URI. // If no external validator for an URI is specified, the service will // use the internal validator. ExternalValidators map[string]MacaroonValidator // StatelessInit denotes if the service was initialized in the stateless // mode where no macaroon files should be created on disk. StatelessInit bool }
Service encapsulates bakery.Bakery and adds a Close() method that zeroes the root key service encryption keys, as well as utility methods to validate a macaroon against the bakery and gRPC middleware for macaroon-based auth.
func NewService ¶
NewService returns a service backed by the macaroon Bolt DB stored in the passed directory. The `checks` argument can be any of the `Checker` type functions defined in this package, or a custom checker if desired. This constructor prevents double-registration of checkers to prevent panics, so listing the same checker more than once is not harmful. Default checkers, such as those for `allow`, `time-before`, `declared`, and `error` caveats are registered automatically and don't need to be added.
func (*Service) NewMacaroon ¶
func (svc *Service) NewMacaroon( ctx context.Context, rootKeyID []byte, ops ...bakery.Op) (*bakery.Macaroon, error)
NewMacaroon wraps around the function Oven.NewMacaroon with the defaults,
- version is always bakery.LatestVersion;
- caveats is always nil.
In addition, it takes a rootKeyID parameter, and puts it into the context. The context is passed through Oven.NewMacaroon(), in which calls the function RootKey(), that reads the context for rootKeyID.
func (*Service) RegisterExternalValidator ¶
func (svc *Service) RegisterExternalValidator(fullMethod string, validator MacaroonValidator) error
RegisterExternalValidator registers a custom, external macaroon validator for the specified absolute gRPC URI. That validator is then fully responsible to make sure any macaroon passed for a request to that URI is valid and satisfies all conditions.
func (*Service) ValidateMacaroon ¶
func (svc *Service) ValidateMacaroon(ctx context.Context, requiredPermissions []bakery.Op, fullMethod string) error
ValidateMacaroon validates the capabilities of a given request given a bakery service, context, and uri. Within the passed context.Context, we expect a macaroon to be encoded as request metadata using the key "macaroon".