Skip to content
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

Fix cluster ID logic for tunnels.local.api... hostname #430

Merged
merged 6 commits into from
Mar 28, 2024
Merged
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
4 changes: 2 additions & 2 deletions cs/src/Management/TunnelManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ private string UserLimitsPath
errorMessage = "Tunnel service error: " +
problemDetails!.Title + " " + problemDetails.Detail;
}

if (problemDetails.Errors != null)
{
foreach (var error in problemDetails.Errors)
Expand Down Expand Up @@ -785,7 +785,7 @@ private Uri BuildUri(
if (!string.IsNullOrEmpty(clusterId) &&
baseAddress.HostNameType == UriHostNameType.Dns)
{
if (baseAddress.Host != "localhost" &&
if (baseAddress.Host != "localhost" && !baseAddress.Host.Contains(".local") &&
!baseAddress.Host.StartsWith($"{clusterId}."))
{
// A specific cluster ID was specified (while not running on localhost).
Expand Down
6 changes: 4 additions & 2 deletions go/tunnels/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func NewManager(userAgents []UserAgent, tp tokenProviderfn, tunnelServiceUrl *ur

var client *http.Client
if httpHandler == nil {
if strings.Contains(tunnelServiceUrl.Host, "localhost") {
if strings.Contains(tunnelServiceUrl.Host, "localhost") || strings.Contains(tunnelServiceUrl.Host, ".local") {
client = &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}
} else {
client = &http.Client{}
Expand Down Expand Up @@ -825,7 +825,9 @@ func (m *Manager) getAccessToken(tunnel *Tunnel, tunnelRequestOptions *TunnelReq
func (m *Manager) buildUri(clusterId string, path string, options *TunnelRequestOptions, query string) *url.URL {
baseAddress := m.uri
if clusterId != "" {
if !strings.HasPrefix(baseAddress.Host, "localhost") && !strings.HasPrefix(baseAddress.Host, clusterId) {
if !strings.HasPrefix(baseAddress.Host, "localhost") &&
!strings.Contains(baseAddress.Host, ".local") &&
!strings.HasPrefix(baseAddress.Host, clusterId) {
// A specific cluster ID was specified (while not running on localhost).
// Prepend the cluster ID to the hostname, and optionally strip a global prefix.
baseAddress.Host = fmt.Sprintf("%s.%s", clusterId, baseAddress.Host)
Expand Down
2 changes: 1 addition & 1 deletion go/tunnels/tunnels.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/rodaine/table"
)

const PackageVersion = "0.1.9"
const PackageVersion = "0.1.10"

func (tunnel *Tunnel) requestObject() (*Tunnel, error) {
convertedTunnel := &Tunnel{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ private URI buildUri(String clusterId,

if (StringUtils.isNotBlank(clusterId)) {
if (!baseAddress.getHost().equals("localhost")
&& !baseAddress.getHost().contains(".local")
&& !baseAddress.getHost().startsWith(clusterId + ".")) {
host = (clusterId + "." + baseAddress.getHost()).replace("global.", "");
} else if (baseAddress.getScheme().equals("https")
Expand Down
2 changes: 1 addition & 1 deletion rs/src/connections/relay_tunnel_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl RelayTunnelHost {
&self.locator,
&TunnelRelayTunnelEndpoint {
base: TunnelEndpoint {
id: format!("{}-relay", self.host_id),
id: Some(format!("{}-relay", self.host_id)),
connection_mode: TunnelConnectionMode::TunnelRelay,
host_id: self.host_id.to_string(),
host_public_keys: vec![],
Expand Down
2 changes: 1 addition & 1 deletion rs/src/contracts/tunnel_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
#[serde(rename_all(serialize = "camelCase", deserialize = "camelCase"))]
pub struct TunnelEndpoint {
// Gets or sets the ID of this endpoint.
pub id: String,
pub id: Option<String>,

// Gets or sets the connection mode of the endpoint.
//
Expand Down
4 changes: 2 additions & 2 deletions rs/src/management/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl TunnelManagementClient {
) -> HttpResult<TunnelEndpoint> {
let mut url = self.build_tunnel_uri(
locator,
Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.id)),
Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.id.as_deref().unwrap())),
);
url.query_pairs_mut()
.append_pair("connectionMode", &endpoint.connection_mode.to_string());
Expand All @@ -180,7 +180,7 @@ impl TunnelManagementClient {
) -> HttpResult<TunnelRelayTunnelEndpoint> {
let mut url = self.build_tunnel_uri(
locator,
Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.base.id)),
Some(&format!("{}/{}", ENDPOINTS_API_SUB_PATH, endpoint.base.id.as_deref().unwrap())),
);
url.query_pairs_mut()
.append_pair("connectionMode", &endpoint.base.connection_mode.to_string());
Expand Down
4 changes: 2 additions & 2 deletions ts/src/connections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"buffer": "^5.2.1",
"debug": "^4.1.1",
"vscode-jsonrpc": "^4.0.0",
"@microsoft/dev-tunnels-contracts": ">1.1.26",
"@microsoft/dev-tunnels-management": ">1.1.26",
"@microsoft/dev-tunnels-contracts": ">1.1.32",
"@microsoft/dev-tunnels-management": ">1.1.32",
"@microsoft/dev-tunnels-ssh": "^3.11.36",
"@microsoft/dev-tunnels-ssh-tcp": "^3.11.36",
"uuid": "^3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion ts/src/management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"buffer": "^5.2.1",
"debug": "^4.1.1",
"vscode-jsonrpc": "^4.0.0",
"@microsoft/dev-tunnels-contracts": ">1.1.26",
"@microsoft/dev-tunnels-contracts": ">1.1.32",
"axios": "^1.6.6"
}
}
5 changes: 4 additions & 1 deletion ts/src/management/tunnelManagementHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,10 @@ export class TunnelManagementHttpClient implements TunnelManagementClient {
if (clusterId) {
const url = new URL(baseAddress);
const portNumber = parseInt(url.port, 10);
if (url.hostname !== 'localhost' && !url.hostname.startsWith(`${clusterId}.`)) {
if (url.hostname !== 'localhost' &&
!url.hostname.includes('.local') &&
!url.hostname.startsWith(`${clusterId}.`)
) {
// A specific cluster ID was specified (while not running on localhost).
// Prepend the cluster ID to the hostname, and optionally strip a global prefix.
url.hostname = `${clusterId}.${url.hostname}`.replace('global.', '');
Expand Down
Loading