Encrypt cache used by ske kubeconfig login
#1244
Merged
+238
−46
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.
Description
ske kubeconfig loginstores retrieved credentials on-disk in a cache. Those files should be handled like secrets but are too large to be stored in the keyring. Thus, just encrypt them with AES-GCM using a secret key that is stored in the keyring. The extra security provided by this is somewhat limited as someone who's able to read the cache entry is likely also able to call the stackit cli to retrieve the decrypted value. However, this encryption ensures consistent secret handling by being consistent with the normal access token that is also stored in the keyring.There is no need for a migration of existing cache entries as the tokens there are short-lived and will be automatically refreshed if they cannot be read from the cache.
The go docs for
cipher.NewGCMWithRandomNoncestate that a key should only be used at most 2^32 times. This limit is unlikely to be ever reached, so I've opted for the simplest option and just refresh the key every 90 days, which is already more than enough. This also provides a good opportunity to clean up stale files in the cache.Relates to STACKITSKE-4927
Checklist
make fmtExamples were added / adjusted (see e.g. here)not relevantmake generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)