Skip to content

Commit

Permalink
fix: octavia tlsContainerRef validation for barbican secrets (#2459)
Browse files Browse the repository at this point in the history
Co-authored-by: Nuckal777 <[email protected]>
  • Loading branch information
k8s-infra-cherrypick-robot and Nuckal777 authored Nov 16, 2023
1 parent c71f064 commit c04bc58
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions pkg/openstack/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers"
"github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers"
v2monitors "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors"
Expand Down Expand Up @@ -1594,16 +1595,30 @@ func (lbaas *LbaasV2) checkService(service *corev1.Service, nodes []*corev1.Node
"initialized and default-tls-container-ref %q is set", svcConf.tlsContainerRef)
}

// check if container exists for 'barbican' container store
// tls container ref has the format: https://{keymanager_host}/v1/containers/{uuid}
// check if container or secret exists for 'barbican' container store
// tls container ref has the format: https://{keymanager_host}/v1/containers/{uuid} or https://{keymanager_host}/v1/secrets/{uuid}
if lbaas.opts.ContainerStore == "barbican" {
slice := strings.Split(svcConf.tlsContainerRef, "/")
containerID := slice[len(slice)-1]
container, err := containers.Get(lbaas.secret, containerID).Extract()
if err != nil {
return fmt.Errorf("failed to get tls container %q: %v", svcConf.tlsContainerRef, err)
if len(slice) < 2 {
return fmt.Errorf("invalid tlsContainerRef for service %s", serviceName)
}
barbicanUUID := slice[len(slice)-1]
barbicanType := slice[len(slice)-2]
if barbicanType == "containers" {
container, err := containers.Get(lbaas.secret, barbicanUUID).Extract()
if err != nil {
return fmt.Errorf("failed to get tls container %q: %v", svcConf.tlsContainerRef, err)
}
klog.V(4).Infof("Default TLS container %q found", container.ContainerRef)
} else if barbicanType == "secrets" {
secret, err := secrets.Get(lbaas.secret, barbicanUUID).Extract()
if err != nil {
return fmt.Errorf("failed to get tls secret %q: %v", svcConf.tlsContainerRef, err)
}
klog.V(4).Infof("Default TLS secret %q found", secret.SecretRef)
} else {
return fmt.Errorf("failed to validate tlsContainerRef for service %s: tlsContainerRef type %s unknown", serviceName, barbicanType)
}
klog.V(4).Infof("Default TLS container %q found", container.ContainerRef)
}
}

Expand Down

0 comments on commit c04bc58

Please sign in to comment.