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

chore(chaos-center): Updated MyHub Rbacs and optimized filetype for fetching hub data #3444

Merged
merged 2 commits into from
Mar 9, 2022

Conversation

amityt
Copy link
Contributor

@amityt amityt commented Feb 3, 2022

Signed-off-by: Amit Kumar Das [email protected]

Proposed changes

This PR fixes the following issues:

  • Fix the rbac issues with hub
  • Updated Filetype as an enum

ref: litmuschaos/litmus-e2e#362

Types of changes

What types of changes does your code introduce to Litmus? Put an x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Dependency

  • Please add the links to the dependent PR need to be merged before this (if any).

Special notes for your reviewer:

@amityt amityt requested review from imrajdas and Jonsy13 February 3, 2022 11:46
@amityt amityt self-assigned this Feb 3, 2022
@codesniffy codesniffy bot added the size/L label Feb 3, 2022
Comment on lines +125 to +131
func (r *mutationResolver) SyncHub(ctx context.Context, id string, projectID string) ([]*model.MyHubStatus, error) {
err := authorization.ValidateRole(ctx, projectID,
authorization.MutationRbacRules[authorization.UpdateChaosWorkflow],
model.InvitationAccepted.String())
if err != nil {
return nil, err
}
Copy link
Member

@gdsoumya gdsoumya Feb 3, 2022

Choose a reason for hiding this comment

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

Will not work creates attack vector. I can send a random project id where I have enough permission and an unrelated hub id where I don't have enough permission, this code will allow me to make changes to the hub even though I shouldn't have access to that. The project id should be derived from the hub id

Copy link
Member

Choose a reason for hiding this comment

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

A simple solution would be to query the hub with the hub id + project id, this would mean if the user sends unrelated hub and project ids db will not return the hub data.

Comment on lines +171 to +177
func (r *mutationResolver) DeleteMyHub(ctx context.Context, hubID string, projectID string) (bool, error) {
err := authorization.ValidateRole(ctx, projectID,
authorization.MutationRbacRules[authorization.DeleteMyHub],
model.InvitationAccepted.String())
if err != nil {
return false, err
}
Copy link
Member

Choose a reason for hiding this comment

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

same attack vector

Comment on lines +421 to +446
err := authorization.ValidateRole(ctx, experimentInput.ProjectID,
authorization.MutationRbacRules[authorization.GetYAMLData],
model.InvitationAccepted.String())
if err != nil {
return "", err
}
return myhub.GetYAMLData(ctx, experimentInput)
}

func (r *queryResolver) GetPredefinedWorkflowList(ctx context.Context, hubName string, projectID string) ([]string, error) {
err := authorization.ValidateRole(ctx, projectID,
authorization.MutationRbacRules[authorization.PredefinedWorkflowOperations],
model.InvitationAccepted.String())
if err != nil {
return nil, err
}
return myhub.GetPredefinedWorkflowList(hubName, projectID)
}

func (r *queryResolver) GetPredefinedExperimentYaml(ctx context.Context, experimentInput model.ExperimentInput) (string, error) {
err := authorization.ValidateRole(ctx, experimentInput.ProjectID,
authorization.MutationRbacRules[authorization.PredefinedWorkflowOperations],
model.InvitationAccepted.String())
if err != nil {
return "", err
}
Copy link
Member

Choose a reason for hiding this comment

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

Make sure the ProjectIDs passed here are actually used to get the required data else, if they are just redundant information the same attack vector exists here 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.

@gdsoumya For the above 2 cases, the Project ID is being used to fetch the chaos-charts data from the hub directories. I believe it wont cause any issue here. Have updated the code for other cases.

Copy link
Member

Choose a reason for hiding this comment

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

Awesome thanks.

@amityt
Copy link
Contributor Author

amityt commented Feb 3, 2022

Thanks @gdsoumya for the review 🚀
I have made the required changes, PTAL!

@amityt amityt requested a review from gdsoumya February 3, 2022 14:15
@amityt amityt requested a review from gdsoumya February 4, 2022 05:09
@imrajdas imrajdas merged commit fb7c415 into litmuschaos:master Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants