Firezone RESTAPI create device

when creating a device, you need a public key with a length of 44 characters, tell me how to create it? For example, in python

I was almost able to create a device

{
  "device": {
    "name": "test_device",
    "public_key": "***"
    "user_id": "***"
  }
}

For create a key, I use

from python_wireguard import Key
private, public = Key.key_pair()
print(public)

But i get 500 interval server error
Why?

You also need the preshared_key. Also I believe your input isn’t valid JSON – may want to check for a missing comma at the end of public_key.

I would use the genkey command to generate the key as WireGuard recommends here:

OK, I use genkey and add preshared_key to JSON, but the api still returns 500. Is there somewhere I can look at the logs?

{
  "device": {
    "name": "new_device",
    "public_key": "***",
    "preshared_key": "***",
    "user_id": "8b0f016a-***"
  }
}

The logs for the 500 should be in the firezone container.

docker compose logs firezone

I have logs. What information can I deduce from them?

==> /var/log/firezone/phoenix/current <==
2023-06-05_21:02:21.72458 00:02:21.724 erl_level=info application=phoenix domain=elixir file=lib/phoenix/logger.ex function=phoenix_endpoint_start/4 line=217 mfa=Phoenix.Logger.phoenix_endpoint_start/4 module=Phoenix.Logger pid=<0.1025.1> request_id=F2XfGs0jBaUXMpYAADoS [info] POST //v0/devices

==> /var/log/firezone/nginx/access.log <==
- - - [2023-06-06T00:02:21+03:00]  "POST //v0/devices HTTP/1.1" 500 845 "0.018" 0 "-" "insomnia/2023.2.2"

==> /var/log/firezone/phoenix/current <==
2023-06-05_21:02:21.74252 00:02:21.739 erl_level=warning application=fz_http domain=elixir file=lib/fz_http/config/errors.ex function=legacy_key_used/3 line=94 mfa=FzHttp.Config.Errors.legacy_key_used/3 module=FzHttp.Config.Errors pid=<0.1025.1> request_id=F2XfGs0jBaUXMpYAADoS [warning] A legacy configuration option 'WIREGUARD_MTU' is used and it will be removed in v0.8. Please use 'DEFAULT_CLIENT_MTU' configuration option instead.
2023-06-05_21:02:21.74276 00:02:21.740 erl_level=error domain=cowboy pid=<0.1024.1> [error] #PID<0.1025.1> running FzHttpWeb.Endpoint (connection #PID<0.1024.1>, stream id 1) terminated
2023-06-05_21:02:21.74277 Server: 5.188.118.228:80 (http)
2023-06-05_21:02:21.74278 Request: POST //v0/devices
2023-06-05_21:02:21.74279 ** (exit) an exception was raised:
2023-06-05_21:02:21.74280     ** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for %Protocol.UndefinedError{protocol: Jason.Encoder, value: %FzHttp.Types.IPPort{type: :ipv4, address: {5, 188, 118, 228}, port: nil}, description: "Jason.Encoder protocol must always be explicitly implemented.\n\nIf you own the struct, you can derive the implementation specifying which fields should be encoded to JSON:\n\n    @derive {Jason.Encoder, only: [....]}\n    defstruct ...\n\nIt is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:\n\n    @derive Jason.Encoder\n    defstruct ...\n\nFinally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:\n\n    Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])\n    Protocol.derive(Jason.Encoder, NameOfTheStruct)\n"} of type Protocol.UndefinedError (a struct), Jason.Encoder protocol must always be explicitly implemented.
2023-06-05_21:02:21.74284 
2023-06-05_21:02:21.74285 If you own the struct, you can derive the implementation specifying which fields should be encoded to JSON:
2023-06-05_21:02:21.74285 
2023-06-05_21:02:21.74286     @derive {Jason.Encoder, only: [....]}
2023-06-05_21:02:21.74287     defstruct ...
2023-06-05_21:02:21.74288 
2023-06-05_21:02:21.74288 It is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:
2023-06-05_21:02:21.74289 
2023-06-05_21:02:21.74290     @derive Jason.Encoder
2023-06-05_21:02:21.74291     defstruct ...
2023-06-05_21:02:21.74291 
2023-06-05_21:02:21.74292 Finally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:
2023-06-05_21:02:21.74293 
2023-06-05_21:02:21.74294     Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])
2023-06-05_21:02:21.74295     Protocol.derive(Jason.Encoder, NameOfTheStruct)
2023-06-05_21:02:21.74295 . This protocol is implemented for the following type(s): Any, Atom, BitString, Date, DateTime, Decimal, Ecto.Association.NotLoaded, Ecto.Schema.Metadata, Float, Integer, Jason.Fragment, Jason.OrderedObject, List, Map, NaiveDateTime, Postgrex.INET, Time
2023-06-05_21:02:21.74299         (jason 1.4.0) lib/jason.ex:213: Jason.encode_to_iodata!/2
2023-06-05_21:02:21.74300         (phoenix 1.7.2) lib/phoenix/controller.ex:1010: anonymous fn/5 in Phoenix.Controller.template_render_to_iodata/4
2023-06-05_21:02:21.74301         (telemetry 1.2.1) /opt/runner/omnibus-local/src/firezone/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
2023-06-05_21:02:21.74302         (phoenix 1.7.2) lib/phoenix/controller.ex:976: Phoenix.Controller.render_and_send/4
2023-06-05_21:02:21.74303         (phoenix 1.7.2) lib/phoenix/endpoint/render_errors.ex:84: Phoenix.Endpoint.RenderErrors.instrument_render_and_send/5
2023-06-05_21:02:21.74303         (phoenix 1.7.2) lib/phoenix/endpoint/render_errors.ex:62: Phoenix.Endpoint.RenderErrors.__catch__/5
2023-06-05_21:02:21.74304         (plug_cowboy 2.6.1) lib/plug/cowboy/handler.ex:11: Plug.Cowboy.Handler.init/2
2023-06-05_21:02:21.74305         (cowboy 2.9.0) /opt/runner/omnibus-local/src/firezone/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2

@HungryStudent Can you verify which version of Firezone you’re running?

How can I find out the version of firezone? (firezone is not installed in docker)

In the console, look at the bottom right corner, it displays the version in use.