Skip to content

Commit edcdc5e

Browse files
authored
Added explanation to HTTP 403 errors (#1011)
Added `Using XXX auth` explanation to HTTP 403 errors, which should help troubleshooting misconfigured authentication or provider aliasing. Example error message now looks like: *cannot create group: /2.0/preview/scim/v2/Groups is only accessible by admins. Using databricks-cli auth: host=https://XXX.cloud.databricks.com/, token=`***REDACTED***`, profile=demo.* All sensitive configuration parameters (`token`, `password`, and `azure_client_secret`) are redacted and replaced with `***REDACTED***` Fixes #821
1 parent c7c60e2 commit edcdc5e

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

CHANGELOG.md

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

33
## 0.4.3
44

5+
* Added `Using XXX auth` explanation to HTTP 403 errors, which should help troubleshooting misconfigured authentication or provider aliasing. Example error message now looks like: *cannot create group: /2.0/preview/scim/v2/Groups is only accessible by admins. Using databricks-cli auth: host=https://XXX.cloud.databricks.com/, token=`***REDACTED***`, profile=demo.* All sensitive configuration parameters (`token`, `password`, and `azure_client_secret`) are redacted and replaced with `***REDACTED***` ([#821](https://github.com/databrickslabs/terraform-provider-databricks/issues/821)).
56
* Improved documentation with regards to public subnets in AWS quick start ([#1005](https://github.com/databrickslabs/terraform-provider-databricks/pull/1005)).
67
* Added `databricks_mount` code genration for [exporter](https://registry.terraform.io/providers/databrickslabs/databricks/latest/docs/guides/experimental-exporter) tooling ([#1006](https://github.com/databrickslabs/terraform-provider-databricks/pull/1006)).
78
* Increase dependency check frequency ([#1007](https://github.com/databrickslabs/terraform-provider-databricks/pull/1007)).

common/client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,16 @@ func (c *DatabricksClient) configDebugString() string {
214214
if value == "" {
215215
continue
216216
}
217+
if attr.Name == "azure_use_msi" && value == "false" {
218+
// include Azure MSI info only when it's relevant
219+
continue
220+
}
217221
if attr.Sensitive {
218222
value = "***REDACTED***"
219223
}
220224
debug = append(debug, fmt.Sprintf("%s=%v", attr.Name, value))
221225
}
222-
return strings.Join(debug, ", ")
226+
return strings.Join(debug, ", ") // lgtm[go/clear-text-logging]
223227
}
224228

225229
// Authenticate lazily authenticates across authorizers or returns error

common/http.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ func (c *DatabricksClient) parseError(resp *http.Response) APIError {
210210
}
211211
errorBody.ErrorCode = fmt.Sprintf("SCIM_%s", errorBody.ScimStatus)
212212
}
213+
if resp.StatusCode == 403 {
214+
errorBody.Message = fmt.Sprintf("%s. Using %s auth: %s",
215+
strings.Trim(errorBody.Message, "."), c.AuthType,
216+
c.configDebugString())
217+
}
213218
return APIError{
214219
Message: errorBody.Message,
215220
ErrorCode: errorBody.ErrorCode,

common/http_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ func TestParseError_API12(t *testing.T) {
131131
"Actual message: %s", err.Error())
132132
}
133133

134+
func TestParseError_Enhance403(t *testing.T) {
135+
ws := DatabricksClient{
136+
Host: "qwerty.cloud.databricks.com",
137+
Token: "x",
138+
}
139+
assert.NoError(t, ws.Authenticate(context.Background()))
140+
err := ws.parseError(&http.Response{
141+
Request: httptest.NewRequest(
142+
"GET", "https://querty.cloud.databricks.com/api/2.0/clusters/list",
143+
nil),
144+
StatusCode: 403,
145+
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
146+
"error_code": "PERMISSION_DENIED",
147+
"message": "You are not authorized."
148+
}`))),
149+
})
150+
assert.EqualError(t, err, "You are not authorized. Using pat auth: "+
151+
"host=https://qwerty.cloud.databricks.com, token=***REDACTED***")
152+
}
153+
134154
func TestParseError_SCIM(t *testing.T) {
135155
ws := DatabricksClient{
136156
Host: "qwerty.cloud.databricks.com",

0 commit comments

Comments
 (0)