Skip to content

Commit e3fd6fc

Browse files
fix: enable AllowNativePasswords for MariaDB authentication. Fixes #15413
Signed-off-by: Mario Apostolov <mario.apostolov@mariadb.com>
1 parent 1fe74c6 commit e3fd6fc

4 files changed

Lines changed: 94 additions & 8 deletions

File tree

.spelling

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Lifecycle-Hook
9090
LitmusChaos
9191
MLOps
9292
Makefile
93+
MariaDB
9394
Metaflow
9495
MinIO
9596
Minikube

docs/workflow-archive.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> v2.5 and after
44
5-
If you want to keep completed workflows for a long time, you can use the workflow archive to save them in a Postgres (>=9.4) or MySQL (>= 5.7.8) database.
5+
If you want to keep completed workflows for a long time, you can use the workflow archive to save them in a Postgres (>=9.4), MySQL (>= 5.7.8), or MariaDB (>= 10.2) database.
66
The workflow archive stores the status of the workflow, which pods have been executed, what was the result etc.
77
The job logs of the workflow pods will not be archived.
88
If you need to save the logs of the pods, you must setup an [artifact repository](artifact-repository-ref.md) according to [this doc](configure-artifact-repository.md).

util/sqldb/sqldb.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,14 @@ func createPostGresDBSessionWithCreds(cfg *config.PostgreSQLConfig, persistPool
196196
func createMySQLDBSessionWithCreds(cfg *config.MySQLConfig, persistPool *config.ConnectionPool, username, password string) (db.Session, error) {
197197
// Build MySQL DSN using mysql.Config to safely handle special characters in credentials
198198
mysqlCfg := mysql.Config{
199-
User: username,
200-
Passwd: password,
201-
Net: "tcp",
202-
Addr: cfg.GetHostname(),
203-
DBName: cfg.Database,
204-
ParseTime: true,
205-
Params: cfg.Options,
199+
User: username,
200+
Passwd: password,
201+
Net: "tcp",
202+
Addr: cfg.GetHostname(),
203+
DBName: cfg.Database,
204+
ParseTime: true,
205+
AllowNativePasswords: true,
206+
Params: cfg.Options,
206207
}
207208
dsn := mysqlCfg.FormatDSN()
208209

util/sqldb/sqldb_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package sqldb
2+
3+
import (
4+
"context"
5+
"runtime"
6+
"strconv"
7+
"testing"
8+
"time"
9+
10+
"github.com/stretchr/testify/require"
11+
testcontainers "github.com/testcontainers/testcontainers-go"
12+
testmysql "github.com/testcontainers/testcontainers-go/modules/mysql"
13+
"github.com/testcontainers/testcontainers-go/wait"
14+
15+
"github.com/argoproj/argo-workflows/v4/config"
16+
"github.com/argoproj/argo-workflows/v4/util/logging"
17+
)
18+
19+
type mysqlVariant struct {
20+
image string
21+
waitMessage string
22+
}
23+
24+
var mysqlVariants = map[string]mysqlVariant{
25+
"MySQL": {image: "mysql:8.4", waitMessage: "port: 3306 MySQL Community Server"},
26+
"MariaDB": {image: "mariadb:11.4", waitMessage: "mariadbd: ready for connections"},
27+
}
28+
29+
func setupMySQLContainer(ctx context.Context, t *testing.T, v mysqlVariant) (config.DBConfig, func()) {
30+
t.Helper()
31+
32+
c, err := testmysql.Run(ctx,
33+
v.image,
34+
testmysql.WithDatabase("argo"),
35+
testmysql.WithUsername("argo"),
36+
testmysql.WithPassword("argo"),
37+
testcontainers.WithWaitStrategy(
38+
wait.ForAll(
39+
wait.ForLog(v.waitMessage).WithStartupTimeout(60*time.Second),
40+
wait.ForListeningPort("3306/tcp"),
41+
)),
42+
)
43+
require.NoError(t, err)
44+
45+
host, err := c.Host(ctx)
46+
require.NoError(t, err)
47+
p, err := c.MappedPort(ctx, "3306/tcp")
48+
require.NoError(t, err)
49+
port, err := strconv.Atoi(p.Port())
50+
require.NoError(t, err)
51+
52+
return config.DBConfig{
53+
MySQL: &config.MySQLConfig{
54+
DatabaseConfig: config.DatabaseConfig{
55+
Database: "argo",
56+
Host: host,
57+
Port: port,
58+
},
59+
},
60+
}, func() { testcontainers.TerminateContainer(c) } //nolint:errcheck
61+
}
62+
63+
// TestMySQLSessionConnect verifies that CreateDBSessionWithCreds can connect
64+
// to both MySQL and MariaDB. MariaDB requires AllowNativePasswords.
65+
func TestMySQLSessionConnect(t *testing.T) {
66+
if runtime.GOOS == "windows" {
67+
t.Skip("test requires Linux container")
68+
}
69+
70+
for name, variant := range mysqlVariants {
71+
t.Run(name, func(t *testing.T) {
72+
ctx := logging.TestContext(t.Context())
73+
dbConfig, cleanup := setupMySQLContainer(ctx, t, variant)
74+
defer cleanup()
75+
76+
sess, dbType, err := CreateDBSessionWithCreds(dbConfig, "argo", "argo")
77+
require.NoError(t, err)
78+
defer sess.Close()
79+
80+
require.Equal(t, MySQL, dbType)
81+
require.NoError(t, sess.Ping())
82+
})
83+
}
84+
}

0 commit comments

Comments
 (0)