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 storage ssl #288

Merged
merged 1 commit into from
Sep 21, 2023
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
6 changes: 6 additions & 0 deletions apis/apps/v1alpha1/nebulacluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ func (nc *NebulaCluster) IsClusterSSLEnabled() bool {
nc.Spec.Storaged.Config["enable_ssl"] == "true"
}

func (nc *NebulaCluster) IsStoragedSSLEnabled() bool {
return nc.Spec.Graphd.Config["enable_storage_ssl"] == "true" &&
nc.Spec.Metad.Config["enable_storage_ssl"] == "true" &&
nc.Spec.Storaged.Config["enable_storage_ssl"] == "true"
}

func (nc *NebulaCluster) IsZoneEnabled() bool {
return nc.Spec.Metad.Config["zone_list"] != ""
}
1 change: 1 addition & 0 deletions apis/apps/v1alpha1/nebulacluster_graphd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (c *graphdComponent) GetDataStorageResources() (*corev1.ResourceRequirement
func (c *graphdComponent) IsSSLEnabled() bool {
return (c.nc.Spec.Graphd.Config["enable_graph_ssl"] == "true" ||
c.nc.Spec.Graphd.Config["enable_meta_ssl"] == "true" ||
c.nc.Spec.Graphd.Config["enable_storage_ssl"] == "true" ||
c.nc.Spec.Graphd.Config["enable_ssl"] == "true") &&
c.nc.Spec.SSLCerts != nil
}
Expand Down
1 change: 1 addition & 0 deletions apis/apps/v1alpha1/nebulacluster_metad.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (c *metadComponent) GetDataStorageResources() (*corev1.ResourceRequirements

func (c *metadComponent) IsSSLEnabled() bool {
return (c.nc.Spec.Metad.Config["enable_meta_ssl"] == "true" ||
c.nc.Spec.Metad.Config["enable_storage_ssl"] == "true" ||
c.nc.Spec.Metad.Config["enable_ssl"] == "true") &&
c.nc.Spec.SSLCerts != nil
}
Expand Down
1 change: 1 addition & 0 deletions apis/apps/v1alpha1/nebulacluster_storaged.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (c *storagedComponent) GetDataStorageResources() (*corev1.ResourceRequireme

func (c *storagedComponent) IsSSLEnabled() bool {
return (c.nc.Spec.Storaged.Config["enable_meta_ssl"] == "true" ||
c.nc.Spec.Storaged.Config["enable_storage_ssl"] == "true" ||
c.nc.Spec.Storaged.Config["enable_ssl"] == "true") &&
c.nc.Spec.SSLCerts != nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/component/metad_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (c *metadCluster) syncMetadPVC(nc *v1alpha1.NebulaCluster) error {
}

func (c *metadCluster) setVersion(nc *v1alpha1.NebulaCluster) error {
options, err := nebula.ClientOptions(nc)
options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/component/storaged_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (c *storagedCluster) syncStoragedPVC(nc *v1alpha1.NebulaCluster) error {
}

func (c *storagedCluster) addStorageHosts(nc *v1alpha1.NebulaCluster, oldReplicas, newReplicas int32) error {
options, err := nebula.ClientOptions(nc)
options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true))
if err != nil {
return err
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func (c *storagedCluster) registeredHosts(mc nebula.MetaInterface) (sets.Set[str

func (c *storagedCluster) addStorageHostsToZone(nc *v1alpha1.NebulaCluster, newReplicas int32) error {
namespace := nc.GetNamespace()
options, err := nebula.ClientOptions(nc)
options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/component/storaged_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (ss *storageScaler) ScaleOut(nc *v1alpha1.NebulaCluster) error {
return nil
}

options, err := nebula.ClientOptions(nc)
options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true))
if err != nil {
return err
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (ss *storageScaler) ScaleIn(nc *v1alpha1.NebulaCluster, oldReplicas, newRep
return err
}

options, err := nebula.ClientOptions(nc)
options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/component/storaged_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *storagedUpdater) Update(
return err
}

options, err := nebula.ClientOptions(nc)
options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/nebularestore/nebula_restore_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (rm *restoreManager) syncRestoreProcess(rt *v1alpha1.NebulaRestore) error {
return err
}

options, err := nebula.ClientOptions(original)
options, err := nebula.ClientOptions(original, nebula.SetIsMeta(true))
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/nebula/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func buildClientTransport(endpoint string, options ...Option) (thrift.Transport,

var err error
var sock thrift.Transport
tlsEnabled := opts.EnableClusterTLS || (opts.EnableMetaTLS && !opts.IsStorage)
tlsEnabled := opts.EnableClusterTLS ||
(opts.EnableMetaTLS && opts.EnableStorageTLS) ||
(opts.EnableMetaTLS && !opts.IsStorage) ||
(opts.EnableStorageTLS && !opts.IsMeta)

if tlsEnabled {
sock, err = thrift.NewSSLSocketTimeout(endpoint, opts.TLSConfig, opts.Timeout)
} else {
Expand Down
20 changes: 19 additions & 1 deletion pkg/nebula/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ type Option func(ops *Options)

type Options struct {
EnableMetaTLS bool
EnableStorageTLS bool
EnableClusterTLS bool
IsStorage bool
IsMeta bool
Timeout time.Duration
TLSConfig *tls.Config
}

func ClientOptions(nc *v1alpha1.NebulaCluster, opts ...Option) ([]Option, error) {
options := []Option{SetTimeout(DefaultTimeout)}
if !nc.IsMetadSSLEnabled() && !nc.IsClusterSSLEnabled() {
if !nc.IsMetadSSLEnabled() && !nc.IsClusterSSLEnabled() && !nc.IsStoragedSSLEnabled() {
return options, nil
}
if nc.Spec.SSLCerts == nil {
Expand All @@ -53,6 +55,10 @@ func ClientOptions(nc *v1alpha1.NebulaCluster, opts ...Option) ([]Option, error)
options = append(options, SetMetaTLS(true))
klog.Infof("cluster [%s/%s] metad SSL enabled", nc.Namespace, nc.Name)
}
if nc.IsStoragedSSLEnabled() && !nc.IsClusterSSLEnabled() {
options = append(options, SetStorageTLS(true))
klog.Infof("cluster [%s/%s] storaged SSL enabled", nc.Namespace, nc.Name)
}
if nc.IsClusterSSLEnabled() {
options = append(options, SetClusterTLS(true))
klog.Infof("cluster [%s/%s] SSL enabled", nc.Namespace, nc.Name)
Expand Down Expand Up @@ -105,12 +111,24 @@ func SetMetaTLS(e bool) Option {
}
}

func SetStorageTLS(e bool) Option {
return func(options *Options) {
options.EnableStorageTLS = e
}
}

func SetClusterTLS(e bool) Option {
return func(options *Options) {
options.EnableClusterTLS = e
}
}

func SetIsMeta(e bool) Option {
return func(options *Options) {
options.IsMeta = e
}
}

func SetIsStorage(e bool) Option {
return func(options *Options) {
options.IsStorage = e
Expand Down