Skip to content

Commit

Permalink
Merge pull request #147 from katherinelc321/delete-key-rotate-secret
Browse files Browse the repository at this point in the history
Delete existing access keys before creating new one
  • Loading branch information
openshift-merge-robot authored Sep 13, 2021
2 parents c5fc1e0 + 60b6330 commit e11985d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/account/rotate-secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,29 @@ func (o *rotateSecretOptions) run() error {
// Username is osdManagedAdmin-aaabbb
osdManagedAdminUsername := common.OSDManagedAdminIAM + "-" + accountIDSuffixLabel

// List and delete any existing access keys
inputListAccessKeys := &iam.ListAccessKeysInput{
UserName: &osdManagedAdminUsername,
}

accessKeys, err := awsClient.ListAccessKeys(inputListAccessKeys)
if err != nil {
return err
}

for _, k := range accessKeys.AccessKeyMetadata {

inputDelKey := &iam.DeleteAccessKeyInput{
AccessKeyId: k.AccessKeyId,
UserName: &osdManagedAdminUsername,
}
_, err = awsClient.DeleteAccessKey(inputDelKey)
if err != nil {
return err
}
}

// Create new access key
createAccessKeyOutput, err := awsClient.CreateAccessKey(&iam.CreateAccessKeyInput{
UserName: aws.String(osdManagedAdminUsername),
})
Expand Down

0 comments on commit e11985d

Please sign in to comment.