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

import offers during model import #1432

Open
wants to merge 3 commits into
base: v3
Choose a base branch
from

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Nov 12, 2024

Description

This PR does two things:

  1. Refactors the ImportModel method. I started getting linting errors on cognitive complexity when trying to add functionality so I took the time to refactor the method.
  2. Adds functionality to the ImportModel method to import a model's application-offers.

Please Note: The first commit contains only the first change and the second commit contains the second change.

One issue that remains is how to handle offer URLs that already exist. This will be tackled in a separate PR.

Partially fixes JUJU-7011

Engineering checklist

Check only items that apply

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

@kian99 kian99 requested a review from a team as a code owner November 12, 2024 12:13
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.

We need to discuss how to set access rights to imported application offers.

}
return nil
})
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: we run handleModelDeltas on L516, which will connect to the controller, create an all watcher and process a single set of deltas.. is that the intent?

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 can't say why it's like that, but that does seem intentional and has been that way for some time, the tests also verify the delta functionality.
The tests show that the deltas are used to update some properties of the model like the status fields, etc.

return errors.E(op, err)
}
for _, offer := range offersToAdd {
var dbOffer dbmodel.ApplicationOffer
Copy link
Collaborator

Choose a reason for hiding this comment

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

while this will add offers to JIMM's database, it will not grant anybody access to imported offers. At the very least, the user importing the model should be granted access.

this will require a bit of thought: each offer comes with a set of users that have access to the offer. If those are external users (those that JIMM cares about), they should be granted access to the offer when it is imported. But i guess in most cases these users would be local users - access to the offer will remain granted on the controller, but JIMM will not know/care about those rights. perhaps we should simply print this info and let the user importing the model handle it. e.g. we imported this model and these app offer and these are the users that have access to the app offer - handle 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.

True, I think we need to create an OpenFGA relation between the offers and the model. That way the model owner will automatically get access. Then they can grant access to other users. The users on the controller should never (at least with the new JIMM) be external users, because nowadays those are never stored on Juju's end (only in JIMM) so I think we can safely discard the users coming from the controller.

But yes printing a message would be helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, relation makes sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can do in a follow up PR @alesstimec

Copy link
Contributor

@SimoneDutto SimoneDutto left a comment

Choose a reason for hiding this comment

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

lgtm


if err := j.checkJimmAdmin(user); err != nil {
return err
func newModelImporter(jimm *JIMM) modelImporter {
Copy link
Collaborator

Choose a reason for hiding this comment

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

pass in the new owner name so that you can immediately return an error if we fail to parse the owner tag or owner is a local user

func newModelImporter(jimm *JIMM, ownerTag names.UserTag) (error, *modelImporter)

@@ -103,7 +103,7 @@ func (m *Model) SetTag(t names.ModelTag) {
m.UUID.Valid = true
}

// FromModelUpdate updates the model from the given ModelUpdate.
// SwitchOwner updates the model owner.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: SetOwner seems a more appropriate name


// TODO(CSS-5458): Remove the below section on cloud credentials once we no longer persist the relation between
// cloud credentials and models.
// Update: We need to investigate this further, if a user updates their cloud-credential it will update the credential
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm. this might be a bit confusing. if a user updates their cloud-credential, sure, jimm will try and update the cloud credential on the controller responsible for this model, but the actual credential used by the model will not be affected. the user would need to use the juju set-credential command to set credentials first and then update them to get the actual model cloud credentials updated.

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 this will need fixing I think. For a follow up PR.

})
}

// ImportModel imports model with the specified UUID from the controller.
Copy link
Contributor

Choose a reason for hiding this comment

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

imports a model and the currently existing offers into JIMM. A new owner must be set to represent the external user who will own this model.

Something like this for the comment?

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

- drive by fix to openfga rebac test that incorrectly assumed ordering
- ensure model owner has access to the offer
- Rename SwitchOwner to SetOwner
- Updated newModelImporter constructor
- Updated godoc
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