crossbario / crossbar

Crossbar.io - WAMP application router
https://crossbar.io/
Other
2.05k stars 274 forks source link

Initialization of master config is broken #1885

Closed om26er closed 2 years ago

om26er commented 3 years ago

Currently running crossbar master init produces a config that is broken. It should rather copy this config file https://github.com/crossbario/crossbar/blob/master/crossbar/master/node/config.json and put it in the newly created .crossbar directory.

Below are the logs of the current behavior

(venv) om26er@HomePC:~/scm/crossbario/crossbar$ crossbar master init

Application directory '/home/om26er/scm/crossbario/crossbar' already exists!
Initializing application directory '/home/om26er/scm/crossbario/crossbar' ..
Using template from '/home/om26er/scm/crossbario/crossbar/crossbar/node/templates/default'
Directory /home/om26er/scm/crossbario/crossbar/web already exists - SKIPPING
Creating directory /home/om26er/scm/crossbario/crossbar/.crossbar
File /home/om26er/scm/crossbario/crossbar/README.md already exists - SKIPPING
File /home/om26er/scm/crossbario/crossbar/web/README.md already exists - SKIPPING
Creating file /home/om26er/scm/crossbario/crossbar/.crossbar/config.json
New node key pair generated! Public key is 0xf52b96eb2faf4b41d8c988abfc81713265dcb91f7d108e3077f66bd336f38208
File permissions on node public key fixed
File permissions on node private key fixed
Node key loaded from /home/om26er/scm/crossbario/crossbar/.crossbar/key.priv
Application directory initialized

To start your node, run 'crossbar start --cbdir /home/om26er/scm/crossbario/crossbar/.crossbar'

(venv) om26er@HomePC:~/scm/crossbario/crossbar$ crossbar master start

2021-08-02T04:33:20+0500 [Controller 166650] 
2021-08-02T04:33:20+0500 [Controller 166650]     :::::::::::::::::
2021-08-02T04:33:20+0500 [Controller 166650]           :::::          _____                 __              _____  __
2021-08-02T04:33:20+0500 [Controller 166650]     :::::   :   :::::   / ___/______  ___ ___ / /  ___ _____  / __/ |/_/
2021-08-02T04:33:20+0500 [Controller 166650]     :::::::   :::::::  / /__/ __/ _ \(_-<(_-</ _ \/ _ `/ __/ / _/_>  <
2021-08-02T04:33:20+0500 [Controller 166650]     :::::   :   :::::  \___/_/  \___/___/___/_.__/\_,_/_/   /_/ /_/|_|
2021-08-02T04:33:20+0500 [Controller 166650]           :::::
2021-08-02T04:33:20+0500 [Controller 166650]     :::::::::::::::::   Crossbar.io FX v21.6.1.dev1 [19000101-0000000]
2021-08-02T04:33:20+0500 [Controller 166650] 
2021-08-02T04:33:20+0500 [Controller 166650]     Copyright (c) 2013-2021 Crossbar.io Technologies GmbH. All rights reserved.
2021-08-02T04:33:20+0500 [Controller 166650] 
2021-08-02T04:33:20+0500 [Controller 166650] Booting master node .. <crossbar.node.main._run_command_start>
2021-08-02T04:33:20+0500 [Controller 166650] Node key files exist and are valid. Node public key is 0xf52b96eb2faf4b41d8c988abfc81713265dcb91f7d108e3077f66bd336f38208
2021-08-02T04:33:20+0500 [Controller 166650] Node key loaded from /home/om26er/scm/crossbario/crossbar/.crossbar/key.priv
2021-08-02T04:33:20+0500 [Controller 166650] Expanding built-in node configuration from local file /home/om26er/scm/crossbario/crossbar/.crossbar/config.json
2021-08-02T04:33:20+0500 [Controller 166650] Traceback (most recent call last):
2021-08-02T04:33:20+0500 [Controller 166650]   File "/home/om26er/scm/crossbario/crossbar/venv/bin/crossbar", line 33, in <module>
2021-08-02T04:33:20+0500 [Controller 166650]     sys.exit(load_entry_point('crossbar', 'console_scripts', 'crossbar')())
2021-08-02T04:33:20+0500 [Controller 166650]   File "/home/om26er/scm/crossbario/crossbar/crossbar/__init__.py", line 303, in run
2021-08-02T04:33:20+0500 [Controller 166650]     sys.exit(main(executable, args, reactor, personality))
2021-08-02T04:33:20+0500 [Controller 166650]   File "/home/om26er/scm/crossbario/crossbar/crossbar/node/main.py", line 1273, in main
2021-08-02T04:33:20+0500 [Controller 166650]     options.func(options, reactor=reactor, personality=personality)
2021-08-02T04:33:20+0500 [Controller 166650]   File "/home/om26er/scm/crossbario/crossbar/crossbar/node/main.py", line 804, in _run_command_start
2021-08-02T04:33:20+0500 [Controller 166650]     config_source, config_path = node.load_config(options.config)
2021-08-02T04:33:20+0500 [Controller 166650]   File "/home/om26er/scm/crossbario/crossbar/crossbar/master/node/node.py", line 524, in load_config
2021-08-02T04:33:20+0500 [Controller 166650]     config = merge_config(config, custom_config)
2021-08-02T04:33:20+0500 [Controller 166650]   File "/home/om26er/scm/crossbario/crossbar/crossbar/_util.py", line 416, in merge_config
2021-08-02T04:33:20+0500 [Controller 166650]     merged_config['workers'] = _deep_merge_list(base_config.get('workers', []), other_config['workers'])
2021-08-02T04:33:20+0500 [Controller 166650]   File "/home/om26er/scm/crossbario/crossbar/crossbar/_util.py", line 353, in _deep_merge_list
2021-08-02T04:33:20+0500 [Controller 166650]     assert len(b) >= len(a)
2021-08-02T04:33:20+0500 [Controller 166650] AssertionError
om26er commented 3 years ago

I can do a PR if copying the config file from https://github.com/crossbario/crossbar/blob/master/crossbar/master/node/config.json makes sense

om26er commented 3 years ago

The error can be reproduced with this config

{
    "version": 2,
    "controller": {
        "id": "center1"
    },
    "workers": [
        {
            "id": "cfrouter1",
            "type": "router",
            "options": {
                "expose_controller": true
            },
            "realms": [
                {
                    "name": "com.crossbario.fabric",
                    "roles": [
                        {
                            "name": "authenticator",
                            "permissions": [
                                {
                                    "uri": "com.crossbario.fabric.authenticate",
                                    "match": "exact",
                                    "allow": {
                                        "call": true,
                                        "register": true
                                    }
                                },
                                {
                                    "uri": "crossbarfabriccenter.node.",
                                    "match": "prefix",
                                    "allow": {
                                        "subscribe": true
                                    }
                                },
                                {
                                    "uri": "crossbarfabriccenter.mrealm.",
                                    "match": "prefix",
                                    "allow": {
                                        "subscribe": true
                                    }
                                }
                            ]
                        }
                    ]
                }
            ],
            "transports": [
                {
                    "type": "rawsocket",
                    "serializers": ["cbor"],
                    "endpoint": {
                        "type": "unix",
                        "path": "sock1"
                    },
                    "options": {
                        "max_message_size": 1048576
                    },
                    "auth": {
                        "anonymous": {
                            "type": "static",
                            "role": "trusted"
                        }
                    }
                },
                {
                    "type": "rawsocket",
                    "serializers": ["cbor"],
                    "endpoint": {
                        "type": "unix",
                        "path": "sock2"
                    },
                    "options": {
                        "max_message_size": 1048576
                    },
                    "auth": {
                        "anonymous": {
                            "type": "static",
                            "role": "user",
                            "authid": "superuser"
                        }
                    }
                },
                {
                    "type": "web",
                    "endpoint": {
                        "type": "tcp",
                        "port": 9000
                    },
                    "paths": {
                        "/": {
                            "type": "nodeinfo"
                        },
                        "ws": {
                            "type": "websocket",
                            "serializers": [
                                "cbor", "msgpack", "json"
                            ],
                            "auth": {
                                "anonymous": {
                                    "type": "static",
                                    "role": "public"
                                },
                                "cryptosign": {
                                    "type": "dynamic",
                                    "authenticator": "com.crossbario.fabric.authenticate",
                                    "authenticator-realm": "com.crossbario.fabric",
                                    "authenticator-role": "authenticator"
                                }
                           }
                        }
                    }
                }
            ],
            "components": [
                {
                    "type": "class",
                    "classname": "crossbar.master.node.authenticator.Authenticator",
                    "realm": "com.crossbario.fabric",
                    "role": "authenticator",
                    "extra": {
                        "mailgun": {
                            "submit_url": "https://api.mailgun.net/v3/mailing.crossbar.io/messages",
                            "access_key": null
                        }
                    }
                }
            ]
        },
        {
            "id": "cfrealmmanager1",
            "type": "container",
            "options": {
                "pythonpath": [".."],
                "expose_shared": true,
                "expose_controller": true,
                "restart": "restart-always",
                "shutdown": "shutdown-manual"
            },
            "components": [
                {
                    "type": "class",
                    "classname": "crossbar.master.node.DomainController",
                    "realm": "com.crossbario.fabric",
                    "transport": {
                        "type": "rawsocket",
                        "serializer": "cbor",
                        "endpoint": {
                           "type": "unix",
                           "path": "sock1"
                        },
                        "options": {
                            "max_message_size": 1048576
                        }
                    }
                }
            ]
        }
    ]
}
oberstet commented 2 years ago

It should rather copy this config file https://github.com/crossbario/crossbar/blob/master/crossbar/master/node/config.json and put it in the newly created .crossbar directory.

no, the problem actually is:

thing is: normally a master node is started with (almost) no local config at all.

oberstet commented 2 years ago

thing is: normally a master node is started with (almost) no local config at all.

this ..

om26er commented 2 years ago

Maybe we could change the config checking code to throw if a stanza is changed that shouldn't be ? The current behavior is somewhat misleading and something we can improve