skoruba / IdentityServer4.Admin

The administration for the IdentityServer4 and Asp.Net Core Identity
MIT License
3.57k stars 1.15k forks source link

release/2.0.0: IdentityClaims table is missing #799

Closed agross closed 3 years ago

agross commented 3 years ago

Describe the bug

I'm attempting to run release/2.0.0 (91f1011742134808c3149cb9a2e380b49d3820f0) on docker.

After all services are up I can log in to STS with the provided default credentials of identitydata.json. Requesting /.well-known/openid-configuration fails with an exception because a table is missing.

Relevant parts of the log file

It seems that the tables was removed as part during that startup of the "admin" container:

$ docker logs identity-server_admin_1 | \grep IdentityClaims
[2021-02-16T14:27:42.0885401+00:00][INFO][14][Microsoft.EntityFrameworkCore.Database.Command] Executed DbCommand ("11"ms) [Parameters=[""], CommandType='Text', CommandTimeout='30']"\n""CREATE TABLE [IdentityClaims] (\n    [Id] int NOT NULL IDENTITY,\n    [Type] nvarchar(200) NOT NULL,\n    [IdentityResourceId] int NOT NULL,\n    CONSTRAINT [PK_IdentityClaims] PRIMARY KEY ([Id]),\n    CONSTRAINT [FK_IdentityClaims_IdentityResources_IdentityResourceId] FOREIGN KEY ([IdentityResourceId]) REFERENCES [IdentityResources] ([Id]) ON DELETE CASCADE\n);"
[2021-02-16T14:27:42.1499508+00:00][INFO][13][Microsoft.EntityFrameworkCore.Database.Command] Executed DbCommand ("3"ms) [Parameters=[""], CommandType='Text', CommandTimeout='30']"\n""CREATE INDEX [IX_IdentityClaims_IdentityResourceId] ON [IdentityClaims] ([IdentityResourceId]);"
[2021-02-16T14:27:43.0981068+00:00][INFO][13][Microsoft.EntityFrameworkCore.Database.Command] Executed DbCommand ("8"ms) [Parameters=[""], CommandType='Text', CommandTimeout='30']"\n""INSERT INTO IdentityResourceClaims\n (Id, [Type], IdentityResourceId)\nSELECT \n Id, [Type], IdentityResourceId\nFROM IdentityClaims"

# DROP TABLE follows:

[2021-02-16T14:27:43.1351639+00:00][INFO][14][Microsoft.EntityFrameworkCore.Database.Command] Executed DbCommand ("4"ms) [Parameters=[""], CommandType='Text', CommandTimeout='30']"\n""DROP TABLE [IdentityClaims];"

The following exception is logged on the request for /.well-known/openid-configuration.

Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'IdentityClaims'.
   at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__164_0(Task`1 result)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at IdentityServer4.EntityFramework.Stores.ResourceStore.GetAllResourcesAsync()
   at IdentityServer4.Stores.IResourceStoreExtensions.GetAllEnabledResourcesAsync(IResourceStore store)
   at IdentityServer4.ResponseHandling.DiscoveryResponseGenerator.CreateDiscoveryDocumentAsync(String baseUrl, String issuerUri)
   at IdentityServer4.Endpoints.DiscoveryEndpoint.ProcessAsync(HttpContext context)
   at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
   at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
   at IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.CspMiddleware.Invoke(HttpContext context)
   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
ClientConnectionId:26bafdb5-75cb-4014-819a-6ef6117d0c87
Error Number:208,State:1,Class:16
skoruba commented 3 years ago

Hello, which database provider do you use? Did you have an empty database before starting? thanks for reporting this issue

agross commented 3 years ago

Hello Jan,

SQL Server 2019 on docker. I started without any data.

Let me know if you need further details.

Alex

skoruba commented 3 years ago

Thanks let me check it.

skoruba commented 3 years ago

@agross - I've refresh dockerfile for admin ui there was missing one package. I've tested new fresh instalation through the docker and everything works good. 👍 One thing is that if the database starts for the first time this process takes more time and first run failed because the database is not ready yet. Please, checkout changes from release/2.0.0 and test it. 😊 Thanks

agross commented 3 years ago

Tried after resetting all docker volumes. It's working now!

What's rather strange is that the IdentityClaims table is still missing. Is it required after all for version 2.0?

skoruba commented 3 years ago

IdentityClaims table was renamed in IS4 v4 to IdentityResourceClaims.

agross commented 3 years ago

Alright, thanks!

skoruba commented 3 years ago

Thanks for letting me know. 👋