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 importing models created by local users #1037

Merged

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Aug 28, 2023

Description

Add the ability for a JIMM admin to import a model that belongs to a local user of a controller.
Currently importing a model that already exists but belongs to a local user will fail because JIMM requires that all models have an associated cloud-credential. A cloud-credential for a local user will never be something that JIMM is aware of.

A good follow-up to this would be the removal of associating cloud-credentials with a model since a cloud-credential is only needed once, when the model is created so it doesn't make sense to persist that info in JIMM.

Fixes CSS-4612

Engineering checklist

Check only items that apply

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

internal/jimm/controller.go Outdated Show resolved Hide resolved
local/candid/config.yaml Outdated Show resolved Hide resolved
Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

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

LGTM, surprised this wasn't already there

Copy link
Collaborator

@alesstimec alesstimec left a comment

Choose a reason for hiding this comment

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

Hmm.. not really fond of this approach because the user doing the import automatically becomes the model owner.

Here's what i propose:

  • whoever is doing the import must be JIMM admin
  • we introduce an additional parameter to the command which will specify who is to be set as owner of the model - this way we basically say "we know owner is a local user, but we want that user to map to this specific user"

internal/jimm/controller.go Outdated Show resolved Hide resolved
@kian99
Copy link
Contributor Author

kian99 commented Aug 30, 2023

@alesstimec

  • It's already the case that the user doing the import must be a JIMM admin.
  • We could do that, but that breaks existing clients, not a biggie, we just need to release a new client version. But I think this approach is somewhat cleaner in that regard, the user doing the import should be the owner (we already check they're a JIMM admin) and they can grant access to whoever they want.

@kian99
Copy link
Contributor Author

kian99 commented Sep 5, 2023

@alesstimec @ale8k
I addressed Ales' comments and changed the import-model function to accept an owner parameter to allow the user to explicitly change the owner of the model. Please take another look.

@@ -40,7 +40,7 @@ jobs:
- name: Start test environment
run: docker compose up -d
- name: Build and Test
run: go test -mod readonly ./...
run: go test -mod readonly ./... -coverprofile cover.out
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 is a driveby change to add coverage information to the output of our tests

@@ -34,7 +34,7 @@ build/server: version/commit.txt version/version.txt
go build -tags version ./cmd/jimmsrv

check: version/commit.txt version/version.txt
go test -p 1 -timeout 30m -tags version $(PROJECT)/...
go test -timeout 30m $(PROJECT)/... -coverprofile cover.out
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also cleaned this up a bit, let me know if you notice anything wrong with these changes. I don't think we are using this make target anywhere though

Copy link
Member

Choose a reason for hiding this comment

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

Without -p 1 I expect the tests to be run in parallel. Right?

Copy link
Contributor

Choose a reason for hiding this comment

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

You need to call t.Parallel to have parallelism in tests

Copy link
Contributor Author

@kian99 kian99 Sep 6, 2023

Choose a reason for hiding this comment

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

I believe so, and I assume that's fine because our CI runs the test without that flag set. Though perhaps that's where the failing watcher tests come from? Alex explained above re parallelism

Copy link
Collaborator

@alesstimec alesstimec left a comment

Choose a reason for hiding this comment

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

LTGM with a few suggestions..

cmd/jimmctl/cmd/importmodel.go Show resolved Hide resolved
internal/jimm/controller.go Show resolved Hide resolved
internal/jimm/controller.go Outdated Show resolved Hide resolved
Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

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

Just to make sure things are traceable, does the audit log record contain both the commanding user and the new-owner (if provided with --owner option)?

@@ -34,7 +34,7 @@ build/server: version/commit.txt version/version.txt
go build -tags version ./cmd/jimmsrv

check: version/commit.txt version/version.txt
go test -p 1 -timeout 30m -tags version $(PROJECT)/...
go test -timeout 30m $(PROJECT)/... -coverprofile cover.out
Copy link
Member

Choose a reason for hiding this comment

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

Without -p 1 I expect the tests to be run in parallel. Right?

owner.SetTag(ownerTag)
err = j.Database.GetUser(ctx, &owner)
if ownerTag.IsLocal() {
return errors.E(op, "cannot import model from local user, try --owner to switch the model owner")
Copy link
Member

Choose a reason for hiding this comment

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

This message is a little confusing for me. Also, there was no test to reproduce it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll add one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be better explained in our documentation, what are local users vs external users. I mentioned --owner to help nudge the user towards reading the jimmctl import-model --help text which explains further

if err != nil {
return errors.E(op, err)
errors.E(op, err)
Copy link
Member

Choose a reason for hiding this comment

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

Why not returning the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Big woops, good spot

@kian99
Copy link
Contributor Author

kian99 commented Sep 6, 2023

@babakks >Just to make sure things are traceable, does the audit log record contain both the commanding user and the new-owner (if provided with --owner option)?

The audit logs should contains all the params for the call so it would include the user and the new owner

@kian99 kian99 merged commit 30c6c9d into canonical:main Sep 6, 2023
1 check passed
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.

4 participants