From 3ab9dff62ed0164287aaeaa3cb27ad0b15ce27c4 Mon Sep 17 00:00:00 2001 From: Andrew Shannon Brown Date: Tue, 7 Jul 2020 16:19:56 -0700 Subject: [PATCH] Set O_TRUNC when re-writing credentials file (#292) This should keep old crud from being included at the end of the file if it shrinks. --- cmd/write-to-credentials.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/write-to-credentials.go b/cmd/write-to-credentials.go index 893ce467..b5a8c6b0 100644 --- a/cmd/write-to-credentials.go +++ b/cmd/write-to-credentials.go @@ -125,7 +125,7 @@ func writeToCredentialsRun(cmd *cobra.Command, args []string) error { section.Key("aws_session_token").SetValue(creds.SessionToken) section.Key("aws_security_token").SetValue(creds.SessionToken) - credFile, err := os.OpenFile(credFilePath, os.O_WRONLY, 0600) + credFile, err := os.OpenFile(credFilePath, os.O_WRONLY|os.O_TRUNC, 0600) if err != nil { return err }