Azure Storage : Unable to access Container blobs with defined Credentials - azure-storage

We are setting a Key for the Storage Account and then using to access the contents as below;
var storageCredentials = new StorageCredentials(mediaStorageAccountName, base64EncodedKey);
var storageAccount = new CloudStorageAccount(storageCredentials, true);
var connString = storageAccount.ToString(true);
Then, using the same "storageAccount" to create the Blob Client;
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
And to get the Container;
var container = blobClient.GetContainerReference(ContainerName);
"storageAccount" Credential properties are "IsSAS" FALSE, "IsSharedKey" TRUE, "IsToken" FALSE and "KeyName" is NULL.
But, when Blob is being accessed with OpenReadAsync, its failing with following exception;
The remote server returned an error: (403) Forbidden.,The remote server returned an error: (403) Forbidden. Line number: Microsoft.WindowsAzure.Storage Trace: at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result)
at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.EndExists(IAsyncResult asyncResult)
at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass2`1.b__0(IAsyncResult ar)
It is basically getting all the references to Container/Blobs etc correctly (gives correct name), but when its tried to read/download/upload those, it fails.
Also, instead of using the "storageAccount" reference directly, even if it is secured with following, it gives same exception;
CloudStorageAccount storageAccount = new CloudStorageAccount(
new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageAccountName, base64EncodedKey), true);
What is wrong here and how to fix this?
Why is KeyName NULL? Is that causing this issue?

The 403 forbidden exception often caused by a wrong access key is used.
As you are using Authorize with Shared Key, all authorized requests must include the Coordinated Universal Time (UTC) timestamp for the request. You can specify the timestamp either in the x-ms-date header, or in the standard HTTP/HTTPS Date header.
The storage services ensure that a request is no older than 15 minutes by the time it reaches the service. This guards against certain security attacks, including replay attacks. When this check fails, the server returns response code 403 (Forbidden).
So, review your server datatime.

Related

.Net Core ReportExecutionServiceSoapClient set credentials

I am using ReportExecutionServiceSoapClient in .Net Core i got the latest version of .net Core and tried to get a report from reporting services to work. after I've used the WCF connection service I was able to add the code with looks like bellow
// Instantiate the Soap client
ReportExecutionServiceSoap rsExec = new ReportExecutionServiceSoapClient(ReportExecutionServiceSoapClient.EndpointConfiguration.ReportExecutionServiceSoap);
// Create a network credential object with the appropriate username and password used
// to access the SSRS web service
string historyID = null;
TrustedUserHeader trustedUserHeader = new TrustedUserHeader();
ExecutionHeader execHeader = new ExecutionHeader();
// Here we call the async LoadReport() method using the "await" keyword, which means any code below this method
// will not execute until the result from the LoadReportAsync task is returned
var taskLoadReport = rsExec.LoadReportAsync(reportPath, historyID);
// By the time the LoadReportAsync task is returned successfully, its "executionInfo" property
// would have already been populated. Now the remaining code in this main thread will resume executing
string deviceInfo = null;
string format = "EXCEL";
// Now, similar to the above task, we will call the RenderAsync() method and await its result
var taskRender = await rsExec.RenderAsync(renderReq);
When it hist renderAsync all falls apart because the credentials for the service are not set anywhere. I've tried to Login async with no success. Also I've tried to set the credentials with SetExecutionCredentialsAsync but I've got and error saying "The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'." I don't know how to change that for ReportExecutionServiceSoapClient.
I have read some posts in which Microsoft guys says that the authentication with a soap is not resolved but for me it seems so close to be true. I feel like I am missing something.
Technology stack: VS 2017, .net Core web api, ssrs 2016, sql server 2016 standard
How can I authenticate the user for this call?
I know this is an old question but I had the same issue and stumbled onto the answer.
After creating the ReportExecutionServiceSoap object you can specify the username and password in the ClientCredentials. I've had success with this using the Basic client credential type. Be sure you are using HTTPS, otherwise your password is sent in plaintext to the reporting server. I also recommend storing the user/password in a secure place and not code.
BasicHttpBinding rsBinding = new BasicHttpBinding();
rsBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
rsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress rsEndpointAddress = new EndpointAddress("https://servername/ReportServer/ReportExecution2005.asmx");
var rsExec = new ReportExecutionServiceSoapClient(rsBinding, rsEndpointAddress);
rsExec.ClientCredentials.UserName.UserName = "username";
rsExec.ClientCredentials.UserName.Password = "pass";

azure blob uploadfile bad request

Hi I am new to azure I am trying to upload a file to azure container using
static void UploadBlobFromFile(Uri blobEndpoint, string accountName, string accountKey)
{
// Create service client for credentialed access to the Blob service.
CloudBlobClient blobClient =
new CloudBlobClient(blobEndpoint,
new StorageCredentials(accountName, accountKey));
// Get a reference to a container, which may or may not exist.
CloudBlobContainer container = blobClient.GetContainerReference("StackOverflowAnalysis");
// Create a new container, if it does not exist
//container.CreateIfNotExist();
// Get a reference to a blob, which may or may not exist.
CloudBlockBlob blob = container.GetBlockBlobReference("QueryResults.csv");
// Upload content to the blob, which will create the blob if it does not already exist.
using (var filst = System.IO.File.OpenRead(#"c:\users\hmohamed\Downloads\QueryResults.csv"))
{ blob.UploadFromStream(filst); }
}'
I am getting error Bad request 400; I am trying this in mvc app I have also tried it with console application where i got error the process cannot access file because it is being used by another process. Responses to similar posts advice to run netstat command to fix the problem but I do not know how to use it and what parameters to supply; can some one please help
All letters in a container name must be lowercase. So, please use "stackoverflowanalysis" as your container name.
For more information on naming, please refer to Naming and Referencing Containers, Blobs, and Metadata.

CloudFileShare CreateIfNotExistsAsync().Wait method throwing The remote server returned an error: (400) Bad Request

I am trying to use the Azure File Service preview as a mapped drive between my two instances of a cloud service and I came across the following blog post with some details:
http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/12/introducing-microsoft-azure-file-service.aspx?CommentPosted=true#commentmessage
I have signed up for the preview version of the storage account and created a new storage account and verified that the file endpoint is included. I then use the following code to attempt to create the share programmatically:
CloudStorageAccount account = CloudStorageAccount.Parse(System.Configuration.ConfigurationManager.AppSettings["SecondaryStorageConnectionString"].ToString());
CloudFileClient client = account.CreateCloudFileClient();
CloudFileShare share = client.GetShareReference("SCORM");
try
{
share.CreateIfNotExistsAsync().Wait();
}
catch (AggregateException e)
{
var test = e.Message;
var test1 = e.InnerException.Message;
}
On the CreateIfNotExistsAsync().Wait() method I am getting a Aggregate exception and when I look at the Inner details it just says The remote server returned an error: (400) Bad Request.
Your comment is the correct answer. Please refer to Naming and Referencing Shares, Directories, Files, and Metadata article for more information.

ODataService Type Provider error: (401) Unauthorized

The type provider
'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders'
reported an error: Error reading schema. The remote server returned an
error: (401) Unauthorized.
Is there a way to use the OData type provider with an OData service which requires a username and password?
Static type parameters for the type provider:
ServiceUri : string The URI string for the OData service.
LocalSchemaFile : string The path to a file that contains the schema. This file is written by the type provider.
ForceUpdate : bool Requires that the direct connection to the service is available at design/compile time and the local service
file is refreshed. The default value is true. When ForceUpdate is
false, the provider reacts to changes in the LocalSchemaFile.
ResolutionFolder : string A folder to be used to resolve relative file paths at compile time. The default value is the folder that
contains the project or script.
DataServiceCollection : bool Generates collections derived from DataServiceCollection. The default value is false.
Yes, but unfortunately it's not quite as slick, and you don't get compile-time validation, which is one of the nice benefits of type providers.
You need to grab the $metadata from your service and save it locally as a .csdl file, then use the LocalSchemaFile static parameter in your code. You can then set credentials on the data context object in order to authenticate at runtime.
// download http://services.odata.org/Northwind/Northwind.svc/$metadata to local file Metadata.csdl
type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc/",
LocalSchemaFile="Metadata.csdl",
ForceUpdate=false>
let db = Northwind.GetDataContext()
db.Credentials <- System.Net.CredentialCache.DefaultCredentials // or whatever creds you need
// go party

call to magento soap api expires immediately

I'm trying to do a call to the magento api to get the details of a specific customer. When I do this call I always get the following error:
PHP Fatal error: Uncaught SoapFault exception: [5] Session expired. Try to relogin. in /var/www/magento-client/magento-customer.php:12
Stack trace:
/var/www/magento-client/magento-customer.php(12): SoapClient->__call('call', Array)
/var/www/magento-client/magento-customer.php(12): SoapClient->call('a1a6863c7dadd95...', 'customer.info', 3)
{main}
thrown in /var/www/magento-client/magento-customer.php on line 12
I have a valid api user in the backend, the api session timeout in the backend is set to 9999999999999, and I've even tried to override the isSessionExpired function in the magento core code, but nothing works.
The code is as follows:
$url = 'http://magentourl/api/soap/?wsdl';
$apiUser = "user";
$apiPass = "password";
$proxy = new SoapClient($url);
$sessionId = $proxy->login($apiUser, $apiPass);
// Get new customer info
var_dump($sessionId);
var_dump($proxy->call($sessionId, 'customer.info', 3));
die();
Does anyone have any ideas what the problem could be?
This occurs if you send headers with the request, check if headers are sent.
maybe you should try to truncate the api_session table in the mysql database