Skip to content

Commit b5e9323

Browse files
Improve error messages for authentication setup and credentials (#6098)
* fix: improve error messages in auth setup and credentials parsing * chore: copy core change into root changelog --------- Co-authored-by: cgoetz-inovex <carlo.goetz@inovex.de>
1 parent 6ccc0da commit b5e9323

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@
101101
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.24.0`
102102
- `vpn`: [v0.4.1](services/vpn/CHANGELOG.md#v041)
103103
- **Dependencies:** Bump STACKIT SDK core module from `v0.23.0` to `v0.24.0`
104-
105-
- `core`: [v0.24.0](core/CHANGELOG.md#v0240)
106-
- **Bugfix:** Allow setting waiter timeouts via context, that are longer than the default timeout.
104+
- `core`:
105+
- [v0.24.1](core/CHANGELOG.md#v0241)
106+
- **Improvement:** Fix misleading error messages in authentication setup and credentials parsing.
107+
- [v0.24.0](core/CHANGELOG.md#v0240)
108+
- **Bugfix:** Allow setting waiter timeouts via context, that are longer than the default timeout.
107109

108110
## Release (2026-03-27)
109111
- `alb`:

core/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.24.1
2+
- **Improvement:** Fix misleading error messages in authentication setup and credentials parsing.
3+
14
## v0.24.0
25
- **Bugfix:** Allow setting waiter timeouts via context, that are longer than the default timeout.
36

core/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.24.0
1+
v0.24.1

core/auth/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func SetupAuth(cfg *config.Configuration) (rt http.RoundTripper, err error) {
5454
} else if cfg.WorkloadIdentityFederation {
5555
wifRoundTripper, err := WorkloadIdentityFederationAuth(cfg)
5656
if err != nil {
57-
return nil, fmt.Errorf("configuring no auth client: %w", err)
57+
return nil, fmt.Errorf("configuring workload identity federation client: %w", err)
5858
}
5959
return wifRoundTripper, nil
6060
} else if cfg.ServiceAccountKey != "" || cfg.ServiceAccountKeyPath != "" {
@@ -278,7 +278,7 @@ func readCredentialsFile(path string) (*Credentials, error) {
278278
var credentials Credentials
279279
err = json.Unmarshal(credentialsRaw, &credentials)
280280
if err != nil {
281-
return nil, fmt.Errorf("unmaPrivateKeyrshalling credentials: %w", err)
281+
return nil, fmt.Errorf("unmarshalling credentials: %w", err)
282282
}
283283
return &credentials, nil
284284
}

core/auth/auth_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@ func TestReadCredentials(t *testing.T) {
367367
}
368368
}
369369

370+
func TestReadCredentialsFileErrorMessage(t *testing.T) {
371+
setTemporaryHome(t)
372+
373+
_, err := readCredentialsFile("test_resources/test_invalid_structure.json")
374+
if err == nil {
375+
t.Fatalf("error expected")
376+
}
377+
if !strings.Contains(err.Error(), "unmarshalling credentials") {
378+
t.Fatalf("expected unmarshalling credentials error, got %s", err)
379+
}
380+
}
381+
370382
func TestDefaultAuth(t *testing.T) {
371383
privateKey, err := generatePrivateKey()
372384
if err != nil {
@@ -768,6 +780,23 @@ func TestKeyAuthPemInsteadOfJsonKeyErrorHandling(t *testing.T) {
768780
}
769781
}
770782

783+
func TestSetupAuthWorkloadIdentityErrorMessage(t *testing.T) {
784+
setTemporaryHome(t)
785+
t.Setenv("STACKIT_SERVICE_ACCOUNT_EMAIL", "")
786+
t.Setenv("STACKIT_FEDERATED_TOKEN_FILE", "")
787+
788+
_, err := SetupAuth(&config.Configuration{WorkloadIdentityFederation: true})
789+
if err == nil {
790+
t.Fatalf("error expected")
791+
}
792+
if !strings.Contains(err.Error(), "configuring workload identity federation client") {
793+
t.Fatalf("expected workload identity federation error, got %s", err)
794+
}
795+
if strings.Contains(err.Error(), "configuring no auth client") {
796+
t.Fatalf("unexpected no auth error message: %s", err)
797+
}
798+
}
799+
771800
func TestNoAuth(t *testing.T) {
772801
for _, test := range []struct {
773802
desc string

0 commit comments

Comments
 (0)