Skip to content

Conversation

@yau-wd
Copy link
Contributor

@yau-wd yau-wd commented Dec 16, 2025

Description

API Key

  1. Migration scripts to add permissions column into apikey table.
  2. API key permissions exclude workspace and admin categories.
  3. Cloud feature-based filtering for API keys excludes permissions associated with disabled feature flags.
  4. User-level filtering for API keys restricts non-admin users to only their explicitly granted permissions.
  5. Deprecate import API keys functionality.

Permissions

  1. Permissions remove apikeys import.
  2. Cloud role permissions exclude sso.
  3. Migration scripts to clean up role permissions values.

API Key

Database

Before

SQLite PostgreSQL MySQL MariaDB
image image image image

After

SQLite PostgreSQL MySQL MariaDB
image image image image

UI

Create/Update

Admin

Open Source Enterprise Cloud Free Cloud Starter Cloud Pro
image image image image image

Non-Admin Users

Role Permissions: chatflow-r, agentflow-crud, apikey-crud

Open Source Enterprise Cloud Free Cloud Starter Cloud Pro
NA image NA NA image

Read

Admin

Open Source Enterprise Cloud Free Cloud Starter Cloud Pro
image image NA NA image

Non-Admin Users

Role Permissions: chatflow-r, agentflow-crud, apikey-crud

Open Source Enterprise Cloud Free Cloud Starter Cloud Pro
NA image NA NA image

Postman

View

High Permissions Low Permissions
image image

Create

API Key Permissions: chatflow-r, agentflow-r, apikeys-crud

Cannot create API key with workspace or admin permissions Cannot create API key with permissions that exceed your own permissions Pass
image image image

Update

API Key Permissions: chatflow-r, agentflow-r, apikeys-crud

Cannot update API key with workspace or admin permissions Cannot update API key with permissions that exceed your own permissions Pass
image image image

Delete

API key without delete permissions API key with delete permissions
image image

Role

Database

-- SQLITE | POSTGRESQL
SELECT  COUNT(*) FROM "role" r WHERE r.permissions LIKE '%sso:manage%' OR r.permissions LIKE '%apikeys:import%'

-- MYSQL | MARIADB
SELECT COUNT(*) FROM `role` r WHERE r.permissions LIKE '%sso:manage%' OR r.permissions LIKE '%apikeys:import%'

Before

SQLite PostgreSQL MySQL MariaDB
image image image image

After

SQLite PostgreSQL MySQL MariaDB
image image image image

UI

Create/Update

Admin

Open Source Enterprise Cloud Free Cloud Starter Cloud Pro
NA image NA NA image

Non-Admin Users

Role Permissions: chatflow-r, agentflow-r, apikey-cru, workspace-crud, admin-crud

Open Source Enterprise Cloud Free Cloud Starter Cloud Pro
NA image NA NA image

Read

Admin

Open Source Enterprise Cloud Free Cloud Starter Cloud Pro
NA image NA NA image

Non-Admin Users

Role Permissions: chatflow-r, agentflow-r, apikey-cru, workspace-crud, admin-crud

Open Source Enterprise Cloud Free Cloud Starter Cloud Pro
NA image NA NA image
@yau-wd yau-wd self-assigned this Dec 16, 2025
@yau-wd yau-wd added the enhancement New feature or request label Dec 16, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yau-wd, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request delivers a crucial security and access control feature by integrating permissions directly into API keys. This allows for a more secure and controlled environment where each API key can be tailored with specific access rights, moving beyond a broad, all-or-nothing access model. The changes span database schema modifications, updates to the backend API logic for managing keys, and a comprehensive overhaul of the frontend UI to support permission selection and display.

Highlights

  • API Key Permissions: Introduced a new permissions field for API keys, allowing granular control over what actions each key can perform. This enhances security by enabling administrators to restrict API key capabilities to specific functionalities.
  • Database Schema Updates: Added a permissions column to the apikey table across MariaDB, MySQL, PostgreSQL, and SQLite databases via new migration files. Existing API keys will be updated to include all available permissions by default.
  • API Endpoint Enhancements: Modified API key management endpoints (getAllApiKeys, createApiKey, updateApiKey, importKeys) to incorporate the new permissions field. This includes validation logic to prevent users from assigning permissions they do not possess.
  • User Interface for Permissions: Implemented a new UI in the API Key dialog (APIKeyDialog.jsx) that allows users to select and view specific permissions when creating or editing an API key. The API key listing also now displays the assigned permissions.
  • Permission Filtering for Non-Admins: Added logic to filter the list of available permissions for non-organization admin users, ensuring they can only view and assign permissions that are a subset of their own.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a permissions system for API keys, a significant security enhancement. The changes span across the backend and UI, allowing for granular control over what each API key can do.

My review focuses on the security implications and maintainability of the new implementation. Here are the key points:

  • A new permissions column is added to the ApiKey entity, and database migrations are included for all supported databases.
  • The API key controller and service layers are updated to validate and filter based on these new permissions, preventing privilege escalation.
  • The UI is updated with a new dialog to manage API key permissions.

I've identified a critical security concern in the database migration scripts, which grant all permissions to existing API keys by default. I've also pointed out a potential data integrity issue with a null value in the permissions list and a potential runtime error in a new database utility function. Additionally, I've suggested some improvements for code maintainability by addressing duplicated logic and silent error handling.

Overall, this is a great feature addition. Addressing the highlighted issues will make it more robust and secure.

@yau-wd
Copy link
Contributor Author

yau-wd commented Dec 17, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a permissions system for API keys, which is a significant and valuable feature. The changes span across the backend (database, services, controllers) and the frontend (UI dialogs, API calls). Key changes include adding a permissions column to the ApiKey entity, updating services and controllers to handle permissions with validation, modifying the UI to allow selecting permissions, and defining permissions for different platforms. The implementation is mostly solid, but I've found a few issues that need attention, including a potential security vulnerability, a bug in the frontend logic, and some areas for improvement in error handling and database migrations.

@yau-wd
Copy link
Contributor Author

yau-wd commented Dec 29, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and valuable feature by adding granular permissions to API keys, which greatly enhances security and flexibility. The implementation is thorough, spanning database migrations, backend services, and a well-designed UI for permission management. I appreciate the careful thought given to permission validation, especially the restrictions on workspace and admin permissions and the platform-aware filtering. The deprecation of the old JSON-based API key import is also a welcome cleanup. My review has identified a recurring pattern of unsafe JSON.parse calls in several places, which could lead to runtime errors or failed migrations if data is malformed. I've provided specific suggestions to make the parsing more robust. Overall, this is an excellent contribution, and addressing the identified issues will make it even more solid.

…ensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

2 participants