Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

cody: replace access-control feature flag with RBAC#58831

Merged
emidoots merged 19 commits into
mainfrom
sg/cody-rbac
Jan 12, 2024
Merged

cody: replace access-control feature flag with RBAC#58831
emidoots merged 19 commits into
mainfrom
sg/cody-rbac

Conversation

@emidoots

@emidoots emidoots commented Dec 7, 2023

Copy link
Copy Markdown
Member

This change replaces the old feature-flag which controls users who have access to Cody, with an RBAC-based implementation instead.

After this change, cody.restrictUsersFeatureFlag is deprecated. For Sourcegraph instances that still have it set, it will still be respected it until the site admin removes it from their config. A warning is displayed to let admins know this needs to be done:

image

Once cody.restrictUsersFeatureFlag is not set in the site config, the new RBAC system is used instead: site admins can manage user roles, and assign/remove cody:access to users or groups of users via the access control web UI.

By default, all users have access (admins can change this default via the access control web UI.)

The new Cody RBAC system defaults to enabled unless cody.restrictUsersFeatureFlag is set in the site config. It can be disabled by setting the new cody.permissions site config option to false, in which case Sourcegraph behaves as it did before this change.

Fixes #58623
Helps (fixes?) #58624
Resolves #58627

Remaining TODOs before this PR can be merged

  • Some Go tests need updating / CI needs to pass
  • These docs need to be updated to tell site admins on new versions what to do, tell site admins on old versions how they can use the old docs, and tell site admins upgrading what to do (remove the old config, and then use the RBAC system going forward.) with the exact Sourcegraph versions mentioned.

Test plan

  • Created a non-admin user, signed into VS Code' Cody via that user, confirmed I have access by default.
  • Using the site admin account, change normal users'

@cla-bot cla-bot Bot added the cla-signed label Dec 7, 2023
@sourcegraph-bot

sourcegraph-bot commented Dec 7, 2023

Copy link
Copy Markdown
Contributor

📖 Storybook live preview

}

func (r *siteResolver) IsCodyEnabled(ctx context.Context) bool { return cody.IsCodyEnabled(ctx) }
func (r *siteResolver) IsCodyEnabled(ctx context.Context) bool { return cody.IsCodyEnabled(ctx, r.db) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like it's always been this way but feels strange to me that the site resolver is returning if Cody is enabled for the current user, not is Cody enabled for the site.

@emidoots emidoots Dec 7, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, it is very (functional, but) strange. It's also weird that we have Cody access control enforced in the feature-flag portion of internal/cody.

I haven't set out to 'correct' this in this PR with the hopes of keeping it from increasing in scope/risk

Comment thread cmd/frontend/internal/completions/resolvers/resolver.go Outdated

@chwarwick chwarwick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If i'm following correctly the RBAC permissions are only used if the config value is set to enable permissions, which means the default case is that all users have access (same as today 👍 )

But what happens in the RBAC UI? Does it look like you are configuring Cody access for groups/all users but because it's not enabled in the config it isn't considered?

@emidoots

emidoots commented Jan 3, 2024

Copy link
Copy Markdown
Member Author

If i'm following correctly the RBAC permissions are only used if the config value is set to enable permissions, which means the default case is that all users have access (same as today 👍 )

But what happens in the RBAC UI? Does it look like you are configuring Cody access for groups/all users but because it's not enabled in the config it isn't considered?

That is correct; however if the RBAC permissions are not being respected then the warning would display at the top of the page indicating you're using the old permission system:

image

The one edge-case here would be if a site admin explicitly disables the new RBAC permissions model (cody.permissions set to false). Eventually I would like to remove the ability for a site admin to do that at all (in +1 release, so many months have passed and everyone has had a chance to upgrade.)

Stephen Gutekanst and others added 8 commits January 8, 2024 19:11
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Co-authored-by: Chris Warwick <christopher.warwick@sourcegraph.com>
…sabled

Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Stephen Gutekanst added 2 commits January 9, 2024 22:24
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
@emidoots

Copy link
Copy Markdown
Member Author

@chwarwick or @eseliger would either of you be up for a quick review? I'd love to land this soon as it's blocking some other work :)

@chwarwick chwarwick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice, this looks correct to me. See note about new docs process.

## Enable Cody only for some users

To enable Cody only for some users, for example, when rolling out a Cody POC, follow all the steps mentioned in [Enabling Cody on your Sourcegraph instance](#enable-cody-on-your-sourcegraph-instance). Then, use the feature flag `cody` to turn Cody on selectively for some users. To do so:
To enable Cody only for some users, for example, when rolling out a Cody POC, follow all the steps mentioned in [Enabling Cody on your Sourcegraph instance](#enable-cody-on-your-sourcegraph-instance). Then, do the following:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Docs changes need to go into the new docs repo. I think having them here will fail the build?

Comment thread internal/cody/feature_flag_test.go Outdated
}
})

t.Run("RBAC, Enabled cody, but not completions", func(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does but not completions mean? This test looks the same as the one above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch, I mirror'd the existing good test suite but for the case of RBAC - and this ended up being redundant. Removed.

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, might warrant a changelog entry to make people aware prior to the upgrade that they need to migrate their access settings :)

Stephen Gutekanst added 2 commits January 10, 2024 17:05
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Stephen Gutekanst added 2 commits January 10, 2024 17:23
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
@emidoots emidoots enabled auto-merge (squash) January 11, 2024 01:13
Stephen Gutekanst added 3 commits January 10, 2024 18:42
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
@emidoots emidoots merged commit cf59539 into main Jan 12, 2024
@emidoots emidoots deleted the sg/cody-rbac branch January 12, 2024 02:31
burmudar added a commit that referenced this pull request Jan 12, 2024
emidoots pushed a commit that referenced this pull request Jan 17, 2024
emidoots pushed a commit that referenced this pull request Jan 17, 2024
* Revert "Revert "cody: replace access-control feature flag with RBAC (#58831)" (#59540)"

This reverts commit 13923a7.

* context/resolvers: fix test by correctly mocking user role with Cody access

Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>

---------

Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

6 participants