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

AmazonSecurityTokenServiceClient.AssumeRoleWithSAML or GetSessionTokenAsync fails with exception #1131

Closed
iprion opened this issue Nov 28, 2018 · 6 comments
Assignees
Labels
guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@iprion
Copy link

iprion commented Nov 28, 2018

If I create a AmazonSecurityTokenServiceClient, calling AssumeRoleWithSAML fails with an exception:

Object reference not set to an instance of an object

Same error occurs when calling GetSessionTokenAsync.

Here is a code sample (method was found on the internet and seems to work for the user who wrote it)

private static async Task<SessionAWSCredentials> GetTemporaryCredentialsAsync()
        {
            using (var stsClient = new AmazonSecurityTokenServiceClient())
            {
                var getSessionTokenRequest = new GetSessionTokenRequest
                {
                    DurationSeconds = 7200 // seconds
                };

                GetSessionTokenResponse sessionTokenResponse =
                              await stsClient.GetSessionTokenAsync(getSessionTokenRequest);

                Credentials credentials = sessionTokenResponse.Credentials;

                var sessionCredentials =
                    new SessionAWSCredentials(credentials.AccessKeyId,
                                              credentials.SecretAccessKey,
                                              credentials.SessionToken);
                return sessionCredentials;
            }
        }

In the debug output I see a lot of exception thrown
Exception thrown: 'System.InvalidOperationException' in AWSSDK.Core.dll
Exception thrown: 'System.IO.DirectoryNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.DirectoryNotFoundException' in mscorlib.dll
Exception thrown: 'Amazon.Runtime.AmazonClientException' in AWSSDK.Core.dll
Exception thrown: 'System.InvalidOperationException' in AWSSDK.Core.dll
Exception thrown: 'System.InvalidOperationException' in AWSSDK.Core.dll
Exception thrown: 'System.InvalidOperationException' in AWSSDK.Core.dll
Exception thrown: 'System.IO.DirectoryNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.DirectoryNotFoundException' in mscorlib.dll
Exception thrown: 'System.InvalidOperationException' in AWSSDK.Core.dll
Exception thrown: 'System.IO.DirectoryNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.DirectoryNotFoundException' in mscorlib.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
Exception thrown: 'System.IO.IOException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
Exception thrown: 'System.IO.IOException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.NullReferenceException' in AWSSDK.Core.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
Exception thrown: 'System.IO.IOException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.NullReferenceException' in AWSSDK.Core.dll
Exception thrown: 'System.NullReferenceException' in AWSSDK.Core.dll
Exception thrown: 'System.NullReferenceException' in AWSSDK.Core.dll

Am I missing something ? Other AWS Api and classes seems to work fine (AmazonS3Client, TransferUtility.DownloadDirectory ...)

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce (for bugs)

Context

Your Environment

  • AWSSDK.Core version used: 3.3.29.12
  • Service assembly and version used:
  • Operating System and version:
  • Visual Studio version: 2017
  • Targeted .NET platform:

.NET Core Info

  • .NET Core version used for development: 4.5
  • .NET Core version installed in the environment where application runs: 4.5
  • Output of dotnet --info:
    .NET Core SDK (reflecting any global.json):
    Version: 2.1.500
    Commit: b68b931422

Runtime Environment:
OS Name: Windows
OS Version: 6.1.7601
OS Platform: Windows
RID: win7-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.500\

Host (useful for support):
Version: 2.1.6
Commit: 3f4f8eebd8

.NET Core SDKs installed:
2.1.500 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNe
tCore.All]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNe
tCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.
App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

  • Contents of project.json/project.csproj:
@klaytaybai klaytaybai added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Nov 29, 2018
@klaytaybai klaytaybai self-assigned this Nov 29, 2018
@klaytaybai klaytaybai added guidance Question that needs advice or information. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Nov 29, 2018
@klaytaybai
Copy link
Contributor

Hi @iprion, I'm sorry to hear you are having difficulties. I was not able to reproduce this issue on a Mac. I could try at a later time to reproduce on a Windows Server 2008 instance.

Are the errors you listed related to AssumeRoleWithSAML or GetSessionTokenAsync?

@klaytaybai klaytaybai added Information Requested closing-soon This issue will automatically close in 4 days unless further comments are made. labels Nov 29, 2018
@klaytaybai klaytaybai removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Dec 10, 2018
@diehlaws diehlaws added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed Information Requested labels Jan 3, 2019
@pbenitez
Copy link

pbenitez commented Mar 25, 2019

I'm seeing the same error on Windows Server 2012 R2.
AWSSDK.Core version used: 3.3.31.19
AWSSDK.SecurityToken : 3.3.4.58 & 3.3.100

@savanbthakkar
Copy link

savanbthakkar commented Jul 18, 2019

Hi @pbenitez , @klaytaybai , I have the exact same problem. Did you find the solution?

Here is my sample code:

using (var stsClient = new AmazonSecurityTokenServiceClient())
{
try
{
var assumeRoleWithSAMLRequest = new AssumeRoleWithSAMLRequest
{
DurationSeconds = 43200,
SAMLAssertion = samlAssertion,
PrincipalArn = principal_arn,
RoleArn = role_arn
};
var response = await stsClient.AssumeRoleWithSAMLAsync(assumeRoleWithSAMLRequest);
var sessionCredentials =
new SessionAWSCredentials(response.Credentials.AccessKeyId,
response.Credentials.SecretAccessKey,
response.Credentials.SessionToken);
return sessionCredentials;
}
catch (Exception ee)
{
string err = ee.Message + ee.StackTrace;
throw;
}

        }

Here is my StackTrace:

Object reference not set to an instance of an object

at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
at Amazon.Runtime.Internal.CredentialsRetriever.d__71.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__101.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Amazon.Runtime.Internal.RetryHandler.d__101.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__91.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.Runtime.Internal.CallbackHandler.d__91.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__51.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.Runtime.Internal.MetricsHandler.d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at SessionManagement.AwsSessionManager.d__12.MoveNext()

@xbaha
Copy link

xbaha commented Aug 25, 2021

I am receiving this error too:
Exception thrown: 'System.InvalidOperationException' in AWSSDK.Core.dll
too many of them I can't count! Has anyone found a solution???

@savanbthakkar
Copy link

I am receiving this error too:
Exception thrown: 'System.InvalidOperationException' in AWSSDK.Core.dll
too many of them I can't count! Has anyone found a solution???

My issue turned out to be a misconfigured role in AWS.
@xbaha , Can you post the full exception including InnerExceptions if any?

@xbaha
Copy link

xbaha commented Aug 25, 2021

There was no exception thrown that stopped my app, it's just in my debug output window and too many of them, my app runs normal, but this happened after I installed AWSSimpleEmail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

6 participants