Skip to content

Add Azure AD authentication support for mssql #166

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
.work
_output
__debug_bin
deploy
7 changes: 7 additions & 0 deletions apis/mssql/v1alpha1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import (
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// UserTypes
const (
UserTypeLocal = "Local"
UserTypeAD = "AD"
)

// A UserSpec defines the desired state of a Database.
type UserSpec struct {
xpv1.ResourceSpec `json:",inline"`
Expand All @@ -48,6 +54,7 @@ type UserParameters struct {
// for this user. If no reference is given, a password will be auto-generated.
// +optional
PasswordSecretRef *xpv1.SecretKeySelector `json:"passwordSecretRef,omitempty"`
Type *string `json:"type,omitempty"`
}

// A UserObservation represents the observed state of a MSSQL user.
Expand Down
5 changes: 5 additions & 0 deletions apis/mssql/v1alpha1/zz_generated.deepcopy.go

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

14 changes: 13 additions & 1 deletion cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (
"os"
"path/filepath"

_ "github.com/denisenkom/go-mssqldb"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
_ "github.com/microsoft/go-mssqldb"
_ "github.com/microsoft/go-mssqldb/azuread"

"gopkg.in/alecthomas/kingpin.v2"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -34,6 +35,9 @@ import (

"github.com/crossplane-contrib/provider-sql/apis"
"github.com/crossplane-contrib/provider-sql/pkg/controller"

azlog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log"
azidentity "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
)

func main() {
Expand All @@ -53,6 +57,14 @@ func main() {
// *very* verbose even at info level, so we only provide it a real
// logger when we're running in debug mode.
ctrl.SetLogger(zl)

// print log output to stdout
azlog.SetListener(func(event azlog.Event, s string) {
log.Debug(s) //fmt.Println(s)
})

// include only azidentity credential logs
azlog.SetEvents(azidentity.EventAuthentication)
}

log.Debug("Starting", "sync-period", syncPeriod.String())
Expand Down
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/secret.yaml
5 changes: 5 additions & 0 deletions examples/mssql/ad/database.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: mssql.sql.crossplane.io/v1alpha1
kind: Database
metadata:
name: example-db-ad
spec: {}
17 changes: 17 additions & 0 deletions examples/mssql/ad/grant.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: mssql.sql.crossplane.io/v1alpha1
kind: Grant
metadata:
name: example-grant
spec:
forProvider:
permissions:
# CONNECT permission is added by default when user created. So, make sure
# to include it unless you are sure that you don't need it.
- CONNECT
- CREATE TABLE
- INSERT
- SELECT
userRef:
name: example-user-ad
databaseRef:
name: example-db-ad
12 changes: 12 additions & 0 deletions examples/mssql/ad/user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: mssql.sql.crossplane.io/v1alpha1
kind: User
metadata:
name: example-user-ad
annotations:
##change to real user inside your AD
crossplane.io/external-name: "example-user@example-domain.com"
spec:
forProvider:
type: AD
databaseRef:
name: example-db-ad
3 changes: 1 addition & 2 deletions examples/mssql/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
apiVersion: mssql.sql.crossplane.io/v1alpha1
kind: ProviderConfig
metadata:
Expand All @@ -8,4 +7,4 @@ spec:
source: MSSQLConnectionSecret
connectionSecretRef:
namespace: default
name: db-conn
name: db-conn
31 changes: 20 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ go 1.21
toolchain go1.21.11

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/crossplane/crossplane-runtime v1.16.0
github.com/crossplane/crossplane-tools v0.0.0-20240522174801-1ad3d4c87f21
github.com/denisenkom/go-mssqldb v0.11.0
github.com/go-sql-driver/mysql v1.5.0
github.com/google/go-cmp v0.6.0
github.com/lib/pq v1.8.0
github.com/microsoft/go-mssqldb v1.7.2
github.com/pkg/errors v0.9.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
k8s.io/api v0.29.1
Expand All @@ -23,6 +25,8 @@ require (

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/alecthomas/kingpin/v2 v2.4.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
Expand All @@ -43,23 +47,27 @@ require (
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
Expand All @@ -70,16 +78,17 @@ require (
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.31.0 // indirect
Expand Down
Loading