Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

fix policy cache missing #26

Closed
wants to merge 1 commit into from
Closed

Conversation

kevindiu
Copy link
Member

No description provided.

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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])
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. ExpiredHook is called after delete, checking policy between time gap with cause error
  2. retry on ExpiredHook fail?
  3. fetchAndCachePolicy() error is not print inside the ExpiredHook

Copy link
Contributor

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
Copy link
Contributor

@WindzCUHK WindzCUHK Jul 22, 2019

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.

  1. ech size = 1
  2. read from ech only 1 times
  3. 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.

Copy link
Contributor

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)
Copy link
Contributor

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

@kpango
Copy link
Member

kpango commented Jul 25, 2019

closed by #27

@kpango kpango closed this Jul 25, 2019
@kpango kpango deleted the fix_etag_hit_policy_cache_empty branch July 25, 2019 04:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants