salt icon indicating copy to clipboard operation
salt copied to clipboard

states.keystone fails to create user-roles for more than 1 tenant/user

Open smithjm opened this issue 13 years ago • 6 comments

The states.keystone module ignores additional tenants if more than one is specified for a user in defining the user-roles. It does work correctly for multiple roles if only one tenant is defined.

The following code fails:

admin_user:
  keystone.user_present:
    - password: "bogus"
    - email: [email protected]
    - tenant: admin_tenant
    - roles:
      - service_tenant:
        - admin_role
        - user_role
      - admin_tenant:
        - admin_role
  require:
    - keystone: Keystone_tenants
    - keystone: Keystone_roles
    - service: openstack-keystone

(Note the TWO tenants, service_tenant and admin_tenant, that are defining their respective user-roles). Basically, the service_tenant roles get created, but the admin_tenant role does not.

Not that it should matter (I think the bug is actually that multiple tenants are not recognized), but the above code is rendered from the original sls via pillars and substitution. The actual state and pillar sls snippets are below:

openstack_keystone.sls snippet:
{% for user, data in pillar['openstack']['users'].items() %}
{{ user }}:
  keystone.user_present:
    - password: "{{ data['password'] }}"
    - email: {{ data['email'] }}
    - tenant: {{ data['tenant'] }}
    - roles:
  {% for role_tenant, role_tenant_data in data['roles'].items() %}
      - {{ role_tenant }}:
    {% for role in role_tenant_data %}
        - {{ role }}
    {% endfor %}
  {% endfor %}
  require:
    - keystone: Keystone_tenants
    - keystone: Keystone_roles
    - service: openstack-keystone
{% endfor %}

where the users is defined in the pillar as follows:

/srv/pillar/openstack.sls:
{# NOTE THAT THE admin_user HAS 2 TENANTS DEFINING 3 USER-ROLES #}
openstack:
  users:
    admin_user:
      password: 'bogus'
      email: [email protected]
      tenant: admin_tenant
      roles:
        admin_tenant:
          - admin_role
        service_tenant:
          - admin_role
          - user_role
    imc_user:
      password: 'bogus2'
      email: [email protected]
      tenant: admin_tenant
      roles:
        user_tenant:
          - user_role
    nova_user:
      password: 'bogus3'
      email: [email protected]
      tenant: service_tenant
      roles:
        service_tenant:
          - admin_role

smithjm avatar Nov 29 '13 18:11 smithjm

Thanks for the report. We'll get this fixed.

basepi avatar Dec 02 '13 23:12 basepi

It should be noted that as of 0.17.4-1 I now get the following error for keystone.user_present. It appears that keystone.user_present is now completely broken:

State: - keystone
Name:      glance_user
Function:  user_present
    Result:    False
    Comment:   An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/state.py", line 1307, in call
ret = self.states[cdata['full']](*cdata['args'])
File "/usr/lib/python2.7/site-packages/salt/states/keystone.py", line 132, in user_present
if tenant and user[name]['tenant_id'] != tenant_id:
KeyError: 'tenant_id'

The odd thing is, nothing has changed in the pillar or the code, which works in 0.17.2-2

{% for user, data in pillar['openstack']['users'].items() %} {{ user }}: keystone.user_present: - password: "{{ data['password'] }}" - email: {{ data['email'] }} - tenant: {{ data['tenant'] }} - roles: {% for role_tenant, role_tenant_data in data['roles'].items() %} - {{ role_tenant }}: {% for role in role_tenant_data %} - {{ role }} {% endfor %} {% endfor %} require: - keystone: Keystone_tenants - keystone: Keystone_roles - service: openstack-keystone - cmd: initialize_keystone_with_database - mysql_database: create_keystone_db - mysql_user: create_keystone_user - mysql_grants: create_keystone_user - mysql_user: create_keystone_localuser - mysql_grants: create_keystone_localuser {% endfor %}

smithjm avatar Jan 02 '14 16:01 smithjm

@smithjm Is it still broken after @rhormaza's pull req?

basepi avatar Jan 06 '14 19:01 basepi

Apologies, it will be a couple of weeks before I can set up a developer test environment and test this.

smithjm avatar Jan 07 '14 13:01 smithjm

No worries. I am going to close this for now, as I think it is fixed. If that turns out not to be the case, please comment!

basepi avatar Jan 08 '14 19:01 basepi

This issue is still present in the current develop branch. To emphasize this using the example given by smithjm:

- roles:
  - service_tenant:
    - admin_role
    - user_role
  - admin_tenant:
    - admin_role

The roles are correctly set for service_tenant, but the admin_tenant gets completely ignored.

I suspect that there is something wrong with the tenant loop in the code (without having much programming knowledge that is, so i might be completely and utterly wrong too...). Line 176 states:

for tenant_role in roles[0]:

The [0] looks to me like it's somehow disabling the loop altogether and only processing the first list element...

Furthermore, the state doesn't seem to support the removal of roles. If i modify the state (after applying the original one) to read:

- roles:
  - service_tenant:
    - admin_role
  - admin_tenant:
    - admin_role

The role user_role doesn't get removed in service_tenant (while the admin_tenant still gets completely ignored)...

devweasel avatar Feb 18 '15 09:02 devweasel