-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[QUERY] What is the recommended way to configure a BlobContainerClientBuilder to use a non-public cloud? #44146
Comments
Here's a quick example of how to override the end points. You can also use the import com.azure.storage.blob.BlobContainerClientBuilder;
import com.azure.identity.ManagedIdentityCredential;
import com.azure.identity.ManagedIdentityCredentialBuilder;
public class BlobStorageConfig {
/**
* Configures a BlobContainerClientBuilder using Managed Identity authentication.
*
* @param containerName The name of the blob container. Must be between 3-63 characters,
* start with a letter or number, and can contain only lowercase letters,
* numbers, and dashes. Example: "my-container-name"
*
* @param endpointUrl The complete URL to your blob storage endpoint. Format varies by environment:
* - Azure Stack Hub:
* https://[account-name].blob.[region].[stack-domain]
* Example: https://myaccount.blob.east.azurestack.contoso.com
*
* - Private Azure Cloud:
* https://[account-name].blob.core.[private-dns-zone]
* Example: https://myaccount.blob.core.private.cloud.contoso.com
*
* - Custom Endpoint:
* Any valid HTTPS endpoint that accepts Azure Blob storage API requests
* Example: https://storage.internal.company.com
*
* @param clientId Optional: The client ID of a user-assigned managed identity.
* Pass null to use system-assigned managed identity.
*
* @return Configured BlobContainerClientBuilder instance
*/
public BlobContainerClientBuilder configureBlobClient(
String containerName,
String endpointUrl,
String clientId) {
// Create ManagedIdentityCredential
ManagedIdentityCredential credential;
if (clientId != null && !clientId.isEmpty()) {
// Use user-assigned managed identity
credential = new ManagedIdentityCredentialBuilder()
.clientId(clientId)
.build();
} else {
// Use system-assigned managed identity
credential = new ManagedIdentityCredentialBuilder()
.build();
}
// Configure the blob container client builder
return new BlobContainerClientBuilder()
.credential(credential)
.containerName(containerName)
.endpoint(endpointUrl);
}
// Example usage
public static void main(String[] args) {
// Container name example: lowercase letters, numbers, and dashes only
String containerName = "user-uploads-2024";
// Example endpoint URLs for different environments:
// Azure Stack Hub example
String azureStackEndpoint = "https://myaccount.blob.eastus.azurestack.contoso.com";
// Private cloud example
String privateCloudEndpoint = "https://myaccount.blob.core.private.cloud.contoso.com";
// Custom endpoint example
String customEndpoint = "https://storage.internal.company.com";
// Choose the appropriate endpoint for your environment
String endpointUrl = azureStackEndpoint; // Change this to your actual endpoint
// Optional: client ID for user-assigned managed identity
String clientId = null;
BlobStorageConfig config = new BlobStorageConfig();
BlobContainerClientBuilder builder = config.configureBlobClient(
containerName,
endpointUrl,
clientId
);
// Create the client
BlobContainerClient containerClient = builder.buildClient();
}
} |
Hi @fabiim. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation. |
/unresolve Thanks for the help @joshfree . I missed that you can have different blob DNS names beyond the variation of the other cloud types (like gov). I am still unsure what to do about authentication. |
Query/Question
Hi all, I'm a bit lost on how to configure a BlobContainerClientBuilder to connect to different clouds.
AZURE_CLOUD
environment variable for that?DefaultAzureCredentialBuilder()
) ?Setup (please complete the following information if applicable):
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
The text was updated successfully, but these errors were encountered: