Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Do not assume admin privileges on keystone #123

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions caso/extract/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from caso import keystone_client
from caso import loading

from keystoneauth1.exceptions.catalog import EmptyCatalog
from keystoneauth1.exceptions.http import Forbidden

cli_opts = [
cfg.ListOpt(
"projects",
Expand Down Expand Up @@ -119,12 +122,20 @@ def __init__(self):
def projects(self):
"""Get list of configured projects."""
projects = CONF.projects
aux = [i.id for i in self.keystone.projects.list(tags=CONF.caso_tag)]
aux = []
try:
aux = [i.id for i in self.keystone.projects.list(tags=CONF.caso_tag)]
except Forbidden as e:
LOG.warning(f"Unable to get projects from Keystone, ignoring - {e}")
return set(projects + aux)

def _get_keystone_client(self):
def _get_keystone_client(self, project=None, system_scope="all"):
"""Get a Keystone Client to get the projects that we will use."""
client = keystone_client.get_client(CONF, system_scope="all")
if project:
system_scope = None
client = keystone_client.get_client(CONF,
project=project,
system_scope=system_scope)
return client

def get_lastrun(self, project):
Expand Down Expand Up @@ -195,7 +206,14 @@ def voms_map(self):

def get_project_vo(self, project_id):
"""Get the VO where the project should be mapped."""
project = self.keystone.projects.get(project_id)
try:
project = self.keystone.projects.get(project_id)
except (EmptyCatalog, Forbidden):
# we may need scoping here, retrying
LOG.warning(f"Scoping the keystone client to the current project {project_id}")
self.keystone = self._get_keystone_client(project_id)
project = self.keystone.projects.get(project_id)

project.get()
vo = project.to_dict().get(CONF.vo_property, None)
if vo is None:
Expand Down
2 changes: 1 addition & 1 deletion caso/extract/openstack/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _get_keystone_session(self):

def _get_keystone_client(self):
"""Get a Keystone Client for the configured project in the object."""
client = keystone_client.get_client(CONF, system_scope="all")
client = keystone_client.get_client(CONF, project=self.project, system_scope="all")
return client

def _get_cinder_client(self):
Expand Down
2 changes: 1 addition & 1 deletion caso/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CloudRecord(_BaseRecord):

image_id: typing.Optional[str]

public_ip_count = 0
public_ip_count: int = pydantic.Field(0)
cpu_count: int
memory: int
disk: int
Expand Down