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

Enable NWC to mutate workflows created by service accounts #16

Merged
merged 15 commits into from
Jul 20, 2023

Conversation

iameskild
Copy link
Member

@iameskild iameskild commented May 31, 2023

Reference Issues or PRs

This PR is a related to the work being done to integrate Jupyter-Scheduler (#1832).

What does this implement/fix?

Put a x in the boxes that apply

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds a feature)
  • Breaking change (fix or feature that would cause existing features not to work as expected)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • Other (please describe):

Testing

  • Did you test the pull request locally?
  • Did you add new tests?

Documentation

Access-centered content checklist

Text styling

  • The content is written with plain language (where relevant).
  • If there are headers, they use the proper header tags (with only one level-one header: H1 or # in markdown).
  • All links describe where they link to (for example, check the Nebari website).
  • This content adheres to the Nebari style guides.

Non-text content

  • All content is represented as text (for example, images need alt text, and videos need captions or descriptive transcripts).
  • If there are emojis, there are not more than three in a row.
  • Don't use flashing GIFs or videos.
  • If the content were to be read as plain text, it still makes sense, and no information is missing.

Any other comments?

@iameskild iameskild changed the title [WIP] Enable NWC to mutate workflows created by service accounts Enable NWC to mutate workflows created by service accounts Jun 13, 2023
@iameskild iameskild requested a review from Adam-D-Lewis June 13, 2023 13:04
@iameskild iameskild added area: user experience 👩🏻‍💻 needs: review 👀 This PR is complete and ready for reviewing type: enhancement 💅🏼 New feature or request labels Jun 13, 2023
@@ -45,6 +48,28 @@ def sent_by_argo(workflow: dict):
return None


def valid_argo_roles():
# TODO: determine a more extensible way of generating a list of valid roles
return ["argo-admin", "argo-developer"]
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be a config option somehow. Most other things in Nebari use traitlets, but I'd feel okay using an VALID_ARGO_ROLES ENV var for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, this is not a good solution. I added a configmap to the nebari-workflow-controller deployment that provides a list of valid Argo roles (here). How does that solution work for you?

Comment on lines 123 to 129
preferred_username = workflow["metadata"]["labels"][
"workflows.argoproj.io/creator-preferred-username"
]
if validate_service_account(keycloak_uid):
for user in kcadm.get_users():
if user["username"] == preferred_username:
return user["id"], preferred_username
Copy link
Member

Choose a reason for hiding this comment

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

This won't work in some cases. You can't always go back to the actual username b/c "Labels only contain [-_.0-9a-zA-Z]", so any other characters will be turned into "-") so not a 1 to 1 mapping.

Copy link
Member Author

@iameskild iameskild Jul 12, 2023

Choose a reason for hiding this comment

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

That's a good catch! I realize though that this is an issue elsewhere here. I added both the sanitize_label and desanitize_label functions to handle grabbing usernames from k8s labels. This is how JupyterHub converts usernames with disallowed characters (although I can't find the source code for how they accomplish this).

The two places where this is most important are:

  • when we list_namespaced_pods based on keycloak username (here)
  • when we grab the username from the label (here)

Copy link
Member

@Adam-D-Lewis Adam-D-Lewis left a comment

Choose a reason for hiding this comment

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

see comments

@iameskild iameskild requested a review from Adam-D-Lewis July 12, 2023 20:01
@Adam-D-Lewis
Copy link
Member

Have you run the tests? Could we add a test for the new functionality?

costrouc

This comment was marked as outdated.

Copy link
Member

@costrouc costrouc left a comment

Choose a reason for hiding this comment

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

LGTM. But like @Adam-D-Lewis mentioned it would be helpful to have tests for this worklfow.

@iameskild
Copy link
Member Author

@costrouc @Adam-D-Lewis I added new tests that cover the special case where the Workflow was created via a service-account.

@iameskild iameskild requested a review from costrouc July 20, 2023 01:35
Copy link
Member

@costrouc costrouc left a comment

Choose a reason for hiding this comment

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

@iameskild this are some detailed tests and I like the fixtures that you created in conftest.py. Thanks! LGTM.

@costrouc
Copy link
Member

Since @Adam-D-Lewis is on PTO and we are trying to get a release out for nebari. I am comfortable with merging. @iameskild feel free to merge when it works best.

@iameskild iameskild merged commit aa6b897 into main Jul 20, 2023
@iameskild iameskild deleted the 20230531eae branch July 20, 2023 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: user experience 👩🏻‍💻 needs: review 👀 This PR is complete and ready for reviewing type: enhancement 💅🏼 New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants