Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added sample for certifiate renewal in test-network #1163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adityajoshi12
Copy link
Contributor

@adityajoshi12 adityajoshi12 commented Jan 9, 2024

This PR adds a script to demonstrate the certificates renewal in thetest-network.

A new moderenewCerts has been added to support certificate renewal
Certificate renewal can be done using network.sh renewCerts

@adityajoshi12 adityajoshi12 requested a review from a team as a code owner January 9, 2024 05:57
@adityajoshi12
Copy link
Contributor Author

@denyeart can you please take a look into this PR.

Copy link
Contributor

@denyeart denyeart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to see since many people have questions about renewing certs.

Did you test to see if this actually works? It would be good to extend the automated tests to make sure transactions work after the renew. Maybe extend
https://github.com/hyperledger/fabric-samples/blob/main/ci/scripts/run-test-network-basic.sh and the associated app to create another asset after the renew.

It is unclear if you are trying to renew the root cert, or at least the TLS root cert. Most of the time when you renew identity certs you don't renew the root cert (create a 2nd root cert). I wouldn't recommend it. If you do intend to create a 2nd root cert, a channel config transaction will be required to add it to the channel.

function renewCerts(){
. ./organizations/fabric-ca/reEnroll.sh

rm "${PWD}"/organizations/fabric-ca/ordererOrg/tls-cert.pem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you delete the tls-cert.pem? Usually when you renew certs the root cert remains the same.

Could you add comments to explain the intent.

. ./organizations/fabric-ca/reEnroll.sh

rm "${PWD}"/organizations/fabric-ca/ordererOrg/tls-cert.pem
docker restart ca_orderer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to restart the CA?

Again, add comments to explain intent.


function reEnrollOrg1() {
infoln "Re-enrolling the CA admin"
mkdir -p organizations/peerOrganizations/org1.example.com/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this directory already exist from the initial creation?

{ set +x; } 2>/dev/null

# Copy org1's CA cert to org1's /msp/tlscacerts directory (for use in the channel MSP definition)
mkdir -p "${PWD}/organizations/peerOrganizations/org1.example.com/msp/tlscacerts"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you re-create the directory, doesn't it already exist?


# Copy org1's CA cert to org1's /msp/tlscacerts directory (for use in the channel MSP definition)
mkdir -p "${PWD}/organizations/peerOrganizations/org1.example.com/msp/tlscacerts"
cp "${PWD}/organizations/fabric-ca/org1/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org1.example.com/msp/tlscacerts/ca.crt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually when you renew certs the root cert remains the same.


infoln "Generating the peer0 msp"
set -x
fabric-ca-client reenroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp" --csr.hosts peer0.org1.example.com --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem" --csr.keyrequest.reusekey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use -csr.hosts for enrollment cert, only needed for tls certs to generate the SANS.

fabric-ca-client reenroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp" --csr.hosts peer0.org1.example.com --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem" --csr.keyrequest.reusekey
{ set +x; } 2>/dev/null

cp "${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/config.yaml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anything in the config.yaml changes when you reenroll. Did you find something that changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants