Repository navigation
Conversation
Commands now authenticate with KERNEL_API_KEY, then with the federation rule in KERNEL_FEDERATION_RULE_ID, then with the saved login. A failed federation exchange fails the command instead of falling back to the saved login. The access token is cached between CLI processes where it can be tied to the workload that obtained it, and the AWS identity token source is linked in.
Bind a token from a file source to the identity token that was exchanged for it, hold a cached token to the 60 second margin when it is sent, make the retry after a 401 final, and keep the token off requests to other hosts.
After a 401, send a request again only when net/http itself would replay it, so a vault write without a body is sent once as well.
…ecret-store # Conflicts: # pkg/auth/federation_cache.go # pkg/auth/federation_test.go
A replacement file takes what its directory gives a new file rather than what the old file had: an access control list set on the credentials file is lost on Windows and macOS, a symbolic link is replaced instead of followed, and a file mounted from elsewhere cannot be renamed over. The credentials lock already keeps CLI processes from reading a file that is being written, so the saved login goes back to being written in place, as it was before this branch. Each store now names how its file is written; the token cache keeps its temporary file and rename. Add tests for the saved login's path, modes and keychain entry, the error a missing login produces, DeleteTokens, and a GitHub Actions job leaving the keychain alone.
Contributor
Author
|
Picked masnwilliams to review: recent commits in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows #330, which is merged.
What changed
The saved login and the workload identity token cache each had their own copy of "keychain first, an owner-only file when the keychain refuses, remove the other copy". They now share one type,
secretStore(pkg/auth/secret_store.go), withread,saveand per-copy delete.storage.go: the saved login uses the store. The helpers that read and deleted the credentials file are gone; the one that wrote it is nowwriteCredentialsFile.federation_cache.go: the token cache uses the store. Its own keychain handling is gone.saved_atfor the login, the later expiry for a token.secretStore.writeFile): the saved login is written in place, the token cache through a temporary file and a rename. Both are whatmaindoes today.What changes for a CLI user
Nothing. Paths, keychain entries, file modes, the refresh lock, how each file is written and the rule for which copy is current are unchanged, including for files saved before
saved_atexisted.An earlier version of this branch also wrote the credentials file through a temporary file and a rename. That is removed. A replacement file takes what its directory gives a new file rather than what the old file had, so the rename:
device or resource busywhen the credentials file is bind-mounted into a container (reproduced on Linux).It bought little in return: every CLI read, save and refresh of the login already holds the credentials lock, so no CLI process reads a half-written file.
One error message differs in a case that needs the home directory lookup to start failing between two calls in the same function: a config directory error while loading the login is prefixed with
failed to read tokens from file:. Theno stored credentials founderror for a missing login is unchanged.Tests added
TestCredentialsFileOnDisk: the credentials file is at~/.config/kernel/credentials, mode 0600 in a 0700 directory, written in place, with no other file left beside it and the lock.TestSavedLoginKeepsItsKeychainEntry: the keychain entry iskernel-cli/oauth-tokens, by value.TestLoadTokensWithoutALogin: the exact error a missing login produces.TestDeleteTokens: both copies are removed, nothing in the keychain is not an error, and any other keychain error is returned.TestGitHubActionsJobLeavesTheKeychainAlone: a GitHub Actions job neither uses nor removes a keychain entry of the same name.Each was checked to fail when the behavior it covers is broken, by changing the source and re-running the package tests.
Verification
Run on the head commit, linux/amd64, Go 1.27.4:
make buildmake test(go vet ./...andgo test ./...)go test -race -count=2 ./pkg/auth/GOOS=windows go build ./...andGOOS=windows go vet ./pkg/auth/GOOS=darwin GOARCH=arm64 go build ./...andGOOS=darwin GOARCH=arm64 go vet ./pkg/auth/Not verified: a real OS keychain (the tests use the mock), and nothing was run on Windows or macOS beyond cross-compiling. The Windows and macOS access control points above come from the platforms' documented behavior and the Go standard library source, not from a run on those systems.