Skip to content

chore(scripts/rules.go): broaden scope of testingWithOwnerUser linter #10548

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

Merged
merged 5 commits into from
Nov 8, 2023

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Nov 6, 2023

This PR broadens the scope of the linter added in #10133.
This would likely have helped catch #10547.
You can just read this commit by commit.

Summary of changes:

  • Updated testingWithOwnerUser rule to detect:
    a) Passing client from coderdenttest.New to clitest.SetupConfig
    b) Usage of any method of the owner client from coderdenttest.New.
  • Added new coderdtest helpers CreateGroup and UpdateTemplateMeta.
  • Modified check_enterprise_import.sh to ignore scripts/rules.go.

The change most likely to be controversial is b) above.
For the enterprise code I feel that it is more critical that we get RBAC correct.
Therefore, any usage of the owner user (excluding some well-known methods) must be justified via //nolint comment.

We don't necessarily want to enforce this on the AGPL code yet, but we could do so in future.

@johnstcn johnstcn self-assigned this Nov 6, 2023
@johnstcn johnstcn force-pushed the cj/linter-rbac-coderenttest branch 2 times, most recently from a992b49 to 8e04dfc Compare November 7, 2023 17:33
@johnstcn johnstcn force-pushed the cj/linter-rbac-coderenttest branch from 45417f6 to c342498 Compare November 8, 2023 09:16
@johnstcn johnstcn marked this pull request as ready for review November 8, 2023 09:23
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Nice improvement! I'm happy to see other feedback, but it is 👍 👍 from me.

The change most likely to be controversial is b) above.

I wouldn't say so. Actually this is specific to coder source, and that's why you described the linter rules this way.

We don't necessarily want to enforce this on the AGPL code yet, but we could do so in future.

This might be opinionated as I like this rule, but maybe we could enable it in a follow up instead of one day in the future?

@johnstcn
Copy link
Member Author

johnstcn commented Nov 8, 2023

maybe we could enable it in a follow up instead of one day in the future?

100% - it will be a big diff though!

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Nice improvement!

@@ -787,6 +806,14 @@ func UpdateActiveTemplateVersion(t testing.TB, client *codersdk.Client, template
require.NoError(t, err)
}

// UpdateTemplateMeta updates the template meta for the given template.
func UpdateTemplateMeta(t testing.TB, client *codersdk.Client, templateID uuid.UUID, meta codersdk.UpdateTemplateMeta) codersdk.Template {
Copy link
Member

Choose a reason for hiding this comment

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

With a helper like this, would it make sense to ensure that all methods of codersdk.Client are implemented here instead of just select ones? This essentially turns 2 lines into 1 which arguably doesn't add a whole lot of value if you still don't know when to use client directly, and when to use coderdtest.

Copy link
Member Author

@johnstcn johnstcn Nov 8, 2023

Choose a reason for hiding this comment

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

The linter won't complain about passing the owner client into a coderdtest method, which I view as both a feature and a semantic difference:

  • coderdtest.X: this thing is part of test setup.
  • client.X: this is the thing we are actually testing where ensuring it works with the least-privileged RBAC role is crucial.

I don't think a 1:1 mapping of client methods -> coderdtest methods is warranted, especially as we have some coderdtest methods that call multiple client methods.

@johnstcn johnstcn merged commit 26740cf into main Nov 8, 2023
@johnstcn johnstcn deleted the cj/linter-rbac-coderenttest branch November 8, 2023 14:54
@github-actions github-actions bot locked and limited conversation to collaborators Nov 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants