How to use Keycloak with SQL Server #6563
-
What needs to be done to run keycloak using SQL Server successfully? I've tried this app-model specifying the connection string as used by #6084 var sqlServer = builder.AddSqlServer("keycloaksql")
.WithDataVolume("keycloakdata");
var sqlDb = sqlServer.AddDatabase("keycloakdb", "keycloakidentity");
var keycloak = builder.AddKeycloak("keycloak")
.WithEnvironment(context =>
{
context.EnvironmentVariables.Add("KC_DB", "mssql");
context.EnvironmentVariables.Add("KC_DB_URL",
$"jdbc:sqlserver://{sqlServer.Resource.PrimaryEndpoint.ContainerHost};databaseName={sqlDb.Resource.DatabaseName};trustServerCertificate=true;user=sa;password={sqlServer.Resource.PasswordParameter.Value};");
})
.WaitFor(sqlDb); Keycloak fails with this error:
Did I miss any configuration required with Keycloak? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, try to view my sample code AppHost/Program.cs var passwordSql = builder.AddParameter("sqlAdminPassword", secret: true); builder.AddProject<Projects.DatabaseMigrations_ApiService>("api") builder.AddProject<Projects.DatabaseMigrations_MigrationService>("migration") var adminKeycloakUsername = builder.AddParameter("adminUsername", secret: true); var keycloak = builder.AddKeycloak("keycloak", adminUsername: adminKeycloakUsername, adminPassword: adminKeycloakPassword)
Dockerfile Enable health and metrics supportENV KC_HEALTH_ENABLED=true Configure a database vendorENV KC_DB=mssql WORKDIR /opt/keycloak for demonstration purposes only, please make sure to use proper certificates in production insteadRUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 RUN /opt/keycloak/bin/kc.sh build FROM quay.io/keycloak/keycloak:latest change these values to point to a running postgres instanceENV KC_DB=mssql Other settings you may need to set.ENV KC_HOSTNAME=localhost ENTRYPOINT ["/opt/keycloak/bin/kc.sh"] JdbcExpression.cs internal static ReferenceExpression Create(IResourceBuilder dbResourceBuilder)
|
Beta Was this translation helpful? Give feedback.
Hi, try to view my sample code
AppHost/Program.cs
var builder = DistributedApplication.CreateBuilder(args);
var passwordSql = builder.AddParameter("sqlAdminPassword", secret: true);
var db1 = builder.AddSqlServer("sql1",passwordSql).AddDatabase("db1");
builder.AddProject<Projects.DatabaseMigrations_ApiService>("api")
.WithReference(db1);
builder.AddProject<Projects.DatabaseMigrations_MigrationService>("migration")
.WithReference(db1);
var adminKeycloakUsername = builder.AddParameter("adminUsername", secret: true);
var adminKeycloakPassword = builder.AddParameter("adminPassword", secret: true);
var keycloak = builder.AddKeycloak("keycloak", adminUsername: adminKeycloakUsername, adminPasswo…