mirror of
https://github.com/rancher/rke.git
synced 2025-08-10 19:22:41 +00:00
Merge pull request #2409 from dramich/encrypt
Update encryption to use JSON tagged structs
This commit is contained in:
commit
462a7ba01e
@ -507,16 +507,7 @@ func disabledProviderFileFromKey(keyList interface{}) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cluster) readEncryptionCustomConfig() (string, error) {
|
func (c *Cluster) readEncryptionCustomConfig() (string, error) {
|
||||||
// directly marshalling apiserverconfig.EncryptionConfiguration to yaml breaks things because TypeMeta
|
jsonConfig, err := json.Marshal(c.RancherKubernetesEngineConfig.Services.KubeAPI.SecretsEncryptionConfig.CustomConfig)
|
||||||
// is nested and all fields don't have tags. apiserverconfigv1 has json tags only. So we do this as a work around.
|
|
||||||
|
|
||||||
out := apiserverconfigv1.EncryptionConfiguration{}
|
|
||||||
err := apiserverconfigv1.Convert_config_EncryptionConfiguration_To_v1_EncryptionConfiguration(
|
|
||||||
c.RancherKubernetesEngineConfig.Services.KubeAPI.SecretsEncryptionConfig.CustomConfig, &out, nil)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
jsonConfig, err := json.Marshal(out)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -529,7 +520,7 @@ func (c *Cluster) readEncryptionCustomConfig() (string, error) {
|
|||||||
struct{ CustomConfig string }{CustomConfig: string(yamlConfig)})
|
struct{ CustomConfig string }{CustomConfig: string(yamlConfig)})
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveCustomEncryptionConfig(clusterFile string) (string, *apiserverconfig.EncryptionConfiguration, error) {
|
func resolveCustomEncryptionConfig(clusterFile string) (string, *apiserverconfigv1.EncryptionConfiguration, error) {
|
||||||
var err error
|
var err error
|
||||||
var r map[string]interface{}
|
var r map[string]interface{}
|
||||||
err = ghodssyaml.Unmarshal([]byte(clusterFile), &r)
|
err = ghodssyaml.Unmarshal([]byte(clusterFile), &r)
|
||||||
@ -559,7 +550,7 @@ func resolveCustomEncryptionConfig(clusterFile string) (string, *apiserverconfig
|
|||||||
return clusterFile, nil, nil
|
return clusterFile, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCustomConfig(customConfig map[string]interface{}) (*apiserverconfig.EncryptionConfiguration, error) {
|
func parseCustomConfig(customConfig map[string]interface{}) (*apiserverconfigv1.EncryptionConfiguration, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
data, err := json.Marshal(customConfig)
|
data, err := json.Marshal(customConfig)
|
||||||
@ -583,7 +574,7 @@ func parseCustomConfig(customConfig map[string]interface{}) (*apiserverconfig.En
|
|||||||
return nil, fmt.Errorf("error decoding data: %v", err)
|
return nil, fmt.Errorf("error decoding data: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
decodedConfig, ok := decodedObj.(*apiserverconfig.EncryptionConfiguration)
|
decodedConfig, ok := decodedObj.(*apiserverconfigv1.EncryptionConfiguration)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("unexpected type: %T", objType)
|
return nil, fmt.Errorf("unexpected type: %T", objType)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
apiserverv1alpha1 "k8s.io/apiserver/pkg/apis/apiserver/v1alpha1"
|
apiserverv1alpha1 "k8s.io/apiserver/pkg/apis/apiserver/v1alpha1"
|
||||||
auditv1 "k8s.io/apiserver/pkg/apis/audit/v1"
|
auditv1 "k8s.io/apiserver/pkg/apis/audit/v1"
|
||||||
apiserverconfig "k8s.io/apiserver/pkg/apis/config"
|
configv1 "k8s.io/apiserver/pkg/apis/config/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RancherKubernetesEngineConfig struct {
|
type RancherKubernetesEngineConfig struct {
|
||||||
@ -980,7 +980,7 @@ type SecretsEncryptionConfig struct {
|
|||||||
// Enable/disable secrets encryption provider config
|
// Enable/disable secrets encryption provider config
|
||||||
Enabled bool `yaml:"enabled" json:"enabled,omitempty"`
|
Enabled bool `yaml:"enabled" json:"enabled,omitempty"`
|
||||||
// Custom Encryption Provider configuration object
|
// Custom Encryption Provider configuration object
|
||||||
CustomConfig *apiserverconfig.EncryptionConfiguration `yaml:"custom_config" json:"customConfig,omitempty" norman:"type=map[json]"`
|
CustomConfig *configv1.EncryptionConfiguration `yaml:"custom_config" json:"customConfig,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||||
v1alpha1 "k8s.io/apiserver/pkg/apis/apiserver/v1alpha1"
|
v1alpha1 "k8s.io/apiserver/pkg/apis/apiserver/v1alpha1"
|
||||||
v1 "k8s.io/apiserver/pkg/apis/audit/v1"
|
v1 "k8s.io/apiserver/pkg/apis/audit/v1"
|
||||||
config "k8s.io/apiserver/pkg/apis/config"
|
configv1 "k8s.io/apiserver/pkg/apis/config/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
@ -1745,7 +1745,7 @@ func (in *SecretsEncryptionConfig) DeepCopyInto(out *SecretsEncryptionConfig) {
|
|||||||
*out = *in
|
*out = *in
|
||||||
if in.CustomConfig != nil {
|
if in.CustomConfig != nil {
|
||||||
in, out := &in.CustomConfig, &out.CustomConfig
|
in, out := &in.CustomConfig, &out.CustomConfig
|
||||||
*out = new(config.EncryptionConfiguration)
|
*out = new(configv1.EncryptionConfiguration)
|
||||||
(*in).DeepCopyInto(*out)
|
(*in).DeepCopyInto(*out)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user