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

feat: support set BackupStorageLocation(BSL) CA certificate #3167

Merged
merged 5 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions changelogs/unreleased/3167-jenting
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: support sets BackupStorageLocation CA certificate by `velero backup-location set --cacert`
jenting marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions design/cli-install-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Commands/flags for backup locations.
set
--default string sets the default backup storage location (default "default") (NEW, -- was `server --default-backup-storage-location; could be set as an annotation on the BSL)
--credentials mapStringString sets the name of the corresponding credentials secret for a provider. Format is provider:credentials-secret-name. (NEW)
--cacert-file mapStringString configuration to use for creating a secret containing a custom certificate for an S3 location of a plugin provider. Format is provider:path-to-file. (NEW)
--cacert mapStringString configuration to use for creating a secret containing a custom certificate for an S3 location of a plugin provider. Format is provider:path-to-file. (NEW)
jenting marked this conversation as resolved.
Show resolved Hide resolved

create NAME [flags]
--default Sets this new location to be the new default backup location. Default is false. (NEW)
Expand All @@ -131,7 +131,7 @@ Commands/flags for backup locations.
--provider string name of the backup storage provider (e.g. aws, azure, gcp)
--show-labels show labels in the last column
--credentials mapStringString sets the name of the corresponding credentials secret for a provider. Format is provider:credentials-secret-name. (NEW)
--cacert-file mapStringString configuration to use for creating a secret containing a custom certificate for an S3 location of a plugin provider. Format is provider:path-to-file. (NEW)
--cacert mapStringString configuration to use for creating a secret containing a custom certificate for an S3 location of a plugin provider. Format is provider:path-to-file. (NEW)

get Display backup storage locations
--default displays the current default backup storage location (NEW)
Expand Down Expand Up @@ -276,7 +276,7 @@ The value for these flags will be stored as annotations.

#### Handling CA certs

In anticipation of a new configuration implementation to handle custom CA certs (as per design doc https://github.com/vmware-tanzu/velero/blob/main/design/custom-ca-support.md), a new flag `velero storage-location create/set --cacert-file mapStringString` is proposed. It sets the configuration to use for creating a secret containing a custom certificate for an S3 location of a plugin provider. Format is provider:path-to-file.
In anticipation of a new configuration implementation to handle custom CA certs (as per design doc https://github.com/vmware-tanzu/velero/blob/main/design/custom-ca-support.md), a new flag `velero backup-location create/set --cacert mapStringString` is proposed. It sets the configuration to use for creating a secret containing a custom certificate for an S3 location of a plugin provider. Format is provider:path-to-file.

See discussion https://github.com/vmware-tanzu/velero/pull/2259#discussion_r384700723 for more clarification.

Expand Down
17 changes: 17 additions & 0 deletions pkg/cmd/cli/backuplocation/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package backuplocation
import (
"context"
"fmt"
"io/ioutil"
"path/filepath"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -51,6 +53,7 @@ func NewSetCommand(f client.Factory, use string) *cobra.Command {

type SetOptions struct {
Name string
CACertFile string
DefaultBackupStorageLocation bool
}

Expand All @@ -59,6 +62,7 @@ func NewSetOptions() *SetOptions {
}

func (o *SetOptions) BindFlags(flags *pflag.FlagSet) {
flags.StringVar(&o.CACertFile, "cacert", o.CACertFile, "File containing a certificate bundle to use when verifying TLS connections to the object store. Optional.")
flags.BoolVar(&o.DefaultBackupStorageLocation, "default", o.DefaultBackupStorageLocation, "Sets this new location to be the new default backup storage location. Optional.")
}

Expand All @@ -82,6 +86,18 @@ func (o *SetOptions) Run(c *cobra.Command, f client.Factory) error {
return errors.WithStack(err)
}

var caCertData []byte
if o.CACertFile != "" {
realPath, err := filepath.Abs(o.CACertFile)
if err != nil {
return err
}
caCertData, err = ioutil.ReadFile(realPath)
if err != nil {
return err
}
}

if o.DefaultBackupStorageLocation {
// There is one and only one default backup storage location.
// Disable the origin default backup storage location.
Expand All @@ -106,6 +122,7 @@ func (o *SetOptions) Run(c *cobra.Command, f client.Factory) error {
}

location.Spec.Default = o.DefaultBackupStorageLocation
location.Spec.StorageType.ObjectStorage.CACert = caCertData
if err := kbClient.Update(context.Background(), location, &kbclient.UpdateOptions{}); err != nil {
return errors.WithStack(err)
}
Expand Down