Skip to content

Commit

Permalink
Merge pull request #580 from cybozu-go/backup-enable-tls
Browse files Browse the repository at this point in the history
Add tls settings for BackupPolicy
  • Loading branch information
ymmt2005 authored Oct 27, 2023
2 parents 7b0b37b + 96c7266 commit c17a4a2
Show file tree
Hide file tree
Showing 28 changed files with 608 additions and 124 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- Add tls settings for BackupPolicy [#580](https://github.com/cybozu-go/moco/pull/580)

## [0.17.0] - 2023-09-11

### Breaking Changes
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/job_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,8 @@ type BucketConfig struct {
// +kubebuilder:default=s3
// +optional
BackendType string `json:"backendType,omitempty"`

// Path to SSL CA certificate file used in addition to system default.
// +optional
CaCert string `json:"caCert,omitempty"`
}
2 changes: 2 additions & 0 deletions api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/v1beta2/job_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ type BucketConfig struct {
// +kubebuilder:default=s3
// +optional
BackendType string `json:"backendType,omitempty"`

// Path to SSL CA certificate file used in addition to system default.
// +optional
CaCert string `json:"caCert,omitempty"`
}

// AffinityApplyConfiguration is the type defined to implement the DeepCopy method.
Expand Down
12 changes: 12 additions & 0 deletions charts/moco/templates/generated/crds/moco_crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down Expand Up @@ -2452,6 +2455,9 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down Expand Up @@ -7722,6 +7728,9 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down Expand Up @@ -13606,6 +13615,9 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down
38 changes: 32 additions & 6 deletions cmd/moco-backup/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package cmd

import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"net/http"
"net/url"
"os"

Expand All @@ -15,12 +18,13 @@ import (
)

var commonArgs struct {
workDir string
threads int
region string
endpointURL string
usePathStyle bool
backendType string
workDir string
threads int
region string
endpointURL string
usePathStyle bool
backendType string
caCertFilePath string
}

func makeBucket(bucketName string) (bucket.Bucket, error) {
Expand All @@ -45,6 +49,27 @@ func makeS3Bucket(bucketName string) (bucket.Bucket, error) {
if commonArgs.usePathStyle {
opts = append(opts, bucket.WithPathStyle())
}
if len(commonArgs.caCertFilePath) > 0 {
caCertFile, err := os.ReadFile(commonArgs.caCertFilePath)
if err != nil {
return nil, err
}
caCertPool, err := x509.SystemCertPool()
if err != nil {
return nil, err
}
if ok := caCertPool.AppendCertsFromPEM(caCertFile); !ok {
return nil, fmt.Errorf("failed to add ca cert")
}
transport := http.DefaultTransport.(*http.Transport).Clone()
if transport.TLSClientConfig == nil {
transport.TLSClientConfig = &tls.Config{}
}
transport.TLSClientConfig.RootCAs = caCertPool
opts = append(opts, bucket.WithHTTPClient(&http.Client{
Transport: transport,
}))
}
return bucket.NewS3Bucket(bucketName, opts...)
}

Expand Down Expand Up @@ -95,4 +120,5 @@ func init() {
pf.StringVar(&commonArgs.endpointURL, "endpoint", "", "Object storage API endpoint URL")
pf.BoolVar(&commonArgs.usePathStyle, "use-path-style", false, "Use path-style S3 API")
pf.StringVar(&commonArgs.backendType, "backend-type", "s3", "The identifier for the object storage to be used.")
pf.StringVar(&commonArgs.caCertFilePath, "ca-cert", "", "Path to SSL CA certificate file used in addition to system default")
}
8 changes: 8 additions & 0 deletions config/crd/bases/moco.cybozu.com_backuppolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition
t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down Expand Up @@ -2649,6 +2653,10 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition
t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/moco.cybozu.com_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3999,6 +3999,10 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition
t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down Expand Up @@ -10430,6 +10434,10 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition
t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition
t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down Expand Up @@ -2648,6 +2652,10 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition
t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4009,6 +4009,10 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition
t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down Expand Up @@ -10440,6 +10444,10 @@ spec:
description: The name of the bucket
minLength: 1
type: string
caCert:
description: Path to SSL CA certificate file used in addition
t
type: string
endpointURL:
description: The API endpoint URL.
pattern: ^https?://.*
Expand Down
3 changes: 3 additions & 0 deletions controllers/mysqlcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,9 @@ func bucketArgs(bc mocov1beta2.BucketConfig) []string {
if bc.BackendType != "" {
args = append(args, "--backend-type="+bc.BackendType)
}
if bc.CaCert != "" {
args = append(args, "--ca-cert="+bc.CaCert)
}

return append(args, bc.BucketName)
}
Expand Down
1 change: 1 addition & 0 deletions docs/crd_backuppolicy_v1beta1.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ BucketConfig is a set of parameter to access an object storage bucket.
| endpointURL | The API endpoint URL. Set this for non-S3 object storages. | string | false |
| usePathStyle | Allows you to enable the client to use path-style addressing, i.e., https?://ENDPOINT/BUCKET/KEY. By default, a virtual-host addressing is used (https?://BUCKET.ENDPOINT/KEY). | bool | false |
| backendType | BackendType is an identifier for the object storage to be used. | string | false |
| caCert | Path to SSL CA certificate file used in addition to system default. | string | false |

[Back to Custom Resources](#custom-resources)

Expand Down
1 change: 1 addition & 0 deletions docs/crd_backuppolicy_v1beta2.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ BucketConfig is a set of parameter to access an object storage bucket.
| endpointURL | The API endpoint URL. Set this for non-S3 object storages. | string | false |
| usePathStyle | Allows you to enable the client to use path-style addressing, i.e., https?://ENDPOINT/BUCKET/KEY. By default, a virtual-host addressing is used (https?://BUCKET.ENDPOINT/KEY). | bool | false |
| backendType | BackendType is an identifier for the object storage to be used. | string | false |
| caCert | Path to SSL CA certificate file used in addition to system default. | string | false |

[Back to Custom Resources](#custom-resources)

Expand Down
1 change: 1 addition & 0 deletions docs/crd_mysqlcluster_v1beta1.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ BucketConfig is a set of parameter to access an object storage bucket.
| endpointURL | The API endpoint URL. Set this for non-S3 object storages. | string | false |
| usePathStyle | Allows you to enable the client to use path-style addressing, i.e., https?://ENDPOINT/BUCKET/KEY. By default, a virtual-host addressing is used (https?://BUCKET.ENDPOINT/KEY). | bool | false |
| backendType | BackendType is an identifier for the object storage to be used. | string | false |
| caCert | Path to SSL CA certificate file used in addition to system default. | string | false |

[Back to Custom Resources](#custom-resources)

Expand Down
1 change: 1 addition & 0 deletions docs/crd_mysqlcluster_v1beta2.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ BucketConfig is a set of parameter to access an object storage bucket.
| endpointURL | The API endpoint URL. Set this for non-S3 object storages. | string | false |
| usePathStyle | Allows you to enable the client to use path-style addressing, i.e., https?://ENDPOINT/BUCKET/KEY. By default, a virtual-host addressing is used (https?://BUCKET.ENDPOINT/KEY). | bool | false |
| backendType | BackendType is an identifier for the object storage to be used. | string | false |
| caCert | Path to SSL CA certificate file used in addition to system default. | string | false |

[Back to Custom Resources](#custom-resources)

Expand Down
1 change: 1 addition & 0 deletions docs/moco-backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Global Flags:
--threads int The number of threads to be used (default 4)
--use-path-style Use path-style S3 API
--work-dir string The writable working directory (default "/work")
--ca-cert string Path to SSL CA certificate file used in addition to system default
```

## Subcommands
Expand Down
1 change: 1 addition & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ endif
$(KUSTOMIZE) build . | $(KUBECTL) apply -f -
$(KUBECTL) -n moco-system wait --for=condition=available --timeout=180s --all deployments
$(KUBECTL) apply -f minio.yaml
$(KUBECTL) apply -f minio-tls.yaml
$(KUBECTL) apply -f fake-gcs-server.yaml
$(KUBECTL) wait --timeout=60s --for=condition=Ready --all pods

Expand Down
Loading

0 comments on commit c17a4a2

Please sign in to comment.