Add account issuers

This commit is contained in:
Ben Toogood 2020-05-21 16:41:55 +01:00
parent 856c73b341
commit 12061bd006
12 changed files with 159 additions and 228 deletions

View File

@ -17,7 +17,7 @@ var (
ErrForbidden = errors.New("resource forbidden") ErrForbidden = errors.New("resource forbidden")
) )
// Auth providers authentication and authorization // Auth provides authentication and authorization
type Auth interface { type Auth interface {
// Init the auth // Init the auth
Init(opts ...Option) Init(opts ...Option)
@ -47,8 +47,8 @@ type Account struct {
ID string `json:"id"` ID string `json:"id"`
// Type of the account, e.g. service // Type of the account, e.g. service
Type string `json:"type"` Type string `json:"type"`
// Provider who issued the account // Issuer of the account
Provider string `json:"provider"` Issuer string `json:"issuer"`
// Any other associated metadata // Any other associated metadata
Metadata map[string]string `json:"metadata"` Metadata map[string]string `json:"metadata"`
// Scopes the account has access to // Scopes the account has access to

View File

@ -55,8 +55,8 @@ func (j *jwt) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e
ID: id, ID: id,
Type: options.Type, Type: options.Type,
Scopes: options.Scopes, Scopes: options.Scopes,
Provider: options.Provider,
Metadata: options.Metadata, Metadata: options.Metadata,
Issuer: j.Options().Namespace,
} }
// generate a JWT secret which can be provided to the Token() method // generate a JWT secret which can be provided to the Token() method
@ -97,12 +97,12 @@ func (j *jwt) Verify(acc *auth.Account, res *auth.Resource, opts ...auth.VerifyO
j.Lock() j.Lock()
defer j.Unlock() defer j.Unlock()
options := auth.VerifyOptions{Scope: j.options.Namespace} var options auth.VerifyOptions
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
return rules.Verify(options.Scope, j.rules, acc, res) return rules.Verify(j.rules, acc, res)
} }
func (j *jwt) Rules() ([]*auth.Rule, error) { func (j *jwt) Rules() ([]*auth.Rule, error) {

View File

@ -154,13 +154,6 @@ func WithMetadata(md map[string]string) GenerateOption {
} }
} }
// WithScopes for the generated account
func WithScopes(s ...string) GenerateOption {
return func(o *GenerateOptions) {
o.Scopes = s
}
}
// WithProvider for the generated account // WithProvider for the generated account
func WithProvider(p string) GenerateOption { func WithProvider(p string) GenerateOption {
return func(o *GenerateOptions) { return func(o *GenerateOptions) {
@ -168,6 +161,13 @@ func WithProvider(p string) GenerateOption {
} }
} }
// WithScopes for the generated account
func WithScopes(s ...string) GenerateOption {
return func(o *GenerateOptions) {
o.Scopes = s
}
}
// NewGenerateOptions from a slice of options // NewGenerateOptions from a slice of options
func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { func NewGenerateOptions(opts ...GenerateOption) GenerateOptions {
var options GenerateOptions var options GenerateOptions
@ -225,15 +225,6 @@ func NewTokenOptions(opts ...TokenOption) TokenOptions {
return options return options
} }
type VerifyOptions struct { type VerifyOptions struct{}
Scope string
}
type VerifyOption func(o *VerifyOptions) type VerifyOption func(o *VerifyOptions)
// WithScope to require when verifying
func WithScope(s string) VerifyOption {
return func(o *VerifyOptions) {
o.Scope = s
}
}

View File

@ -11,7 +11,7 @@ import (
// Verify an account has access to a resource using the rules provided. If the account does not have // Verify an account has access to a resource using the rules provided. If the account does not have
// access an error will be returned. If there are no rules provided which match the resource, an error // access an error will be returned. If there are no rules provided which match the resource, an error
// will be returned // will be returned
func Verify(namespace string, rules []*auth.Rule, acc *auth.Account, res *auth.Resource) error { func Verify(rules []*auth.Rule, acc *auth.Account, res *auth.Resource) error {
// the rule is only to be applied if the type matches the resource or is catch-all (*) // the rule is only to be applied if the type matches the resource or is catch-all (*)
validTypes := []string{"*", res.Type} validTypes := []string{"*", res.Type}

View File

@ -190,7 +190,7 @@ type Account struct {
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
Scopes []string `protobuf:"bytes,5,rep,name=scopes,proto3" json:"scopes,omitempty"` Scopes []string `protobuf:"bytes,5,rep,name=scopes,proto3" json:"scopes,omitempty"`
Provider string `protobuf:"bytes,6,opt,name=provider,proto3" json:"provider,omitempty"` Issuer string `protobuf:"bytes,6,opt,name=issuer,proto3" json:"issuer,omitempty"`
Secret string `protobuf:"bytes,7,opt,name=secret,proto3" json:"secret,omitempty"` Secret string `protobuf:"bytes,7,opt,name=secret,proto3" json:"secret,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
@ -250,9 +250,9 @@ func (m *Account) GetScopes() []string {
return nil return nil
} }
func (m *Account) GetProvider() string { func (m *Account) GetIssuer() string {
if m != nil { if m != nil {
return m.Provider return m.Issuer
} }
return "" return ""
} }
@ -1085,62 +1085,62 @@ func init() {
func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) }
var fileDescriptor_21300bfacc51fc2a = []byte{ var fileDescriptor_21300bfacc51fc2a = []byte{
// 871 bytes of a gzipped FileDescriptorProto // 872 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x5f, 0x8f, 0xdb, 0x44, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x51, 0x8f, 0xdb, 0x44,
0x10, 0x3f, 0xe7, 0x8f, 0x93, 0x9b, 0xc4, 0x77, 0xd1, 0xf6, 0x5a, 0xac, 0x94, 0x6b, 0xaf, 0x2e, 0x10, 0x3e, 0x27, 0xb1, 0x93, 0x9b, 0xc4, 0x77, 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ff, 0xff, 0xda, 0x1b, 0xd7, 0x4c, 0x88, 0x1f, 0x1c, 0xf5, 0xa3, 0xf5, 0xf0, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff,
0xef, 0x0e, 0x5f, 0x8d, 0x09, 0x00, 0x00, 0x52, 0x12, 0xc2, 0xdb, 0x89, 0x09, 0x00, 0x00,
} }
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.

View File

@ -37,7 +37,7 @@ message Account {
string type = 2; string type = 2;
map<string, string> metadata = 4; map<string, string> metadata = 4;
repeated string scopes = 5; repeated string scopes = 5;
string provider = 6; string issuer = 6;
string secret = 7; string secret = 7;
} }

View File

@ -78,12 +78,19 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e
// Grant access to a resource // Grant access to a resource
func (s *svc) Grant(rule *auth.Rule) error { func (s *svc) Grant(rule *auth.Rule) error {
access := pb.Access_UNKNOWN
if rule.Access == auth.AccessGranted {
access = pb.Access_GRANTED
} else if rule.Access == auth.AccessDenied {
access = pb.Access_DENIED
}
_, err := s.rule.Create(context.TODO(), &pb.CreateRequest{ _, err := s.rule.Create(context.TODO(), &pb.CreateRequest{
Rule: &pb.Rule{ Rule: &pb.Rule{
Id: rule.ID, Id: rule.ID,
Scope: rule.Scope, Scope: rule.Scope,
Priority: rule.Priority, Priority: rule.Priority,
Access: pb.Access_GRANTED, Access: access,
Resource: &pb.Resource{ Resource: &pb.Resource{
Type: rule.Resource.Type, Type: rule.Resource.Type,
Name: rule.Resource.Name, Name: rule.Resource.Name,
@ -91,6 +98,7 @@ func (s *svc) Grant(rule *auth.Rule) error {
}, },
}, },
}) })
go s.loadRules(s.options.Namespace) go s.loadRules(s.options.Namespace)
return err return err
} }
@ -100,6 +108,7 @@ func (s *svc) Revoke(rule *auth.Rule) error {
_, err := s.rule.Delete(context.TODO(), &pb.DeleteRequest{ _, err := s.rule.Delete(context.TODO(), &pb.DeleteRequest{
Id: rule.ID, Id: rule.ID,
}) })
go s.loadRules(s.options.Namespace) go s.loadRules(s.options.Namespace)
return err return err
} }
@ -110,16 +119,16 @@ func (s *svc) Rules() ([]*auth.Rule, error) {
// Verify an account has access to a resource // Verify an account has access to a resource
func (s *svc) Verify(acc *auth.Account, res *auth.Resource, opts ...auth.VerifyOption) error { func (s *svc) Verify(acc *auth.Account, res *auth.Resource, opts ...auth.VerifyOption) error {
options := auth.VerifyOptions{Scope: s.options.Namespace} var options auth.VerifyOptions
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
// load the rules if none are loaded // load the rules if none are loaded
s.loadRulesIfEmpty(options.Scope) s.loadRulesIfEmpty(s.Options().Namespace)
// verify the request using the rules // verify the request using the rules
return rules.Verify(options.Scope, s.rules[options.Scope], acc, res) return rules.Verify(s.rules[s.Options().Namespace], acc, res)
} }
// Inspect a token // Inspect a token
@ -215,8 +224,8 @@ func serializeAccount(a *pb.Account) *auth.Account {
return &auth.Account{ return &auth.Account{
ID: a.Id, ID: a.Id,
Secret: a.Secret, Secret: a.Secret,
Issuer: a.Issuer,
Metadata: a.Metadata, Metadata: a.Metadata,
Provider: a.Provider,
Scopes: a.Scopes, Scopes: a.Scopes,
} }
} }

View File

@ -13,7 +13,6 @@ import (
type authClaims struct { type authClaims struct {
Type string `json:"type"` Type string `json:"type"`
Scopes []string `json:"scopes"` Scopes []string `json:"scopes"`
Provider string `json:"provider"`
Metadata map[string]string `json:"metadata"` Metadata map[string]string `json:"metadata"`
jwt.StandardClaims jwt.StandardClaims
@ -51,8 +50,9 @@ func (j *JWT) Generate(acc *auth.Account, opts ...token.GenerateOption) (*token.
// generate the JWT // generate the JWT
expiry := time.Now().Add(options.Expiry) expiry := time.Now().Add(options.Expiry)
t := jwt.NewWithClaims(jwt.SigningMethodRS256, authClaims{ t := jwt.NewWithClaims(jwt.SigningMethodRS256, authClaims{
acc.Type, acc.Scopes, acc.Provider, acc.Metadata, jwt.StandardClaims{ acc.Type, acc.Scopes, acc.Metadata, jwt.StandardClaims{
Subject: acc.ID, Subject: acc.ID,
Issuer: acc.Issuer,
ExpiresAt: expiry.Unix(), ExpiresAt: expiry.Unix(),
}, },
}) })
@ -97,9 +97,9 @@ func (j *JWT) Inspect(t string) (*auth.Account, error) {
// return the token // return the token
return &auth.Account{ return &auth.Account{
ID: claims.Subject, ID: claims.Subject,
Issuer: claims.Issuer,
Type: claims.Type, Type: claims.Type,
Scopes: claims.Scopes, Scopes: claims.Scopes,
Provider: claims.Provider,
Metadata: claims.Metadata, Metadata: claims.Metadata,
}, nil }, nil
} }

View File

@ -166,9 +166,7 @@ type CreateOptions struct {
// create type of service // create type of service
Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"` Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"`
// image to use // image to use
Image string `protobuf:"bytes,6,opt,name=image,proto3" json:"image,omitempty"` Image string `protobuf:"bytes,6,opt,name=image,proto3" json:"image,omitempty"`
// namespace to use
Namespace string `protobuf:"bytes,7,opt,name=namespace,proto3" json:"namespace,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
@ -241,13 +239,6 @@ func (m *CreateOptions) GetImage() string {
return "" return ""
} }
func (m *CreateOptions) GetNamespace() string {
if m != nil {
return m.Namespace
}
return ""
}
type CreateRequest struct { type CreateRequest struct {
Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
Options *CreateOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` Options *CreateOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"`
@ -332,9 +323,7 @@ type ReadOptions struct {
// version of the service // version of the service
Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"`
// type of service // type of service
Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"`
// namespace of service
Namespace string `protobuf:"bytes,4,opt,name=namespace,proto3" json:"namespace,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
@ -386,13 +375,6 @@ func (m *ReadOptions) GetType() string {
return "" return ""
} }
func (m *ReadOptions) GetNamespace() string {
if m != nil {
return m.Namespace
}
return ""
}
type ReadRequest struct { type ReadRequest struct {
Options *ReadOptions `protobuf:"bytes,1,opt,name=options,proto3" json:"options,omitempty"` Options *ReadOptions `protobuf:"bytes,1,opt,name=options,proto3" json:"options,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -472,8 +454,6 @@ func (m *ReadResponse) GetServices() []*Service {
} }
type DeleteOptions struct { type DeleteOptions struct {
// namespace of the service
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
@ -504,13 +484,6 @@ func (m *DeleteOptions) XXX_DiscardUnknown() {
var xxx_messageInfo_DeleteOptions proto.InternalMessageInfo var xxx_messageInfo_DeleteOptions proto.InternalMessageInfo
func (m *DeleteOptions) GetNamespace() string {
if m != nil {
return m.Namespace
}
return ""
}
type DeleteRequest struct { type DeleteRequest struct {
Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
Options *DeleteOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` Options *DeleteOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"`
@ -590,8 +563,6 @@ func (m *DeleteResponse) XXX_DiscardUnknown() {
var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo
type UpdateOptions struct { type UpdateOptions struct {
// namespace of the service
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
@ -622,13 +593,6 @@ func (m *UpdateOptions) XXX_DiscardUnknown() {
var xxx_messageInfo_UpdateOptions proto.InternalMessageInfo var xxx_messageInfo_UpdateOptions proto.InternalMessageInfo
func (m *UpdateOptions) GetNamespace() string {
if m != nil {
return m.Namespace
}
return ""
}
type UpdateRequest struct { type UpdateRequest struct {
Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
Options *UpdateOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` Options *UpdateOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"`
@ -708,8 +672,6 @@ func (m *UpdateResponse) XXX_DiscardUnknown() {
var xxx_messageInfo_UpdateResponse proto.InternalMessageInfo var xxx_messageInfo_UpdateResponse proto.InternalMessageInfo
type ListOptions struct { type ListOptions struct {
// namespace to list from
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
@ -740,13 +702,6 @@ func (m *ListOptions) XXX_DiscardUnknown() {
var xxx_messageInfo_ListOptions proto.InternalMessageInfo var xxx_messageInfo_ListOptions proto.InternalMessageInfo
func (m *ListOptions) GetNamespace() string {
if m != nil {
return m.Namespace
}
return ""
}
type ListRequest struct { type ListRequest struct {
Options *ListOptions `protobuf:"bytes,1,opt,name=options,proto3" json:"options,omitempty"` Options *ListOptions `protobuf:"bytes,1,opt,name=options,proto3" json:"options,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -826,8 +781,6 @@ func (m *ListResponse) GetServices() []*Service {
} }
type LogsOptions struct { type LogsOptions struct {
// namespace of the service
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
@ -858,13 +811,6 @@ func (m *LogsOptions) XXX_DiscardUnknown() {
var xxx_messageInfo_LogsOptions proto.InternalMessageInfo var xxx_messageInfo_LogsOptions proto.InternalMessageInfo
func (m *LogsOptions) GetNamespace() string {
if m != nil {
return m.Namespace
}
return ""
}
type LogsRequest struct { type LogsRequest struct {
// service to request logs for // service to request logs for
Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
@ -1031,52 +977,50 @@ func init() {
} }
var fileDescriptor_2434d8152598889b = []byte{ var fileDescriptor_2434d8152598889b = []byte{
// 711 bytes of a gzipped FileDescriptorProto // 683 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x0e, 0x5d, 0xf9, 0x46, 0x48, 0xcb, 0xdb, 0xb1, 0xa9,
0xd8, 0x80, 0xab, 0x35, 0x0c, 0x54, 0x3a, 0x7d, 0xbd, 0x48, 0xe7, 0x95, 0xdc, 0x90, 0xae, 0x75, 0x1e, 0xed, 0x28, 0xba, 0xbf, 0xf7, 0xca, 0xf9, 0xda, 0x57, 0x3f, 0x16, 0x67, 0xff, 0x02, 0x00,
0x33, 0xb7, 0xc8, 0x29, 0x78, 0xb2, 0x47, 0x48, 0x47, 0xef, 0xd8, 0x54, 0x0f, 0x36, 0x14, 0x3d, 0x00, 0xff, 0xff, 0xe1, 0x5b, 0x52, 0x93, 0x7f, 0x08, 0x00, 0x00,
0xd8, 0x7a, 0xe9, 0x7c, 0x1d, 0xa8, 0x9f, 0xa1, 0xe3, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8e,
0x6c, 0x03, 0x59, 0x33, 0x09, 0x00, 0x00,
} }
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.

View File

@ -41,8 +41,6 @@ message CreateOptions {
string type = 5; string type = 5;
// image to use // image to use
string image = 6; string image = 6;
// namespace to use
string namespace = 7;
} }
message CreateRequest { message CreateRequest {
@ -59,8 +57,6 @@ message ReadOptions {
string version = 2; string version = 2;
// type of service // type of service
string type = 3; string type = 3;
// namespace of service
string namespace = 4;
} }
message ReadRequest { message ReadRequest {
@ -72,8 +68,6 @@ message ReadResponse {
} }
message DeleteOptions { message DeleteOptions {
// namespace of the service
string namespace = 1;
} }
message DeleteRequest { message DeleteRequest {
@ -84,8 +78,6 @@ message DeleteRequest {
message DeleteResponse {} message DeleteResponse {}
message UpdateOptions { message UpdateOptions {
// namespace of the service
string namespace = 1;
} }
message UpdateRequest { message UpdateRequest {
@ -96,8 +88,6 @@ message UpdateRequest {
message UpdateResponse {} message UpdateResponse {}
message ListOptions { message ListOptions {
// namespace to list from
string namespace = 1;
} }
message ListRequest { message ListRequest {
@ -109,8 +99,6 @@ message ListResponse {
} }
message LogsOptions { message LogsOptions {
// namespace of the service
string namespace = 1;
} }
message LogsRequest{ message LogsRequest{

View File

@ -54,12 +54,11 @@ func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error {
Metadata: svc.Metadata, Metadata: svc.Metadata,
}, },
Options: &pb.CreateOptions{ Options: &pb.CreateOptions{
Command: options.Command, Command: options.Command,
Args: options.Args, Args: options.Args,
Env: options.Env, Env: options.Env,
Type: options.Type, Type: options.Type,
Image: options.Image, Image: options.Image,
Namespace: options.Namespace,
}, },
} }
@ -84,9 +83,6 @@ func (s *svc) Logs(service *runtime.Service, opts ...runtime.LogsOption) (runtim
Service: service.Name, Service: service.Name,
Stream: options.Stream, Stream: options.Stream,
Count: options.Count, Count: options.Count,
Options: &pb.LogsOptions{
Namespace: options.Namespace,
},
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -176,10 +172,9 @@ func (s *svc) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error) {
// runtime service create request // runtime service create request
req := &pb.ReadRequest{ req := &pb.ReadRequest{
Options: &pb.ReadOptions{ Options: &pb.ReadOptions{
Service: options.Service, Service: options.Service,
Version: options.Version, Version: options.Version,
Type: options.Type, Type: options.Type,
Namespace: options.Namespace,
}, },
} }
@ -220,9 +215,6 @@ func (s *svc) Update(svc *runtime.Service, opts ...runtime.UpdateOption) error {
Source: svc.Source, Source: svc.Source,
Metadata: svc.Metadata, Metadata: svc.Metadata,
}, },
Options: &pb.UpdateOptions{
Namespace: options.Namespace,
},
} }
if _, err := s.runtime.Update(options.Context, req); err != nil { if _, err := s.runtime.Update(options.Context, req); err != nil {
@ -250,9 +242,6 @@ func (s *svc) Delete(svc *runtime.Service, opts ...runtime.DeleteOption) error {
Source: svc.Source, Source: svc.Source,
Metadata: svc.Metadata, Metadata: svc.Metadata,
}, },
Options: &pb.DeleteOptions{
Namespace: options.Namespace,
},
} }
if _, err := s.runtime.Delete(options.Context, req); err != nil { if _, err := s.runtime.Delete(options.Context, req); err != nil {

View File

@ -190,18 +190,28 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper {
// Extract the token if present. Note: if noop is being used // Extract the token if present. Note: if noop is being used
// then the token can be blank without erroring // then the token can be blank without erroring
var token string var account *auth.Account
if header, ok := metadata.Get(ctx, "Authorization"); ok { if header, ok := metadata.Get(ctx, "Authorization"); ok {
// Ensure the correct scheme is being used // Ensure the correct scheme is being used
if !strings.HasPrefix(header, auth.BearerScheme) { if !strings.HasPrefix(header, auth.BearerScheme) {
return errors.Unauthorized(req.Service(), "invalid authorization header. expected Bearer schema") return errors.Unauthorized(req.Service(), "invalid authorization header. expected Bearer schema")
} }
token = header[len(auth.BearerScheme):] // Strip the prefix and inspect the resulting token
account, _ = a.Inspect(strings.TrimPrefix(header, auth.BearerScheme))
} }
// Inspect the token and get the account // Extract the namespace header
account, _ := a.Inspect(token) ns, ok := metadata.Get(ctx, "Micro-Namespace")
if !ok {
ns = a.Options().Namespace
ctx = metadata.Set(ctx, "Micro-Namespace", ns)
}
// Check the issuer matches the services namespace
if account != nil && account.Issuer != ns {
return errors.Forbidden(req.Service(), "Account was not issued by %v", ns)
}
// construct the resource // construct the resource
res := &auth.Resource{ res := &auth.Resource{