JupiterOne / starbase

Graph-based security analysis for everyone
Mozilla Public License 2.0
337 stars 32 forks source link

keyword: 'type', message: 'must be object' #100

Closed juju4 closed 1 year ago

juju4 commented 1 year ago

Thanks for sharing this project. I'm currently testing it and getting above error at starbase setup or run with azure integration and another. Problem is there is no field type in my config.yaml, nor I see one in the docs. Config setup following https://github.com/JupiterOne/graph-azure/blob/main/docs/development.md#azure-setup-for-integration

Not sure if I miss something.

_starbase@starbasevm:~$ cd ~/starbase/
_starbase@starbasevm:~/starbase$ /usr/local/lib/npm/bin/yarn starbase run
yarn run v1.22.19
$ ts-node ./src/index.ts run
YAMLException: bad indentation of a mapping entry (23:7)
[...]
_starbase@starbasevm:~/starbase$ /usr/local/lib/npm/bin/yarn starbase run
yarn run v1.22.19
$ ts-node ./src/index.ts run
ERROR:  config file validation error(s):   [
  {
    instancePath: '/integrations/0/config',
    schemaPath: '#/properties/integrations/items/properties/config/type',
    keyword: 'type',
    params: { type: 'object' },
    message: 'must be object'
  },
  {
    instancePath: '/integrations/2/config',
    schemaPath: '#/properties/integrations/items/properties/config/type',
    keyword: 'type',
    params: { type: 'object' },
    message: 'must be object'
  }
]
Error: One or more errors found with configuration file.  Please correct above errors and try again.
    at validateStarbaseConfigSchema (/var/_starbase/starbase/src/starbase/config.ts:123:11)
    at parseConfigYaml (/var/_starbase/starbase/src/starbase/config.ts:137:39)
    at async Command.<anonymous> (/var/_starbase/starbase/src/cli/run.ts:37:29)
    at async Command.parseAsync (/var/_starbase/starbase/node_modules/commander/lib/command.js:935:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
_starbase@starbasevm:~/starbase$ /usr/local/lib/npm/bin/yarn starbase setup
yarn run v1.22.19
$ ts-node ./src/index.ts setup
ERROR:  config file validation error(s):   [
  {
    instancePath: '/integrations/0/config',
    schemaPath: '#/properties/integrations/items/properties/config/type',
    keyword: 'type',
    params: { type: 'object' },
    message: 'must be object'
  },
  {
    instancePath: '/integrations/2/config',
    schemaPath: '#/properties/integrations/items/properties/config/type',
    keyword: 'type',
    params: { type: 'object' },
    message: 'must be object'
  }
]
Error: One or more errors found with configuration file.  Please correct above errors and try again.
    at validateStarbaseConfigSchema (/var/_starbase/starbase/src/starbase/config.ts:123:11)
    at parseConfigYaml (/var/_starbase/starbase/src/starbase/config.ts:137:39)
    at async Command.<anonymous> (/var/_starbase/starbase/src/cli/setup.ts:13:27)
    at async Command.parseAsync (/var/_starbase/starbase/node_modules/commander/lib/command.js:935:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

(starbase v0.7.0)

adam-in-ict commented 1 year ago

One item we've struggled to document is that when setting the config section of an integration in the config.yaml file, we have to convert the format a bit from the normal format we would place in a .env file to accommodate .yaml file conventions. This means that where our Azure integration would normally have a .env file like:

CLIENT_ID=app_registration_service_principal_client_id CLIENT_SECRET=app_registration_service_principal_client_secret DIRECTORY_ID=development_directory_id SUBSCRIPTION_ID=development_subscription_id INGEST_ACTIVE_DIRECTORY=true INGEST_RESOURCE_MANAGER=true

We would need to switch it to look something like this for the Starbase .yaml file:

integrations:

name: graph-azure
instanceId: testAzureInstance
directory: ./.integrations/graph-azure
gitRemoteUrl: https://github.com/JupiterOne/graph-azure.git
config:
  CLIENT_ID: app_registration_service_principal_client_id
  CLIENT_SECRET: app_registration_service_principal_client_secret
  DIRECTORY_ID: development_directory_id
  SUBSCRIPTION_ID: development_subscription_id
  INGEST_ACTIVE_DIRECTORY: true
  INGEST_RESOURCE_MANAGER: true

The biggest difference is that we separate the config properties from their values with a colon in the .yaml file instead of the normal equals sign we would use in a .env file.

Would you be able to double check your config.yaml and see if that is at all related to the error you're getting?

juju4 commented 1 year ago

Thanks. After checking, yes, that's it. I think a contributing factor is sometimes it is not clear part of documentation if it is just for .env or yaml file. Also, it seems some entries like CLIENT_ID, CLIENT_SECRET, or DIRECTORY_ID must be string. Enclosing in single quotes, worked fine. strangely not SUBSCRIPTION_ID.

It would be good to have a validate/configcheck option (something like yarn starbase configcheck) to ensure configuration is correctly formatted and operational. That could be used inside automation tool like ansible to automatically validate config when deploying.

After, still failing setup because of nodejs 14 to 18 switch. Any way to use an older version of integration? I tried gitRemoteUrl: https://github.com/JupiterOne/graph-azure.git@vX.Y.Z but it did not help. starbase is still picking latest release.

adam-in-ict commented 1 year ago

Unfortunately we don't currently have a method for pulling a specific release yet. We've captured that in the past as a new feature to add but haven't had availability to get to it yet.

For your node version error, are you using Starbase version 0.7.0 or the latest 0.9.0? The older version 0.7.0 that you have listed in your initial issue comment was before the transition to node 18 and should be working without any node version errors with integrations like our graph-azure integration that haven't been updated to node 18 yet.

juju4 commented 1 year ago

My current test system is 0.7.0. Testing both in CI but one of the integration was already transitioned to nodejs 18 and thus not working. If only azure one, fine. Thanks a lot for the help. Closing.