Can't set_rules without using config file in policy

Bug #1279198 reported by Shuangtai Tian
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo-incubator
Fix Released
Medium
Shuangtai Tian

Bug Description

In the policy modules, the load_rules will always load the rules from the cache or config file when check the policy.
So the set_rules doesn't work. and the Enforcer init with rules also does not work.

for example:
   ENFORCER = policy.Enforcer()
   ENFORCER.set_rules({'a': 'b'})
   self.assertEqual(self.enforcer.rules, {'a': 'b'}) --- success
   action = 'a'
   creds = {'roles': ''}
   self.assertEqual(self.enforcer.enforce(action, {}, creds), True) -- failed

the last assert failed just because in the enforce() would call load_rules() and rewrote the rules using the config file (policy.json), the file is modified.
https://github.com/openstack/oslo-incubator/blob/master/openstack/common/policy.py#L228

Changed in oslo:
assignee: nobody → Shuangtai Tian (shuangtai-tian)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo-incubator (master)

Fix proposed to branch: master
Review: https://review.openstack.org/72848

Changed in oslo:
status: New → In Progress
Ben Nemec (bnemec)
Changed in oslo:
importance: Undecided → Medium
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo-incubator (master)

Reviewed: https://review.openstack.org/72848
Committed: https://git.openstack.org/cgit/openstack/oslo-incubator/commit/?id=15722f1702bc8c2fb2c93261a8d395f69bc4df1d
Submitter: Jenkins
Branch: master

commit 15722f1702bc8c2fb2c93261a8d395f69bc4df1d
Author: Shuangtai Tian <email address hidden>
Date: Wed Feb 12 14:09:53 2014 +0800

    Adds a flag to determine whether to reload the rules in policy

    Initing a Enforcer class with rules can not set rules, because the policy
    file is modified , the load_rules always try to load the rules from the cache
    or config file when checks the policy. This patch adds a flag to determine
    whether to reload the rules from policy file.

    Closes-Bug: #1279198

    Change-Id: Ife84189be4b86a3ee90da4539ff2dbed125be23d

Changed in oslo:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in oslo:
milestone: none → icehouse-3
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in oslo:
milestone: icehouse-3 → 2014.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.