Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions framework/configstore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ConfigStoreType string
const (
ConfigStoreTypeSQLite ConfigStoreType = "sqlite"
ConfigStoreTypePostgres ConfigStoreType = "postgres"
ConfigStoreTypeMySQL ConfigStoreType = "mysql"
)

// Config represents the configuration for the config store.
Expand Down Expand Up @@ -58,6 +59,12 @@ func (c *Config) UnmarshalJSON(data []byte) error {
return fmt.Errorf("failed to unmarshal postgres config: %w", err)
}
c.Config = &postgresConfig
case ConfigStoreTypeMySQL:
var mysqlConfig MySQLConfig
if err := json.Unmarshal(temp.Config, &mysqlConfig); err != nil {
return fmt.Errorf("failed to unmarshal mysql config: %w", err)
}
c.Config = &mysqlConfig
default:
return fmt.Errorf("unknown config store type: %s", temp.Type)
}
Expand Down
34 changes: 34 additions & 0 deletions framework/configstore/mysql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package configstore

import (
"context"
"fmt"

"github.com/maximhq/bifrost/core/schemas"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)

// MySQLConfig represents the configuration for a MySQL database.
type MySQLConfig struct {
User string `json:"user"`
Password string `json:"password"`
Host string `json:"host"`
Port int `json:"port"`
DBName string `json:"db_name"`
SSLMode string `json:"ssl_mode"`
}

// newMySQLConfigStore creates a new MySQL config store.
func newMySQLConfigStore(ctx context.Context, config *MySQLConfig, logger schemas.Logger) (ConfigStore, error) {
db, err := gorm.Open(mysql.Open(fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local&sslmode=%s", config.User, config.Password, config.Host, config.Port, config.DBName, config.SSLMode)), &gorm.Config{})
if err != nil {
return nil, err
}
d := &RDBConfigStore{db: db, logger: logger}
// Run migrations
if err := triggerMigrations(ctx, db); err != nil {
return nil, err
}
return d, nil
}
5 changes: 5 additions & 0 deletions framework/configstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func NewConfigStore(ctx context.Context, config *Config, logger schemas.Logger)
return newPostgresConfigStore(ctx, postgresConfig, logger)
}
return nil, fmt.Errorf("invalid postgres config: %T", config.Config)
case ConfigStoreTypeMySQL:
if mysqlConfig, ok := config.Config.(*MySQLConfig); ok {
return newMySQLConfigStore(ctx, mysqlConfig, logger)
}
return nil, fmt.Errorf("invalid mysql config: %T", config.Config)
}
return nil, fmt.Errorf("unsupported config store type: %s", config.Type)
}
3 changes: 3 additions & 0 deletions framework/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ require (
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify MySQL driver versions and security advisories.

Ensure the MySQL driver dependencies are up-to-date and free from known vulnerabilities.

Run the following script to check for the latest versions and security advisories:

Also applies to: 98-98


🏁 Script executed:

#!/bin/bash
# Description: Check MySQL driver versions and security advisories

echo "=== Checking latest versions on pkg.go.dev ==="
echo "Current: gorm.io/driver/mysql v1.6.0"
curl -s "https://proxy.golang.org/gorm.io/driver/mysql/@latest" | jq -r '.Version'

echo -e "\nCurrent: github.com/go-sql-driver/mysql v1.8.1"
curl -s "https://proxy.golang.org/github.com/go-sql-driver/mysql/@latest" | jq -r '.Version'

echo -e "\n=== Checking for security advisories ==="
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: GO, package: "github.com/go-sql-driver/mysql") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 237


Update MySQL driver to v1.9.3
Bump github.com/go-sql-driver/mysql from v1.8.1 to v1.9.3 in framework/go.mod (lines 19–20); gorm.io/driver/mysql at line 98 remains at v1.6.0 (latest). No GO ecosystem security advisories detected.

🤖 Prompt for AI Agents
In framework/go.mod around lines 19 to 20, the MySQL driver is pinned to
github.com/go-sql-driver/mysql v1.8.1; update that module to v1.9.3 by changing
the version specifier, then run go mod tidy (and commit updated go.sum) to pull
the new version and clean dependencies; after updating, run unit/integration
tests (and verify gorm.io/driver/mysql v1.6.0 compatibility) and fix any minor
API or dependency issues surfaced by the new driver.

github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
Expand Down Expand Up @@ -93,5 +95,6 @@ require (
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.6.0
gorm.io/driver/postgres v1.6.0
)
6 changes: 6 additions & 0 deletions framework/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cloud.google.com/go/compute/metadata v0.8.0 h1:HxMRIbao8w17ZX6wBnjhcDkW6lTFpgcaobyVfZWqRLA=
cloud.google.com/go/compute/metadata v0.8.0/go.mod h1:sYOGTp851OV9bOFJ9CH7elVvyzopvWQFNNghtDQ/Biw=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
Expand Down Expand Up @@ -102,6 +104,8 @@ github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ
github.com/go-openapi/validate v0.21.0/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg=
github.com/go-openapi/validate v0.24.0 h1:LdfDKwNbpB6Vn40xhTdNZAnfLECL81w+VX3BumrGD58=
github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1+zquzJEf2BAQ=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
Expand Down Expand Up @@ -360,6 +364,8 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4=
gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo=
gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ=
Expand Down
101 changes: 98 additions & 3 deletions transports/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://www.getbifrost.ai/schema",
"$id": "https://www.getbifrost.ai/schema",
"title": "Bifrost Configuration Schema",
"description": "Schema for Bifrost HTTP transport configuration",
"type": "object",
Expand Down Expand Up @@ -175,7 +175,8 @@
"type": "string",
"enum": [
"sqlite",
"postgres"
"postgres",
"mysql"
],
"description": "Configuration store type"
},
Expand Down Expand Up @@ -249,6 +250,53 @@
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"type": {
"const": "mysql"
}
}
},
"then": {
"type": "object",
"properties": {
"host": {
"type": "string",
"description": "Database host"
},
"port": {
"type": "string",
"description": "Database port"
},
"user": {
"type": "string",
"description": "Database user"
},
"password": {
"type": "string",
"description": "Database password. Leave empty if you want to use IAM role authentication."
},
"db_name": {
"type": "string",
"description": "Database name"
},
"ssl_mode": {
"type": "string",
"description": "Database SSL mode"
}
},
"required": [
"host",
"port",
"user",
"password",
"db_name",
"ssl_mode"
],
"additionalProperties": false
}
}
Comment on lines +254 to 300
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Port type inconsistency and IAM authentication concerns.

The MySQL configuration for config_store has two concerns:

  1. Port type inconsistency: Line 270 defines port as type "string", but the logs_store MySQL schema at line 408 defines it as type "integer". Port numbers should consistently be integers across all database configurations.

  2. IAM authentication note: Line 279 states "Leave empty if you want to use IAM role authentication" for the password field. IAM authentication is specific to AWS RDS and may not apply to generic MySQL deployments. Either clarify this is only for AWS RDS MySQL, or remove the IAM reference if not universally supported.

Additionally, consider adding enum constraints for ssl_mode (line 285-287) to specify valid values like "disable", "require", "verify-ca", "verify-identity", etc.

Apply this diff to fix the port type:

                   "port": {
-                    "type": "string",
+                    "type": "integer",
                     "description": "Database port"
                   },

Also update the Postgres config_store schema at line 222-224 for consistency:

                   "port": {
-                    "type": "string",
+                    "type": "integer",
                     "description": "Database port"
                   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"if": {
"properties": {
"type": {
"const": "mysql"
}
}
},
"then": {
"type": "object",
"properties": {
"host": {
"type": "string",
"description": "Database host"
},
"port": {
"type": "string",
"description": "Database port"
},
"user": {
"type": "string",
"description": "Database user"
},
"password": {
"type": "string",
"description": "Database password. Leave empty if you want to use IAM role authentication."
},
"db_name": {
"type": "string",
"description": "Database name"
},
"ssl_mode": {
"type": "string",
"description": "Database SSL mode"
}
},
"required": [
"host",
"port",
"user",
"password",
"db_name",
"ssl_mode"
],
"additionalProperties": false
}
}
{
"if": {
"properties": {
"type": {
"const": "mysql"
}
}
},
"then": {
"type": "object",
"properties": {
"host": {
"type": "string",
"description": "Database host"
},
"port": {
"type": "integer",
"description": "Database port"
},
"user": {
"type": "string",
"description": "Database user"
},
"password": {
"type": "string",
"description": "Database password. Leave empty if you want to use IAM role authentication."
},
"db_name": {
"type": "string",
"description": "Database name"
},
"ssl_mode": {
"type": "string",
"description": "Database SSL mode"
}
},
"required": [
"host",
"port",
"user",
"password",
"db_name",
"ssl_mode"
],
"additionalProperties": false
}
}
🤖 Prompt for AI Agents
In transports/config.schema.json around lines 254 to 300 (MySQL config_store)
and lines 222 to 224 (Postgres config_store), change the port property type from
"string" to "integer" to match logs_store and ensure consistency; update the
password property's description to remove or scope the IAM reference (either
remove "Leave empty if you want to use IAM role authentication" or change it to
"For AWS RDS IAM auth, leave empty" to clarify scope); add an enum constraint to
ssl_mode with allowed values such as "disable", "require", "verify-ca",
"verify-identity" to restrict valid modes; and make the same port-type change in
the Postgres config_store block to keep database port types consistent across
schemas.

]
}
Expand All @@ -267,7 +315,8 @@
"type": "string",
"enum": [
"sqlite",
"postgres"
"postgres",
"mysql"
],
"description": "Logs store type"
},
Expand Down Expand Up @@ -340,6 +389,52 @@
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"../type": {
"const": "mysql"
}
}
},
"then": {
"properties": {
"host": {
"type": "string",
"description": "Database host"
},
"port": {
"type": "integer",
"description": "Database port"
},
"user": {
"type": "string",
"description": "Database user"
},
"password": {
"type": "string",
"description": "Database password. Leave empty if you want to use IAM role authentication."
},
"db_name": {
"type": "string",
"description": "Database name"
},
"ssl_mode": {
"type": "string",
"description": "Database SSL mode"
}
},
"required": [
"host",
"port",
"user",
"password",
"db_name",
"ssl_mode"
],
"additionalProperties": false
}
}
]
}
Expand Down