Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support add/delete User manager my sql #1120

Merged
merged 47 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
88ab456
support mysql datbase user add/delete
buhongw7583c May 26, 2020
eb0ded3
Merge branch 'master' of https://github.com/Azure/azure-service-opera…
buhongw7583c May 26, 2020
30bbd3d
Merge branch 'master' of https://github.com/Azure/azure-service-opera…
buhongw7583c May 28, 2020
0d5537c
add API related files that were missed in first commit. Handle the IP…
buhongw7583c May 29, 2020
af281c8
Merge branch 'UserManagerMySQL' of https://github.com/buhongw7583c/az…
buhongw7583c Jun 1, 2020
c645443
handle the error 'resourcenofound' of mysqlfirwallrule
buhongw7583c Jun 1, 2020
901cd68
delete the mysqluser when the IP address has no access to server
buhongw7583c Jun 1, 2020
ebfff07
Merge branch 'master' into UserManagerMySQL
melonrush13 Jun 1, 2020
868b90a
Merge branch 'UserManagerMySQL' of https://github.com/buhongw7583c/az…
buhongw7583c Jun 2, 2020
e5e594b
changes per comments: modify the cert verion in cainjection, change t…
buhongw7583c Jun 2, 2020
c4134c5
Merge branch 'master' into UserManagerMySQL
frodopwns Jun 2, 2020
f6b9689
update project file
buhongw7583c Jun 3, 2020
22dedce
go mod, go.sum. Remove unneccsary user defined format secret. Small c…
buhongw7583c Jun 3, 2020
03bf8cf
Merge branch 'UserManagerMySQL' of https://github.com/buhongw7583c/az…
buhongw7583c Jun 3, 2020
006b31b
Merge branch 'master' into UserManagerMySQL
buhongw7583c Jun 3, 2020
3ea55b9
Merge branch 'master' into UserManagerMySQL
buhongw7583c Jun 3, 2020
03e1e20
update the mysql.md to include the newly added mysql user operator.
Jun 3, 2020
9d08fab
Merge branch 'master' into UserManagerMySQL
melonrush13 Jun 3, 2020
1fe0cbd
Merge branch 'master' into UserManagerMySQL
melonrush13 Jun 3, 2020
735c194
Merge branch 'master' of https://github.com/Azure/azure-service-opera…
Jun 4, 2020
3161403
delete the wrong short name
Jun 4, 2020
12be7e3
Merge branch 'jananivMS/psqluser-crd-fix' of https://github.com/buhon…
Jun 4, 2020
ba4a268
update kustomization.yaml
Jun 4, 2020
b4a8452
Merge branch 'master' into UserManagerMySQL
buhongw7583c Jun 4, 2020
3ba02d4
modify the mysqluser rbac files' comments
Jun 4, 2020
0536f59
Merge branch 'master' into UserManagerMySQL
jananivMS Jun 4, 2020
ca8c85a
changes to make mysqluser rbac work & updated helm chart
jananivMS Jun 5, 2020
10ee37a
Merge pull request #2 from jananivMS/UserManagerMySQL
buhongw7583c Jun 5, 2020
d04b725
Merge branch 'UserManagerMySQL' of https://github.com/buhongw7583c/az…
Jun 5, 2020
73d96e8
small sequence change
Jun 5, 2020
28f4001
Merge branch 'master' into UserManagerMySQL
buhongw7583c Jun 5, 2020
50e7835
some issues fixed
jananivMS Jun 5, 2020
ddb8300
Merge pull request #3 from jananivMS/mysqlprchanges
buhongw7583c Jun 6, 2020
67b1feb
Merge branch 'master' into UserManagerMySQL
buhongw7583c Jun 6, 2020
63ec023
helm chart needed update
jananivMS Jun 6, 2020
e1ff735
Merge pull request #4 from jananivMS/mysqlhelmupdate
buhongw7583c Jun 6, 2020
9ae711d
roles
jananivMS Jun 6, 2020
85359a3
yaml
jananivMS Jun 6, 2020
408c13a
update the charts and index
Jun 6, 2020
8d2e9f6
Merge branch 'UserManagerMySQL' of https://github.com/buhongw7583c/az…
Jun 6, 2020
92b3d20
Merge pull request #5 from jananivMS/mysqlhelmupdate
buhongw7583c Jun 6, 2020
554a18d
to modify the grant usage command
Jun 6, 2020
b4d4df2
Update docs/services/mysql/mysql.md
jananivMS Jun 7, 2020
5dd2ad7
Update docs/services/mysql/mysql.md
jananivMS Jun 7, 2020
9d60f74
Update pkg/resourcemanager/mysql/mysqluser/mysqluser_reconcile.go
jananivMS Jun 7, 2020
a34f2ae
chart updates
jananivMS Jun 8, 2020
bbce8d7
Merge pull request #6 from jananivMS/chartupd
jananivMS Jun 8, 2020
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: 4 additions & 3 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ resources:
version: v1alpha1
kind: MySQLVNetRule
- group: azure
kind: MySQLUser
version: v1alpha1
- group: azure
kind: AzureVirtualMachine
buhongw7583c marked this conversation as resolved.
Show resolved Hide resolved
buhongw7583c marked this conversation as resolved.
Show resolved Hide resolved
version: v1alpha1
- group: azure
version: v1alpha1
kind: AzureSQLManagedUser
Expand Down Expand Up @@ -130,6 +133,4 @@ resources:
- group: azure
kind: AzureVirtualMachineExtension
version: v1alpha1
- group: azure
kind: AzureVirtualMachineExtension
version: v1alpha1

58 changes: 58 additions & 0 deletions api/v1alpha1/mysqluser_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// MySQLUserSpec defines the desired state of MySqlUser
type MySQLUserSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Server string `json:"server"`
DbName string `json:"dbName"`
ResourceGroup string `json:"resourceGroup,omitempty"`
Roles []string `json:"roles"`
// optional
AdminSecret string `json:"adminSecret,omitempty"`
AdminSecretKeyVault string `json:"adminSecretKeyVault,omitempty"`
Username string `json:"username,omitempty"`
KeyVaultToStoreSecrets string `json:"keyVaultToStoreSecrets,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// MySQLUser is the Schema for the mysqlusers API
// +kubebuilder:printcolumn:name="Provisioned",type="string",JSONPath=".status.provisioned"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.message"
type MySQLUser struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec MySQLUserSpec `json:"spec,omitempty"`
Status ASOStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// MySQLUserList contains a list of MySQLUser
type MySQLUserList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MySQLUser `json:"items"`
}

func init() {
SchemeBuilder.Register(&MySQLUser{}, &MySQLUserList{})
}

// IsSubmitted checks if sqluser is provisioning
func (s *MySQLUser) IsSubmitted() bool {
return s.Status.Provisioning || s.Status.Provisioned
}
79 changes: 79 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified charts/azure-service-operator-0.1.0.tgz
Binary file not shown.
6 changes: 3 additions & 3 deletions charts/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ entries:
azure-service-operator:
- apiVersion: v2
appVersion: 0.1.0
created: "2020-06-02T09:40:24.98057+08:00"
created: "2020-06-07T20:44:33.146559-06:00"
dependencies:
- condition: azureUseMI
name: aad-pod-identity
repository: https://raw.githubusercontent.com/Azure/aad-pod-identity/master/charts
version: 1.5.5
description: Deploy components and dependencies of azure-service-operator
digest: b549a78f07f6dca8a8f761cd65791ca8cad73b3bf90b03891101fa2cd70e3de8
digest: e5b46b9d1fb5a9183673bee06dc9592b3106aa692cfd9bef807ccab615163603
home: https://github.com/Azure/azure-service-operator
name: azure-service-operator
sources:
- https://github.com/Azure/azure-service-operator
urls:
- azure-service-operator-0.1.0.tgz
version: 0.1.0
generated: "2020-06-02T09:40:24.976336+08:00"
generated: "2020-06-07T20:44:33.143346-06:00"
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ resources:
- bases/azure.microsoft.com_mysqlservers.yaml
- bases/azure.microsoft.com_mysqldatabases.yaml
- bases/azure.microsoft.com_mysqlfirewallrules.yaml
- bases/azure.microsoft.com_mysqlusers.yaml
- bases/azure.microsoft.com_azurepublicipaddresses.yaml
- bases/azure.microsoft.com_azurenetworkinterfaces.yaml
- bases/azure.microsoft.com_mysqlvnetrules.yaml
Expand Down Expand Up @@ -83,6 +84,7 @@ patches:
#- patches/webhook_in_rediscacheactions.yaml
#- patches/webhook_in_rediscachefirewallrules.yaml
#- patches/webhook_in_azurevirtualmachineextensions.yaml
#- patches/webhook_in_mysqlusers.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CAINJECTION] patches here are for enabling the CA injection for each CRD
Expand Down Expand Up @@ -123,6 +125,7 @@ patches:
#- patches/cainjection_in_rediscacheactions.yaml
#- patches/cainjection_in_rediscachefirewallrules.yaml
#- patches/cainjection_in_azurevirtualmachineextensions.yaml
#- patches/cainjection_in_mysqlusers.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
9 changes: 9 additions & 0 deletions config/crd/patches/cainjection_in_mysqlusers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# The following patch adds a directive for certmanager to inject CA into the CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: mysqlusers.azure.microsoft.com
17 changes: 17 additions & 0 deletions config/crd/patches/webhook_in_mysqlusers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: mysqlusers.azure.microsoft.com
spec:
conversion:
strategy: Webhook
webhookClientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
24 changes: 24 additions & 0 deletions config/rbac/mysqluser_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# permissions for end users to edit mysqlusers.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: mysqluser-editor-role
rules:
- apiGroups:
- azure.microsoft.com
resources:
- mysqlusers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- azure.microsoft.com
resources:
- mysqlusers/status
verbs:
- get
20 changes: 20 additions & 0 deletions config/rbac/mysqluser_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# permissions for end users to view mysqlusers.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: mysqluser-viewer-role
rules:
- apiGroups:
- azure.microsoft.com
resources:
- mysqlusers
verbs:
- get
- list
- watch
- apiGroups:
- azure.microsoft.com
resources:
- mysqlusers/status
verbs:
- get
36 changes: 36 additions & 0 deletions config/samples/azure_v1alpha1_mysql_everything.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: azure.microsoft.com/v1alpha1
kind: MySQLServer
metadata:
name: mysqlserver-sample
spec:
location: eastus2
resourceGroup: resourcegroup-azure-operators
serverVersion: "8.0"
sslEnforcement: Enabled
createMode: Default # Possible values include: Default, Replica, PointInTimeRestore (not implemented), GeoRestore (not implemented)
sku:
name: GP_Gen5_4 # tier + family + cores eg. - B_Gen4_1, GP_Gen5_4
tier: GeneralPurpose # possible values - 'Basic', 'GeneralPurpose', 'MemoryOptimized'
family: Gen5
size: "51200"
capacity: 4
---
apiVersion: azure.microsoft.com/v1alpha1
kind: MySQLDatabase
metadata:
name: mysqldatabase-sample
spec:
resourceGroup: resourcegroup-azure-operators
server: mysqlserver-sample

---
apiVersion: azure.microsoft.com/v1alpha1
kind: MySQLFirewallRule
metadata:
name: mysqlfirewallrule-sample
spec:
resourceGroup: resourcegroup-azure-operators
server: mysqlserver-sample
startIpAddress: 0.0.0.0
endIpAddress: 0.0.0.0

25 changes: 25 additions & 0 deletions config/samples/azure_v1alpha1_mysqluser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: azure.microsoft.com/v1alpha1
kind: MySQLUser
metadata:
name: mysqluser-sample
spec:
server: mysqlserver-sample
dbName: mysqldatabase-sample
resourceGroup: resourcegroup-azure-operators
roles:
#now only supports to grant privileges to a new user, the privileges could be one or more of the below
#SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES,
#CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT,
#CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER
# This adds the privileges to the specified database
- SELECT
# Specify a specific username for the user
# username: mysqluser-sample
# Specify adminSecret and adminSecretKeyVault if you want to
# read the MYSQL server admin creds from a specific keyvault secret
# adminSecret: mysqlserver-sample
# adminSecretKeyVault: asokeyvault

# Use the field below to optionally specify a different keyvault
# to store the secrets in
# keyVaultToStoreSecrets: asokeyvault
29 changes: 29 additions & 0 deletions controllers/mysqluser_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package controllers

import (
ctrl "sigs.k8s.io/controller-runtime"

azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1"
)

// MySQLUserReconciler reconciles a MySQLUser object
type MySQLUserReconciler struct {
Reconciler *AsyncReconciler
}

// Reconcile for mysqluser
// +kubebuilder:rbac:groups=azure.microsoft.com,resources=mysqlusers,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=azure.microsoft.com,resources=mysqlusers/status,verbs=get;update;patch
func (r *MySQLUserReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return r.Reconciler.Reconcile(req, &azurev1alpha1.MySQLUser{})
}

// SetupWithManager runs reconcile loop with manager
func (r *MySQLUserReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&azurev1alpha1.MySQLUser{}).
Complete(r)
}
Loading