hyperledger-labs / fablo

Fablo is a simple tool to generate the Hyperledger Fabric blockchain network and run it on Docker. It supports RAFT and solo consensus protocols, multiple organizations and channels, chaincode installation and upgrade.
Apache License 2.0
194 stars 72 forks source link

User initialization #432

Open Nova38 opened 6 months ago

Nova38 commented 6 months ago

Would it be possible to support creating users via the schema document. This would allow for streamlined setup of multi user environments, in addition to potentially useful for the snapshot feature in testing.

dzikowski commented 6 months ago

What do you mean by schema document?

Currently when you create a snapshot of the network in Fablo, it also keeps all CA user accounts. You just need to create them upfront.

Nova38 commented 6 months ago

Ah okay that is helpful. The schema i was refering to is the json schema for the config file (https://github.com/hyperledger-labs/fablo/releases/download/1.2.1-unstable.0/schema.json)

My main thought was to extend the config file to include declartive user creation.

The values bellow i used the hlf bevel operator cmd as a refrence (https://github.com/hyperledger/bevel-operator-fabric?tab=readme-ov-file#register-and-enrolling-org1msp-identity)

kubectl hlf ca register --name=org1-ca --namespace=default --user=admin --secret=adminpw \
    --type=admin --enroll-id enroll --enroll-secret=enrollpw --mspid=Org1MSP
{
  "organization": {
    "name": "Org1",
    "domain": "org1.example.com"
  },
  "peer": {
    "instances": 2,
    "db": "LevelDb"
  },
  "ca":{ 
    "enrollId": "enroll",
    "enrollSecret": "enrollpw",
    "users": [
      {
        "name": "admin",
        "type": "admin",
        "secret": "adminpw"
      }
    ]
  }
}
dzikowski commented 6 months ago

I see. That would be useful. I suppose it involves two things:

  1. Adding relevant fields to config class (src/types/FabloConfigJson.ts) and config extended class (src/types/FabloConfigExtended.ts), and changing hardcoded values here: setup-docker/templates/fabric-docker/.env
  2. Register users, by calling CA server CLI or endpoint somewhere here (additional function?): setup-docker/templates/fabric-docker/commands-generated.sh.
Nova38 commented 6 months ago

Awesome, when I get a chance this week/next I will take a look and put together a pull request

Nova38 commented 6 months ago

Do you mind if I include the code needed to also generate a network configuration file for hyperledger caliper as with the users generated it should be simple to populate the needed paths in the config file for all the given users.

https://hyperledger.github.io/caliper/v0.5.0/fabric-tutorial/tutorials-fabric-existing/#create-a-template-network-configuration-file

That would also partially address issue #298 298

Or would it be better to do that in another pull request if there is interest in it?

dzikowski commented 6 months ago

Please do it in a way that is more convenient for you. We'll be more than happy to have Caliper onboard. Thanks!

Nova38 commented 6 months ago

It looks like the cli (fabric-tools) container doesn't have the fabric-ca-client exe. Should I download it dynamically, based on the fabric version, and then put it in the /workspaces/fablo/fablo-target/fabric-docker/scripts/cli folder that is mounted by the fabric-ci-box? Or is there a better place i should put it?

dzikowski commented 6 months ago

Yeah, I think this is a good approach, since we want to deprecate fabric-tools anyway (https://github.com/hyperledger-labs/fablo/issues/245). It's also deprecated in Hyperledger Fabric.

Have a look at this PR: https://github.com/hyperledger-labs/fablo/pull/316. It seems there was an effort towards downloading binaries, but I'm not sure why it's not merged. I guess it was just not required at that time. (@gzhk do you remember?).

Anyway, I think you can reuse some code from https://github.com/hyperledger-labs/fablo/pull/316 if you find it useful. And yes, scripts/cli path sounds good.

dzikowski commented 5 months ago

Hi @Nova38 how is it going? Do you need some help with this issue?