Skip to content

Commit

Permalink
Delete former credentials when rotating (granted credentials rotate) (
Browse files Browse the repository at this point in the history
#582)

* delete former credentials when rotating (`granted credentials rotate`)
closes #388

* rotate credentials delete opt-in behaviour introduced
  • Loading branch information
n3s7or authored Mar 1, 2024
1 parent 794a48e commit 8847355
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/granted/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,10 @@ var ExportCredentialsCommand = cli.Command{
var RotateCredentialsCommand = cli.Command{
Name: "rotate",
Usage: "Generates new access key for the profile in AWS, and updates the profile",
Flags: []cli.Flag{&cli.StringFlag{Name: "profile", Usage: "If provided, generates new access key for the specified profile"}},
Flags: []cli.Flag{
&cli.StringFlag{Name: "profile", Usage: "If provided, generates new access key for the specified profile"},
&cli.BoolFlag{Name: "delete", Usage: "delete the previous active key"},
},
Action: func(c *cli.Context) error {
profileName := c.String("profile")

Expand Down Expand Up @@ -583,6 +586,13 @@ var RotateCredentialsCommand = cli.Command{
return err
}

if c.Bool("delete") {
_, err = iamClient.DeleteAccessKey(c.Context, &iam.DeleteAccessKeyInput{AccessKeyId: &t.AccessKeyID})
if err != nil {
return err
}
}

clio.Successf("Access Key of '%s' profile has been successfully rotated and updated in secure storage\n", profileName)

return nil
Expand Down

0 comments on commit 8847355

Please sign in to comment.