Skip to content

Commit 1106b54

Browse files
authored
feat(core): bump SDK and consume new platform connection validation (#493)
- bumps SDK and its modules - differentiates between a platform configuration error and a platform unreachability error with new SDK validation
1 parent 60a18f7 commit 1106b54

File tree

8 files changed

+25
-30
lines changed

8 files changed

+25
-30
lines changed

cmd/root.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,11 @@ func NewHandler(c *cli.Cli) handlers.Handler {
177177
}
178178

179179
if err := auth.ValidateProfileAuthCredentials(c.Context(), cp); err != nil {
180-
if errors.Is(err, auth.ErrPlatformConfigNotFound) {
181-
cli.ExitWithError(fmt.Sprintf("Failed to get platform configuration. Is the platform accepting connections at '%s'?", cp.GetEndpoint()), nil)
180+
if errors.Is(err, sdk.ErrPlatformUnreachable) {
181+
cli.ExitWithError(fmt.Sprintf("Failed to connect to the platform. Is the platform accepting connections at '%s'?", cp.GetEndpoint()), nil)
182+
}
183+
if errors.Is(err, sdk.ErrPlatformConfigFailed) {
184+
cli.ExitWithError(fmt.Sprintf("Failed to get the platform configuration. Is the platform serving a well-known configuration at '%s'?", cp.GetEndpoint()), nil)
182185
}
183186
if inMemoryProfile {
184187
cli.ExitWithError("Failed to authenticate with flag-provided client credentials.", err)

e2e/auth.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ teardown_file() {
2828
BAD_HOST='--host http://localhost:9000'
2929
run_otdfctl $BAD_HOST $WITH_CREDS policy attributes list
3030
assert_failure
31-
assert_output --partial "Failed to get platform configuration. Is the platform accepting connections at"
31+
assert_output --partial "Failed to connect to the platform. Is the platform accepting connections at"
3232
}
3333

3434
@test "helpful error if bad credentials" {

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ require (
1616
github.com/golang-jwt/jwt v3.2.2+incompatible
1717
github.com/google/uuid v1.6.0
1818
github.com/opentdf/platform/lib/flattening v0.1.3
19-
github.com/opentdf/platform/protocol/go v0.2.26
20-
github.com/opentdf/platform/sdk v0.3.25
19+
github.com/opentdf/platform/protocol/go v0.2.27
20+
github.com/opentdf/platform/sdk v0.3.27
2121
github.com/spf13/cobra v1.8.1
2222
github.com/spf13/viper v1.19.0
2323
github.com/stretchr/testify v1.10.0
@@ -79,7 +79,7 @@ require (
7979
github.com/muesli/reflow v0.3.0 // indirect
8080
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
8181
github.com/muhlemmer/gu v0.3.1 // indirect
82-
github.com/opentdf/platform/lib/ocrypto v0.1.7 // indirect
82+
github.com/opentdf/platform/lib/ocrypto v0.1.8 // indirect
8383
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
8484
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
8585
github.com/rivo/uniseg v0.4.7 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ github.com/opentdf/platform/lib/fixtures v0.2.10 h1:R688b98ctsEiDRlQSvLxmAWT7bXv
226226
github.com/opentdf/platform/lib/fixtures v0.2.10/go.mod h1:wGhclxDeDXf8bp5VAWztT1nY2gWVNGQLd8rWs5wtXV0=
227227
github.com/opentdf/platform/lib/flattening v0.1.3 h1:IuOm/wJVXNrzOV676Ticgr0wyBkL+lVjsoSfh+WSkNo=
228228
github.com/opentdf/platform/lib/flattening v0.1.3/go.mod h1:Gs/T+6FGZKk9OAdz2Jf1R8CTGeNRYrq1lZGDeYT3hrY=
229-
github.com/opentdf/platform/lib/ocrypto v0.1.7 h1:IcCYRrwmMqntqUE8frmUDg5EZ0WMdldpGeGhbv9+/A8=
230-
github.com/opentdf/platform/lib/ocrypto v0.1.7/go.mod h1:4bhKPbRFzURMerH5Vr/LlszHvcoXQbfJXa0bpY7/7yg=
231-
github.com/opentdf/platform/protocol/go v0.2.26 h1:22ugJFhAjlz7BRAky3eBljIQrsLzmsdkKVM+pjuG09k=
232-
github.com/opentdf/platform/protocol/go v0.2.26/go.mod h1:eldxqX2oF2ADtG8ivhfwn1lALVMX4aaUM+Lp9ynOJXs=
233-
github.com/opentdf/platform/sdk v0.3.25 h1:dZEVeWKfbjrnEXKzSado8ebpzIrk2n6R7RSZRbX+FwE=
234-
github.com/opentdf/platform/sdk v0.3.25/go.mod h1:F+RGbT2o9GlzWH9s8VkZyUNUEEAWA3V2RSs8jNQHbqM=
229+
github.com/opentdf/platform/lib/ocrypto v0.1.8 h1:FUKMHsVCjU4NmgaXgS1RFstl19tkX/7USTIubAuUBlA=
230+
github.com/opentdf/platform/lib/ocrypto v0.1.8/go.mod h1:UTtqh8mvhAYA+sEnaMxpr/406e84L5Q1sAxtKGIXfu4=
231+
github.com/opentdf/platform/protocol/go v0.2.27 h1:ZnfXvVio+j/LzfEY8cHo8/tS45XAPWa2xO7Y1tn/hWs=
232+
github.com/opentdf/platform/protocol/go v0.2.27/go.mod h1:eldxqX2oF2ADtG8ivhfwn1lALVMX4aaUM+Lp9ynOJXs=
233+
github.com/opentdf/platform/sdk v0.3.27 h1:O9jCdpnxz3FEaTXj/hAOixR5mk/APsalcWCexGxfwkM=
234+
github.com/opentdf/platform/sdk v0.3.27/go.mod h1:ZJyz6hy0CMiD3MFfG4PrByTnSJnEtArTGA6ZoR1Xg6E=
235235
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
236236
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
237237
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=

pkg/auth/auth.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func getPlatformConfiguration(endpoint, publicClientID string, tlsNoVerify bool)
8383
return c, err
8484
}
8585

86-
opts := []sdk.Option{}
86+
opts := []sdk.Option{sdk.WithConnectionValidation()}
8787
if tlsNoVerify {
8888
opts = append(opts, sdk.WithInsecureSkipVerifyConn())
8989
}
@@ -309,9 +309,6 @@ func newOidcRelyingParty(ctx context.Context, endpoint string, tlsNoVerify bool,
309309

310310
pc, err := getPlatformConfiguration(endpoint, pcClient, tlsNoVerify)
311311
if err != nil {
312-
if errors.Is(err, sdk.ErrPlatformConfigFailed) {
313-
return nil, ErrPlatformConfigNotFound
314-
}
315312
return nil, err
316313
}
317314

pkg/auth/errors.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ package auth
33
import "errors"
44

55
var (
6-
ErrAccessTokenExpired = errors.New("access token expired")
7-
ErrAccessTokenNotFound = errors.New("no access token found")
8-
ErrClientCredentialsNotFound = errors.New("client credentials not found")
9-
ErrInvalidAuthType = errors.New("invalid auth type")
10-
ErrUnauthenticated = errors.New("not logged in")
11-
ErrParsingAccessToken = errors.New("failed to parse access token")
12-
)
13-
14-
var (
6+
ErrAccessTokenExpired = errors.New("access token expired")
7+
ErrAccessTokenNotFound = errors.New("no access token found")
8+
ErrClientCredentialsNotFound = errors.New("client credentials not found")
9+
ErrInvalidAuthType = errors.New("invalid auth type")
10+
ErrUnauthenticated = errors.New("not logged in")
11+
ErrParsingAccessToken = errors.New("failed to parse access token")
1512
ErrProfileCredentialsNotFound = errors.New("profile missing credentials")
16-
ErrPlatformConfigNotFound = errors.New("platform configuration not found")
1713
)

pkg/handlers/kas-grants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,6 @@ func (h Handler) ListKasGrants(ctx context.Context, kas_id, kas_uri string, limi
111111
if err != nil {
112112
return nil, nil, err
113113
}
114+
//nolint:staticcheck // deprecated but not removed while public keys work is experimental
114115
return resp.GetGrants(), resp.GetPagination(), nil
115116
}

pkg/handlers/sdk.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,12 @@ func New(opts ...handlerOptsFunc) (Handler, error) {
8484
o.sdkOpts = append(o.sdkOpts, sdk.WithInsecureSkipVerifyConn())
8585
}
8686

87-
// TODO let's make sure we still support plaintext connections
88-
8987
// get auth
90-
ao, err := auth.GetSDKAuthOptionFromProfile(o.profile)
88+
authSDKOpt, err := auth.GetSDKAuthOptionFromProfile(o.profile)
9189
if err != nil {
9290
return Handler{}, err
9391
}
94-
o.sdkOpts = append(o.sdkOpts, ao)
92+
o.sdkOpts = append(o.sdkOpts, authSDKOpt, sdk.WithConnectionValidation())
9593

9694
if u.Scheme == "http" {
9795
o.sdkOpts = append(o.sdkOpts, sdk.WithInsecurePlaintextConn())

0 commit comments

Comments
 (0)