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

OSASINFRA-3657: Add support for storing OpenStack CA bundles #780

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ metadata:
data:
clouds.yaml: Base64encodeCloudCreds
clouds.conf: Base64encodeCloudCredsINI
cabundle.pem: Base64encodeCABundle
```

### Ovirt
Expand Down
12 changes: 9 additions & 3 deletions pkg/openstack/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (a *OpenStackActuator) sync(ctx context.Context, cr *minterv1.CredentialsRe
return err
}

clouds, err := GetRootCloudCredentialsSecretData(credentialsRootSecret, logger)
clouds, cabundle, err := GetRootCloudCredentialsSecretData(credentialsRootSecret, logger)
if err != nil {
logger.WithError(err).Error("issue with cloud credentials secret")
return &actuatoriface.ActuatorError{
Expand All @@ -106,7 +106,7 @@ func (a *OpenStackActuator) sync(ctx context.Context, cr *minterv1.CredentialsRe
}

logger.Debugf("provisioning secret")
err = a.syncCredentialSecret(ctx, cr, clouds, logger)
err = a.syncCredentialSecret(ctx, cr, clouds, cabundle, logger)
if err != nil {
msg := "error creating/updating secret"
logger.WithError(err).Error(msg)
Expand All @@ -119,7 +119,7 @@ func (a *OpenStackActuator) sync(ctx context.Context, cr *minterv1.CredentialsRe
return nil
}

func (a *OpenStackActuator) syncCredentialSecret(ctx context.Context, cr *minterv1.CredentialsRequest, clouds string, logger log.FieldLogger) error {
func (a *OpenStackActuator) syncCredentialSecret(ctx context.Context, cr *minterv1.CredentialsRequest, clouds, cabundle string, logger log.FieldLogger) error {
sLog := logger.WithFields(log.Fields{
"targetSecret": fmt.Sprintf("%s/%s", cr.Spec.SecretRef.Namespace, cr.Spec.SecretRef.Name),
"cr": fmt.Sprintf("%s/%s", cr.Namespace, cr.Name),
Expand All @@ -145,6 +145,12 @@ func (a *OpenStackActuator) syncCredentialSecret(ctx context.Context, cr *minter
secret.Data = map[string][]byte{}
}
secret.Data[RootOpenStackCredsSecretKey] = []byte(clouds)

// This means we only write cabundle.pem if clouds.yaml is present. That's okay, since
// the former is useless without the latter.
if cabundle != "" {
secret.Data[RootOpenStackCAFileSecretKey] = []byte(cabundle)
}
}
return nil
})
Expand Down
27 changes: 16 additions & 11 deletions pkg/openstack/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,34 @@ import (
)

const (
RootOpenStackCredsSecretKey = "clouds.yaml"
OpenStackCloudName = "openstack"
CACertFile = "/etc/kubernetes/static-pod-resources/configmaps/cloud-config/ca-bundle.pem"
RootOpenStackCredsSecretKey = "clouds.yaml"
RootOpenStackCAFileSecretKey = "ca-bundle.pem"
OpenStackCloudName = "openstack"
CACertFile = "/etc/kubernetes/static-pod-resources/configmaps/cloud-config/ca-bundle.pem"
)

func GetRootCloudCredentialsSecretData(cloudCredSecret *corev1.Secret, logger log.FieldLogger) (string, error) {
var clouds string

keyBytes, ok := cloudCredSecret.Data[RootOpenStackCredsSecretKey]
func GetRootCloudCredentialsSecretData(cloudCredSecret *corev1.Secret, logger log.FieldLogger) (string, string, error) {
creds, ok := cloudCredSecret.Data[RootOpenStackCredsSecretKey]
if !ok {
return "", fmt.Errorf("secret did not have expected key: %v", RootOpenStackCredsSecretKey)
return "", "", fmt.Errorf("secret did not have expected key: %v", RootOpenStackCredsSecretKey)
}

clouds = string(keyBytes)
// cacert is optional, so it's okay if it's not present
cabundle, _ := cloudCredSecret.Data[RootOpenStackCAFileSecretKey]

logger.Debug("found clouds.yaml in target secret")

return clouds, nil
return string(creds), string(cabundle), nil
}

func SetRootCloudCredentialsSecretData(cloudCredSecret *corev1.Secret, clouds string) {
func SetRootCloudCredentialsSecretData(cloudCredSecret *corev1.Secret, clouds, cafile string) {
if cloudCredSecret.Data == nil {
cloudCredSecret.Data = make(map[string][]byte)
}

cloudCredSecret.Data[RootOpenStackCredsSecretKey] = []byte(clouds)

if len(cafile) > 0 {
cloudCredSecret.Data[RootOpenStackCAFileSecretKey] = []byte(cafile)
}
}
4 changes: 2 additions & 2 deletions pkg/operator/secretannotator/openstack/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (r *ReconcileCloudCredSecret) Reconcile(ctx context.Context, request reconc
return reconcile.Result{}, err
}

clouds, err := openstack.GetRootCloudCredentialsSecretData(secret, r.Logger)
clouds, cabundle, err := openstack.GetRootCloudCredentialsSecretData(secret, r.Logger)
if err != nil {
r.Logger.WithError(err).Error("errored getting clouds.yaml from secret")
return reconcile.Result{}, err
Expand All @@ -169,7 +169,7 @@ func (r *ReconcileCloudCredSecret) Reconcile(ctx context.Context, request reconc
}

if cloudsUpdated {
openstack.SetRootCloudCredentialsSecretData(secret, clouds)
openstack.SetRootCloudCredentialsSecretData(secret, clouds, cabundle)
err := r.RootCredClient.Update(context.TODO(), secret)
if err != nil {
r.Logger.WithError(err).Error("error writing updated root secret")
Expand Down