Skip to content

fix(rbac): drop redundant enforcer.SavePolicy() after grant/revoke#357

Merged
aktech merged 1 commit into
mainfrom
fix/rbac-remove-redundant-savepolicy
May 28, 2026
Merged

fix(rbac): drop redundant enforcer.SavePolicy() after grant/revoke#357
aktech merged 1 commit into
mainfrom
fix/rbac-remove-redundant-savepolicy

Conversation

@aktech

@aktech aktech commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

AddPolicy / RemovePolicy already persist via the adapter's AutoSave (enabled by default). The following SavePolicy() call is therefore unnecessary for correctness, but expensive: it deletes every row in casbin_rule and bulk-reinserts every policy from the in-memory model on every grant.

The custom in-tree adapter's SavePolicy confirms the cost:

https://github.com/nebari-dev/nebi/blob/0afe891/internal/rbac/adapter.go#L71-L92

And AddPolicy on the same adapter already does the single-row INSERT that AutoSave triggers:

https://github.com/nebari-dev/nebi/blob/0afe891/internal/rbac/adapter.go#L94-L97

Upstream guidance: https://casbin.apache.org/docs/adapters/#autosave

Discussed on #346.

Changes

  • Drop enforcer.SavePolicy() from GrantWorkspaceAccess, RevokeWorkspaceAccess, MakeAdmin, RevokeAdmin.
  • Propagate the two previously-swallowed errors from RemovePolicy calls in RevokeWorkspaceAccess.

AddPolicy/RemovePolicy already persist via the adapter's AutoSave (on
by default), so the following SavePolicy() call is a no-op for
correctness but expensive: it deletes every row in casbin_rule and
bulk-reinserts every policy from the in-memory model on every grant.

Also propagate the previously-swallowed errors from the two
RemovePolicy calls in RevokeWorkspaceAccess.
@netlify

netlify Bot commented May 28, 2026

Copy link
Copy Markdown

Deploy Preview for nebi-docs canceled.

Name Link
🔨 Latest commit b1d2c63
🔍 Latest deploy log https://app.netlify.com/projects/nebi-docs/deploys/6a185399e8ef6d0008a7167a

@netlify

netlify Bot commented May 28, 2026

Copy link
Copy Markdown

👷 Deploy Preview for nebi-docs processing.

Name Link
🔨 Latest commit b1d2c63
🔍 Latest deploy log https://app.netlify.com/projects/nebi-docs/deploys/6a185399e8ef6d0008a7167a

@aktech aktech merged commit a135ac4 into main May 28, 2026
14 checks passed
@aktech aktech deleted the fix/rbac-remove-redundant-savepolicy branch May 28, 2026 14:50
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.

1 participant