Skip to content

Conversation

speza
Copy link
Contributor

@speza speza commented Aug 2, 2020

  • Call GetAllSubjects() instead for listing RBAC roles. GetAllRoles() only gets roles that have actually been assigned to a user. This is because 'p' policy lines are defined for the roles. 'g' policy lines are for assignment of a role to a user. GetAllRoles() calls the 'g' line at index 2 to list roles.

  • Fixed a bug with role:readonly looking for wildcard 'get' action which no longer exists because our actions became more specific - e.g. 'pipelines:runs, get-run' rather than 'pipelines:runs, get'

  • Added a check to make sure all newly created roles have a prefix of 'role:x'

  • Made the instantiation of the rbac more testable by using DI instead of instantiating concrete resources within the constructor

  • Add missing service.go unit tests

* Call GetAllSubjects() instead for listing RBAC roles. GetAllRoles() only gets roles that have actually been assigned to a user. This is because 'p' policy lines are defined for the roles. 'g' policy lines are for assignment of a role to a user. GetAllRoles() calls the 'g' line at index 2 to list roles.

* Fixed a bug with role:readonly looking for wildcard 'get' action which no longer exists because our actions became more specific - e.g. 'pipelines:runs, get-run' rather than 'pipelines:runs, get'

* Added a check to make sure all newly created roles have a prefix of 'role:x'

* Made the instantiation of the rbac more testable by using DI instead of instantiating concrete resources within the constructor

* Add missing service.go unit tests
@speza
Copy link
Contributor Author

speza commented Aug 2, 2020

@Skarlso some fixes for RBAC, more tests, and general quality of life changes.

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

/test

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

Command received. Building new test image.

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

Failed to fetch and build pr.

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

Oh f*ck off. :D @speza You have a / in your branch-name which is an invalid docker tag character. :D

@speza
Copy link
Contributor Author

speza commented Aug 2, 2020

@Skarlso 🤣 just finding bugs in your code bro!

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

yeah :D

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

/test rbac-fixes-281

3 similar comments
@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

/test rbac-fixes-281

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

/test rbac-fixes-281

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

/test rbac-fixes-281

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

Command received. Building new test image.

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

Failed to fetch and build pr.

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

@gaia-bot OH FUCK OFF

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

/test rbac-fixes-281

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

Command received. Building new test image.

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

Failed to fetch and build pr.

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

/test gaiapipeline:testing/rbac-fixes-281

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

Command received. Building new test image.

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

Failed to fetch and build pr.

@Skarlso
Copy link
Member

Skarlso commented Aug 2, 2020

/test gaiapipeline/testing:rbac-fixes-281

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

Command received. Building new test image.

@gaia-bot
Copy link

gaia-bot commented Aug 2, 2020

The new test version has been pushed.

@speza
Copy link
Contributor Author

speza commented Aug 2, 2020

@Skarlso would be cool if the bot posted the link to the running service... I'm lazy! 🤣

@Skarlso
Copy link
Member

Skarlso commented Aug 3, 2020

https://gaia.cronohub.org :P It didn't change. :D

@Skarlso
Copy link
Member

Skarlso commented Aug 3, 2020

/help

@gaia-bot
Copy link

gaia-bot commented Aug 3, 2020

Hello, I'm Gaia Bot. I help the team build, test and manage PRs and other issues.
These are my available commands:
/test: Apply the current PR to our testing infrastructure at https://gaia.cronohub.org.
Example: /test, /test gaiapipeline/testing:tag-name

svc, err := rbac.NewEnforcerSvc(gaia.Cfg.RBACDebug, store.CasbinStore())
model, err := rbac.LoadModel()
if err != nil {
return nil, fmt.Errorf("error loading model: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

Please Log the error and return a userfriendly message. The log is enough to check out the rest. And below too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We wrap the error and log in the calling code. I think these errors are only really for us anyway?
We could return a user friendly error in the calling code that is just a blanket "failed to init RBAC". But here, I'd prefer to wrap and then log where we call initRBACService.

}

func loadModel() (model.Model, error) {
// LoadModel loads the rbac model string from the assethelper and parses it into a Casbin model.Model.
func LoadModel() (model.Model, error) {
modelStr, err := assethelper.LoadRBACModel()
if err != nil {
return nil, fmt.Errorf("error loading rbac model from assethelper: %w", err)
Copy link
Member

@Skarlso Skarlso Aug 6, 2020

Choose a reason for hiding this comment

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

Here too, please return something user friendly and log the actual error. And everywhere else too. :) These usually are user facing and note that a large enough error might break the output too because the div can't handle log strings. So make it something userfriendly instead of concatenating the error. And log the error so it can be investigated. :) Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Skarlso I prefer to wrap errors so we can more easily debug. Its up to the caller of this method to log. Therefore I'd prefer adding the logf into server.go#initRBACService (for which I definitely forgot!). If this specific error occurred it would be more for us to diagnose a problem than a user issue. So I'd rather include as much context as possible?

Copy link
Member

Choose a reason for hiding this comment

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

In that case use errors.Wrap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fmt.Errorf("error loading rbac model from assethelper: %w", err) is wrapping errors? Its the Go std lib way of wrapping errors introduced in 1.13 :)

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, I forgot. :D But then in the upper calls we'll need to do some logic in unwrapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you do the log on the error it will show the full error string of all errors. So something like error a: error b: error c all the way down the error stack). But other benefits are being able to use errors.Is and errors.As to look for any errors in the wrapped error.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's why I asked that we would need to inspect the errors if it's something we can recover from. Anyways, fine then. I just don't want anything to creep up to the user. But I followed through that calls so this should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Let me just make this code a little bit more consistent dude. You're right though, in some circumstances we'd definitely want to recover. I feel like here if something fails to load (like the model) we're buggered though! Recovery could be turning RBAC off, but that would be bad if it was meant to be on!

Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's not do that. :) ( turning it off I mean. )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha! Don't worry!

Copy link
Member

@Skarlso Skarlso left a comment

Choose a reason for hiding this comment

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

LGTM after the errors have been adjusted. :)

@Skarlso
Copy link
Member

Skarlso commented Aug 6, 2020

Holy shit. npm is down.

@speza
Copy link
Contributor Author

speza commented Aug 6, 2020

Holy shit. npm is down.

Hoping it was just a wobble... https://status.npmjs.org/

@Skarlso Skarlso merged commit 107cfb1 into gaia-pipeline:master Aug 6, 2020
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