Skip to content

Conversation

@yencli
Copy link

@yencli yencli commented Jan 6, 2017

The "PrivateData" parameter from Slurm configuration is now partially introduced to slurm-web. However, this change is only compatible with a modified version of pyslurm that contains an extra output (see edf-hpc/pyslurm@634ed69). Also, the mocks for testing are modified along with.

Jobs and Reservations views are affected in this change. Regular users may only see their own jobs or reservations if defined in PrivateData previously.

Copy link
Contributor

@rezib rezib left a comment

Choose a reason for hiding this comment

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

Additionally to all other comments, can you please also move mocks mods into a separate commit to avoid confusions between the feature and all the stuff related to tests.

doc/usage.rst Outdated

.. figure:: img/screenshot_job_close_details.*

The Jobs view starts taking Slurm's Private Data parameter into account partially
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be mentioned only in the usage guide but also in the installation (§auth) and architecture guides (§auth). It is useless to mention slurm-web version since the documentation is versioned along with the software. A link should be added to related slurm documentation. The possible values with their impact on slurm-web behaviour should be explained explicitely. The mention "partially taken into account" is definitely too vague.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please also explain what guest user still has access to in presence of privatedata.

doc/usage.rst Outdated
#. The start time of this reservation
#. The end time of this reservation

The Reservation view starts taking Slurm's Private Data parameter into account partially
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid copy/paste.

@authentication_verify()
@cache()
def get_reservations():
if auth_enabled:
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens here if auth is disabled?

rest/auth.py Outdated
to be enabled to retrieve current user")

token = request.headers['Authorization'].split()[1]
return User.verify_auth_token(token)
Copy link
Contributor

Choose a reason for hiding this comment

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

Explain in comment why you don't catch the auth verification exceptions here.

return abort(403, "Authentication has \
to be enabled to retrieve current user")

token = request.headers['Authorization'].split()[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

The token extraction logic should be factorized to avoid loosely access to request headers dict from anywhere in the code.

)
return jobs

if onlyUsersJobs:
Copy link
Contributor

Choose a reason for hiding this comment

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

This if should be removed. We should have only one dict of jobs at this point, whatever the value of onlyUsersJobs is true or false.

# pyslurm >= 16.05 expects a string in parameter of job.find_id()
job = pyslurm.job().find_id(str(job_id))
fill_job_user(job)
config = pyslurm.config().get()
Copy link
Contributor

Choose a reason for hiding this comment

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

What if auth is disabled?

def find_id(self, jobid):
for job in context.CTLD.jobs:
if job.jobid == jobid:
if str(job.jobid) == str(jobid):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably useless since all jobids should already be strings at this point.

result = {}
if auth_enabled:
# Fetch the attributs of private_data
config = pyslurm.config().get()
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic to extract the configuration, parse the privatedata and set a boolean should done in a factorized function since this code is very similar in the various routes.

@rezib
Copy link
Contributor

rezib commented Jan 9, 2017

2 additional notes:

  • Your commit message does not follow the contribution guidelines. It also mentions a commit hash that has to be reverted so it will disappear in the long term. You can eventually add a reference to a commit hash but it must be a commit on upstream repository of PySLURM.
  • Can you please also remove this weird merge commit from the commit list?

yencli added a commit to yencli/slurm-web that referenced this pull request Jan 16, 2017
Updates following "Add jobs and reservations privacy settings rackslab#149".
Elements built previously for data privacy settings are refactored and documentation has been added.
yencli added a commit to yencli/slurm-web that referenced this pull request Jan 16, 2017
Updates following "Add jobs and reservations privacy settings rackslab#149".
Elements built previously for data privacy settings are refactored and documentation has been added.
rezib added a commit that referenced this pull request Jan 17, 2017
This reverts commit 27a47fd since it
has several issues. Notably, it does not compile on python 2.6:

$ python -m py_compile rest/slurmrestapi.py
SyntaxError: ('invalid syntax', ('rest/slurmrestapi.py', 241, 24, ' \
  return {k: v for k, v in reservations.iteritems()\n'))

The feature is reviewed in PR #149.
@rezib
Copy link
Contributor

rezib commented Jan 17, 2017

Can you please rebase your PR on current master branch 431e189?

Can you also please respect contribution guidelines (https://github.com/edf-hpc/slurm-web/blob/master/CONTRIBUTING.md) in your commit messages?

@yencli yencli force-pushed the master branch 5 times, most recently from 3c12ccb to d8407da Compare January 17, 2017 13:41

Slurm-web also takes into account of the Private data parameter from
`Slurm <https://slurm.schedmd.com/slurm.conf.html>`_. The python wrapper
edf-hpc/`pyslurm <https://github.com/edf-hpc/pyslurm/>`_ has been
Copy link
Contributor

@rezib rezib Jan 18, 2017

Choose a reason for hiding this comment

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

The ling to Slurm configuration man is not properly formatted in generated documentation. The fact that PySLURM has been modified is not a useful information for slurm-web users and administrators. Please fix this.

doc/usage.rst Outdated
parameter in edf-hpc/`pyslurm <https://github.com/edf-hpc/pyslurm/>`_. The original
description can be found in`Slurm <https://slurm.schedmd.com/slurm.conf.html>`_.
If ``jobs`` has been defined previously in Slurm configuration, regular users can
only see their own jobs whereas the superusers see all the jobs and guests can see
Copy link
Contributor

Choose a reason for hiding this comment

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

Slurm-web has no notion of superusers. There are admins, users and guests but none superusers.



# Retrive current user role and login
def get_current_user():
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add docstring to explain what this function does, notably in which cases it aborts.



def retrieve_token():
if 'Authorization' not in request.headers:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add docstring to explain what this function does, notably in which case it aborts.

Copy link
Author

Choose a reason for hiding this comment

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

The file has been updated.

rest/auth.py Outdated
to be enabled to retrieve current user")

token = retrieve_token()
# No exception is thrown from this method but return None when failed
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is wrong, it does not return None.


token = retrieve_token()
# No exception is thrown from this method but return None when failed
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a copy/paste of the code in the decorator, please factorize.

jobs = pyslurm.job().get()
result = {}
if auth_enabled:
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

PEP-8 says that block comment should use #[1], not docstrings, please fix it.

[1] https://www.python.org/dev/peps/pep-0008/#block-comments



def check_private_data_for_entity(user, entity):
onlyUsersEntities = False
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add docstring to explain what this function does.

Copy link
Contributor

Choose a reason for hiding this comment

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

The user argument is not used, please fix it.

Copy link
Author

Choose a reason for hiding this comment

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

The user argument is used as well as entity.

Copy link
Contributor

Choose a reason for hiding this comment

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

The code sets currentUser with user but currentUser then receives the result of get_current_user() before being actually used if the if check. If you remove currentUser = user the function is the same. Then, no, the argument is definitely not used.

@yencli yencli force-pushed the master branch 4 times, most recently from 0cab2fe to ecb078e Compare January 23, 2017 08:39
@yencli yencli force-pushed the master branch 5 times, most recently from acfec8f to 28af211 Compare February 6, 2017 08:45
Copy link
Contributor

@rezib rezib left a comment

Choose a reason for hiding this comment

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

PEP8 says variable names must be in lowercase separated by underscore. For instance, you should replace currentUser by current_user. Please fix this.

return onlyUsersEntities


def filter_entities(entity, entitiesList):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add missing docstring here.

rest/cache.py Outdated


def cache():
def cache(userSpecific=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a good solution as the cache is not shared between users. It implies that n different users accessing the jobs will generate n RPC to slurmctld and this is not what we want. N users accessing the jobs in a short period of time (< jobs cache expiration) should generate only 1 RPC to slurmctld.

Copy link
Author

Choose a reason for hiding this comment

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

Do you prefer to have the job filter inside the cache?

Copy link
Contributor

Choose a reason for hiding this comment

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

Clearly, no. This cache function is not about jobs so there is no reason to filter jobs here. Caching and filtering are 2 different purposes that must be treated separately.

Copy link
Author

Choose a reason for hiding this comment

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

Any suggestion? Userspecific only when privateData is on?

Copy link
Contributor

Choose a reason for hiding this comment

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

Userspecific only when privateData is on?

This doesn't solve the mentioned problem neither.

For me, the right solution is to manage the cache at pyslurm calls level, not at API route level. This is what I suggested last friday.

Private Data settings.
"""
onlyUsersEntities = False
currentUser = user
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid this useless additional variable. The rest of the function code can simply use the user argument directly.

currentUser, entity)

if onlyUsersEntities:
# if private data is applied and the jobs' owner is different from
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is wrong as the logic here is not only about jobs.

# show if auth disabled, onlyUsersJobs becomes always False and all
# the jobs are added to the job list to show

return dict((k, v) for k, v in entitiesList.iteritems()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the indentation here:

C:556, 0: Wrong continued indentation.
                        v['users']) or (entity == 'jobs' and
                        ^| (bad-continuation)
C:557, 0: Wrong continued indentation.
                        currentUser.login == v['login'])))
                        ^               | (bad-continuation)

The readability of the of this nested logic is not that great. I think it would be relevantly replaced by an additional if statement before the return and its iteration...

@yencli yencli force-pushed the master branch 2 times, most recently from da04f2f to 1f4aff9 Compare February 7, 2017 08:57
@rezib
Copy link
Contributor

rezib commented Feb 7, 2017

Please split commit with cache mechanism change and privatedata introduction. Even though the later requires the former, they are 2 distinct and complex things that really deserve 2 separate commits.

@rezib
Copy link
Contributor

rezib commented Feb 7, 2017

Cache change is a requirement for privatedata so please put cache change before privatedata introduction.

@yencli yencli force-pushed the master branch 5 times, most recently from ce1038b to c555876 Compare February 7, 2017 12:41
@rezib
Copy link
Contributor

rezib commented Feb 7, 2017

Please remove the @cache decorator everywhere as it is confusing to have 2 distinct ways of using the cache.

@rezib
Copy link
Contributor

rezib commented Feb 8, 2017

Please remove the code of the cache decorator itself as it is useless as of now.

@yencli
Copy link
Author

yencli commented Feb 8, 2017

OK, I removed the decorator.

''.join("%s-%r" % (key, val) for (key,
val) in kwargs.iteritems())
)
def get_from_cache(f, overrideName=None, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a docstring on this new function.

reservations = get_from_cache(
pyslurm.reservation().get, 'get_reservations')
return reservations
return filter_entities('reservations', reservations)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lot of changes are missing in this file.

Copy link
Author

Choose a reason for hiding this comment

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

I put it back.

This modification prevents regular users from seeing other users'
previous requests before the caches expired.
The application of Slurm's Private Data settings for jobs and
reservations has been introduced to Slurm-web.

Descriptions of Slurm's configuration can be found in
https://slurm.schedmd.com/slurm.conf.html (see "PrivateData").This
implies that regular users may only see their own jobs or reservations
if PrivateData is set previously in Slurm's configuration. Associated
documentations has been updated accordingly.
Update mock pyslurm and define private_data in 2 mock clusters.
@rezib
Copy link
Contributor

rezib commented Feb 8, 2017

OK, it's been merged.

@rezib rezib closed this Feb 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants