Skip to content

Commit 5a0c6e4

Browse files
committed
Fix service account email format for sovereign cloud projects
GCD documentation shows service account emails use the format: name@project-id.PREFIX.iam.gserviceaccount.com For sovereign cloud project IDs like 'eu0:my-project', the service account email should be: cluster-m@my-project.eu0.iam.gserviceaccount.com Updated GetDefaultServiceAccount to: - Check if project ID has a known sovereign cloud prefix - Swap format from 'prefix:project-id' to 'project-id.prefix' - Apply only to known sovereign prefixes (maintains backward compatibility for organization-scoped projects) Reference: https://berlin.devsitetest.how/iam/docs/service-accounts-create
1 parent d0c756a commit 5a0c6e4

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

pkg/types/gcp/platform.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/sirupsen/logrus"
9+
"k8s.io/apimachinery/pkg/util/sets"
910

1011
"github.com/openshift/installer/pkg/types/dns"
1112
)
@@ -206,16 +207,32 @@ func GetConfiguredServiceAccount(platform *Platform, mpool *MachinePool) string
206207

207208
// GetDefaultServiceAccount returns the default service account email to use based on role.
208209
// The default should be used when an existing service account is not configured.
209-
// For sovereign cloud projects (e.g., eu0:project-id), extracts the project name after the colon.
210+
// For sovereign cloud project IDs (e.g., eu0:project-id), the service account email format is:
211+
//
212+
// service-account-name@project-id.eu0.iam.gserviceaccount.com
213+
//
214+
// For standard project IDs, the format is:
215+
//
216+
// service-account-name@project-id.iam.gserviceaccount.com
210217
func GetDefaultServiceAccount(platform *Platform, clusterID string, role string) string {
211218
projectID := platform.ProjectID
212-
// For sovereign cloud project IDs in format "prefix:project-id", use only the project-id part
219+
220+
// For sovereign cloud project IDs in format "prefix:project-id", swap to "project-id.prefix"
213221
if strings.Contains(projectID, ":") {
214222
parts := strings.SplitN(projectID, ":", 2)
215223
if len(parts) == 2 {
216-
projectID = parts[1]
224+
prefix := parts[0]
225+
if sets.New(sovereignCloudProjectPrefixes...).Has(prefix) {
226+
// Sovereign cloud: swap to project-id.prefix format
227+
projectID = fmt.Sprintf("%s.%s", parts[1], prefix)
228+
} else {
229+
// For non-sovereign colon-formatted projects (e.g., orgname:project-id),
230+
// strip the prefix for backward compatibility
231+
projectID = parts[1]
232+
}
217233
}
218234
}
235+
219236
return fmt.Sprintf("%s-%s@%s.iam.gserviceaccount.com", clusterID, role[0:1], projectID)
220237
}
221238

@@ -240,14 +257,9 @@ func GetCloudEnvironmentWithRegion(projectID, region string) string {
240257
// Check if project ID has a known sovereign cloud prefix
241258
if strings.Contains(projectID, ":") {
242259
parts := strings.SplitN(projectID, ":", 2)
243-
if len(parts) == 2 {
244-
prefix := parts[0]
245-
for _, knownPrefix := range sovereignCloudProjectPrefixes {
246-
if prefix == knownPrefix {
247-
// Known sovereign prefix is definitive - this IS a sovereign cloud project
248-
return CloudEnvironmentSovereign
249-
}
250-
}
260+
if len(parts) == 2 && sets.New(sovereignCloudProjectPrefixes...).Has(parts[0]) {
261+
// Known sovereign prefix is definitive - this IS a sovereign cloud project
262+
return CloudEnvironmentSovereign
251263
}
252264
}
253265

0 commit comments

Comments
 (0)