Skip to content

Commit 14be4ff

Browse files
committed
fix #106 add ability to set auth_plugin for mysql users
1 parent b582eb9 commit 14be4ff

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

cluster/local/integration_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ echo "${INSTALL_YAML}" | "${KUBECTL}" delete -f -
265265
timeout=60
266266
current=0
267267
step=3
268-
while [[ $(kubectl get providerrevision.pkg.crossplane.io -o name | wc -l) != "0" ]]; do
268+
while [[ $(kubectl get providerrevision.pkg.crossplane.io -o name | wc -l | awk '{print $1}') != "0" ]]; do
269269
echo "waiting for provider to be deleted for another $step seconds"
270270
current=$current+$step
271271
if ! [[ $timeout > $current ]]; then

examples/mysql/user.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ metadata:
44
name: example-user
55
spec:
66
forProvider:
7-
authPlugin: AWSAuthenticationPlugin
87
passwordSecretRef:
98
name: example-pw
109
namespace: default

package/crds/mysql.sql.crossplane.io_users.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ spec:
7272
instance.
7373
properties:
7474
authPlugin:
75-
description: AuthPlugin defines the authentication plugin to be used.
76-
Meant to add support for AWS IAM DB authentication (ie. AWSAuthenticationPlugin)
75+
description: |-
76+
AuthPlugin defines the MySQL auth plugin (ie. AWSAuthenticationPlugin for AWS IAM authentication when using AWS RDS )
77+
See https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.DBAccounts.html
7778
type: string
7879
binlog:
7980
description: BinLog defines whether the create, delete, update

pkg/controller/mysql/user/reconciler.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
245245
ro := resourceOptionsToClauses(cr.Spec.ForProvider.ResourceOptions)
246246
binlog := cr.Spec.ForProvider.BinLog
247247

248-
var authplugin string
248+
var authplugin string
249+
249250
if cr.Spec.ForProvider.AuthPlugin != "" {
250251
authplugin = cr.Spec.ForProvider.AuthPlugin
251-
} else {
252-
authplugin = "mysql_native_password"
253252
}
254253
var pw string
255254

256-
if authplugin == "mysql_native_password" {
255+
switch authplugin {
256+
case "":
257257
var err error
258258
pw, _, err = c.getPassword(ctx, cr)
259259
if err != nil {
@@ -266,11 +266,11 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
266266
return managed.ExternalCreation{}, err
267267
}
268268
}
269-
auth = fmt.Sprintf("%s BY %s", authplugin, mysql.QuoteValue(pw))
270-
} else if authplugin == "AWSAuthenticationPlugin" {
271-
auth = fmt.Sprintf("%s AS %s", authplugin, mysql.QuoteValue("RDS"))
272-
} else {
273-
return managed.ExternalCreation{}, errors.New(errAuthPluginNotSupported)
269+
auth = fmt.Sprintf("BY %s", mysql.QuoteValue(pw))
270+
case "AWSAuthenticationPlugin":
271+
auth = fmt.Sprintf("WITH %s AS %s", authplugin, mysql.QuoteValue("RDS"))
272+
default:
273+
return managed.ExternalCreation{}, errors.New(errAuthPluginNotSupported)
274274
}
275275

276276
if err := c.executeCreateUserQuery(ctx, username, host, ro, auth, binlog); err != nil {
@@ -293,13 +293,12 @@ func (c *external) executeCreateUserQuery(ctx context.Context, username string,
293293
}
294294

295295
query := fmt.Sprintf(
296-
"CREATE USER %s@%s IDENTIFIED WITH %s%s",
296+
"CREATE USER %s@%s IDENTIFIED %s%s",
297297
mysql.QuoteValue(username),
298298
mysql.QuoteValue(host),
299299
auth,
300300
resourceOptions,
301301
)
302-
fmt.Println(query)
303302

304303
if err := mysql.ExecWithBinlogAndFlush(ctx, c.db, mysql.ExecQuery{Query: query, ErrorValue: errCreateUser}, mysql.ExecOptions{Binlog: binlog}); err != nil {
305304
return err

0 commit comments

Comments
 (0)