Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Log Authenticated User from UI-Server in Workflow Log #4522

Merged
merged 11 commits into from
Jan 25, 2022

Conversation

datamel
Copy link
Contributor

@datamel datamel commented Nov 17, 2021

Log the authenticated user executing the mutation command from the UI.

A test user pausing the workflow of another user, will result in a log message below in the workflow log:
image

The owner then resuming the workflow, will result in a log message..
image

These changes close #4294 and cylc/cylc-uiserver#224 by its sibling: cylc/cylc-uiserver#288

Requirements check-list

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to both setup.py and
    conda-environment.yml.
  • Appropriate tests are not included (unit and/or functional). - Only manually tested. This will require multi user testing setup to get this into the automated test battery.
  • No change log entry required (why? Logging change).
  • No documentation update required.

@datamel datamel self-assigned this Nov 17, 2021
@datamel datamel added this to the cylc-8.0rc1 milestone Nov 17, 2021
cylc/flow/network/client.py Outdated Show resolved Hide resolved
Comment on lines 187 to 188
if auth_user:
set_authenticated_user(self.header, auth_user)
Copy link
Member

Choose a reason for hiding this comment

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

This is updating the client's header which is shared between multiple requests (so potentially for multiple authenticated users). We can delay this a couple of lines and set it on the message rather than the shared header.

@@ -175,6 +184,8 @@ async def async_request(self, command, args=None, timeout=None):
# there is no need to encrypt messages ourselves before sending.

# send message
if auth_user:
set_authenticated_user(self.header, auth_user)
msg = {'command': command, 'args': args}
msg.update(self.header)
Copy link
Member

Choose a reason for hiding this comment

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

We can delay this a couple of lines

Here:

        msg.update(self.header)
        msg['meta']['auth_user'] = auth_user

cylc/flow/network/client.py Show resolved Hide resolved
command,
args=None,
timeout=None,
auth_user=None
Copy link
Member

Choose a reason for hiding this comment

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

If it's quick, it might be a good idea to generalise this to handle arbitrary metadata in a dictionary.

We could do:

# add the shared header
msg.update(self.header)
# add the request metadata
msg['meta'].update(request_meta)

This would make it easier to pass through additional information e.g. the app that issued the command or the GraphQL operation name (could be useful if the request contains multiple mutations).

@hjoliver
Copy link
Member

hjoliver commented Dec 7, 2021

@datamel - I'm quite keen to get this in! Are you planning to address @oliver-sanders 's comments above? (Pinging you just in case you missed them).

@datamel
Copy link
Contributor Author

datamel commented Dec 7, 2021

@datamel - I'm quite keen to get this in! Are you planning to address @oliver-sanders 's comments above? (Pinging you just in case you missed them).

Yes, on it today. Sorry for the delay. Had paused for the multi-mutation fix.

cylc/flow/scheduler.py Outdated Show resolved Hide resolved
@hjoliver
Copy link
Member

Tested both branches, looks good 👍

What gets logged for direct commands (not via the UIS) looks dodgy however:

INFO - Authenticated user ? has submitted request kill_tasks

vs

INFO - Authenticated user oliverh has submitted request force_trigger_tasks

Perhaps we could say owner has submitted request... for direct commands?

@MetRonnie MetRonnie self-requested a review January 19, 2022 12:17
result = (True, 'Command queued')
return [{'id': w_id, 'response': result}]

async def nodes_mutator(self, *m_args):
Copy link
Member

Choose a reason for hiding this comment

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

Why is nodes_mutator being removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was picked up when adding the unpacking of the meta and was discussed with @oliver-sanders, who looked at codecov for verification. It is seemingly dead code and was asked to remove it. Pinged @dwsutherland on the sibling to verify it is indeed unused code.

Copy link
Member

Choose a reason for hiding this comment

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

It was in use, until:
#3469
specifically:
https://github.com/cylc/cylc-flow/pull/3469/files#diff-97f4d62be41218e2d70a203edfca6d44d7c0046b6908cefa8e3af7c02cd31920

And the idea behind it was that mutations being multi-workflow could be given node ids from different workflows, and then these ids would be parsed and mutations sent to the appropriate workflow..

The fact that we moved away from this, means we are happy with not using this functionality... i.e. a node mutation will always be associated with only one workflow and/or the workflow parsing happens somewhere else.


# Hardcoded, for new - but much of this functionality can be
# removed more swingingly.
LOG.debug(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oliver-sanders, just thinking about removing this line. It does remove the comms_method which may be useful for debugging in future? Want me to put any logging information about the comms method to replace this, or are you happy with the info loss from the removal?

Copy link
Member

@oliver-sanders oliver-sanders Jan 20, 2022

Choose a reason for hiding this comment

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

We can pass the comms_method down with the metadata and log it with the command.

cylc/flow/network/resolvers.py Outdated Show resolved Hide resolved
Comment on lines -32 to -34
grep_ok "\[client-command\] graphql ssh" \
"$RUN_DIR/${WORKFLOW_NAME}/log/workflow/log"

Copy link
Member

Choose a reason for hiding this comment

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

This was a safety test to ensure that the comms method is logged.

Perhaps we could add a Cylc client command into the workflow e.g. cylc hold $CYLC_WORKFLOW_ID//1/elephant which should give us a [command] entry that we can check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, are you happy if I do this in the ssh async request PR as this test is broken anyway?

@oliver-sanders
Copy link
Member

Looking good, will have a quick test soon.

Co-authored-by: Oliver Sanders <oliver.sanders@metoffice.gov.uk>
@oliver-sanders
Copy link
Member

Tested, works wonderfully 🎉

@MetRonnie MetRonnie merged commit f6f6c14 into cylc:master Jan 25, 2022
@datamel datamel deleted the pass-user-to-cylc-flow branch September 1, 2022 14:04
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.

mutations: log the authenticated user
5 participants