From 1c675e42af5a76d5207ab7c20d45015f0734455e Mon Sep 17 00:00:00 2001 From: Andrew Shannon Brown Date: Tue, 7 Jul 2020 13:55:22 -0700 Subject: [PATCH] Set O_TRUNC when writing file 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 }