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

[auth] More easily add developers to developer namespaces #13180

Merged

Conversation

daniel-goldstein
Copy link
Contributor

@daniel-goldstein daniel-goldstein commented Jun 14, 2023

I decided to break off this chunk from another PR that has stalled. That PR will ultimately build on this to add all developers automatically to dev AND test namespaces, but this should be an improvement for now. A few things in here:

  • Deleted all the DatabaseResource stuff in the auth driver. Since databases now are created and destroyed with the namespace and not the developer, this is basically dead code.
  • Added the ability to add a user for an existing hail identity. This is only permitted in dev namespaces and serves as a way for developers to use the same hail identity across namespaces. There is one caveat here: create_initial_account.py tries to copy the <dev-name>-gsa-key secret from default into the developer namespace and this code will not do that anymore. For the developer to submit jobs to the namespace, they must first manually copy in the secret from default if it does not already exist inside the namespace. This is awkward, but IMO acceptable because:
    • the copying code in create_initial_account.py is already broken anyway because when that script is run in a dev deploy it does not have access to production secrets
    • I hope that when we eventually go keyless we can delete the gsa key secrets and this whole problem goes away.
    • I feel like it's not too bad to do this manual one time copy as opposed to maintaining code that is privileged enough to reach across namespaces. Seems error prone and like a security headache.
  • Deletes create_initial_account.py in favor of using our actual API to create the dev user.

@@ -481,21 +398,14 @@ async def _create_user(app, user, skip_trial_bp, cleanup):
updates['hail_credentials_secret_name'] = hail_credentials_secret_name

namespace_name = user['namespace_name']
if namespace_name is None and user['is_developer'] == 1:
# auth services in test namespaces cannot/should not be creating and deleting namespaces
if namespace_name is None and user['is_developer'] == 1 and not is_test_deployment:
Copy link
Contributor Author

@daniel-goldstein daniel-goldstein Jun 14, 2023

Choose a reason for hiding this comment

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

Prior to this line of code, adding a developer to a dev namespace through the auth API would cause their namespace to be deleted. It feels generally correct that a dev/test auth should not be creating/deleting namespaces.

@@ -53,7 +53,6 @@ async def _deploy(branch: str, steps: List[str], excluded_steps: List[str], extr

deploy_config = get_deploy_config()
steps = unpack_comma_delimited_inputs(steps)
print(steps)
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 accidentally snuck in when I was rewriting hailctl.

jigold
jigold previously requested changes Jun 15, 2023
Copy link
Contributor

@jigold jigold left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you for the comments inlined into the code.

For the developer to submit jobs to the namespace, they must first manually copy in the secret from default if it does not already exist inside the namespace.

Can we dummy proof this a bit more to have a nice error message if this is not the case?

@daniel-goldstein
Copy link
Contributor Author

Can we dummy proof this a bit more to have a nice error message if this is not the case?

Happy to, but I'm not exactly sure what you mean by "if this is not the case". What would you like to add?

@@ -481,21 +398,14 @@ async def _create_user(app, user, skip_trial_bp, cleanup):
updates['hail_credentials_secret_name'] = hail_credentials_secret_name

namespace_name = user['namespace_name']
if namespace_name is None and user['is_developer'] == 1:
# auth services in test namespaces cannot/should not be creating and deleting namespaces
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would want a check here if it is a dev deployment that the expected secret given by hail_credentials_secret_name exists in that namespace using the k8s client.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this should be the create_user function in auth.py

@daniel-goldstein daniel-goldstein dismissed jigold’s stale review June 15, 2023 15:52

Done. I tried to add jigold to my namespace in azure using hailctl before copying the secret, got the BadRequest error. Copied the secret, and then created the user successfully with hailctl.

jigold
jigold previously requested changes Jun 15, 2023
try:
k8s_cache: K8sCache = request.app['k8s_cache']
res = await k8s_cache.read_secret(hail_credentials_secret_name, DEFAULT_NAMESPACE)
log.info(res)
Copy link
Contributor

Choose a reason for hiding this comment

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

delete?

log.info(res)
except kubernetes_asyncio.client.rest.ApiException as e:
raise web.HTTPBadRequest(
text=f'hail credentials secret name specified but was not found: {hail_credentials_secret_name}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add the namespace we're looking at as well in the error message?

@danking danking merged commit 54e3fad into hail-is:main Jun 15, 2023
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.

3 participants