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>
@Column({ type: 'text' })
keyName: string

@Column({ nullable: false, type: 'text', default: '[]' })
Copy link
Contributor

Choose a reason for hiding this comment

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

also is it possible to use simple-json instead?

@Column({
    type: 'simple-json', 
    nullable: false, 
    default: '[]' 
})
permissions: string[]; // TypeORM handles the stringify/parse automatically

I am under the impression that TypeORM can automatically pick the best column type for the underlying DB (it will use JSONB in Postgres, JSON in MySQL, and TEXT in SQLite), would you be able to help verify?

This would allow us to mitigate the performance and maintenance bottleneck especially if in the future we need to scale to combine JWT scopes with other services

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, but this PR is to address Jira2 Ticket Flowise-12 quickly. Migrating to simple-json could be a separate initiative if this becomes a bottleneck.

Priority is testing and ensuring no unintended side effects in other parts of the codebase.

Copy link
Contributor

@jocelynlin-wd jocelynlin-wd Jan 6, 2026

Choose a reason for hiding this comment

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

depends on how much effort it would take to try out simple-json since changing the data type later on will be much more expensive (and the type was a recommendation by gemini for scalability and to avoid tech debt)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test PostgreSQL

1. Initial attempt with LIKE (fails on PostgreSQL)

                    const apiKeysWithChatflowsView = await this.AppDataSource.getRepository(ApiKey)
                        .createQueryBuilder('apikey')
                        .where('apikey.permissions LIKE :permission', { permission: '%chatflows:view%' })
                        .getMany()
                    // Log or use the filtered API keys as needed
                    logger.info(`Found ${apiKeysWithChatflowsView.length} API keys with chatflows:view permission`)

Error:

query failed: SELECT "apikey"."id" AS "apikey_id", "apikey"."apiKey" AS "apikey_apiKey", "apikey"."apiSecret" AS "apikey_apiSecret", "apikey"."keyName" AS "apikey_keyName", "apikey"."permissions" AS "apikey_permissions", "apikey"."updatedDate" AS "apikey_updatedDate", "apikey"."workspaceId" AS "apikey_workspaceId" FROM "apikey" "apikey" WHERE "apikey"."permissions" LIKE $1 -- PARAMETERS: ["%chatflows:view%"]
error: error: operator does not exist: jsonb ~~ unknown

2. Fixed with PostgreSQL JSONB operator (works)

                    const apiKeysWithChatflowsView = await this.AppDataSource.getRepository(ApiKey)
                        .createQueryBuilder('apikey')
                        .where('apikey.permissions::jsonb @> :permission', { permission: '"chatflows:view"' })
                        .getMany()
                    // Log or use the filtered API keys as needed
                    logger.info(`Found ${apiKeysWithChatflowsView.length} API keys with chatflows:view permission`)

Success:

2026-01-06 20:55:44 [INFO]: Found 1 API keys with chatflows:view permission

My opinion

Without maintaining multiple queries, we'd have to fall back to loading all records and filtering in-memory, which defeats the purpose of database-level optimization, or using TEXT across different database platforms.

SQLite does not support the jsonb type and PostgreSQL's JSON operators (?, @>, etc.).

Database-specific solutions:

  1. PostgreSQL: Use jsonb operators (?, @>)
  2. SQLite: Use LIKE with text pattern matching
  3. MySQL & MariaDB: Use JSON_CONTAINS()

Copy link
Contributor Author

@yau-wd yau-wd Jan 7, 2026

Choose a reason for hiding this comment

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

* @param operation - The operation being performed (for error message)
* @throws InternalFlowiseError if validation fails
*/
function validatePermissions(user: LoggedInUser, requestedPermissions: string[], operation: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[minor] do we want to limit operation with a type or enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably in the next phase, as we also need to take Stripe product metadata into consideration so everything can be standardized and we can determine whether a type, enum, or other declaration or method is most appropriate.

@yau-wd
Copy link
Contributor Author

yau-wd commented Jan 8, 2026

Edge Case: Pro plan users downgrading while retaining API keys with sharing permissions

Done: feat(PricingDialog.jsx): handle downgrade with excessive apikey permissions

Test

UI

organizationId: c34ee07a-7d67-41bc-a2ad-dd4e68ec2b09

Cannot Downgrade Can Downgrade
image image image image image

Database

organizationId: c34ee07a-7d67-41bc-a2ad-dd4e68ec2b09

Before After
image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants