esl / MongoosePush

MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS.
Apache License 2.0
108 stars 24 forks source link

Crash at startup with token.p8 - bad_auth #206

Closed theanhoo closed 4 months ago

theanhoo commented 1 year ago

I am trying to start MongoosePush ver 2.1.0 from the command line: _build/prod/rel/mongoose_push/bin/mongoose_push start

It would crash with the following errors:

{
   "application":"mongoose_push",
   "at":"Elixir.MongoosePush.Service.APNS.Supervisor.convert_token_pool_to_sparrow/2:150",
   "erl_level":"error",
   "file":"lib/mongoose_push/service/apns/supervisor.ex",
   "key":null,
   "mode":"dev",
   "p8_file":"/home/developer/MongoosePush-master/_build/prod/rel/mongoose_push/lib/mongoose_push-2.1.0/priv/apns/token.p8",
   "pid":"#PID<0.1801.0>",
   "reason":"bad_auth",
   "result":"error",
   "severity":"error",
   "team":null,
   "text":"Required configuration missing",
   "what":"configuration",
   "when":"2022-10-02T19:02:12.722",
   "domain[0]":"elixir"
}
{
  "application": "mongoose_push",
  "at": "Elixir.MongoosePush.Service.APNS.Supervisor.convert_token_pool_to_sparrow/2:150",
  "erl_level": "error",
  "file": "lib/mongoose_push/service/apns/supervisor.ex",
  "key": null,
  "mode": "prod",
  "p8_file": "/home/developer/MongoosePush-master/_build/prod/rel/mongoose_push/lib/mongoose_push-2.1.0/priv/apns/token.p8",
  "pid": "#PID<0.1801.0>",
  "reason": "bad_auth",
  "result": "error",
  "severity": "error",
  "team": null,
  "text": "Required configuration missing",
  "what": "configuration",
  "when": "2022-10-02T19:02:12.722",
  "domain[0]": "elixir"
}

I have copied the files from Apple into the /home/developer/MongoosePush-master/_build/prod/rel/mongoose_push/lib/mongoose_push-2.1.0/priv directories.

Does anyone have any idea or solution about these?

It says "Required configuration missing" but it doesn't seem to be using any files under the config directory.

Many thanks in advance.

szjozsef commented 1 year ago

Same here, with the mention that the first error logged is:

{
    "application": "mongoose_push",
    "at": "Elixir.MongoosePush.Application.check_runtime_configuration_status/0:212",
    "erl_level": "info",
    "file": "lib/mongoose_push/application.ex",
    "pid": "#PID<0.1802.0>",
    "reason": "no_release",
    "severity": "info",
    "status": "error",
    "text": "Skipping TOML configuration due to non-release boot",
    "what": "toml_configuration",
    "when": "2022-10-19T06:38:14.772",
    "domain[0]": "elixir"
}

This with the "latest" docker release Maybe it is related to the #204 The config.toml is there, is valid, at least it is working well with the previous docker image: mongooseim/mongoose-push:235ab4d The config.toml is parsed (if some I set some invalid values, then at the start the correct error is logged), but somehow get overwritten ? and the application starts with some kind of default configuration, at least that can be the reason why tries to parse p8_file, even if I had not configured such kind of options in apns section. My config.toml is pretty much similar to the example from: guides/configuration.md

Maybe the issue is that in mix.exs the Config lines order was reversed in the last commits:

        config_providers: [
          {MongoosePush.Config.Provider.Toml, [path: "var/config.toml"]},
          {MongoosePush.Config.Provider.Confex, []}
        ]

and it seems the Toml generated config get's overwritten by the default config via Confex

pawlooss1 commented 6 months ago

@theanhoo it seems like MongoosePush is really using the default config which for MIX_ENV=prod fails if some required values are not configured. In this case you have "key":null, "team":null which should be set when using token auth. Also, the "p8_file" is also default: priv/apns/token.p8. Could you show me your configuration file? Or maybe you're setting your base config via environmental variables?

pawlooss1 commented 6 months ago

@szjozsef Thanks for pointing out to that PR. However, it is not the order of config providers that causes the issue. Confex will override only those options which were not set previously and can be defined in environmental variables. It is this change which causes such log. Old code would set such flag to later indicate in the logs if TOML config was used. However, this log should be harmless because other configuration options should be set MongoosePush.Config.Provider.Toml. The real problem is that the system is trying to configure pools from both TOML configuration and environment variables configuration which fails if the required ones are not defined. I'll prepare a fix for this.