Skip to content

feat: use Cloud Connector ID in GCP Workload Identity Federation session name#3955

Open
amirbenun wants to merge 3 commits intoelastic:mainfrom
amirbenun:cloud-connector-id-gcplib
Open

feat: use Cloud Connector ID in GCP Workload Identity Federation session name#3955
amirbenun wants to merge 3 commits intoelastic:mainfrom
amirbenun:cloud-connector-id-gcplib

Conversation

@amirbenun
Copy link
Contributor

Adds a deployment-specific Cloud Connector ID to the GCP Cloud Connectors auth flow so that the AWS AssumeRoleWithWebIdentity session name matches the format required by GCP Workload Identity Federation (ResourceID-CloudConnectorID). Introduces a cloud_connector_id config option on GcpClientOpt, a GCPCloudConnectorsParams struct to pass audience, service account email, and connector ID into the auth provider, and refactors FindCloudConnectorsCredentials to accept this struct and set RoleSessionName to the concatenated value. Config and credentials call sites, mocks, and tests are updated accordingly.

@amirbenun amirbenun requested a review from a team as a code owner February 12, 2026 13:29
Copilot AI review requested due to automatic review settings February 12, 2026 13:29
@mergify
Copy link

mergify bot commented Feb 12, 2026

This pull request does not have a backport label. Could you fix it @amirbenun? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the GCP Cloud Connectors authentication flow to include a deployment-specific Cloud Connector ID in the AWS AssumeRoleWithWebIdentity session name, matching the GCP Workload Identity Federation-required format (ResourceID-CloudConnectorID).

Changes:

  • Add CloudConnectorID (cloud_connector_id) to config.GcpClientOpt.
  • Introduce GCPCloudConnectorsParams and refactor FindCloudConnectorsCredentials to accept it and set RoleSessionName to ResourceID-CloudConnectorID.
  • Update call sites, mocks, and tests to use the new API shape.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/resources/providers/gcplib/auth/credentials_test.go Updates test configs to include CloudConnectorID and adjusts mock expectations for the refactored auth provider API.
internal/resources/providers/gcplib/auth/credentials_mock.go Regenerates/updates mock signatures to accept GCPCloudConnectorsParams.
internal/resources/providers/gcplib/auth/credentials.go Passes audience, service account email, and connector ID via GCPCloudConnectorsParams to the auth provider.
internal/resources/providers/gcplib/auth/auth_provider.go Adds GCPCloudConnectorsParams, validates connector ID, and sets AWS RoleSessionName to the concatenated format.
internal/config/config.go Adds the cloud_connector_id config field to GcpClientOpt.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

// Session name must match GCP Workload Identity Federation: elastic_resource_id-cloud_connector_id
sessionName := ccConfig.ResourceID + "-" + params.CloudConnectorID
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sessionName is used as stscreds.WebIdentityRoleOptions.RoleSessionName, which must be <= 64 characters for AWS STS. Since it concatenates ResourceID + "-" + CloudConnectorID, this can exceed the limit and cause runtime STS failures. Consider validating the combined length (and returning a clear error) before calling STS.

Suggested change
sessionName := ccConfig.ResourceID + "-" + params.CloudConnectorID
sessionName := ccConfig.ResourceID + "-" + params.CloudConnectorID
const maxSessionNameLen = 64
if len(sessionName) > maxSessionNameLen {
return nil, fmt.Errorf("cloud connectors session name %q exceeds AWS STS limit of %d characters (got %d); check ResourceID and CloudConnectorID", sessionName, maxSessionNameLen, len(sessionName))
}

Copilot uses AI. Check for mistakes.
}

if params.CloudConnectorID == "" {
return nil, errors.New("cloud connectors config CloudConnectorID is required")
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message for a missing params.CloudConnectorID says "cloud connectors config CloudConnectorID is required", but CloudConnectorID is not part of ccConfig (it comes from the GCP credentials params). Updating the message to point to the correct config source will make troubleshooting easier.

Suggested change
return nil, errors.New("cloud connectors config CloudConnectorID is required")
return nil, errors.New("GCP cloud connectors params CloudConnectorID is required")

Copilot uses AI. Check for mistakes.
Comment on lines 109 to 116
cfg := externalaccount.Config{
Audience: audience,
Audience: params.Audience,
SubjectTokenType: awsTokenType,
TokenURL: gcpSTSTokenURL,
Scopes: []string{gcpCloudPlatformScope},
AwsSecurityCredentialsSupplier: credSupplier,
ServiceAccountImpersonationURL: gcpIAMCredentialsURL + serviceAccountEmail + ":generateAccessToken",
ServiceAccountImpersonationURL: gcpIAMCredentialsURL + params.ServiceAccountEmail + ":generateAccessToken",
}
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params.Audience and params.ServiceAccountEmail are now passed via GCPCloudConnectorsParams but aren't validated. If either is empty, externalaccount.NewTokenSource will fail later with a less actionable error. Consider adding explicit required-field validation for these params alongside the existing ccConfig checks.

Copilot uses AI. Check for mistakes.
Comment on lines 400 to 403
func mockGoogleAuthProviderWithCloudConnectors(err error) *MockGoogleAuthProviderAPI {
googleProviderAPI := &MockGoogleAuthProviderAPI{}
on := googleProviderAPI.EXPECT().FindCloudConnectorsCredentials(mock.Anything, mock.Anything, testAudience, testServiceAccountEmail)
on := googleProviderAPI.EXPECT().FindCloudConnectorsCredentials(mock.Anything, mock.Anything, mock.Anything)
if err == nil {
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mockGoogleAuthProviderWithCloudConnectors now matches FindCloudConnectorsCredentials with mock.Anything for the params argument, which stops the test from asserting that Audience, ServiceAccountEmail, and CloudConnectorID are correctly plumbed into the auth provider call. Consider using a matcher (e.g., mock.MatchedBy) to verify the expected fields on GCPCloudConnectorsParams.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant