Add Namespace to Auth (#1438)
Co-authored-by: Ben Toogood <ben@micro.mu>
This commit is contained in:
parent
3d7d5ce6b4
commit
4db2f5e79d
@ -68,6 +68,8 @@ type Account struct {
|
|||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
// Any other associated metadata
|
// Any other associated metadata
|
||||||
Metadata map[string]string `json:"metadata"`
|
Metadata map[string]string `json:"metadata"`
|
||||||
|
// Namespace the account belongs to, default blank
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Token can be short or long lived
|
// Token can be short or long lived
|
||||||
@ -86,6 +88,8 @@ type Token struct {
|
|||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
// Metadata embedded in the token
|
// Metadata embedded in the token
|
||||||
Metadata map[string]string `json:"metadata"`
|
Metadata map[string]string `json:"metadata"`
|
||||||
|
// Namespace the token belongs to
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -73,6 +73,8 @@ type GenerateOptions struct {
|
|||||||
Roles []string
|
Roles []string
|
||||||
// SecretExpiry is the time the secret should live for
|
// SecretExpiry is the time the secret should live for
|
||||||
SecretExpiry time.Duration
|
SecretExpiry time.Duration
|
||||||
|
// Namespace the account belongs too
|
||||||
|
Namespace string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GenerateOption func(o *GenerateOptions)
|
type GenerateOption func(o *GenerateOptions)
|
||||||
@ -91,6 +93,13 @@ func WithRoles(rs ...string) GenerateOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithNamespace for the generated account
|
||||||
|
func WithNamespace(n string) GenerateOption {
|
||||||
|
return func(o *GenerateOptions) {
|
||||||
|
o.Namespace = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithSecretExpiry for the generated account's secret expires
|
// WithSecretExpiry for the generated account's secret expires
|
||||||
func WithSecretExpiry(ex time.Duration) GenerateOption {
|
func WithSecretExpiry(ex time.Duration) GenerateOption {
|
||||||
return func(o *GenerateOptions) {
|
return func(o *GenerateOptions) {
|
||||||
|
@ -28,6 +28,7 @@ type Token struct {
|
|||||||
Subject string `protobuf:"bytes,5,opt,name=subject,proto3" json:"subject,omitempty"`
|
Subject string `protobuf:"bytes,5,opt,name=subject,proto3" json:"subject,omitempty"`
|
||||||
Roles []string `protobuf:"bytes,6,rep,name=roles,proto3" json:"roles,omitempty"`
|
Roles []string `protobuf:"bytes,6,rep,name=roles,proto3" json:"roles,omitempty"`
|
||||||
Metadata map[string]string `protobuf:"bytes,7,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,7,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||||
|
Namespace string `protobuf:"bytes,8,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:"-"`
|
||||||
@ -107,11 +108,19 @@ func (m *Token) GetMetadata() map[string]string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Token) GetNamespace() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Namespace
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
Secret *Token `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"`
|
Secret *Token `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"`
|
||||||
Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,omitempty"`
|
Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,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"`
|
||||||
|
Namespace string `protobuf:"bytes,5,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:"-"`
|
||||||
@ -170,6 +179,13 @@ func (m *Account) GetMetadata() map[string]string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Account) GetNamespace() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Namespace
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type Resource struct {
|
type Resource struct {
|
||||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
|
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
|
||||||
@ -230,6 +246,7 @@ type GenerateRequest struct {
|
|||||||
Roles []string `protobuf:"bytes,2,rep,name=roles,proto3" json:"roles,omitempty"`
|
Roles []string `protobuf:"bytes,2,rep,name=roles,proto3" json:"roles,omitempty"`
|
||||||
Metadata map[string]string `protobuf:"bytes,3,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,3,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||||
SecretExpiry int64 `protobuf:"varint,4,opt,name=secret_expiry,json=secretExpiry,proto3" json:"secret_expiry,omitempty"`
|
SecretExpiry int64 `protobuf:"varint,4,opt,name=secret_expiry,json=secretExpiry,proto3" json:"secret_expiry,omitempty"`
|
||||||
|
Namespace string `protobuf:"bytes,5,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:"-"`
|
||||||
@ -288,6 +305,13 @@ func (m *GenerateRequest) GetSecretExpiry() int64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *GenerateRequest) GetNamespace() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Namespace
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type GenerateResponse struct {
|
type GenerateResponse struct {
|
||||||
Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
|
Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
|
||||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
@ -671,44 +695,45 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fileDescriptor_b246cecfa8195ff3 = []byte{
|
var fileDescriptor_b246cecfa8195ff3 = []byte{
|
||||||
// 612 bytes of a gzipped FileDescriptorProto
|
// 630 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x6e, 0xd3, 0x40,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x6e, 0xd3, 0x40,
|
||||||
0x10, 0xae, 0xed, 0x34, 0x49, 0x27, 0x4d, 0x13, 0xad, 0xaa, 0x60, 0x45, 0xa2, 0x04, 0x83, 0x50,
|
0x10, 0xae, 0xed, 0xfc, 0xb8, 0x93, 0xa6, 0xa9, 0x56, 0x55, 0xb1, 0x22, 0x28, 0xc1, 0x20, 0x54,
|
||||||
0x84, 0x8a, 0x83, 0xd2, 0x0b, 0xe2, 0x4f, 0x54, 0x50, 0x95, 0x1f, 0x95, 0x83, 0x85, 0x04, 0x37,
|
0xa1, 0xe2, 0xa0, 0xf4, 0x82, 0xf8, 0x13, 0x15, 0x54, 0xe5, 0x47, 0xe5, 0x60, 0x21, 0xc1, 0x0d,
|
||||||
0xe4, 0x38, 0x43, 0x62, 0xd2, 0x78, 0xcd, 0x7a, 0x1d, 0x91, 0xb7, 0xe0, 0x01, 0xb9, 0x71, 0xe6,
|
0xb9, 0xce, 0xd0, 0x98, 0x34, 0x5e, 0xb3, 0x5e, 0x47, 0xe4, 0xc8, 0x0b, 0xf1, 0x66, 0xbc, 0x00,
|
||||||
0x1d, 0xd0, 0xae, 0x77, 0x5d, 0xc7, 0x49, 0x38, 0xf0, 0x73, 0x89, 0x66, 0x66, 0x67, 0xbf, 0x6f,
|
0x27, 0xb4, 0xeb, 0x5d, 0xc7, 0x71, 0x12, 0x84, 0x50, 0xb9, 0x44, 0x33, 0xe3, 0x99, 0x6f, 0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f, 0x43,
|
||||||
0x53, 0xdd, 0x59, 0xe6, 0x3c, 0x34, 0x1f, 0x18, 0xce, 0x77, 0x03, 0x6a, 0xa7, 0x41, 0x40, 0xd3,
|
0x7b, 0xa1, 0x90, 0xec, 0x80, 0x35, 0xc6, 0x99, 0x5a, 0x5c, 0x98, 0x62, 0xac, 0x69, 0x70, 0x99,
|
||||||
0x88, 0x93, 0x03, 0x30, 0xc3, 0xb1, 0xba, 0x66, 0x86, 0x63, 0x72, 0x0c, 0xd5, 0x04, 0x03, 0x86,
|
0xe9, 0xbd, 0x73, 0xe7, 0x91, 0xf9, 0xd0, 0x70, 0x7f, 0x19, 0xd0, 0x3c, 0x0e, 0x43, 0x9a, 0xc5,
|
||||||
0x5c, 0x5e, 0x6b, 0x0c, 0x0f, 0x37, 0x95, 0xe5, 0xa9, 0x9c, 0xab, 0xe6, 0xac, 0x62, 0x73, 0xcf,
|
0x9c, 0x6c, 0x83, 0x19, 0x0d, 0x55, 0x99, 0x19, 0x0d, 0xc9, 0x21, 0x34, 0x52, 0x0c, 0x19, 0x72,
|
||||||
0x0a, 0xcd, 0x55, 0x64, 0x73, 0xb7, 0x4b, 0x28, 0x8a, 0xfd, 0xff, 0xb4, 0xf7, 0x16, 0xea, 0x1e,
|
0x59, 0xd6, 0x1a, 0xec, 0xae, 0x1a, 0xda, 0x57, 0x39, 0xf3, 0xd5, 0xad, 0xf2, 0xea, 0xcf, 0x4b,
|
||||||
0x26, 0x34, 0x65, 0x01, 0x8a, 0xe9, 0x46, 0xfe, 0x1c, 0xd5, 0x45, 0x69, 0x6f, 0x9c, 0x78, 0x17,
|
0xab, 0xd7, 0xe4, 0xea, 0x77, 0x2a, 0x28, 0xaa, 0xfb, 0xdf, 0x2d, 0x5f, 0xbf, 0xd2, 0xe5, 0xdf,
|
||||||
0xea, 0x18, 0x8d, 0x63, 0x1a, 0x46, 0x5c, 0x8e, 0x7c, 0xcf, 0xcb, 0x7d, 0xe7, 0x87, 0x01, 0xad,
|
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0x82, 0x06, 0x00, 0x00,
|
0x66, 0xdc, 0x8d, 0xf3, 0x86, 0xfc, 0x73, 0x3a, 0xfa, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xb6, 0x18,
|
||||||
|
0xd0, 0x5a, 0xdc, 0x06, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ message Token {
|
|||||||
string subject = 5;
|
string subject = 5;
|
||||||
repeated string roles = 6;
|
repeated string roles = 6;
|
||||||
map<string, string> metadata = 7;
|
map<string, string> metadata = 7;
|
||||||
|
string namespace = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Account {
|
message Account {
|
||||||
@ -23,6 +24,7 @@ message Account {
|
|||||||
Token secret = 2;
|
Token secret = 2;
|
||||||
repeated string roles = 3;
|
repeated string roles = 3;
|
||||||
map<string, string> metadata = 4;
|
map<string, string> metadata = 4;
|
||||||
|
string namespace = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Resource{
|
message Resource{
|
||||||
@ -36,6 +38,7 @@ message GenerateRequest {
|
|||||||
repeated string roles = 2;
|
repeated string roles = 2;
|
||||||
map<string, string> metadata = 3;
|
map<string, string> metadata = 3;
|
||||||
int64 secret_expiry = 4;
|
int64 secret_expiry = 4;
|
||||||
|
string namespace = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GenerateResponse {
|
message GenerateResponse {
|
||||||
|
@ -85,6 +85,7 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e
|
|||||||
Id: id,
|
Id: id,
|
||||||
Roles: options.Roles,
|
Roles: options.Roles,
|
||||||
Metadata: options.Metadata,
|
Metadata: options.Metadata,
|
||||||
|
Namespace: options.Namespace,
|
||||||
SecretExpiry: int64(options.SecretExpiry.Seconds()),
|
SecretExpiry: int64(options.SecretExpiry.Seconds()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -275,9 +276,10 @@ func serializeAccount(a *authPb.Account) *auth.Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &auth.Account{
|
return &auth.Account{
|
||||||
ID: a.Id,
|
ID: a.Id,
|
||||||
Roles: a.Roles,
|
Roles: a.Roles,
|
||||||
Metadata: a.Metadata,
|
Metadata: a.Metadata,
|
||||||
Secret: secret,
|
Namespace: a.Namespace,
|
||||||
|
Secret: secret,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,14 @@ func (b *Basic) Generate(subject string, opts ...token.GenerateOption) (*auth.To
|
|||||||
|
|
||||||
// construct the token
|
// construct the token
|
||||||
token := auth.Token{
|
token := auth.Token{
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Type: b.String(),
|
Type: b.String(),
|
||||||
Token: uuid.New().String(),
|
Token: uuid.New().String(),
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
Expiry: time.Now().Add(options.Expiry),
|
Expiry: time.Now().Add(options.Expiry),
|
||||||
Metadata: options.Metadata,
|
Metadata: options.Metadata,
|
||||||
Roles: options.Roles,
|
Roles: options.Roles,
|
||||||
|
Namespace: options.Namespace,
|
||||||
}
|
}
|
||||||
|
|
||||||
// marshal the account to bytes
|
// marshal the account to bytes
|
||||||
|
@ -11,8 +11,9 @@ import (
|
|||||||
|
|
||||||
// authClaims to be encoded in the JWT
|
// authClaims to be encoded in the JWT
|
||||||
type authClaims struct {
|
type authClaims struct {
|
||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
Metadata map[string]string `json:"metadata"`
|
Metadata map[string]string `json:"metadata"`
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
|
|
||||||
jwt.StandardClaims
|
jwt.StandardClaims
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ func (j *JWT) Generate(subject string, opts ...token.GenerateOption) (*auth.Toke
|
|||||||
// 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{
|
||||||
options.Roles, options.Metadata, jwt.StandardClaims{
|
options.Roles, options.Metadata, options.Namespace, jwt.StandardClaims{
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
ExpiresAt: expiry.Unix(),
|
ExpiresAt: expiry.Unix(),
|
||||||
},
|
},
|
||||||
@ -61,13 +62,14 @@ func (j *JWT) Generate(subject string, opts ...token.GenerateOption) (*auth.Toke
|
|||||||
|
|
||||||
// return the token
|
// return the token
|
||||||
return &auth.Token{
|
return &auth.Token{
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Token: tok,
|
Token: tok,
|
||||||
Type: j.String(),
|
Type: j.String(),
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
Expiry: expiry,
|
Expiry: expiry,
|
||||||
Roles: options.Roles,
|
Roles: options.Roles,
|
||||||
Metadata: options.Metadata,
|
Metadata: options.Metadata,
|
||||||
|
Namespace: options.Namespace,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,10 +100,11 @@ func (j *JWT) Inspect(t string) (*auth.Token, error) {
|
|||||||
|
|
||||||
// return the token
|
// return the token
|
||||||
return &auth.Token{
|
return &auth.Token{
|
||||||
Token: t,
|
Token: t,
|
||||||
Subject: claims.Subject,
|
Subject: claims.Subject,
|
||||||
Metadata: claims.Metadata,
|
Metadata: claims.Metadata,
|
||||||
Roles: claims.Roles,
|
Roles: claims.Roles,
|
||||||
|
Namespace: claims.Namespace,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,8 @@ type GenerateOptions struct {
|
|||||||
Metadata map[string]string
|
Metadata map[string]string
|
||||||
// Roles/scopes associated with the account
|
// Roles/scopes associated with the account
|
||||||
Roles []string
|
Roles []string
|
||||||
|
// Namespace the account belongs too
|
||||||
|
Namespace string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GenerateOption func(o *GenerateOptions)
|
type GenerateOption func(o *GenerateOptions)
|
||||||
@ -82,6 +84,13 @@ func WithRoles(rs ...string) func(o *GenerateOptions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithNamespace for the token
|
||||||
|
func WithNamespace(n string) func(o *GenerateOptions) {
|
||||||
|
return func(o *GenerateOptions) {
|
||||||
|
o.Namespace = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
Loading…
Reference in New Issue
Block a user