Skip to content

Commit

Permalink
Incorrect value of clientTLSPolicy from ComputeBackendService
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Oct 25, 2024
1 parent 8eea0b6 commit 9f454d2
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config/servicemappings/compute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ spec:
kind: NetworkSecurityClientTLSPolicy
version: v1beta1
group: networksecurity.cnrm.cloud.google.com
valueTemplate: "projects/{{project}}/locations/{{location}}/clientTlsPolicies/{{value}}"
dclBasedResource: true
- tfField: iap.oauth2_client_id
description: OAuth2 Client ID for IAP.
Expand Down Expand Up @@ -2529,7 +2530,7 @@ spec:
kind: NetworkSecurityServerTLSPolicy
version: v1beta1
group: networksecurity.cnrm.cloud.google.com
valueTemplate: "projects/{{project}}/locations/{{location}}/serverTlsPolicies/{{value}}"
valueTemplate: "projects/{{project}}/locations/global/serverTlsPolicies/{{value}}"
dclBasedResource: true
containers:
- type: project
Expand Down
10 changes: 10 additions & 0 deletions pkg/krmtotf/templating.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ func expandFieldTemplate(template string, r *Resource, c client.Client, smLoader
if val, exists, _ := unstructured.NestedString(r.GetStatusOrObservedState(), strings.Split(path, ".")...); exists {
return val
}

// todo(yuhou): Special handling to resolve project from DCL-based resource
// Only used for fixtures/globalcomputebackendservicesecuritysettings test for now
if path == "project" {
dclPath := "projectRef.external"
if val, exists, _ := unstructured.NestedString(r.Spec, strings.Split(dclPath, ".")...); exists {
return val
}
}

if isRequired {
resolutionError = fmt.Errorf("unable to resolve missing value: %v", field)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/test/resourcefixture/contexts/compute_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func init() {
SkipUpdate: true,
}

resourceContextMap["globalcomputebackendservicesecuritysettings"] = ResourceContext{
ResourceKind: "ComputeBackendService",
// It's expected that during reconciliation, the event reason changes from Updating to UpToDate
// There's no change on the object.
SkipNoChange: true,
}

resourceContextMap["computeexternalvpngateway"] = ResourceContext{
ResourceKind: "ComputeExternalVPNGateway",
SkipUpdate: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: compute.cnrm.cloud.google.com/v1beta1
kind: ComputeBackendService
metadata:
name: computebackendservice-yuhou1025
spec:
loadBalancingScheme: INTERNAL_SELF_MANAGED
# The security settings that apply to this backend service. This field is applicable to
# global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED
securitySettings:
clientTLSPolicyRef:
name: clienttlspolicy-yuhou1025
subjectAltNames:
- spiffe://junk.svc.id.goog/ns/test/sa/frontend
timeoutSec: 10
location: global
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: networksecurity.cnrm.cloud.google.com/v1beta1
kind: NetworkSecurityClientTLSPolicy
metadata:
name: clienttlspolicy-yuhou1025
spec:
clientCertificate:
certificateProviderInstance:
pluginInstance: google_cloud_private_spiffe
location: global
serverValidationCa:
- certificateProviderInstance:
pluginInstance: google_cloud_private_spiffe
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: compute.cnrm.cloud.google.com/v1beta1
kind: ComputeBackendService
metadata:
name: computebackendservice-${uniqueId}
spec:
loadBalancingScheme: INTERNAL_SELF_MANAGED
# The security settings that apply to this backend service. This field is applicable to
# global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED
securitySettings:
clientTLSPolicyRef:
name: clienttlspolicy-${uniqueId}
subjectAltNames:
- spiffe://junk.svc.id.goog/ns/test/sa/frontend
timeoutSec: 5
location: global
Original file line number Diff line number Diff line change
Expand Up @@ -4305,11 +4305,7 @@ func expandComputeBackendServiceSecuritySettings(v interface{}, d tpgresource.Te
}

func expandComputeBackendServiceSecuritySettingsClientTlsPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
f, err := tpgresource.ParseGlobalFieldValue("regions", v.(string), "project", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for client_tls_policy: %s", err)
}
return f.RelativeLink(), nil
return v, nil
}

func expandComputeBackendServiceSecuritySettingsSubjectAltNames(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
Expand Down

0 comments on commit 9f454d2

Please sign in to comment.