Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for deleting tokens & keypairs #3359

Merged
merged 2 commits into from
Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cmd/kops/delete_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"fmt"

"io"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -128,7 +127,12 @@ func RunDeleteSecret(f *util.Factory, out io.Writer, options *DeleteSecretOption
return fmt.Errorf("found multiple matching secrets; specify the id of the key")
}

err = keyStore.DeleteSecret(secrets[0])
switch secrets[0].Type {
case fi.SecretTypeSecret:
err = secretStore.DeleteSecret(secrets[0])
default:
err = keyStore.DeleteSecret(secrets[0])
}
if err != nil {
return fmt.Errorf("error deleting secret: %v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions upup/pkg/fi/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
type SecretStore interface {
// Get a secret. Returns an error if not found
Secret(id string) (*Secret, error)
// DeleteSecret deletes the specified secret
DeleteSecret(item *KeystoreItem) error
// Find a secret, if exists. Returns nil,nil if not found
FindSecret(id string) (*Secret, error)
// Create or replace a secret
Expand Down
16 changes: 14 additions & 2 deletions upup/pkg/fi/secrets/vfs_secretstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func NewVFSSecretStore(basedir vfs.Path) fi.SecretStore {
return c
}

func (s *VFSSecretStore) VFSPath() vfs.Path {
return s.basedir
func (c *VFSSecretStore) VFSPath() vfs.Path {
return c.basedir
}

func (c *VFSSecretStore) buildSecretPath(id string) vfs.Path {
Expand All @@ -55,6 +55,18 @@ func (c *VFSSecretStore) FindSecret(id string) (*fi.Secret, error) {
return s, nil
}

// DeleteSecret implements fi.SecretStore DeleteSecret
func (c *VFSSecretStore) DeleteSecret(item *fi.KeystoreItem) error {
switch item.Type {
case fi.SecretTypeSecret:
p := c.buildSecretPath(item.Name)
return p.Remove()

default:
return fmt.Errorf("deletion of secretstore items of type %v not (yet) supported", item.Type)
}
}

func (c *VFSSecretStore) ListSecrets() ([]string, error) {
files, err := c.basedir.ReadDir()
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions upup/pkg/fi/vfs_castore.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,21 @@ func (c *VFSCAStore) DeleteSecret(item *KeystoreItem) error {
p := c.buildSSHPublicKeyPath(item.Name, item.Id)
return p.Remove()

case SecretTypeKeypair:
version, ok := big.NewInt(0).SetString(item.Id, 10)
if !ok {
return fmt.Errorf("keypair had non-integer version: %q", item.Id)
}
p := c.buildCertificatePath(item.Name, version)
if err := p.Remove(); err != nil {
return fmt.Errorf("error deleting certificate: %v", err)
}
p = c.buildPrivateKeyPath(item.Name, version)
if err := p.Remove(); err != nil {
return fmt.Errorf("error deleting private key: %v", err)
}
return nil

default:
// Primarily because we need to make sure users can recreate them!
return fmt.Errorf("deletion of keystore items of type %v not (yet) supported", item.Type)
Expand Down
2 changes: 2 additions & 0 deletions util/pkg/vfs/s3fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (p *S3Path) Remove() error {
return err
}

glog.V(8).Infof("removing file %s", p)

request := &s3.DeleteObjectInput{}
request.Bucket = aws.String(p.bucket)
request.Key = aws.String(p.key)
Expand Down