diff --git a/cs/src/Contracts/TunnelConstraints.cs b/cs/src/Contracts/TunnelConstraints.cs index db76f3db..59ae43aa 100644 --- a/cs/src/Contracts/TunnelConstraints.cs +++ b/cs/src/Contracts/TunnelConstraints.cs @@ -43,7 +43,11 @@ public static class TunnelConstraints /// /// Max length of V2 tunnelId. /// - public const int NewTunnelIdMaxLength = 60; + /// + /// Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + /// (-<port>-inspect) remain within the DNS label limit of 63 characters. + /// + public const int NewTunnelIdMaxLength = 49; /// /// Length of a tunnel alias. @@ -59,8 +63,18 @@ public static class TunnelConstraints /// /// Max length of tunnel name. /// + /// + /// Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + /// (-<port>-inspect) remain within the DNS label limit of 63 characters. + /// /// - public const int TunnelNameMaxLength = 60; + public const int TunnelNameMaxLength = 49; + + /// + /// Max length of SSH username. + /// + /// + public const int SshUserMaxLength = 60; /// /// Max length of tunnel or port description. @@ -241,11 +255,12 @@ public static class TunnelConstraints /// Regular expression that can match or validate tunnel ID strings. /// /// - /// Tunnel IDs are fixed-length and have a limited character set of - /// numbers and lowercase letters (minus vowels and y). + /// Tunnel IDs have a limited character set of numbers and lowercase letters. + /// Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + /// remain within the DNS label limit of 63 characters. /// /// - public const string NewTunnelIdPattern = "[a-z0-9][a-z0-9-]{1,58}[a-z0-9]"; + public const string NewTunnelIdPattern = "[a-z0-9][a-z0-9-]{1,47}[a-z0-9]"; /// /// Regular expression that can match or validate tunnel ID strings. @@ -270,9 +285,11 @@ public static class TunnelConstraints /// /// Tunnel Aliases are fixed-length and have a limited character set of /// numbers and lowercase letters (minus vowels and y). + /// Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + /// remain within the DNS label limit of 63 characters. /// /// - public const string TunnelAliasPattern = "[" + TunnelAliasChars + "]{3,60}"; + public const string TunnelAliasPattern = "[" + TunnelAliasChars + "]{3,49}"; /// /// Regular expression that can match or validate tunnel alias strings. @@ -290,9 +307,11 @@ public static class TunnelConstraints /// /// Tunnel names are alphanumeric and may contain hyphens. The pattern also /// allows an empty string because tunnels may be unnamed. + /// Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + /// remain within the DNS label limit of 63 characters. /// /// - public const string TunnelNamePattern = "([a-z0-9][a-z0-9-]{1,58}[a-z0-9])|(^$)"; + public const string TunnelNamePattern = "([a-z0-9][a-z0-9-]{1,47}[a-z0-9])|(^$)"; /// /// Regular expression that can match or validate tunnel names. diff --git a/cs/src/Contracts/TunnelPort.cs b/cs/src/Contracts/TunnelPort.cs index 7073b19c..34ee515f 100644 --- a/cs/src/Contracts/TunnelPort.cs +++ b/cs/src/Contracts/TunnelPort.cs @@ -137,7 +137,7 @@ public TunnelPort() /// Should be provided if the is Ssh. /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - [StringLength(TunnelNameMaxLength)] + [StringLength(SshUserMaxLength)] public string? SshUser { get; set; } /// diff --git a/cs/test/TunnelsSDK.Test/TunnelConstraintsTests.cs b/cs/test/TunnelsSDK.Test/TunnelConstraintsTests.cs index 413ed2f8..c7241b94 100644 --- a/cs/test/TunnelsSDK.Test/TunnelConstraintsTests.cs +++ b/cs/test/TunnelsSDK.Test/TunnelConstraintsTests.cs @@ -46,8 +46,8 @@ public void IsValidTunnelId_NotValid(string tunnelId) [InlineData("test")] [InlineData("aaa")] [InlineData("bcd-ghjk")] - [InlineData("jfullerton44-name-with-special-char--jrw9q5vrfjpwx")] - [InlineData("012345678901234567890123456789012345678901234567890123456789")] + [InlineData("username-name-with-special-char--jrw9q5vrfjpwx")] + [InlineData("0123456789012345678901234567890123456789012345678")] public void IsValidTunnelName_Valid(string tunnelName) { Assert.True(IsValidTunnelName(tunnelName)); @@ -55,6 +55,8 @@ public void IsValidTunnelName_Valid(string tunnelName) [Theory] [InlineData("a")] + [InlineData("username2345-name-with-special-char--jrw9q5vrfjpwx")] + [InlineData("012345678901234567890123456789012345678901234567890123456789")] [InlineData("0123456789012345678901234567890123456789012345678901234567890")] [InlineData("89bcdfgh")] [InlineData("stvwxzzz")] diff --git a/go/tunnels/tunnel_constraints.go b/go/tunnels/tunnel_constraints.go index 929e10b9..de833be0 100644 --- a/go/tunnels/tunnel_constraints.go +++ b/go/tunnels/tunnel_constraints.go @@ -23,7 +23,10 @@ const ( TunnelConstraintsNewTunnelIDMinLength = 3 // Max length of V2 tunnelId. - TunnelConstraintsNewTunnelIDMaxLength = 60 + // + // Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + // (-<port>-inspect) remain within the DNS label limit of 63 characters. + TunnelConstraintsNewTunnelIDMaxLength = 49 // Length of a tunnel alias. TunnelConstraintsTunnelAliasLength = 8 @@ -32,7 +35,13 @@ const ( TunnelConstraintsTunnelNameMinLength = 3 // Max length of tunnel name. - TunnelConstraintsTunnelNameMaxLength = 60 + // + // Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + // (-<port>-inspect) remain within the DNS label limit of 63 characters. + TunnelConstraintsTunnelNameMaxLength = 49 + + // Max length of SSH username. + TunnelConstraintsSshUserMaxLength = 60 // Max length of tunnel or port description. TunnelConstraintsDescriptionMaxLength = 400 @@ -113,9 +122,10 @@ const ( // Regular expression that can match or validate tunnel ID strings. // - // Tunnel IDs are fixed-length and have a limited character set of numbers and lowercase - // letters (minus vowels and y). - TunnelConstraintsNewTunnelIDPattern = "[a-z0-9][a-z0-9-]{1,58}[a-z0-9]" + // Tunnel IDs have a limited character set of numbers and lowercase letters. Limited to + // 49 characters to ensure tunnel URIs with ports and inspection suffixes remain within + // the DNS label limit of 63 characters. + TunnelConstraintsNewTunnelIDPattern = "[a-z0-9][a-z0-9-]{1,47}[a-z0-9]" // Characters that are valid in tunnel IDs. Includes numbers and lowercase letters, // excluding vowels and 'y' (to avoid accidentally generating any random words). @@ -124,14 +134,17 @@ const ( // Regular expression that can match or validate tunnel alias strings. // // Tunnel Aliases are fixed-length and have a limited character set of numbers and - // lowercase letters (minus vowels and y). - TunnelConstraintsTunnelAliasPattern = "[" + TunnelConstraintsTunnelAliasChars + "]{3,60}" + // lowercase letters (minus vowels and y). Limited to 49 characters to ensure tunnel URIs + // with ports and inspection suffixes remain within the DNS label limit of 63 characters. + TunnelConstraintsTunnelAliasPattern = "[" + TunnelConstraintsTunnelAliasChars + "]{3,49}" // Regular expression that can match or validate tunnel names. // // Tunnel names are alphanumeric and may contain hyphens. The pattern also allows an - // empty string because tunnels may be unnamed. - TunnelConstraintsTunnelNamePattern = "([a-z0-9][a-z0-9-]{1,58}[a-z0-9])|(^$)" + // empty string because tunnels may be unnamed. Limited to 49 characters to ensure tunnel + // URIs with ports and inspection suffixes remain within the DNS label limit of 63 + // characters. + TunnelConstraintsTunnelNamePattern = "([a-z0-9][a-z0-9-]{1,47}[a-z0-9])|(^$)" // Regular expression that can match or validate tunnel or port labels. TunnelConstraintsLabelPattern = "[\\w-=]{1,50}" diff --git a/go/tunnels/tunnels.go b/go/tunnels/tunnels.go index 3286c78e..fa7b93f0 100644 --- a/go/tunnels/tunnels.go +++ b/go/tunnels/tunnels.go @@ -10,7 +10,7 @@ import ( "github.com/rodaine/table" ) -const PackageVersion = "0.1.21" +const PackageVersion = "0.1.22" func (tunnel *Tunnel) requestObject() (*Tunnel, error) { convertedTunnel := &Tunnel{ diff --git a/java/src/main/java/com/microsoft/tunnels/contracts/TunnelConstraints.java b/java/src/main/java/com/microsoft/tunnels/contracts/TunnelConstraints.java index d7f4bde6..666b888b 100644 --- a/java/src/main/java/com/microsoft/tunnels/contracts/TunnelConstraints.java +++ b/java/src/main/java/com/microsoft/tunnels/contracts/TunnelConstraints.java @@ -32,8 +32,11 @@ public class TunnelConstraints { /** * Max length of V2 tunnelId. + * + * Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + * (-<port>-inspect) remain within the DNS label limit of 63 characters. */ - public static final int newTunnelIdMaxLength = 60; + public static final int newTunnelIdMaxLength = 49; /** * Length of a tunnel alias. @@ -47,8 +50,16 @@ public class TunnelConstraints { /** * Max length of tunnel name. + * + * Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + * (-<port>-inspect) remain within the DNS label limit of 63 characters. + */ + public static final int tunnelNameMaxLength = 49; + + /** + * Max length of SSH username. */ - public static final int tunnelNameMaxLength = 60; + public static final int sshUserMaxLength = 60; /** * Max length of tunnel or port description. @@ -197,10 +208,11 @@ public class TunnelConstraints { /** * Regular expression that can match or validate tunnel ID strings. * - * Tunnel IDs are fixed-length and have a limited character set of numbers and - * lowercase letters (minus vowels and y). + * Tunnel IDs have a limited character set of numbers and lowercase letters. Limited + * to 49 characters to ensure tunnel URIs with ports and inspection suffixes remain + * within the DNS label limit of 63 characters. */ - public static final String newTunnelIdPattern = "[a-z0-9][a-z0-9-]{1,58}[a-z0-9]"; + public static final String newTunnelIdPattern = "[a-z0-9][a-z0-9-]{1,47}[a-z0-9]"; /** * Regular expression that can match or validate tunnel ID strings. @@ -220,9 +232,11 @@ public class TunnelConstraints { * Regular expression that can match or validate tunnel alias strings. * * Tunnel Aliases are fixed-length and have a limited character set of numbers and - * lowercase letters (minus vowels and y). + * lowercase letters (minus vowels and y). Limited to 49 characters to ensure tunnel + * URIs with ports and inspection suffixes remain within the DNS label limit of 63 + * characters. */ - public static final String tunnelAliasPattern = "[" + TunnelConstraints.tunnelAliasChars + "]{3,60}"; + public static final String tunnelAliasPattern = "[" + TunnelConstraints.tunnelAliasChars + "]{3,49}"; /** * Regular expression that can match or validate tunnel alias strings. @@ -236,9 +250,11 @@ public class TunnelConstraints { * Regular expression that can match or validate tunnel names. * * Tunnel names are alphanumeric and may contain hyphens. The pattern also allows an - * empty string because tunnels may be unnamed. + * empty string because tunnels may be unnamed. Limited to 49 characters to ensure + * tunnel URIs with ports and inspection suffixes remain within the DNS label limit of + * 63 characters. */ - public static final String tunnelNamePattern = "([a-z0-9][a-z0-9-]{1,58}[a-z0-9])|(^$)"; + public static final String tunnelNamePattern = "([a-z0-9][a-z0-9-]{1,47}[a-z0-9])|(^$)"; /** * Regular expression that can match or validate tunnel names. diff --git a/rs/src/contracts/tunnel_constraints.rs b/rs/src/contracts/tunnel_constraints.rs index a1e04e89..942f59c3 100644 --- a/rs/src/contracts/tunnel_constraints.rs +++ b/rs/src/contracts/tunnel_constraints.rs @@ -17,7 +17,10 @@ pub const OLD_TUNNEL_ID_LENGTH: i32 = 8; pub const NEW_TUNNEL_ID_MIN_LENGTH: i32 = 3; // Max length of V2 tunnelId. -pub const NEW_TUNNEL_ID_MAX_LENGTH: i32 = 60; +// +// Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes +// (-<port>-inspect) remain within the DNS label limit of 63 characters. +pub const NEW_TUNNEL_ID_MAX_LENGTH: i32 = 49; // Length of a tunnel alias. pub const TUNNEL_ALIAS_LENGTH: i32 = 8; @@ -26,7 +29,13 @@ pub const TUNNEL_ALIAS_LENGTH: i32 = 8; pub const TUNNEL_NAME_MIN_LENGTH: i32 = 3; // Max length of tunnel name. -pub const TUNNEL_NAME_MAX_LENGTH: i32 = 60; +// +// Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes +// (-<port>-inspect) remain within the DNS label limit of 63 characters. +pub const TUNNEL_NAME_MAX_LENGTH: i32 = 49; + +// Max length of SSH username. +pub const SSH_USER_MAX_LENGTH: i32 = 60; // Max length of tunnel or port description. pub const DESCRIPTION_MAX_LENGTH: i32 = 400; @@ -107,9 +116,10 @@ pub const NEW_TUNNEL_ID_CHARS: &str = r#"0123456789abcdefghijklmnopqrstuvwxyz-"# // Regular expression that can match or validate tunnel ID strings. // -// Tunnel IDs are fixed-length and have a limited character set of numbers and lowercase -// letters (minus vowels and y). -pub const NEW_TUNNEL_ID_PATTERN: &str = r#"[a-z0-9][a-z0-9-]{1,58}[a-z0-9]"#; +// Tunnel IDs have a limited character set of numbers and lowercase letters. Limited to 49 +// characters to ensure tunnel URIs with ports and inspection suffixes remain within the +// DNS label limit of 63 characters. +pub const NEW_TUNNEL_ID_PATTERN: &str = r#"[a-z0-9][a-z0-9-]{1,47}[a-z0-9]"#; // Characters that are valid in tunnel IDs. Includes numbers and lowercase letters, // excluding vowels and 'y' (to avoid accidentally generating any random words). @@ -118,14 +128,16 @@ pub const TUNNEL_ALIAS_CHARS: &str = r#"0123456789bcdfghjklmnpqrstvwxz"#; // Regular expression that can match or validate tunnel alias strings. // // Tunnel Aliases are fixed-length and have a limited character set of numbers and -// lowercase letters (minus vowels and y). -pub const TUNNEL_ALIAS_PATTERN: &str = r#"[0123456789bcdfghjklmnpqrstvwxz]{3,60}"#; +// lowercase letters (minus vowels and y). Limited to 49 characters to ensure tunnel URIs +// with ports and inspection suffixes remain within the DNS label limit of 63 characters. +pub const TUNNEL_ALIAS_PATTERN: &str = r#"[0123456789bcdfghjklmnpqrstvwxz]{3,49}"#; // Regular expression that can match or validate tunnel names. // // Tunnel names are alphanumeric and may contain hyphens. The pattern also allows an empty -// string because tunnels may be unnamed. -pub const TUNNEL_NAME_PATTERN: &str = r#"([a-z0-9][a-z0-9-]{1,58}[a-z0-9])|(^$)"#; +// string because tunnels may be unnamed. Limited to 49 characters to ensure tunnel URIs +// with ports and inspection suffixes remain within the DNS label limit of 63 characters. +pub const TUNNEL_NAME_PATTERN: &str = r#"([a-z0-9][a-z0-9-]{1,47}[a-z0-9])|(^$)"#; // Regular expression that can match or validate tunnel or port labels. pub const LABEL_PATTERN: &str = r#"[\w-=]{1,50}"#; diff --git a/ts/src/connections/package.json b/ts/src/connections/package.json index ad68e329..4c3aa00a 100644 --- a/ts/src/connections/package.json +++ b/ts/src/connections/package.json @@ -18,8 +18,8 @@ "buffer": "^5.2.1", "debug": "^4.1.1", "vscode-jsonrpc": "^4.0.0", - "@microsoft/dev-tunnels-contracts": "^1.3.8", - "@microsoft/dev-tunnels-management": "^1.3.8", + "@microsoft/dev-tunnels-contracts": "^1.3.9", + "@microsoft/dev-tunnels-management": "^1.3.9", "uuid": "^3.3.3", "await-semaphore": "^0.1.3", "websocket": "^1.0.28", diff --git a/ts/src/contracts/tunnelConstraints.ts b/ts/src/contracts/tunnelConstraints.ts index 19f02060..527f0c61 100644 --- a/ts/src/contracts/tunnelConstraints.ts +++ b/ts/src/contracts/tunnelConstraints.ts @@ -29,8 +29,11 @@ export namespace TunnelConstraints { /** * Max length of V2 tunnelId. + * + * Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + * (-<port>-inspect) remain within the DNS label limit of 63 characters. */ - export const newTunnelIdMaxLength: number = 60; + export const newTunnelIdMaxLength: number = 49; /** * Length of a tunnel alias. @@ -44,8 +47,16 @@ export namespace TunnelConstraints { /** * Max length of tunnel name. + * + * Limited to 49 characters to ensure tunnel URIs with ports and inspection suffixes + * (-<port>-inspect) remain within the DNS label limit of 63 characters. + */ + export const tunnelNameMaxLength: number = 49; + + /** + * Max length of SSH username. */ - export const tunnelNameMaxLength: number = 60; + export const sshUserMaxLength: number = 60; /** * Max length of tunnel or port description. @@ -194,10 +205,11 @@ export namespace TunnelConstraints { /** * Regular expression that can match or validate tunnel ID strings. * - * Tunnel IDs are fixed-length and have a limited character set of numbers and - * lowercase letters (minus vowels and y). + * Tunnel IDs have a limited character set of numbers and lowercase letters. Limited + * to 49 characters to ensure tunnel URIs with ports and inspection suffixes remain + * within the DNS label limit of 63 characters. */ - export const newTunnelIdPattern: string = '[a-z0-9][a-z0-9-]{1,58}[a-z0-9]'; + export const newTunnelIdPattern: string = '[a-z0-9][a-z0-9-]{1,47}[a-z0-9]'; /** * Regular expression that can match or validate tunnel ID strings. @@ -217,9 +229,11 @@ export namespace TunnelConstraints { * Regular expression that can match or validate tunnel alias strings. * * Tunnel Aliases are fixed-length and have a limited character set of numbers and - * lowercase letters (minus vowels and y). + * lowercase letters (minus vowels and y). Limited to 49 characters to ensure tunnel + * URIs with ports and inspection suffixes remain within the DNS label limit of 63 + * characters. */ - export const tunnelAliasPattern: string = '[' + TunnelConstraints.tunnelAliasChars + ']{3,60}'; + export const tunnelAliasPattern: string = '[' + TunnelConstraints.tunnelAliasChars + ']{3,49}'; /** * Regular expression that can match or validate tunnel alias strings. @@ -233,9 +247,11 @@ export namespace TunnelConstraints { * Regular expression that can match or validate tunnel names. * * Tunnel names are alphanumeric and may contain hyphens. The pattern also allows an - * empty string because tunnels may be unnamed. + * empty string because tunnels may be unnamed. Limited to 49 characters to ensure + * tunnel URIs with ports and inspection suffixes remain within the DNS label limit of + * 63 characters. */ - export const tunnelNamePattern: string = '([a-z0-9][a-z0-9-]{1,58}[a-z0-9])|(^$)'; + export const tunnelNamePattern: string = '([a-z0-9][a-z0-9-]{1,47}[a-z0-9])|(^$)'; /** * Regular expression that can match or validate tunnel names. diff --git a/ts/src/management/package.json b/ts/src/management/package.json index f390aead..48fda08f 100644 --- a/ts/src/management/package.json +++ b/ts/src/management/package.json @@ -18,7 +18,7 @@ "buffer": "^5.2.1", "debug": "^4.1.1", "vscode-jsonrpc": "^4.0.0", - "@microsoft/dev-tunnels-contracts": "^1.3.8", + "@microsoft/dev-tunnels-contracts": "^1.3.9", "axios": "^1.8.4" } }