Skip to content

Commit 6ca6a89

Browse files
Merge pull request openshift#7987 from cjschaef/ocpbugs-28870
OCPBUGS-28870: IBMCloud: Restrict CIS and DNS Service lookup
2 parents 6c90567 + ac2d5fe commit 6ca6a89

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pkg/asset/installconfig/ibmcloud/metadata.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Metadata struct {
2727
computeSubnets map[string]Subnet
2828
controlPlaneSubnets map[string]Subnet
2929
dnsInstance *DNSInstance
30+
publishStrategy types.PublishingStrategy
3031
serviceEndpoints []configv1.IBMCloudServiceEndpoint
3132

3233
mutex sync.Mutex
@@ -46,6 +47,7 @@ func NewMetadata(config *types.InstallConfig) *Metadata {
4647
BaseDomain: config.BaseDomain,
4748
ComputeSubnetNames: config.Platform.IBMCloud.ComputeSubnets,
4849
ControlPlaneSubnetNames: config.Platform.IBMCloud.ControlPlaneSubnets,
50+
publishStrategy: config.Publish,
4951
Region: config.Platform.IBMCloud.Region,
5052
serviceEndpoints: config.Platform.IBMCloud.ServiceEndpoints,
5153
}
@@ -79,7 +81,8 @@ func (m *Metadata) CISInstanceCRN(ctx context.Context) (string, error) {
7981
m.mutex.Lock()
8082
defer m.mutex.Unlock()
8183

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

114-
// Prevent multiple attempts to retrieve (set) the dnsInstance if it hasn't been set (multiple threads reach mutex concurrently)
115-
if m.dnsInstance == nil {
117+
// Only attempt to find the DNS Services instance if using InternalPublishingStrategy and also
118+
// prevent multiple attempts to retrieve (set) the dnsInstance if it hasn't been set (multiple threads reach mutex concurrently)
119+
if m.publishStrategy == types.InternalPublishingStrategy && m.dnsInstance == nil {
116120
client, err := m.Client()
117121
if err != nil {
118122
return nil, err

pkg/asset/installconfig/ibmcloud/metadata_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,14 @@ func baseMetadata() *Metadata {
178178
Region: region,
179179
},
180180
},
181+
Publish: types.ExternalPublishingStrategy,
181182
})
182183
}
183184

185+
func setInternalPublishingStrategy(m *Metadata) {
186+
m.publishStrategy = types.InternalPublishingStrategy
187+
}
188+
184189
func TestAccountID(t *testing.T) {
185190
testCases := []struct {
186191
name string
@@ -406,6 +411,7 @@ func TestDNSInstance(t *testing.T) {
406411
for _, tCase := range testCases {
407412
t.Run(tCase.name, func(t *testing.T) {
408413
metadata := baseMetadata()
414+
setInternalPublishingStrategy(metadata)
409415
metadata.client = ibmcloudClient
410416
for _, edit := range tCase.edits {
411417
edit(metadata)
@@ -438,6 +444,7 @@ func TestSetDNSInstance(t *testing.T) {
438444
for _, tCase := range testCases {
439445
t.Run(tCase.name, func(t *testing.T) {
440446
metadata := baseMetadata()
447+
setInternalPublishingStrategy(metadata)
441448

442449
metadata.dnsInstance = &DNSInstance{
443450
ID: tCase.dnsID,

0 commit comments

Comments
 (0)