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