コンテンツへスキップ
言語を選択日本語

Importing Users from a Database

このコンテンツはまだ日本語訳がありません。

Import the users stored in your own application database (Postgres, MySQL or MariaDB) into a Skycloak realm, with their existing passwords when they are stored in a supported hash format.

You connect to your database with a host, user and password. Skycloak reads the users of one table or view once, shows you what the import would do, and then creates the users in a realm. There is no ongoing sync: later changes in your database are not picked up, and you can run the import again.

The import goes through four steps: Connect, Map, Preview and Import.

You choose one table or view and map its columns to these fields:

Skycloak field Notes
Username Username or email must be mapped.
Email
Email verified
First name and last name
Enabled Users marked as disabled are created disabled.
Password hash See the hash formats below.

Users who already exist in the realm, with the same username or email, are skipped and never changed. Roles, groups and custom attributes are not imported.

Importing from a database is available on the same plans as the Auth0 import: Launch, Business, and Enterprise, and during a free trial.

  • The database must accept connections from the internet. Skycloak does not use a fixed list of source IP addresses, so you cannot allow-list it. Databases that are only reachable inside a private network, or through a tunnel, are not supported. Hosts that resolve to a private, loopback or link-local address are refused.
  • TLS is required. A connection without TLS is refused. If your server certificate is signed by a public authority, nothing else is needed. If it is signed by your own authority, paste the CA certificate in the connect step.
  • Create a read-only database user for the import, so the credentials can do nothing else. Grant it SELECT on the one table or view you want to import, and nothing more.
  • Know which column holds the password hash, if you want passwords to keep working.

Skycloak only reads your database’s schema and runs SELECT statements. It never writes to your database and never runs SQL that you supply.

The database password is stored encrypted for the length of the import, is never shown again, and is deleted when the import is done, fails or is cancelled.

CREATE ROLE skycloak_import LOGIN PASSWORD '<a strong password>';
GRANT CONNECT ON DATABASE app TO skycloak_import;
GRANT USAGE ON SCHEMA public TO skycloak_import;
GRANT SELECT ON public.users TO skycloak_import;
CREATE USER 'skycloak_import'@'%' IDENTIFIED BY '<a strong password>' REQUIRE SSL;
GRANT SELECT ON app.users TO 'skycloak_import'@'%';

Remove the user when the import is finished.

You can start an import from three places:

  • From the Clusters page: click Migrate, then choose Database. Skycloak first asks where your users should go: pick one of your clusters, or create a new one and the import carries on when it is ready. It then creates a new realm on that cluster for them.
  • Into a new realm on a cluster you already have: on the cluster’s page, open Import above the realms and choose Import from a database.
  • Into an existing realm: open the realm and choose Import then Import from a database, or use Actions, then Import from a database, on the realm’s Users page.

During onboarding, choose Import from my existing auth system, then Database. The users go to your trial realm.

Choose the engine (Postgres or MySQL), then enter the host, port, database, user and password. Test connection reports success, or names the problem: the host is not allowed, TLS is missing or could not be verified, the sign-in failed, the host could not be reached, or the connection timed out.

Skycloak lists the tables and views your user can see. Pick one, and map its columns to the fields above. You cannot continue until username or email is mapped.

Nothing is written yet. The preview shows counts and, for each user, what would happen: create, skip, invalid, password kept or password reset. You can page through the users and download them as a CSV file.

Choose a new or existing realm and start the import. It shows live progress and can be cancelled by the person who started it. It ends on a result with the numbers created, skipped and failed, how many passwords were imported, and samples of any failures.

The password hash must be in one column, as a standard encoded string. These formats import as working passwords, so users sign in with their old password:

Format Examples
bcrypt $2a$, $2b$, $2y$
PBKDF2 (SHA-1, SHA-256, SHA-512) $pbkdf2-sha256$..., Django’s pbkdf2_sha256$...
Argon2 (argon2i, argon2d, argon2id) $argon2id$...

Any other value, an empty value, or a PBKDF2 hash stored as separate salt and iteration columns creates the user without a password and with the Update Password required action, so they set a new one at first sign-in. Skycloak does not send reset emails for you.

A cluster has to be able to verify a hash format for it to be kept. If your cluster cannot, the format is shown as unavailable in the wizard, and the preview lists those users as password reset.

  • A plan can hold up to 250,000 users. A larger table is refused.
  • An import during onboarding is limited to 10,000 users. Larger imports need a dedicated cluster.
  • A plan expires after 24 hours. If it does, connect again.
  • Each connection and each query has a time limit, so very slow databases may need a replica or a view.