Skip to content

fix(authentication): service account becomes invalid on macos when the service account key is too big for keychain - #1758

Open
marceljk wants to merge 2 commits into
mainfrom
fix/STACKITCLI-252-authentication-on-macos-fails-with-new-sa-keys
Open

marceljk wants to merge 2 commits into
mainfrom
fix/STACKITCLI-252-authentication-on-macos-fails-with-new-sa-keys

Conversation

@marceljk

@marceljk marceljk commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

relates to STACKITCLI-252 and #1716

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see e.g. here)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@marceljk
marceljk requested a review from a team as a code owner November 19, 2026 13:55
…n mac when the Service Account Key is too big for keychain
@marceljk
marceljk force-pushed the fix/STACKITCLI-252-authentication-on-macos-fails-with-new-sa-keys branch from e71e239 to e061960 Compare November 19, 2026 14:05
Comment thread internal/pkg/auth/storage_test.go Outdated
}

textFilePath := filepath.Join(config.GetProfileFolderPath(profile), textFileName)
_ = os.Remove(textFilePath)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it removes my real cli-auth-storage.txt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a SetDefaultConfigFolderPath function which allows overwriting the path for the profiles. Each tests runs now in a test dir for the profiles and don't has conflicts anymore with existing configs or modifies there anything

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ ls ~/Library/Application\ Support/stackit
cli-api-auth-storage.txt  cli-config.json           profiles/
cli-auth-storage.txt      cli-profile.txt

$ make test

$ ls ~/Library/Application\ Support/stackit
cli-api-auth-storage.txt  cli-config.json           profiles/

I'm not sure where, but there are still deletes in my real files

Comment on lines +111 to +114
_ = deleteAuthFieldInKeyring(profile, key)
} else {
// If writing to the keyring succeeded, clean up any old entry from the encoded text file.
_ = deleteAuthFieldInEncodedTextFile(profile, key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't error handling necessary here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just tries to remove stale keys. If the deletion for the keyring fails, it means that there was no key before. For the deletion in the encoded text files it can have multiple issues, mostly permission issues or a broken file. If we would have a logger here, we could do log the here, but I wouldn't return an error when something in deleteAuthFieldInEncodedTextFile failed while the actual setting of auth fields in the keyring was successful

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked the library: it'll return keyring.ErrNotFound when not found. I'd add a conditional and report the other errors to the user.

Comment thread internal/pkg/auth/service_account.go Resolved
@github-actions

Copy link
Copy Markdown

Merging this branch changes the coverage (1 decrease, 1 increase)

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/stackit-cli/internal/pkg/auth 58.52% (+0.92%) 👍
github.com/stackitcloud/stackit-cli/internal/pkg/config 70.49% (-0.25%) 👎
Coverage details

Compared to commit 03f7993 (run #44488115488)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/stackit-cli/internal/pkg/auth/service_account.go 74.39% (-3.39%) 82 (+10) 61 (+5) 21 (+5) 👎
github.com/stackitcloud/stackit-cli/internal/pkg/auth/storage.go 78.64% (+1.72%) 206 (+24) 162 (+22) 44 (+2) 👍
github.com/stackitcloud/stackit-cli/internal/pkg/config/config.go 90.28% (-1.27%) 72 (+1) 65 7 (+1) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files:

  • github.com/stackitcloud/stackit-cli/internal/pkg/auth/storage_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants