diff --git a/internal/daemon/controller/handlers/targets/target_service.go b/internal/daemon/controller/handlers/targets/target_service.go index 5fe6d07607..7e6bb67d5b 100644 --- a/internal/daemon/controller/handlers/targets/target_service.go +++ b/internal/daemon/controller/handlers/targets/target_service.go @@ -40,6 +40,7 @@ import ( "github.com/hashicorp/boundary/internal/types/subtypes" "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes" pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/targets" + fm "github.com/hashicorp/boundary/version" "github.com/hashicorp/go-bexpr" "github.com/hashicorp/go-secure-stdlib/strutil" "github.com/mr-tron/base58" @@ -984,6 +985,13 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession } } + // this is an edge case issue where the hostId cannot be empty when trying to execute an ssh connection + // on a tcp target type. By setting the hostId to the targetId value, this will enable support of previous + // boundary cli versions. + if fm.SupportsFeature(fm.Binary, fm.UseTargetIdForHostId) && t.GetAddress() != "" { + hostId = t.GetPublicId() + } + sad := &pb.SessionAuthorizationData{ SessionId: sess.PublicId, TargetId: t.GetPublicId(), diff --git a/version/feature_manager.go b/version/feature_manager.go index 7066851930..76e83a603c 100644 --- a/version/feature_manager.go +++ b/version/feature_manager.go @@ -28,6 +28,7 @@ const ( MultiHopSessionFeature IncludeStatusInCli CredentialLibraryVaultSubtype + UseTargetIdForHostId ) var featureMap map[Feature]MetadataConstraint @@ -65,6 +66,15 @@ func init() { MetaInfo: []Metadata{OSS, HCP}, Constraints: mustNewConstraints("< 0.14.0"), } + + // UseTargetIdForHostId supports old CLI clients that are unaware of host-sourceless targets, + // this feature populates the target's public id into the AuthorizeSessionResponse + // and the SessionAuthroizationData so the CLI can properly build the ssh command + // when calling "boundary connect ssh..." + featureMap[UseTargetIdForHostId] = MetadataConstraint{ + MetaInfo: []Metadata{OSS, HCP}, + Constraints: mustNewConstraints("< 0.14.0"), + } } func metadataStringToMetadata(m string) Metadata {