Skip to content

CORS-4062: Migrate endpoints in pkg/types/aws/platform.go to sdk v2 #9759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/asset/installconfig/aws/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,13 @@ func RequiredPermissionGroups(ic *types.InstallConfig) []PermissionGroup {
permissionGroups = append(permissionGroups, PermissionKMSEncryptionKeys)
}

isSecretRegion, err := IsSecretRegion(ic.AWS.Region)
if err != nil {
logrus.Warnf("Unable to determine if AWS region is secret: %v", err)
return permissionGroups
}
// Add delete permissions for non-C2S installs.
if !aws.IsSecretRegion(ic.AWS.Region) {
if !isSecretRegion {
permissionGroups = append(permissionGroups, PermissionDeleteBase)
if usingExistingVPC {
permissionGroups = append(permissionGroups, PermissionDeleteSharedNetworking)
Expand Down
21 changes: 21 additions & 0 deletions pkg/asset/installconfig/aws/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import (
"context"
"fmt"

"github.com/aws/aws-sdk-go-v2/service/ec2"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/types"
)

const (
isoPartition = "aws-iso"
isobPartition = "aws-iso-b"
)

// knownPublicRegions is the subset of public AWS regions where RHEL CoreOS images are published.
// This subset does not include supported regions which are found in other partitions, such as us-gov-east-1.
// Returns: a list of region names.
Expand Down Expand Up @@ -39,3 +45,18 @@ func IsKnownPublicRegion(region string, architecture types.Architecture) (bool,
}
return sets.New(publicRegions...).Has(region), nil
}

// IsSecretRegion determines if the region is part of a secret partition.
func IsSecretRegion(region string) (bool, error) {
endpoint, err := ec2.NewDefaultEndpointResolver().ResolveEndpoint(region, ec2.EndpointResolverOptions{})
if err != nil {
return false, fmt.Errorf("failed to resolve AWS ec2 endpoint: %w", err)
}

switch endpoint.PartitionID {
case isoPartition, isobPartition:
return true, nil
}

return false, nil
}
7 changes: 6 additions & 1 deletion pkg/asset/manifests/cloudproviderconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
awsic "github.com/openshift/installer/pkg/asset/installconfig/aws"
ibmcloudmachines "github.com/openshift/installer/pkg/asset/machines/ibmcloud"
"github.com/openshift/installer/pkg/asset/manifests/azure"
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
Expand Down Expand Up @@ -101,7 +102,11 @@ func (cpc *CloudProviderConfig) Generate(ctx context.Context, dependencies asset
case awstypes.Name:
// Store the additional trust bundle in the ca-bundle.pem key if the cluster is being installed on a C2S region.
trustBundle := installConfig.Config.AdditionalTrustBundle
if trustBundle != "" && awstypes.IsSecretRegion(installConfig.Config.AWS.Region) {
isSecretRegion, err := awsic.IsSecretRegion(installConfig.Config.AWS.Region)
if err != nil {
return fmt.Errorf("failed to determine if AWS region is secret: %w", err)
}
if trustBundle != "" && isSecretRegion {
cm.Data[cloudProviderConfigCABundleDataKey] = trustBundle
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/asset/tls/cloudprovidercabundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package tls

import (
"context"
"fmt"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
awsic "github.com/openshift/installer/pkg/asset/installconfig/aws"
awstypes "github.com/openshift/installer/pkg/types/aws"
)

Expand Down Expand Up @@ -35,7 +37,12 @@ func (a *CloudProviderCABundle) Generate(_ context.Context, deps asset.Parents)
if ic.Config.Platform.Name() != awstypes.Name {
return nil
}
if !awstypes.IsSecretRegion(ic.Config.Platform.AWS.Region) {

isSecretRegion, err := awsic.IsSecretRegion(ic.Config.Platform.AWS.Region)
if err != nil {
return fmt.Errorf("failed to determine if AWS region is secret: %w", err)
}
if !isSecretRegion {
return nil
}

Expand Down
15 changes: 0 additions & 15 deletions pkg/types/aws/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package aws
import (
"os"

"github.com/aws/aws-sdk-go/aws/endpoints"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/installer/pkg/types/dns"
)
Expand Down Expand Up @@ -232,19 +230,6 @@ const (
ControlPlaneInternalLBSubnetRole SubnetRoleType = "ControlPlaneInternalLB"
)

// IsSecretRegion returns true if the region is part of either the ISO or ISOB partitions.
func IsSecretRegion(region string) bool {
partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), region)
if !ok {
return false
}
switch partition.ID() {
case endpoints.AwsIsoPartitionID, endpoints.AwsIsoBPartitionID:
return true
}
return false
}

// IsPublicOnlySubnetsEnabled returns whether the public-only subnets feature has been enabled via env var.
func IsPublicOnlySubnetsEnabled() bool {
// Even though this looks too simple for a function, it's better than having to update the logic everywhere it's
Expand Down