-
Notifications
You must be signed in to change notification settings - Fork 159
Whitelisting Onelake API & Workspace PL FQDNs #552
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
Closed
+104
−26
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3960a7a
Whitelisting Onelake API & Workspace PL FQDNs
5b9dd47
Addressing comments to whitelist api-onelake fqdns and add UTs
4ba4321
Reverting the mistakenly modified UT
3826e5b
Adding validation for xy in WS-PL URL & case insensitive regex
897b528
Making regex an optional dependency
5d7a1fd
Eliminating the use of regex for ws-pl fqdn matching
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -671,36 +671,74 @@ impl MicrosoftAzureBuilder { | |
| self.container_name = Some(validate(parsed.username())?); | ||
| self.account_name = Some(validate(a)?); | ||
| self.use_fabric_endpoint = true.into(); | ||
| } else if let Some(a) = host.strip_suffix(".blob.core.windows.net") { | ||
| self.container_name = Some(validate(parsed.username())?); | ||
| self.account_name = Some(validate(a)?); | ||
| } else if let Some(a) = host.strip_suffix(".blob.fabric.microsoft.com") { | ||
| self.container_name = Some(validate(parsed.username())?); | ||
| self.account_name = Some(validate(a)?); | ||
| self.use_fabric_endpoint = true.into(); | ||
| } else { | ||
| return Err(Error::UrlNotRecognised { url: url.into() }.into()); | ||
| } | ||
| } | ||
| "https" => match host.split_once('.') { | ||
| Some((a, "dfs.core.windows.net")) | Some((a, "blob.core.windows.net")) => { | ||
| self.account_name = Some(validate(a)?); | ||
| let container = parsed.path_segments().unwrap().next().expect( | ||
| "iterator always contains at least one string (which may be empty)", | ||
| ); | ||
| if !container.is_empty() { | ||
| self.container_name = Some(validate(container)?); | ||
| "https" => { | ||
| // "{workspaceid}.z??.(onelake|dfs|blob).fabric.microsoft.com" | ||
| match host.split_once('.') { | ||
|
|
||
| // Workspace-level Private Link detection | ||
| Some((workspaceid, rest)) if rest.starts_with('z') && rest.ends_with("fabric.microsoft.com") => { | ||
| // rest looks like: "z28.dfs.fabric.microsoft.com" / "z28.blob.fabric.microsoft.com" / etc. | ||
| // Account name for WS-PL is two labels: "{wsid}.z{xy}" | ||
| let (zone, _) = rest | ||
| .split_once('.') | ||
| .unwrap_or((rest, "")); | ||
|
|
||
| let wsid = validate(workspaceid)?; | ||
| let zone = validate(zone)?; | ||
|
|
||
| self.account_name = Some(format!("{wsid}.{zone}")); | ||
|
|
||
| // Attempt to infer the container name from the URL | ||
| let container = parsed.path_segments().unwrap().next() | ||
| .expect("iterator always contains at least one string (which may be empty)"); | ||
|
|
||
| if !container.is_empty() { | ||
| self.container_name = Some(validate(container)?); | ||
| } | ||
|
|
||
| self.use_fabric_endpoint = true.into(); | ||
| } | ||
| } | ||
| Some((a, "dfs.fabric.microsoft.com")) | Some((a, "blob.fabric.microsoft.com")) => { | ||
| self.account_name = Some(validate(a)?); | ||
| // Attempt to infer the container name from the URL | ||
|
SmritiAgrawal04 marked this conversation as resolved.
|
||
| // - https://onelake.dfs.fabric.microsoft.com/<workspaceGUID>/<itemGUID>/Files/test.csv | ||
| // - https://onelake.dfs.fabric.microsoft.com/<workspace>/<item>.<itemtype>/<path>/<fileName> | ||
| // | ||
| // See <https://learn.microsoft.com/en-us/fabric/onelake/onelake-access-api> | ||
| let workspace = parsed.path_segments().unwrap().next().expect( | ||
| "iterator always contains at least one string (which may be empty)", | ||
| ); | ||
| if !workspace.is_empty() { | ||
| self.container_name = Some(workspace.to_string()) | ||
|
|
||
| // Azure Storage public | ||
| Some((a, "dfs.core.windows.net")) | Some((a, "blob.core.windows.net")) => { | ||
| self.account_name = Some(validate(a)?); | ||
|
|
||
| // Attempt to infer the container name from the URL | ||
| let container = parsed.path_segments().unwrap().next() | ||
| .expect("iterator always contains at least one string (which may be empty)"); | ||
|
|
||
| if !container.is_empty() { | ||
| self.container_name = Some(validate(container)?); | ||
| } | ||
| } | ||
| self.use_fabric_endpoint = true.into(); | ||
|
|
||
| // Fabric endpoints | ||
| Some((a, "dfs.fabric.microsoft.com")) | Some((a, "blob.fabric.microsoft.com")) => { | ||
| self.account_name = Some(validate(a)?); | ||
|
|
||
| let workspace = parsed.path_segments().unwrap().next() | ||
| .expect("iterator always contains at least one string (which may be empty)"); | ||
|
|
||
| if !workspace.is_empty() { | ||
| self.container_name = Some(workspace.to_string()); | ||
| } | ||
|
|
||
| self.use_fabric_endpoint = true.into(); | ||
| } | ||
|
|
||
| _ => return Err(Error::UrlNotRecognised { url: url.into() }.into()), | ||
| } | ||
| _ => return Err(Error::UrlNotRecognised { url: url.into() }.into()), | ||
| }, | ||
| scheme => { | ||
| let scheme = scheme.into(); | ||
|
|
@@ -1165,7 +1203,7 @@ mod tests { | |
| assert_eq!(builder.account_name, Some("account".to_string())); | ||
| assert_eq!(builder.container_name, None); | ||
| assert!(builder.use_fabric_endpoint.get().unwrap()); | ||
|
|
||
| let mut builder = MicrosoftAzureBuilder::new(); | ||
| builder | ||
| .parse_url("https://account.dfs.fabric.microsoft.com/container") | ||
|
|
@@ -1174,6 +1212,14 @@ mod tests { | |
| assert_eq!(builder.container_name.as_deref(), Some("container")); | ||
| assert!(builder.use_fabric_endpoint.get().unwrap()); | ||
|
|
||
| let mut builder = MicrosoftAzureBuilder::new(); | ||
| builder | ||
| .parse_url("https://onelake.dfs.fabric.microsoft.com/c047b3e3-4e89-407a-98d7-cf9949ae92a3/9f1a2b3c-4d5e-6f70-8a9b-c0d1e2f3a456.lakehouse/Files/tables/sales/data.parquet") | ||
| .unwrap(); | ||
| assert_eq!(builder.account_name, Some("onelake".to_string())); | ||
| assert_eq!(builder.container_name.as_deref(), Some("c047b3e3-4e89-407a-98d7-cf9949ae92a3")); | ||
| assert!(builder.use_fabric_endpoint.get().unwrap()); | ||
|
|
||
| let mut builder = MicrosoftAzureBuilder::new(); | ||
| builder | ||
| .parse_url("https://account.blob.fabric.microsoft.com/") | ||
|
|
@@ -1190,14 +1236,46 @@ mod tests { | |
| assert_eq!(builder.container_name.as_deref(), Some("container")); | ||
| assert!(builder.use_fabric_endpoint.get().unwrap()); | ||
|
|
||
| let mut builder = MicrosoftAzureBuilder::new(); | ||
| builder | ||
| .parse_url("https://Ab000000000000000000000000000000.zAb.dfs.fabric.microsoft.com/") | ||
| .unwrap(); | ||
| assert_eq!(builder.account_name, Some("ab000000000000000000000000000000.zab".to_string())); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the account name really supposed to have the |
||
| assert_eq!(builder.container_name.as_deref(), None); | ||
| assert!(builder.use_fabric_endpoint.get().unwrap()); | ||
|
|
||
| let mut builder = MicrosoftAzureBuilder::new(); | ||
| builder | ||
| .parse_url("https://ab000000000000000000000000000000.zab.dfs.fabric.microsoft.com/") | ||
| .unwrap(); | ||
| assert_eq!(builder.account_name, Some("ab000000000000000000000000000000.zab".to_string())); | ||
| assert_eq!(builder.container_name.as_deref(), None); | ||
| assert!(builder.use_fabric_endpoint.get().unwrap()); | ||
|
|
||
| let mut builder = MicrosoftAzureBuilder::new(); | ||
| builder | ||
| .parse_url("https://c047b3e34e89407a98d7cf9949ae92a3.zc0.blob.fabric.microsoft.com/c047b3e3-4e89-407a-98d7-cf9949ae92a3/9f1a2b3c-4d5e-6f70-8a9b-c0d1e2f3a456/file") | ||
| .unwrap(); | ||
| assert_eq!(builder.account_name, Some("c047b3e34e89407a98d7cf9949ae92a3.zc0".to_string())); | ||
| assert_eq!(builder.container_name.as_deref(), Some("c047b3e3-4e89-407a-98d7-cf9949ae92a3")); | ||
| assert!(builder.use_fabric_endpoint.get().unwrap()); | ||
|
|
||
| let mut builder = MicrosoftAzureBuilder::new(); | ||
| builder | ||
| .parse_url("https://c047b3e34e89407a98d7cf9949ae92a3.zc0.onelake.fabric.microsoft.com/c047b3e3-4e89-407a-98d7-cf9949ae92a3/9f1a2b3c-4d5e-6f70-8a9b-c0d1e2f3a456/file") | ||
| .unwrap(); | ||
| assert_eq!(builder.account_name, Some("c047b3e34e89407a98d7cf9949ae92a3.zc0".to_string())); | ||
| assert_eq!(builder.container_name.as_deref(), Some("c047b3e3-4e89-407a-98d7-cf9949ae92a3")); | ||
| assert!(builder.use_fabric_endpoint.get().unwrap()); | ||
|
|
||
| let err_cases = [ | ||
| "mailto://account.blob.core.windows.net/", | ||
| "az://blob.mydomain/", | ||
| "abfs://container.foo/path", | ||
| "abfss://file_system@account.foo.dfs.core.windows.net/", | ||
| "abfss://file_system.bar@account.dfs.core.windows.net/", | ||
| "https://blob.mydomain/", | ||
| "https://blob.foo.dfs.core.windows.net/", | ||
| "https://blob.foo.dfs.core.windows.net/" | ||
| ]; | ||
| let mut builder = MicrosoftAzureBuilder::new(); | ||
| for case in err_cases { | ||
|
|
@@ -1256,4 +1334,4 @@ mod tests { | |
| panic!("{key} not propagated as ClientConfigKey"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.