Skip to content

Commit

Permalink
support storage ssl (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaByte875 authored Sep 20, 2023
1 parent 3b7cb00 commit 25253a4
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 9 deletions.
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 @@ -91,6 +91,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 @@ -108,6 +108,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 @@ -109,6 +109,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 @@ -174,7 +174,7 @@ func (c *metadCluster) syncMetadConfigMap(nc *v1alpha1.NebulaCluster) (*corev1.C
}

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 @@ -228,7 +228,7 @@ func (c *storagedCluster) syncStoragedConfigMap(nc *v1alpha1.NebulaCluster) (*co
}

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 @@ -272,7 +272,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

0 comments on commit 25253a4

Please sign in to comment.