Skip to content

Commit

Permalink
Merge pull request #8197 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…7987-to-release-4.15

[release-4.15] OCPBUGS-31274: IBMCloud: Restrict CIS and DNS Service lookup
  • Loading branch information
openshift-merge-bot[bot] committed Mar 26, 2024
2 parents ad8f056 + e288086 commit f4f5d0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/asset/installconfig/ibmcloud/metadata.go
Expand Up @@ -27,6 +27,7 @@ type Metadata struct {
computeSubnets map[string]Subnet
controlPlaneSubnets map[string]Subnet
dnsInstance *DNSInstance
publishStrategy types.PublishingStrategy
serviceEndpoints []configv1.IBMCloudServiceEndpoint

mutex sync.Mutex
Expand All @@ -46,6 +47,7 @@ func NewMetadata(config *types.InstallConfig) *Metadata {
BaseDomain: config.BaseDomain,
ComputeSubnetNames: config.Platform.IBMCloud.ComputeSubnets,
ControlPlaneSubnetNames: config.Platform.IBMCloud.ControlPlaneSubnets,
publishStrategy: config.Publish,
Region: config.Platform.IBMCloud.Region,
serviceEndpoints: config.Platform.IBMCloud.ServiceEndpoints,
}
Expand Down Expand Up @@ -79,7 +81,8 @@ func (m *Metadata) CISInstanceCRN(ctx context.Context) (string, error) {
m.mutex.Lock()
defer m.mutex.Unlock()

if m.cisInstanceCRN == "" {
// Only attempt to find the CIS instance if using ExternalPublishingStrategy and we have not collected it already
if m.publishStrategy == types.ExternalPublishingStrategy && m.cisInstanceCRN == "" {
client, err := m.Client()
if err != nil {
return "", err
Expand Down Expand Up @@ -111,8 +114,9 @@ func (m *Metadata) DNSInstance(ctx context.Context) (*DNSInstance, error) {
m.mutex.Lock()
defer m.mutex.Unlock()

// Prevent multiple attempts to retrieve (set) the dnsInstance if it hasn't been set (multiple threads reach mutex concurrently)
if m.dnsInstance == nil {
// Only attempt to find the DNS Services instance if using InternalPublishingStrategy and also
// prevent multiple attempts to retrieve (set) the dnsInstance if it hasn't been set (multiple threads reach mutex concurrently)
if m.publishStrategy == types.InternalPublishingStrategy && m.dnsInstance == nil {
client, err := m.Client()
if err != nil {
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions pkg/asset/installconfig/ibmcloud/metadata_test.go
Expand Up @@ -178,9 +178,14 @@ func baseMetadata() *Metadata {
Region: region,
},
},
Publish: types.ExternalPublishingStrategy,
})
}

func setInternalPublishingStrategy(m *Metadata) {
m.publishStrategy = types.InternalPublishingStrategy
}

func TestAccountID(t *testing.T) {
testCases := []struct {
name string
Expand Down Expand Up @@ -406,6 +411,7 @@ func TestDNSInstance(t *testing.T) {
for _, tCase := range testCases {
t.Run(tCase.name, func(t *testing.T) {
metadata := baseMetadata()
setInternalPublishingStrategy(metadata)
metadata.client = ibmcloudClient
for _, edit := range tCase.edits {
edit(metadata)
Expand Down Expand Up @@ -438,6 +444,7 @@ func TestSetDNSInstance(t *testing.T) {
for _, tCase := range testCases {
t.Run(tCase.name, func(t *testing.T) {
metadata := baseMetadata()
setInternalPublishingStrategy(metadata)

metadata.dnsInstance = &DNSInstance{
ID: tCase.dnsID,
Expand Down

0 comments on commit f4f5d0e

Please sign in to comment.