Skip to content

Commit edd3db9

Browse files
authored
materialize-sqlserver: add azure iam auth (#3813)
Adds support for authenticating to SQL Server on Azure using IAM authentication.
1 parent 17f9b0f commit edd3db9

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎materialize-sqlserver/.snapshots/TestSpecification‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,34 @@
8787
"aws_role_arn"
8888
],
8989
"title": "AWS IAM"
90+
},
91+
{
92+
"$schema": "https://json-schema.org/draft/2020-12/schema",
93+
"$id": "https://github.com/estuary/connectors/go/auth/iam/azure-config",
94+
"properties": {
95+
"auth_type": {
96+
"type": "string",
97+
"const": "AzureIAM",
98+
"default": "AzureIAM",
99+
"order": 0
100+
},
101+
"azure_client_id": {
102+
"type": "string",
103+
"title": "Azure Client ID",
104+
"description": "Azure App Registration Client ID for Azure Active Directory authentication"
105+
},
106+
"azure_tenant_id": {
107+
"type": "string",
108+
"title": "Azure Tenant ID",
109+
"description": "Azure Tenant ID for Azure Active Directory authentication"
110+
}
111+
},
112+
"type": "object",
113+
"required": [
114+
"azure_client_id",
115+
"azure_tenant_id"
116+
],
117+
"title": "Azure IAM"
90118
}
91119
],
92120
"type": "object",
@@ -98,7 +126,8 @@
98126
"propertyName": "auth_type"
99127
},
100128
"order": 6,
101-
"x-iam-auth": true
129+
"x-iam-auth": true,
130+
"x-iam-azure-scope": "https://database.windows.net/.default"
102131
},
103132
"dbt_job_trigger": {
104133
"properties": {

‎materialize-sqlserver/driver.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type AuthType string
3838
const (
3939
UserPassword AuthType = "UserPassword"
4040
AWSIAM AuthType = "AWSIAM"
41+
AzureIAM AuthType = "AzureIAM"
4142
)
4243

4344
type UserPasswordConfig struct {
@@ -57,6 +58,8 @@ func (CredentialsConfig) JSONSchema() *jsonschema.Schema {
5758
}
5859
subSchemas = append(subSchemas,
5960
schemagen.OneOfSubSchema("AWS IAM", iam.AWSConfig{}, string(AWSIAM)))
61+
subSchemas = append(subSchemas,
62+
schemagen.OneOfSubSchema("Azure IAM", iam.AzureConfig{}, string(AzureIAM)))
6063

6164
schema := schemagen.OneOfSchema("Authentication", "", "auth_type", string(UserPassword), subSchemas...)
6265
return schema
@@ -70,6 +73,8 @@ func (c *CredentialsConfig) Validate() error {
7073
}
7174
return nil
7275
case AWSIAM:
76+
fallthrough
77+
case AzureIAM:
7378
if err := c.ValidateIAM(); err != nil {
7479
return err
7580
}
@@ -100,7 +105,7 @@ type config struct {
100105
Database string `json:"database" jsonschema:"title=Database,description=Name of the logical database to materialize to." jsonschema_extras:"order=3"`
101106
Schema string `json:"schema,omitempty" jsonschema:"title=Database Schema,description=Database schema for bound collection tables (unless overridden within the binding resource configuration) as well as associated materialization metadata tables" jsonschema_extras:"order=4"`
102107
HardDelete bool `json:"hardDelete,omitempty" jsonschema:"title=Hard Delete,description=If this option is enabled items deleted in the source will also be deleted from the destination. By default is disabled and _meta/op in the destination will signify whether rows have been deleted (soft-delete).,default=false" jsonschema_extras:"order=5"`
103-
Credentials *CredentialsConfig `json:"credentials" jsonschema:"title=Authentication" jsonschema_extras:"x-iam-auth=true,order=6"`
108+
Credentials *CredentialsConfig `json:"credentials" jsonschema:"title=Authentication" jsonschema_extras:"x-iam-auth=true,x-iam-azure-scope=https://database.windows.net/.default,order=6"`
104109

105110
DBTJobTrigger dbt.JobConfig `json:"dbt_job_trigger,omitempty" jsonschema:"title=dbt Cloud Job Trigger,description=Trigger a dbt Job when new data is available"`
106111

@@ -176,6 +181,8 @@ func (c *config) ToURI() *url.URL {
176181
userInfo = url.UserPassword(c.User, pass)
177182
case AWSIAM:
178183
userInfo = url.User(c.User)
184+
case AzureIAM:
185+
userInfo = nil
179186
}
180187
}
181188

@@ -219,6 +226,11 @@ func (c *config) ToSQLConnector(ctx context.Context) (driver.Connector, error) {
219226
}
220227

221228
return mssqldb.NewConnectorWithAccessTokenProvider(uri.String(), tokenProvider)
229+
case AzureIAM:
230+
token := c.Credentials.AzureToken()
231+
return mssqldb.NewAccessTokenConnector(uri.String(), func() (string, error) {
232+
return token, nil
233+
})
222234
}
223235
}
224236

0 commit comments

Comments
 (0)