-
Notifications
You must be signed in to change notification settings - Fork 9
Conversation
@@ -330,7 +310,7 @@ func (p *policyd) fetchPolicy(ctx context.Context, domain string) (*SignedPolicy | |||
return sp, true, nil | |||
} | |||
|
|||
func simplifyAndCachePolicy(ctx context.Context, rp gache.Gache, sp *SignedPolicy) error { | |||
func simplifyAndCachePolicy(ctx context.Context, dom string, sp *SignedPolicy) (map[string][]*Assertion, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func simplifyAndCachePolicy(ctx context.Context, dom string, sp *SignedPolicy) (map[string][]*Assertion, error) { | |
func simplifyPolicy(ctx context.Context, dom string, sp *SignedPolicy) (map[string][]*Assertion, error) { |
continue | ||
} | ||
|
||
// remove duplication of `role+action+reource' assertion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// remove duplication of `role+action+reource' assertion | |
// remove duplication of `role+action+resource' assertion |
@@ -343,6 +323,12 @@ func simplifyAndCachePolicy(ctx context.Context, rp gache.Gache, sp *SignedPolic | |||
case <-ctx.Done(): | |||
return ctx.Err() | |||
default: | |||
if strings.SplitN(ass.Role, ":role.", 2)[0] != dom { | |||
glg.Errorf("role is not matches with the domain, role: %v, domain: %v", ass.Role, dom) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glg.Errorf("role is not matches with the domain, role: %v, domain: %v", ass.Role, dom) | |
glg.Debugf("role is not matches with the domain, role: %v, domain: %v", ass.Role, dom) |
// cache | ||
var retErr error | ||
assm.Range(func(k interface{}, val interface{}) bool { | ||
ass := val.(*util.Assertion) | ||
a, err := NewAssertion(ass.Action, ass.Resource, ass.Effect) | ||
if err != nil { | ||
glg.Debugf("error adding assertion to the cache, err: %v", err) | ||
glg.Errorf("error adding assertion to the cache, assertion: %+v, err: %v", ass, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glg.Errorf("error adding assertion to the cache, assertion: %+v, err: %v", ass, err) | |
glg.Errorf("error creating policy.Assertion, assertion: %+v, err: %v", ass, err) |
SetExpiredHook(func(ctx context.Context, key string) { | ||
//key = <domain>:role.<role> | ||
p.fetchAndCachePolicy(ctx, strings.Split(key, ":role.")[0]) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ExpiredHook is called after delete, checking policy between time gap with cause error
- retry on ExpiredHook fail?
- fetchAndCachePolicy() error is not print inside the ExpiredHook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to: #28
if roleAsss, ok := p.rolePolicies.Get(domain); ok { | ||
if asss, ok := roleAsss.(map[string][]*Assertion)[r]; ok { | ||
for _, ass := range asss { | ||
glg.Debugf("Checking policy domain: %s, role: %v, action: %s, resource: %s, assertion: %v", domain, roles, action, resource, ass) | ||
if strings.EqualFold(ass.ResourceDomain, domain) && ass.Reg.MatchString(strings.ToLower(action+"-"+resource)) { | ||
ch <- ass.Effect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will have deadlock here, when multiple deny policy match.
- ech size = 1
- read from ech only 1 times
- when, write more than 2, the go func cannot return, wg.Wait() will block forever
I think the old logic may still have the same problem,
but the old logic handles ctx cancel in a better way,
better to keep the old logic first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to: #30
|
||
go func() { | ||
defer close(ech) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to close the channel explicitly
closed by #27 |
No description provided.