github.com/cactusblossom/fabric-ca@v0.0.0-20200611062428-0082fc643826/docs/source/operations_guide.rst (about) 1 Fabric CA Operations Guide 2 ============================ 3 4 This guide will illustrate how to use Fabric CA to setup 5 a Fabric network. All identities that participate on a Hyperledger Fabric 6 blockchain network must be authorized. This authorization 7 is provided in the form of cryptographic material that is 8 verified against trusted authorities. 9 10 In this guide, you will see the process for setting up a 11 blockchain network that includes two organizations, each with two peers 12 and an orderer. You'll see how to generate cryptographic material for orderers, 13 peers, administrators, and end users so that private keys never leave 14 the host or container where they are generated. 15 16 Topology 17 --------- 18 19 In this example, we will look at how to setup up an orderer, peers, and CAs 20 across three organizations. The topology of this deployment can be seen in the 21 image below: 22 23 .. image:: ./images/network_topology.png 24 25 This example will simulate a deployment using docker containers. The 26 containers will be treated as if they are running on different host machines. 27 This is done so that you can see which assets need to be exchanged out-of-band 28 between the parties involved in the network. 29 30 The network configuration for docker assumes that all containers are running in 31 the same network. If your deployment is spread across different networks, the 32 example will need to be adjusted to work with your network configurations. 33 34 The documentation below breaks down the docker-compose file to talk about individual 35 components. To see the entire docker-compose, click :doc:`here <docker_compose>`. 36 37 .. toctree:: 38 :maxdepth: 2 39 40 Setup CAs 41 ---------- 42 43 Download fabric-ca-client binary 44 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 45 46 For each host that needs to acquire cryptographic material, you will need to have the 47 fabric-ca-client binary available on the host machine. The client will be used to 48 connect to the Fabric CA server container. 49 50 To download the fabric-ca-client binary, browse to this `repository <https://github.com/hyperledger/fabric-ca/releases>`_ and 51 select the latest binary for your machine. 52 53 54 .. note:: This example is using version 1.4.0 of fabric-ca-client. 55 56 Setup TLS CA 57 ^^^^^^^^^^^^^^ 58 59 A TLS CA is used to issue TLS certificates. These certificates are required in 60 order to secure the communication between various processes. 61 62 In order to simplify this example, all organizations will use the same TLS CA 63 and TLS mutual authentication is disabled. 64 65 .. note:: In a production environment, you will probably use your organization's CA 66 to get TLS certificates. You will have to transfer out-of-band your CA's 67 certificate with organizations that will validate your TLS certificates. 68 Thus, unlike this example, each organization would have its own TLS CA. 69 70 A docker service, such as the one below can be used to a launch a Fabric TLS CA 71 container. 72 73 .. code:: yaml 74 75 ca-tls: 76 container_name: ca-tls 77 image: hyperledger/fabric-ca 78 command: sh -c 'fabric-ca-server start -d -b tls-ca-admin:tls-ca-adminpw --port 7052' 79 environment: 80 - FABRIC_CA_SERVER_HOME=/tmp/hyperledger/fabric-ca/crypto 81 - FABRIC_CA_SERVER_TLS_ENABLED=true 82 - FABRIC_CA_SERVER_CSR_CN=ca-tls 83 - FABRIC_CA_SERVER_CSR_HOSTS=0.0.0.0 84 - FABRIC_CA_SERVER_DEBUG=true 85 volumes: 86 - /tmp/hyperledger/tls/ca:/tmp/hyperledger/fabric-ca 87 networks: 88 - fabric-ca 89 ports: 90 - 7052:7052 91 92 This container can be started using the following docker command. 93 94 .. code:: bash 95 96 docker-compose up ca-tls 97 98 On a successful launch of the container, you will see the following line in 99 the CA container's log. 100 101 .. code:: bash 102 103 [INFO] Listening on https://0.0.0.0:7052 104 105 At this point the TLS CA server is on a listening on a secure socket, and can start 106 issuing TLS certificates. 107 108 Enroll TLS CA's Admin 109 ~~~~~~~~~~~~~~~~~~~~~~~ 110 111 Before you can start using the CA client, you must acquire the signing 112 certificate for the CA's TLS certificate. This is a required step before you 113 can connect using TLS. 114 115 In our example, you would need to acquire the file located at ``/tmp/hyperledger/tls-ca/crypto/ca-cert.pem`` 116 on the machine running the TLS CA server and copy this file over to the host where 117 you will be running the CA client binary. This certificate, also known as the TLS 118 CA's signing certificate is going to be used to validate the TLS certificate of 119 the CA. Once the certificate has been copied over to the CA client's host 120 machine, you can start issuing commands using the CA. 121 122 The TLS CA's signing certificate will need to be available on each host that will run 123 commands against the TLS CA. 124 125 The TLS CA server was started with a bootstrap identity which has full admin 126 privileges for the server. One of the key abilities of the admin 127 is the ability to register new identities. The administrator for this CA will 128 use the Fabric CA client to register four new identities with the CA, one for 129 each peer and one for the orderer. These identities will be used to get TLS 130 certificates for peers and orderers. 131 132 You will issue the commands below to enroll the TLS CA admin and then register 133 identities. We assume the trusted root certificate for the TLS CA has been copied 134 to ``/tmp/hyperledger/tls-ca/crypto/tls-ca-cert.pem`` on all host machines that 135 will communicate with this CA via the fabric-ca-client. 136 137 .. code:: bash 138 139 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/tls-ca/crypto/tls-ca-cert.pem 140 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/tls-ca/admin 141 fabric-ca-client enroll -d -u https://tls-ca-admin:tls-ca-adminpw@0.0.0.0:7052 142 fabric-ca-client register -d --id.name peer1-org1 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7052 143 fabric-ca-client register -d --id.name peer2-org1 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7052 144 fabric-ca-client register -d --id.name peer1-org2 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7052 145 fabric-ca-client register -d --id.name peer2-org2 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7052 146 fabric-ca-client register -d --id.name orderer1-org0 --id.secret ordererPW --id.type orderer -u https://0.0.0.0:7052 147 148 .. note:: If the path of the environment variable FABRIC_CA_CLIENT_TLS_CERTFILES is not 149 an absolute path, it will be parsed as relative to the client's home directory. 150 151 With the identities registered on the TLS CA, we can move forward to setting up the 152 each organization's network. Anytime we need to get TLS certificates for a node in an 153 organization, we will refer to this CA. 154 155 Setup Orderer Org CA 156 ~~~~~~~~~~~~~~~~~~~~~ 157 158 Each organization must have its own Certificate Authority (CA) for 159 issuing enrollment certificates. The CA will issue the certificates 160 for each of the peers and clients in the organization. 161 162 Your CA creates the identities that belong to your organization and issue 163 each identity a public and private key. These keys are what allow all of your 164 nodes and applications to sign and verify their actions. Any identity signed 165 by your CA will be understood by other members of the network to identify the 166 components that belong to your organization. 167 168 An administrator for Org0 will launch a Fabric CA docker container, which 169 will be used by Org0 to issue cryptographic material for identities in Org0. 170 171 A docker service such as the one below can be used to a launch a Fabric CA 172 container. 173 174 .. code:: yaml 175 176 rca-org0: 177 container_name: rca-org0 178 image: hyperledger/fabric-ca 179 command: /bin/bash -c 'fabric-ca-server start -d -b rca-org0-admin:rca-org0-adminpw --port 7053' 180 environment: 181 - FABRIC_CA_SERVER_HOME=/tmp/hyperledger/fabric-ca/crypto 182 - FABRIC_CA_SERVER_TLS_ENABLED=true 183 - FABRIC_CA_SERVER_CSR_CN=rca-org0 184 - FABRIC_CA_SERVER_CSR_HOSTS=0.0.0.0 185 - FABRIC_CA_SERVER_DEBUG=true 186 volumes: 187 - /tmp/hyperledger/org0/ca:/tmp/hyperledger/fabric-ca 188 networks: 189 - fabric-ca 190 ports: 191 - 7053:7053 192 193 On a successful launch of the container, you will see the following line in 194 the CA container's log. 195 196 .. code:: bash 197 198 [INFO] Listening on https://0.0.0.0:7053 199 200 At this point the CA server is listening on a secure socket, and can start 201 issuing cryptographic material. 202 203 Enroll Orderer Org's CA Admin 204 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 205 206 You will issue the commands below to enroll the CA admin and then register 207 both of Org0's identities. 208 209 In the commands below, we will assume the trusted root certificate for the CA's 210 TLS certificate has been copied to 211 ``/tmp/hyperledger/org0/ca/crypto/ca-cert.pem`` 212 on the host machine where the fabric-ca-client binary is present. 213 If the client binary is located on a different host, you will need to get 214 the signing certificate through an out-of-band process. 215 216 The following identities will be registered: 217 - Orderer (orderer1-org0) 218 - Orderer admin (admin-org0) 219 220 .. code:: bash 221 222 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/ca/crypto/ca-cert.pem 223 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/ca/admin 224 fabric-ca-client enroll -d -u https://rca-org0-admin:rca-org0-adminpw@0.0.0.0:7053 225 fabric-ca-client register -d --id.name orderer1-org0 --id.secret ordererpw --id.type orderer -u https://0.0.0.0:7053 226 fabric-ca-client register -d --id.name admin-org0 --id.secret org0adminpw --id.type admin --id.attrs "hf.Registrar.Roles=client,hf.Registrar.Attributes=*,hf.Revoker=true,hf.GenCRL=true,admin=true:ecert,abac.init=true:ecert" -u https://0.0.0.0:7053 227 228 The enroll command you executed above, would have populated the 229 ``/tmp/hyperledger/org0/ca/admin`` directory with the cryptographic material 230 issued form the CA. You will see files such as the ones below: 231 232 .. code:: text 233 234 admin 235 ├── fabric-ca-client-config.yaml 236 └── msp 237 ├── IssuerPublicKey 238 ├── IssuerRevocationPublicKey 239 ├── cacerts 240 │ └── 0-0-0-0-7053.pem 241 ├── keystore 242 │ └── 60b6a16b8b5ba3fc3113c522cce86a724d7eb92d6c3961cfd9afbd27bf11c37f_sk 243 ├── signcerts 244 │ └── cert.pem 245 └── user 246 247 The ``fabric-ca-client-config.yaml`` is a file that is generated by the CA client, 248 this file contains the configuration of the CA client. There are three other important files 249 to note. First one is ``0-0-0-0-7053.pem``, this is the public certificate of the 250 CA that issued the certificate for this identity. Second is ``60b6a16b8b5ba3fc3113c522cce86a724d7eb92d6c3961cfd9afbd27bf11c37f_sk``, 251 this is the private key that was generated by the client. The name of this file 252 is variable and will be different every time a key is generated. The last item is ``cert.pem``, 253 this is the certificate of the admin was that was signed and issued by the CA. 254 255 Setup Org1's CA 256 ~~~~~~~~~~~~~~~~~ 257 258 The same set of steps you performed for Org0 apply to Org1's CA. 259 260 An administrator for Org1 will launch a Fabric CA docker container, which 261 will be used by Org1 to issue cryptographic material for identities in Org1. 262 263 A docker service, such as the one below can be used to a launch a Fabric CA 264 container. 265 266 .. code:: yaml 267 268 rca-org1: 269 container_name: rca-org1 270 image: hyperledger/fabric-ca 271 command: /bin/bash -c 'fabric-ca-server start -d -b rca-org1-admin:rca-org1-adminpw' 272 environment: 273 - FABRIC_CA_SERVER_HOME=/tmp/hyperledger/fabric-ca/crypto 274 - FABRIC_CA_SERVER_TLS_ENABLED=true 275 - FABRIC_CA_SERVER_CSR_CN=rca-org1 276 - FABRIC_CA_SERVER_CSR_HOSTS=0.0.0.0 277 - FABRIC_CA_SERVER_DEBUG=true 278 volumes: 279 - /tmp/hyperledger/org1/ca:/tmp/hyperledger/fabric-ca 280 networks: 281 - fabric-ca 282 ports: 283 - 7054:7054 284 285 On a successful launch of the container, you will see the following line in 286 the CA container's log. 287 288 .. code:: bash 289 290 [INFO] Listening on https://0.0.0.0:7054 291 292 At this point the CA server is listening on a secure socket, and can start 293 issuing cryptographic material. 294 295 Enroll Org1's CA Admin 296 ^^^^^^^^^^^^^^^^^^^^^^^ 297 298 You will issue the commands below to enroll the CA admin and then register 299 both of Org1's identities. 300 301 The following identities are being registered: 302 - Peer 1 (peer1-org1) 303 - Peer 2 (peer2-org1) 304 - Admin (admin1-org1) 305 - End user (user-org1) 306 307 In the commands below, we will assume the trusted root certificate for the CA's 308 TLS certificate has been copied to 309 ``/tmp/hyperledger/org1/ca/crypto/ca-cert.pem`` 310 on the host machine where the fabric-ca-client binary is present. 311 If the client's binary is located on a different host, you will need to get the 312 signing certificate through an out-of-band process. 313 314 .. code:: bash 315 316 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/ca/crypto/ca-cert.pem 317 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/ca/admin 318 fabric-ca-client enroll -d -u https://rca-org1-admin:rca-org1-adminpw@0.0.0.0:7054 319 fabric-ca-client register -d --id.name peer1-org1 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7054 320 fabric-ca-client register -d --id.name peer2-org1 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7054 321 fabric-ca-client register -d --id.name admin-org1 --id.secret org1AdminPW --id.type user -u https://0.0.0.0:7054 322 fabric-ca-client register -d --id.name user-org1 --id.secret org1UserPW --id.type user -u https://0.0.0.0:7054 323 324 Setup Org2's CA 325 ~~~~~~~~~~~~~~~~~ 326 327 The same set of steps that you followed for Org1 apply to Org2. So, we will quickly 328 go through the set of steps that the administrator for Org2 will perform. 329 330 A docker service, such as the one below can be used to a launch a Fabric CA for 331 Org2. 332 333 .. code:: yaml 334 335 rca-org2: 336 container_name: rca-org2 337 image: hyperledger/fabric-ca 338 command: /bin/bash -c 'fabric-ca-server start -d -b rca-org2-admin:rca-org2-adminpw --port 7055' 339 environment: 340 - FABRIC_CA_SERVER_HOME=/tmp/hyperledger/fabric-ca/crypto 341 - FABRIC_CA_SERVER_TLS_ENABLED=true 342 - FABRIC_CA_SERVER_CSR_CN=rca-org2 343 - FABRIC_CA_SERVER_CSR_HOSTS=0.0.0.0 344 - FABRIC_CA_SERVER_DEBUG=true 345 volumes: 346 - /tmp/hyperledger/org2/ca:/tmp/hyperledger/fabric-ca 347 networks: 348 - fabric-ca 349 ports: 350 - 7055:7055 351 352 On a successful launch of the container, you will see the following line in 353 the CA container's log. 354 355 .. code:: bash 356 357 [INFO] Listening on https://0.0.0.0:7055 358 359 At this point the CA server is listening on a secure socket, and can start 360 issuing cryptographic material. 361 362 Enrolling Org2's CA Admin 363 ^^^^^^^^^^^^^^^^^^^^^^^^^^ 364 365 You will issue the commands below to get the CA admin enrolled and all peer 366 related identities registered. In the commands below, we will assume the trusted 367 root certificate of CA's TLS certificate has been copied to 368 ``/tmp/hyperledger/org2/ca/crypto/ca-cert.pem``. 369 370 .. code:: bash 371 372 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/ca/crypto/ca-cert.pem 373 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/ca/admin 374 fabric-ca-client enroll -d -u https://rca-org2-admin:rca-org2-adminpw@0.0.0.0:7055 375 fabric-ca-client register -d --id.name peer1-org2 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7055 376 fabric-ca-client register -d --id.name peer2-org2 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7055 377 fabric-ca-client register -d --id.name admin-org2 --id.secret org2AdminPW --id.type user -u https://0.0.0.0:7055 378 fabric-ca-client register -d --id.name user-org2 --id.secret org2UserPW --id.type user -u https://0.0.0.0:7055 379 380 Setup Peers 381 ----------------- 382 383 Once the CAs are up and running, we can start enrolling peers. 384 385 Setup Org1's Peers 386 ^^^^^^^^^^^^^^^^^^^ 387 388 An administrator for Org1 will enroll the peers with its CA and then launch the 389 peer docker containers. Before you can start up a peer, you will need to enroll 390 the peer identities with the CA to get the MSP that the peer will use. 391 This is known as the local peer MSP. 392 393 Enroll Peer1 394 ~~~~~~~~~~~~~ 395 396 If the host machine running Peer1 does not have the fabric-ca-client binary, 397 refer to the instructions above on to download the binary. 398 399 In the command below, we will assume the trusted root certificate of Org1 has 400 been copied to ``/tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem`` 401 on Peer1's host machine. Acquiring of the signing certificate is an out of 402 band process. 403 404 .. code:: bash 405 406 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/peer1 407 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem 408 export FABRIC_CA_CLIENT_MSPDIR=msp 409 fabric-ca-client enroll -d -u https://peer1-org1:peer1PW@0.0.0.0:7054 410 411 Next step is to get the TLS cryptographic material for the peer. This requires another enrollment, 412 but this time you will enroll against the ``tls`` profile on the TLS CA. You will 413 also need to provide the address of the Peer1's host machine in the enrollment 414 request as the input to the ``csr.hosts`` flag. In the command below, we will 415 assume the certificate of the TLS CA has been copied to 416 ``/tmp/hyperledger/org1/peer1/assets/tls-ca/tls-ca-cert.pem`` 417 on Peer1's host machine. 418 419 .. code:: bash 420 421 export FABRIC_CA_CLIENT_MSPDIR=tls-msp 422 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/tls-ca/tls-ca-cert.pem 423 fabric-ca-client enroll -d -u https://peer1-org1:peer1PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer1-org1 424 425 Go to path ``/tmp/hyperledger/org1/peer1/tls-msp/keystore`` and change the name of 426 the key to ``key.pem``. This will make it easy to be able to refer to in 427 later steps. 428 429 At this point, you will have two MSP directories. One MSP contains peer's enrollment 430 certificate and the other has the peer's TLS certificate. However, there needs to be 431 an additional folder added in the enrollment MSP directory, and this is the ``admincerts`` 432 folder. This folder will contain certificate(s) for the administrator of Org1. 433 We will talk more about this when we enroll Org1's admin a little further down. 434 435 Enroll Peer2 436 ~~~~~~~~~~~~~ 437 438 You will perform similar commands for Peer2. In the commands below, we will 439 assume the trusted root certificate of Org1 has been copied to 440 ``/tmp/hyperledger/org1/peer2/assets/ca/org1-ca-cert.pem`` on Peer2's host 441 machine. 442 443 .. code:: bash 444 445 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/peer2 446 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer2/assets/ca/org1-ca-cert.pem 447 export FABRIC_CA_CLIENT_MSPDIR=msp 448 fabric-ca-client enroll -d -u https://peer2-org1:peer2PW@0.0.0.0:7054 449 450 Next step is to get the TLS cryptographic material for the peer. This requires another enrollment, 451 but this time you will enroll against the ``tls`` profile on the TLS CA. You will 452 also need to provide the address of the Peer2's host machine in the enrollment 453 request as the input to the ``csr.hosts`` flag. In the command below, we will 454 assume the certificate of the TLS CA has been copied to 455 ``/tmp/hyperledger/org1/peer2/assets/tls-ca/tls-ca-cert.pem`` 456 on Peer2's host machine. 457 458 .. code:: bash 459 460 export FABRIC_CA_CLIENT_MSPDIR=tls-msp 461 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer2/assets/tls-ca/tls-ca-cert.pem 462 fabric-ca-client enroll -d -u https://peer2-org1:peer2PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer2-org1 463 464 Go to path ``/tmp/hyperledger/org1/peer2/tls-msp/keystore`` and change the name of 465 the key to ``key.pem``. This will make it easy to be able to refer to in 466 later steps. 467 468 At this point, you will have two MSP directories. One MSP contains peer's enrollment 469 certificate and the other has the peer's TLS certificate. You will add the 470 ``admincerts`` folder to the enrollment MSP once the admin has been enrolled. 471 472 Enroll Org1's Admin 473 ~~~~~~~~~~~~~~~~~~~~ 474 475 At this point, both peers have been enrolled. Now, you will enroll 476 Org1's admin identity. The admin identity is responsible for activities such as 477 installing and instantiating chaincode. The steps below will enroll the admin. 478 In the commands below, we will assume that they are being executed on Peer1's host machine. 479 480 .. code:: bash 481 482 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/admin 483 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem 484 export FABRIC_CA_CLIENT_MSPDIR=msp 485 fabric-ca-client enroll -d -u https://admin-org1:org1AdminPW@0.0.0.0:7054 486 487 After enrollment, you should have an admin MSP. You will copy the 488 certificate from this MSP and move it to the Peer1's MSP in the ``admincerts`` 489 folder. You will need to disseminate this admin certificate to other peers in the 490 org, and it will need to go in to the ``admincerts`` folder of each peers' MSP. 491 492 The command below is only for Peer1, the exchange of the admin certificate to Peer2 will 493 happen out-of-band. 494 495 .. code:: bash 496 497 mkdir /tmp/hyperledger/org1/peer1/msp/admincerts 498 cp /tmp/hyperledger/org1/admin/msp/signcerts/cert.pem /tmp/hyperledger/org1/peer1/msp/admincerts/org1-admin-cert.pem 499 500 If the ``admincerts`` folder is missing from the peer's local MSP, the peer will 501 fail to start up. 502 503 Launch Org1's Peers 504 ~~~~~~~~~~~~~~~~~~~~ 505 506 Once we have enrolled all the peers and org admin, we have the necessary MSPs to 507 start the peers. 508 509 A docker service, such as the one below can be used to a launch a container for 510 Peer1. 511 512 .. code:: yaml 513 514 peer1-org1: 515 container_name: peer1-org1 516 image: hyperledger/fabric-peer 517 environment: 518 - CORE_PEER_ID=peer1-org1 519 - CORE_PEER_ADDRESS=peer1-org1:7051 520 - CORE_PEER_LOCALMSPID=org1MSP 521 - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/peer1/msp 522 - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock 523 - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca 524 - FABRIC_LOGGING_SPEC=debug 525 - CORE_PEER_TLS_ENABLED=true 526 - CORE_PEER_TLS_CERT_FILE=/tmp/hyperledger/org1/peer1/tls-msp/signcerts/cert.pem 527 - CORE_PEER_TLS_KEY_FILE=/tmp/hyperledger/org1/peer1/tls-msp/keystore/key.pem 528 - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org1/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem 529 - CORE_PEER_GOSSIP_USELEADERELECTION=true 530 - CORE_PEER_GOSSIP_ORGLEADER=false 531 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1-org1:7051 532 - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true 533 working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org1/peer1 534 volumes: 535 - /var/run:/host/var/run 536 - /tmp/hyperledger/org1/peer1:/tmp/hyperledger/org1/peer1 537 networks: 538 - fabric-ca 539 540 Launching the peer service will bring up a peer container, and in the logs you will 541 see the following line: 542 543 .. code:: bash 544 545 serve -> INFO 020 Started peer with ID=[name:"peer1-org1" ], network ID=[dev], address=[peer1-org1:7051] 546 547 A docker service, such as the one below can be used to a launch a container for 548 Peer2. 549 550 .. code:: yaml 551 552 peer2-org1: 553 container_name: peer2-org1 554 image: hyperledger/fabric-peer 555 environment: 556 - CORE_PEER_ID=peer2-org1 557 - CORE_PEER_ADDRESS=peer2-org1:7051 558 - CORE_PEER_LOCALMSPID=org1MSP 559 - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/peer2/msp 560 - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock 561 - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca 562 - FABRIC_LOGGING_SPEC=grpc=debug:info 563 - CORE_PEER_TLS_ENABLED=true 564 - CORE_PEER_TLS_CERT_FILE=/tmp/hyperledger/org1/peer2/tls-msp/signcerts/cert.pem 565 - CORE_PEER_TLS_KEY_FILE=/tmp/hyperledger/org1/peer2/tls-msp/keystore/key.pem 566 - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org1/peer2/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem 567 - CORE_PEER_GOSSIP_USELEADERELECTION=true 568 - CORE_PEER_GOSSIP_ORGLEADER=false 569 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer2-org1:7051 570 - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true 571 - CORE_PEER_GOSSIP_BOOTSTRAP=peer1-org1:7051 572 working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org1/peer2 573 volumes: 574 - /var/run:/host/var/run 575 - /tmp/hyperledger/org1/peer2:/tmp/hyperledger/org1/peer2 576 networks: 577 - fabric-ca 578 579 Launching the peer service will bring up a peer container, and in the logs you 580 will see the following line: 581 582 .. code:: bash 583 584 serve -> INFO 020 Started peer with ID=[name:"peer2-org1" ], network ID=[dev], address=[peer2-org1:7051] 585 586 Setup Org2's Peers 587 ^^^^^^^^^^^^^^^^^^^^ 588 589 An administrator for Org2 will use the CA's bootstrap identity to enroll the peers 590 with the CA and then launch the peer docker containers. 591 592 Enroll Peer1 593 ~~~~~~~~~~~~ 594 595 You will issue the commands below to enroll Peer1. In the commands below, 596 we will assume the trusted root certificate of Org2 is available at 597 ``/tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem`` on Peer1's host machine. 598 599 .. code:: bash 600 601 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/peer1 602 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem 603 export FABRIC_CA_CLIENT_MSPDIR=msp 604 fabric-ca-client enroll -d -u https://peer1-org2:peer1PW@0.0.0.0:7055 605 606 Next, you will get the TLS certificate. In the command below, we will assume the 607 certificate of the TLS CA has been copied to ``/tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem`` 608 on Peer1's host machine. 609 610 .. code:: bash 611 612 export FABRIC_CA_CLIENT_MSPDIR=tls-msp 613 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem 614 fabric-ca-client enroll -d -u https://peer1-org2:peer1PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer1-org2 615 616 Go to path ``/tmp/hyperledger/org2/peer1/tls-msp/keystore`` and change the name of the 617 key to ``key.pem``. 618 619 Enroll Peer2 620 ~~~~~~~~~~~~ 621 622 You will issue the commands below to get Peer2 enrolled. In the commands below, 623 we will assume the trusted root certificate of Org2 is available at 624 ``/tmp/hyperledger/org2/peer2/tls/org2-ca-cert.pem`` on Peer2's host machine. 625 626 .. code:: bash 627 628 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/peer2 629 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer2/assets/ca/org2-ca-cert.pem 630 export FABRIC_CA_CLIENT_MSPDIR=msp 631 fabric-ca-client enroll -d -u https://peer2-org2:peer2PW@0.0.0.0:7055 632 633 Next, you will get the TLS certificate. In the command below, we will assume the 634 certificate of the TLS CA has been copied to ``/tmp/hyperledger/org2/peer2/assets/tls-ca/tls-ca-cert.pem`` 635 on Peer2's host machine. 636 637 .. code:: bash 638 639 export FABRIC_CA_CLIENT_MSPDIR=tls-msp 640 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer2/assets/tls-ca/tls-ca-cert.pem 641 fabric-ca-client enroll -d -u https://peer2-org2:peer2PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer2-org2 642 643 Go to path ``/tmp/hyperledger/org2/peer2/tls-msp/keystore`` and change the name 644 of the key to ``key.pem``. 645 646 Enroll Org2's Admin 647 ~~~~~~~~~~~~~~~~~~~~~ 648 649 At this point, you will have two MSP directories. One MSP contains your enrollment 650 certificate and the other has your TLS certificate. However, there needs be one 651 additional folder added in the enrollment MSP directory, and this is the ``admincerts`` 652 folder. This folder will contain certificates for the administrator of Org2. 653 The steps below will enroll the admin. In the commands below, we will assume that they are being executed on Peer1's host machine. 654 655 .. code:: bash 656 657 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/admin 658 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem 659 export FABRIC_CA_CLIENT_MSPDIR=msp 660 fabric-ca-client enroll -d -u https://admin-org2:org2AdminPW@0.0.0.0:7055 661 662 After enrollment, you should have an admin MSP. You will copy the certificate from 663 this MSP and move it to the peer MSP under the ``admincerts`` folder. The commands 664 below are only for Peer1, the exchange of admin cert to peer2 will happen out-of-band. 665 666 .. code:: bash 667 668 mkdir /tmp/hyperledger/org2/peer1/msp/admincerts 669 cp /tmp/hyperledger/org2/admin/msp/signcerts/cert.pem /tmp/hyperledger/org2/peer1/msp/admincerts/org2-admin-cert.pem 670 671 If the ``admincerts`` folder is missing from the peer's local MSP, the peer will 672 fail to start up. 673 674 Launch Org2's Peers 675 ~~~~~~~~~~~~~~~~~~~~ 676 677 Once we have enrolled all the peers and admin, we have the necessary MSPs to 678 start the peers. 679 680 A docker service, such as the one below can be used to a launch a container for 681 the peer1. 682 683 .. code:: yaml 684 685 peer1-org2: 686 container_name: peer1-org2 687 image: hyperledger/fabric-peer 688 environment: 689 - CORE_PEER_ID=peer1-org2 690 - CORE_PEER_ADDRESS=peer1-org2:7051 691 - CORE_PEER_LOCALMSPID=org2MSP 692 - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/peer1/msp 693 - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock 694 - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca 695 - FABRIC_LOGGING_SPEC=debug 696 - CORE_PEER_TLS_ENABLED=true 697 - CORE_PEER_TLS_CERT_FILE=/tmp/hyperledger/org2/peer1/tls-msp/signcerts/cert.pem 698 - CORE_PEER_TLS_KEY_FILE=/tmp/hyperledger/org2/peer1/tls-msp/keystore/key.pem 699 - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org2/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem 700 - CORE_PEER_GOSSIP_USELEADERELECTION=true 701 - CORE_PEER_GOSSIP_ORGLEADER=false 702 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1-org2:7051 703 - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true 704 working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org2/peer1 705 volumes: 706 - /var/run:/host/var/run 707 - /tmp/hyperledger/org2/peer1:/tmp/hyperledger/org2/peer1 708 networks: 709 - fabric-ca 710 711 Launching the peer service will bring up a peer container, and in the logs you 712 will see the following line: 713 714 .. code:: bash 715 716 serve -> INFO 020 Started peer with ID=[name:"peer1-org2" ], network ID=[dev], address=[peer1-org2:7051] 717 718 A docker service, such as the one below can be used to a launch a container for 719 the peer1. 720 721 .. code:: yaml 722 723 peer2-org2: 724 container_name: peer2-org2 725 image: hyperledger/fabric-peer 726 environment: 727 - CORE_PEER_ID=peer2-org2 728 - CORE_PEER_ADDRESS=peer2-org2:7051 729 - CORE_PEER_LOCALMSPID=org2MSP 730 - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/peer2/msp 731 - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock 732 - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca 733 - FABRIC_LOGGING_SPEC=debug 734 - CORE_PEER_TLS_ENABLED=true 735 - CORE_PEER_TLS_CERT_FILE=/tmp/hyperledger/org2/peer2/tls-msp/signcerts/cert.pem 736 - CORE_PEER_TLS_KEY_FILE=/tmp/hyperledger/org2/peer2/tls-msp/keystore/key.pem 737 - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org2/peer2/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem 738 - CORE_PEER_GOSSIP_USELEADERELECTION=true 739 - CORE_PEER_GOSSIP_ORGLEADER=false 740 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer2-org2:7051 741 - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true 742 - CORE_PEER_GOSSIP_BOOTSTRAP=peer1-org2:7051 743 working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org2/peer2 744 volumes: 745 - /var/run:/host/var/run 746 - /tmp/hyperledger/org2/peer2:/tmp/hyperledger/org2/peer2 747 networks: 748 - fabric-ca 749 750 Launching the peer service will bring up a peer container, and in the logs you 751 will see the following line: 752 753 .. code:: bash 754 755 serve -> INFO 020 Started peer with ID=[name:"peer2-org2" ], network ID=[dev], address=[peer2-org2:7052] 756 757 Setup Orderer 758 --------------- 759 760 The last thing we need to setup is the orderer. We need to take a couple 761 of actions before we can start up the orderer. 762 763 Enroll Orderer 764 ^^^^^^^^^^^^^^^ 765 766 Before starting the orderer, you will need to enroll the orderer's identity with a 767 CA to get the MSP that the orderer will use. This is known as the local orderer 768 MSP. 769 770 If the host machine does not have the fabric-ca-client binary, please refer to 771 the instructions above on to download the binary. 772 773 You will issue the commands below to get the orderer enrolled. In the commands 774 below, we will assume the trusted root certificates for Org0 is available in 775 ``/tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem`` on the orderer's 776 host machine. 777 778 .. code:: bash 779 780 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/orderer 781 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem 782 fabric-ca-client enroll -d -u https://orderer1-org0:ordererpw@0.0.0.0:7053 783 784 Next, you will get the TLS certificate. In the command below, we will assume the 785 certificate of the TLS CA has been copied to ``/tmp/hyperledger/org0/orderer/assets/tls-ca/tls-ca-cert.pem`` 786 on Orderer's host machine. 787 788 .. code:: bash 789 790 export FABRIC_CA_CLIENT_MSPDIR=tls-msp 791 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/orderer/assets/tls-ca/tls-ca-cert.pem 792 fabric-ca-client enroll -d -u https://orderer1-org0:ordererPW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts orderer1-org0 793 794 Go to path ``/tmp/hyperledger/org0/orderer/tls-msp/keystore`` and change the name 795 of the key to ``key.pem``. 796 797 At this point, you will have two MSP directories. One MSP contains your enrollment 798 certificate and the other has your TLS certificate. However, there needs be one 799 additional folder added in the enrollment MSP directory, this is the ``admincerts`` 800 folder. This folder will contain certificates for the administrator of peer 1. 801 Now, you will enroll the Org0's admin identity by issuing the commands below. 802 803 Enroll Org0's Admin 804 ^^^^^^^^^^^^^^^^^^^^ 805 806 The command below assumes that this is being executed on the orderer's host machine. 807 808 .. code:: bash 809 810 export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/admin 811 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem 812 export FABRIC_CA_CLIENT_MSPDIR=msp 813 fabric-ca-client enroll -d -u https://orderer-org0-admin:ordererAdminPW@0.0.0.0:7053 814 815 After enrollment, you should have an msp folder at ``/tmp/hyperledger/org0/admin``. 816 You will copy the certificate from this MSP and move it to the orderer's MSP under the 817 ``admincerts`` folder. 818 819 .. code:: bash 820 821 mkdir /tmp/hyperledger/org0/orderer/msp/admincerts 822 cp /tmp/hyperledger/org0/admin/msp/signcerts/cert.pem /tmp/hyperledger/org0/orderer/msp/admincerts/orderer-admin-cert.pem 823 824 Create Genesis Block and Channel Transaction 825 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 826 827 The orderer requires a genesis block that it uses to bootstrap itself. 828 You can find more information in the `Hyperledger Fabric documentation <https://hyperledger-fabric.readthedocs.io/en/release-1.4/configtx.html?channel-configuration-configtx>`_ 829 830 In documentation below, you'll find a snippet of ``configtx.yaml`` that is written for this 831 specific deployment. For the full ``configtx.yaml``, click :doc:`here <configtx>`. 832 833 On the orderer's host machine, we need to collect the MSPs for all the 834 organizations. The ``organization`` section in the ``configtx.yaml`` looks like: 835 836 .. code:: yaml 837 838 Organizations: 839 840 - &org0 841 842 Name: org0 843 844 ID: org0MSP 845 846 MSPDir: /tmp/hyperledger/org0/msp 847 848 - &org1 849 850 Name: org1 851 852 ID: org1MSP 853 854 MSPDir: /tmp/hyperledger/org1/msp 855 856 AnchorPeers: 857 - Host: peer1-org1 858 Port: 7051 859 860 - &org2 861 862 Name: org2 863 864 ID: org2MSP 865 866 MSPDir: /tmp/hyperledger/org2/msp 867 868 AnchorPeers: 869 - Host: peer1-org2 870 Port: 7051 871 872 The MSP for Org0 will contain the trusted root certificate of Org0, 873 the certificate of the Org0's admin identity, and the trusted root certificate of 874 the TLS CA. The MSP folder structure can be seen below. 875 876 .. code:: text 877 878 /tmp/hyperledger/org0/msp 879 ├── admincerts 880 │ └── admin-org0-cert.pem 881 ├── cacerts 882 │ └── org0-ca-cert.pem 883 ├── tlscacerts 884 │ └── tls-ca-cert.pem 885 └── users 886 887 The pattern is the same for all organization. The MSP folder structure for 888 Org1 would like: 889 890 .. code:: text 891 892 /tmp/hyperledger/org1/msp 893 ├── admincerts 894 │ └── admin-org1-cert.pem 895 ├── cacerts 896 │ └── org1-ca-cert.pem 897 ├── tlscacerts 898 │ └── tls-ca-cert.pem 899 └── users 900 901 The MSP folder structure for Org2 would like: 902 903 .. code:: text 904 905 /tmp/hyperledger/org2/msp 906 ├── admincerts 907 │ └── admin-org2-cert.pem 908 ├── cacerts 909 │ └── org2-ca-cert.pem 910 ├── tlscacerts 911 │ └── tls-ca-cert.pem 912 └── users 913 914 Once all these MSPs are present on the orderer's host machine you will execute the 915 following commands from the directory in which ``configtx.yaml`` is present: 916 917 .. code:: bash 918 919 configtxgen -profile OrgsOrdererGenesis -outputBlock /tmp/hyperledger/org0/orderer/genesis.block -channelID syschannel 920 configtxgen -profile OrgsChannel -outputCreateChannelTx /tmp/hyperledger/org0/orderer/channel.tx -channelID mychannel 921 922 This will generate two artifacts, ``genesis.block`` and ``channel.tx``, which will 923 be used in later steps. 924 925 Commands for gathering certificates 926 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 927 928 The Fabric CA client has a couple commands that are useful in acquiring the certificates 929 for the orderer genesis and peer MSP setup. 930 931 The first command is the `fabric-ca-client certificate` command. This command can be used 932 to get certificates for the admincerts folder. For more information on how to use this command 933 , please refer to: `listing certificate information <https://hyperledger-fabric-ca.readthedocs.io/en/latest/users-guide.html#listing-certificate-information>`__ 934 935 The second command is the `fabric-ca-client getcainfo` command. This command can be used to gather 936 certificates for the `cacerts` and `tlscacerts` folders. The `getcainfo` command returns back the 937 certificate of the CA. 938 939 Mutual TLS 940 ^^^^^^^^^^^^ 941 942 Endpoints can be secured using Mutual TLS as well. If the CA, Peer, or Orderer are using mutual 943 TLS then the client must also present a TLS certificate that will be verified by the server. 944 945 Mutual TLS requires the client to acquire a TLS certificate that it will present to the server. 946 Acquiring a TLS certificate can be done via a TLS certificate authority that does have mutual TLS enabled. 947 Once the client has acquired a TLS certificate, then it can start communication with mutual TLS enabled servers as long as the trusted TLS authority on the server is the same as issuing authority for the client's TLS certificate. 948 949 Launch Orderer 950 ^^^^^^^^^^^^^^^ 951 952 Once you have created the genesis block and the channel transaction, you can 953 define an orderer service that points to the genesis.block created above. 954 955 .. code:: yaml 956 957 orderer1-org0: 958 container_name: orderer1-org0 959 image: hyperledger/fabric-orderer 960 environment: 961 - ORDERER_HOME=/tmp/hyperledger/orderer 962 - ORDERER_HOST=orderer1-org0 963 - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 964 - ORDERER_GENERAL_GENESISMETHOD=file 965 - ORDERER_GENERAL_GENESISFILE=/tmp/hyperledger/org0/orderer/genesis.block 966 - ORDERER_GENERAL_LOCALMSPID=org0MSP 967 - ORDERER_GENERAL_LOCALMSPDIR=/tmp/hyperledger/org0/orderer/msp 968 - ORDERER_GENERAL_TLS_ENABLED=true 969 - ORDERER_GENERAL_TLS_CERTIFICATE=/tmp/hyperledger/org0/orderer/tls-msp/signcerts/cert.pem 970 - ORDERER_GENERAL_TLS_PRIVATEKEY=/tmp/hyperledger/org0/orderer/tls-msp/keystore/key.pem 971 - ORDERER_GENERAL_TLS_ROOTCAS=[/tmp/hyperledger/org0/orderer/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem] 972 - ORDERER_GENERAL_LOGLEVEL=debug 973 - ORDERER_DEBUG_BROADCASTTRACEDIR=data/logs 974 volumes: 975 - /tmp/hyperledger/org0/orderer:/tmp/hyperledger/org0/orderer/ 976 networks: 977 - fabric-ca 978 979 Launching the orderer service will bring up an orderer container, and in the logs 980 you will see the following line: 981 982 .. code:: bash 983 984 UTC [orderer/common/server] Start -> INFO 0b8 Beginning to serve requests 985 986 Create CLI Containers 987 ---------------------- 988 989 Communication with peers requires a CLI container, the container contains the appropriate 990 binaries that will allow you to issue peer related commands. You will create 991 a CLI container for each org. In this example, we launch a CLI container 992 in the same host machine as Peer1 for each org. 993 994 Launch Org1's CLI 995 ^^^^^^^^^^^^^^^^^^ 996 997 .. code:: yaml 998 999 cli-org1: 1000 container_name: cli-org1 1001 image: hyperledger/fabric-tools 1002 tty: true 1003 stdin_open: true 1004 environment: 1005 - GOPATH=/opt/gopath 1006 - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock 1007 - FABRIC_LOGGING_SPEC=DEBUG 1008 - CORE_PEER_ID=cli-org1 1009 - CORE_PEER_ADDRESS=peer1-org1:7051 1010 - CORE_PEER_LOCALMSPID=org1MSP 1011 - CORE_PEER_TLS_ENABLED=true 1012 - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org1/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem 1013 - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/peer1/msp 1014 working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org1 1015 command: sh 1016 volumes: 1017 - /tmp/hyperledger/org1/peer1:/tmp/hyperledger/org1/peer1 1018 - /tmp/hyperledger/org1/peer1/assets/chaincode:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode 1019 - /tmp/hyperledger/org1/admin:/tmp/hyperledger/org1/admin 1020 networks: 1021 - fabric-ca 1022 1023 Launch Org2's CLI 1024 ^^^^^^^^^^^^^^^^^^ 1025 1026 .. code:: yaml 1027 1028 cli-org2: 1029 container_name: cli-org2 1030 image: hyperledger/fabric-tools 1031 tty: true 1032 stdin_open: true 1033 environment: 1034 - GOPATH=/opt/gopath 1035 - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock 1036 - FABRIC_LOGGING_SPEC=DEBUG 1037 - CORE_PEER_ID=cli-org2 1038 - CORE_PEER_ADDRESS=peer1-org2:7051 1039 - CORE_PEER_LOCALMSPID=org2MSP 1040 - CORE_PEER_TLS_ENABLED=true 1041 - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org2/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem 1042 - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/peer1/msp 1043 working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org2 1044 command: sh 1045 volumes: 1046 - /tmp/hyperledger/org2/peer1:/tmp/hyperledger/org2/peer1 1047 - /tmp/hyperledger/org1/peer1/assets/chaincode:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode 1048 - /tmp/hyperledger/org2/admin:/tmp/hyperledger/org2/admin 1049 networks: 1050 - fabric-ca 1051 1052 Create and Join Channel 1053 ------------------------ 1054 1055 Org1 1056 ^^^^^ 1057 1058 With the CLI containers up and running, you can now issue commands to create and 1059 join a channel. We are going to use Peer1 to create the channel. In the 1060 host machine of Peer1, you will execute: 1061 1062 .. code:: bash 1063 1064 docker exec -it cli-org1 sh 1065 1066 This command will bring you inside the CLI container and open up a terminal. From 1067 here, you will execute the following commands using the admin MSP: 1068 1069 .. code:: bash 1070 1071 export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp 1072 peer channel create -c mychannel -f /tmp/hyperledger/org1/peer1/assets/channel.tx -o orderer1-org0:7050 --outputBlock /tmp/hyperledger/org1/peer1/assets/mychannel.block --tls --cafile /tmp/hyperledger/org1/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem 1073 1074 The ``channel.tx`` is an artifact that was generated by running the 1075 ``configtxgen`` command on the orderer. This artifact needs to be transferred 1076 to Peer1's host machine out-of-band from the orderer. The command above will generate 1077 ``mychannel.block`` on Peer1 at the specified output path ``/tmp/hyperledger/org1/peer1/assets/mychannel.block``, 1078 which will be used by all peers in the network that wish 1079 to join the channel. This ``mychannel.block`` will be need to transferred to all peers 1080 in both Org1 and Org2 out-of-band. 1081 1082 The next commands you are going to run is to have Peer1 and Peer2 in join 1083 the channel. 1084 1085 .. code:: bash 1086 1087 export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp 1088 export CORE_PEER_ADDRESS=peer1-org1:7051 1089 peer channel join -b /tmp/hyperledger/org1/peer1/assets/mychannel.block 1090 1091 export CORE_PEER_ADDRESS=peer2-org1:7051 1092 peer channel join -b /tmp/hyperledger/org1/peer1/assets/mychannel.block 1093 1094 Org2 1095 ^^^^^ 1096 1097 Run the following command to enter the CLI docker container. 1098 1099 .. code:: bash 1100 1101 docker exec -it cli-org2 sh 1102 1103 In Org2, you only need to have the peers join the channel. Peers in Org2 do not 1104 need to create the channel, this was already done by Org1. From inside the Org2 1105 CLI container, you will execute the following commands using the admin MSP: 1106 1107 .. code:: bash 1108 1109 export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/admin/msp 1110 export CORE_PEER_ADDRESS=peer1-org2:7051 1111 peer channel join -b /tmp/hyperledger/org2/peer1/assets/mychannel.block 1112 1113 export CORE_PEER_ADDRESS=peer2-org2:7051 1114 peer channel join -b /tmp/hyperledger/org2/peer1/assets/mychannel.block 1115 1116 1117 Install and Instantiate Chaincode 1118 ---------------------------------- 1119 1120 Download this `chaincode <https://github.com/hyperledger/fabric-samples/tree/master/chaincode/abac/go>`_ 1121 from Github to the local file system on Peer1 in both orgs. 1122 1123 Org1 1124 ^^^^^ 1125 1126 On Peer1, you are going to install chaincode. The command assumes that the 1127 chaincode that needs to be installed is available inside the GOPATH. In this 1128 example we will assume the chaincode is located at 1129 ``/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode/abac/go`` with the 1130 GOPATH being ``/opt/gopath``. From Org1's CLI container, you will 1131 execute the following command: 1132 1133 .. code:: bash 1134 1135 export CORE_PEER_ADDRESS=peer1-org1:7051 1136 export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp 1137 peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric-samples/chaincode/abac/go 1138 1139 The same set of steps will be followed for peer2. 1140 1141 .. code:: bash 1142 1143 export CORE_PEER_ADDRESS=peer2-org1:7051 1144 export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp 1145 peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric-samples/chaincode/abac/go 1146 1147 Org2 1148 ^^^^^ 1149 1150 On Peer1, you are going to perform the same steps as Org1. The command 1151 assumes that the chaincode that needs to be installed is available at 1152 ``/opt/gopath/src/github.com/hyperledger/org2/peer1/assets/chaincode/abac/go``. 1153 From Org2's CLI container, you will execute the following command: 1154 1155 .. code:: bash 1156 1157 export CORE_PEER_ADDRESS=peer1-org2:7051 1158 export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/admin/msp 1159 peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric-samples/chaincode/abac/go 1160 1161 The same set of steps will be followed for peer2. 1162 1163 .. code:: bash 1164 1165 export CORE_PEER_ADDRESS=peer2-org2:7051 1166 export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/admin/msp 1167 peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric-samples/chaincode/abac/go 1168 1169 The next step is going to be to instantiate the chaincode. This done by 1170 executing: 1171 1172 .. code:: bash 1173 1174 peer chaincode instantiate -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -o orderer1-org0:7050 --tls --cafile /tmp/hyperledger/org2/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem 1175 1176 Invoke and Query Chaincode 1177 ---------------------------------- 1178 1179 From Org1's CLI container, execute: 1180 1181 .. code:: bash 1182 1183 export CORE_PEER_ADDRESS=peer1-org1:7051 1184 export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp 1185 peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' 1186 1187 This should return a value of ``100``. 1188 1189 From Org2's CLI container, execute: 1190 1191 .. code:: bash 1192 1193 export CORE_PEER_ADDRESS=peer1-org2:7051 1194 export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/admin/msp 1195 peer chaincode invoke -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}' --tls --cafile /tmp/hyperledger/org2/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem 1196 1197 This is going to subtract 10 from value of ``a`` and move it to ``b``. Now, if 1198 you query by running: 1199 1200 .. code:: bash 1201 1202 peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' 1203 1204 This should return a value of ``90``. 1205 1206 This concludes the Operations Guide for Fabric CA.