Skip to content

Add feature permission revoke for profiles#549

Merged
danimhr merged 2 commits into
mainfrom
feat/permission
May 13, 2025
Merged

Add feature permission revoke for profiles#549
danimhr merged 2 commits into
mainfrom
feat/permission

Conversation

@danimhr
Copy link
Copy Markdown
Contributor

@danimhr danimhr commented May 12, 2025

This PR adds the ability to revoke a specific feature permission for a given profile.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
swap-staging ⬜️ Ignored (Inspect) Visit Preview May 13, 2025 6:37am

@danimhr danimhr force-pushed the feat/permission branch from 1efcaa5 to e6ae166 Compare May 12, 2025 11:19
id UUID PRIMARY KEY,
profile_id UUID NOT NULL REFERENCES profile(id) ON DELETE CASCADE,
feature VARCHAR(255) NOT NULL,
state permission_state NOT NULL,
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.

this could just be a boolean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I prefer using an enum over a boolean, as it offers greater extensibility and simplifies future migrations.

Comment thread auction-server/api-types/src/profile.rs Outdated

#[derive(Serialize, Deserialize, ToSchema, Clone, ToResponse)]
#[serde(rename_all = "snake_case")]
pub enum PermissionState {
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.

this can also be a boolean? unless you anticipate this having more states soon?

if let Some(permission) = permissions.get(&(profile_id, feature.clone())) {
Ok(permission.state == models::PermissionState::Enabled)
} else {
Ok(true)
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.

i think cancel quote shouldn't be allowed if a permission hasn't been created? aka this should be whitelist, not blacklist

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.

in other words, you need to have Permission enabled in order to cancel quote. if permission is disabled, this fails. if the permission doesn't exist for this profile_id, it fails as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why do you think whitelist is better than blacklist :-?

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.

i think cancellation should be a privileged action because it has costs on the system. if anyone abuses it, then that can cause bad impacts on downstream consumers. thus, it should be enabled for trusted parties and not for any anonymous integrator

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree with your point. For this reason the api is behind the authentication module. It means you can only access the API with API KEY. So by default it's enabled if you have API KEY. If you have API KEY and abuse the feature, then we'll revoke your access by adding a disabled row to your profile Id Privilege model.

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.

you're right that it is behind the authentication guard. but if an API key passes the authentication guard but doesn't have the Privilege, as it stands right now the cancellation will be allowed. I think that the default behavior should be that it is not allowed.

for example, right now, if there is an API key for a random entity that isn't a searcher, then that entity can make a bid and then cancel it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm still not fully convinced this is better. Using an API key is already a form of whitelisting, right? We only generate keys for trusted partners, and if any feature is misused, we can just revoke the privilege of that feature.

Introducing an additional layer feels like double whitelisting, which seems unnecessary to me.

Also, I’m not too keen on the idea of having to create a migration every time we add a new feature behind the privileged module—just to grant access to all existing profiles or API keys.

Copy link
Copy Markdown
Contributor

@m30m m30m left a comment

Choose a reason for hiding this comment

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

I think this adds a double meaning to the term permission into the rep. Maybe use something like Privilege?

feature VARCHAR(255) NOT NULL,
state permission_state NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
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's the use of this column? As far as I understood, rows will not get updated.

Copy link
Copy Markdown
Contributor Author

@danimhr danimhr May 13, 2025

Choose a reason for hiding this comment

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

It's a normal practice. Here it may not be necessary but I prefer to have it in all tables.

Comment thread auction-server/src/server.rs Outdated
Comment thread auction-server/migrations/20250512094618_permission.up.sql Outdated
@danimhr danimhr merged commit a132954 into main May 13, 2025
3 checks passed
@danimhr danimhr deleted the feat/permission branch May 13, 2025 14:33
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