Connection and authentication

immudb runs on port 3323 as the default. The code samples below illustrate how to connect your client to the server and authenticate using default options and the default username and password. You can modify defaults on the immudb server in immudb.toml in the config folder.

The Login method returns a token required for all interactions with the server.

  1. c, err := client.NewImmuClient(client.DefaultOptions())
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. ctx := context.Background()
  6. // login with default username and password and storing a token
  7. lr , err := c.Login(ctx, []byte(`immudb`), []byte(`immudb2`))
  8. if err != nil {
  9. log.Fatal(err)
  10. }
  11. // set up an authenticated context that will be required in future operations
  12. md := metadata.Pairs("authorization", lr.Token)
  13. ctx = metadata.NewOutgoingContext(context.Background(), md)

Under the hood, during login, a token is being retrieved from the server, stored in memory and reused for subsequent operations.

The state is internally used for doing verified operations (such as verifiedSet or verifiedGet).

  1. // Setting the "store" where the internal states are being persisted.
  2. FileImmuStateHolder stateHolder = FileImmuStateHolder.newBuilder()
  3. .withStatesFolder("immu_states")
  4. .build();
  5. // Creating an new ImmuClient instance.
  6. ImmuClient immuClient = ImmuClient.newBuilder()
  7. .withStateHolder(stateHolder)
  8. .withServerUrl("localhost")
  9. .withServerPort(3322)
  10. .build();
  11. // Login with default credentials.
  12. immuClient.login("immudb", "immudb");

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectConnection and authentication - 图1 (opens new window)

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Node.js sdk github projectConnection and authentication - 图2 (opens new window)

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectConnection and authentication - 图3 (opens new window)

If you’re using another development language, please read up on our immugwConnection and authentication - 图4 (opens new window) option.

Mutual TLS

To enable mutual authentication, a certificate chain must be provided to both the server and client. That will cause each to authenticate with the other simultaneously. In order to generate certs, use the openssl tool: generate.shConnection and authentication - 图5 (opens new window).

  1. ./generate.sh localhost mysecretpassword

This generates a list of folders containing certificates and private keys to set up a mTLS connection.

  1. client, err := c.NewImmuClient(
  2. c.DefaultOptions().WithMTLsOptions(
  3. c.MTLsOptions{}.WithCertificate("{path-to-immudb-src-folder}/tools/mtls/4_client/certs/localhost.cert.pem").
  4. WithPkey("{path-to-immudb-src-folder}/tools/mtls/4_client/private/localhost.key.pem").
  5. WithClientCAs("{path-to-immudb-src-folder}/tools/mtls/2_intermediate/certs/ca-chain.cert.pem").
  6. WithServername("localhost"),
  7. ).
  8. WithMTLs(true),
  9. )
  10. if err != nil {
  11. log.Fatal(err)
  12. }
  13. ctx := context.Background()
  14. // login with default username and password
  15. lr , err := client.Login(ctx, []byte(`immudb`), []byte(`immudb`))

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Java sdk github projectConnection and authentication - 图6 (opens new window)

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectConnection and authentication - 图7 (opens new window)

  1. import ImmudbClient from 'immudb-node'
  2. import Parameters from 'immudb-node/types/parameters'
  3. const IMMUDB_HOST = '127.0.0.1'
  4. const IMMUDB_PORT = '3322'
  5. const IMMUDB_USER = 'immudb'
  6. const IMMUDB_PWD = 'immudb'
  7. const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });
  8. (async () => {
  9. const loginReq: Parameters.Login = { user: IMMUDB_USER, password: IMMUDB_PWD }
  10. const loginRes = await cl.login(loginReq)
  11. console.log('success: login:', loginRes)
  12. })()

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectConnection and authentication - 图8 (opens new window)

If you’re using another development language, please read up on our immugwConnection and authentication - 图9 (opens new window) option.

Disable authentication

You also have the option to run immudb with authentication disabled. However, without authentication enabled, it’s not possible to connect to a server already configured with databases and user permissions. If a valid token is present, authentication is enabled by default.

  1. client, err := c.NewImmuClient(
  2. c.DefaultOptions().WithAuth(false),
  3. )
  4. if err != nil {
  5. log.Fatal(err)
  6. }
  7. vi, err := client.VerifiedSet(ctx, []byte(`immudb`), []byte(`hello world`))
  8. if err != nil {
  9. log.Fatal(err)
  10. }
  1. FileImmuStateHolder stateHolder = FileImmuStateHolder.newBuilder()
  2. .withStatesFolder("immu_states")
  3. .build();
  4. ImmuClient immuClient = ImmuClient.newBuilder()
  5. .withStateHolder(stateHolder)
  6. .withServerUrl("localhost")
  7. .withServerPort(3322)
  8. .withAuth(false) // No authentication is needed.
  9. .build();
  10. try {
  11. immuClient.set(key, val);
  12. } catch (CorruptedDataException e) {
  13. // ...
  14. }

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectConnection and authentication - 图10 (opens new window)

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Node.js sdk github projectConnection and authentication - 图11 (opens new window)

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectConnection and authentication - 图12 (opens new window)

If you’re using another development language, please read up on our immugwConnection and authentication - 图13 (opens new window) option.