Skip to content

Commit 8e780c0

Browse files
committed
Implement revocation list for follower and main channel
Signed-off-by: dviejokfs <[email protected]>
1 parent 57da045 commit 8e780c0

File tree

6 files changed

+105
-24
lines changed

6 files changed

+105
-24
lines changed

.vscode/settings.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/crd/bases/hlf.kungfusoftware.es_fabricmainchannels.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ spec:
319319
items:
320320
type: string
321321
type: array
322+
revocationList:
323+
default: []
324+
items:
325+
type: string
326+
nullable: true
327+
type: array
322328
signRootCert:
323329
type: string
324330
tlsRootCert:
@@ -400,6 +406,12 @@ spec:
400406
- namespace
401407
type: object
402408
type: array
409+
revocationList:
410+
default: []
411+
items:
412+
type: string
413+
nullable: true
414+
type: array
403415
signCACert:
404416
type: string
405417
tlsCACert:

controllers/followerchannel/followerchannel_controller.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,8 @@ func (r *FabricFollowerChannelReconciler) Reconcile(ctx context.Context, req ctr
293293
}
294294

295295
r.Log.Info("Setting CRL configuration")
296-
297-
msp := app.MSP()
298-
mspConf, err := msp.Configuration()
299-
if err != nil {
300-
r.setConditionStatus(ctx, fabricFollowerChannel, hlfv1alpha1.FailedStatus, false, err, false)
301-
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricFollowerChannel)
302-
}
303296
var revocationList []*pkix.CertificateList
297+
// Then add the new CRLs
304298
for _, revocation := range fabricFollowerChannel.Spec.RevocationList {
305299
crl, err := utils.ParseCRL([]byte(revocation))
306300
if err != nil {
@@ -309,14 +303,30 @@ func (r *FabricFollowerChannelReconciler) Reconcile(ctx context.Context, req ctr
309303
}
310304
revocationList = append(revocationList, crl)
311305
}
312-
mspConf.RevocationList = revocationList
313-
err = app.SetMSP(mspConf)
306+
307+
org, err := cftxGen.Application().Organization(mspID).Configuration()
314308
if err != nil {
315309
r.setConditionStatus(ctx, fabricFollowerChannel, hlfv1alpha1.FailedStatus, false, err, false)
316310
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricFollowerChannel)
317311
}
312+
org.MSP.RevocationList = revocationList
313+
err = cftxGen.Application().SetOrganization(org)
314+
if err != nil {
315+
r.setConditionStatus(ctx, fabricFollowerChannel, hlfv1alpha1.FailedStatus, false, err, false)
316+
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricFollowerChannel)
317+
}
318+
318319
r.Log.Info("CRL configuration set")
319320
r.Log.Info("Updating channel configuration")
321+
updatedConfig := cftxGen.UpdatedConfig()
322+
// convert to json and print it as log
323+
var buf3 bytes.Buffer
324+
err = protolator.DeepMarshalJSON(&buf3, updatedConfig)
325+
if err != nil {
326+
r.setConditionStatus(ctx, fabricFollowerChannel, hlfv1alpha1.FailedStatus, false, err, false)
327+
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricFollowerChannel)
328+
}
329+
r.Log.Info(fmt.Sprintf("Updated config: %s", buf2.String()))
320330
configUpdateBytes, err := cftxGen.ComputeMarshaledUpdate(fabricFollowerChannel.Spec.Name)
321331
if err != nil {
322332
if !strings.Contains(err.Error(), "no differences detected between original and updated config") {

controllers/mainchannel/mainchannel_controller.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ func (r *FabricMainChannelReconciler) mapToConfigTX(channel *hlfv1alpha1.FabricM
826826
for _, ordererOrg := range channel.Spec.OrdererOrganizations {
827827
var tlsCACert *x509.Certificate
828828
var caCert *x509.Certificate
829+
829830
if ordererOrg.CAName != "" && ordererOrg.CANamespace != "" {
830831
certAuth, err := helpers.GetCertAuthByName(
831832
clientSet,
@@ -854,7 +855,20 @@ func (r *FabricMainChannelReconciler) mapToConfigTX(channel *hlfv1alpha1.FabricM
854855
return configtx.Channel{}, err
855856
}
856857
}
857-
ordererOrgs = append(ordererOrgs, r.mapOrdererOrg(ordererOrg.MSPID, ordererOrg.OrdererEndpoints, caCert, tlsCACert))
858+
859+
// Parse revocation list if provided
860+
revocationList := []*pkix.CertificateList{}
861+
if len(ordererOrg.RevocationList) > 0 {
862+
for _, revocation := range ordererOrg.RevocationList {
863+
crl, err := utils.ParseCRL([]byte(revocation))
864+
if err != nil {
865+
return configtx.Channel{}, errors.Wrapf(err, "failed to parse revocation list for orderer org %s", ordererOrg.MSPID)
866+
}
867+
revocationList = append(revocationList, crl)
868+
}
869+
}
870+
871+
ordererOrgs = append(ordererOrgs, r.mapOrdererOrg(ordererOrg.MSPID, ordererOrg.OrdererEndpoints, caCert, tlsCACert, revocationList))
858872
}
859873
for _, ordererOrg := range channel.Spec.ExternalOrdererOrganizations {
860874
tlsCACert, err := utils.ParseX509Certificate([]byte(ordererOrg.TLSRootCert))
@@ -865,7 +879,15 @@ func (r *FabricMainChannelReconciler) mapToConfigTX(channel *hlfv1alpha1.FabricM
865879
if err != nil {
866880
return configtx.Channel{}, err
867881
}
868-
ordererOrgs = append(ordererOrgs, r.mapOrdererOrg(ordererOrg.MSPID, ordererOrg.OrdererEndpoints, caCert, tlsCACert))
882+
revocationList := []*pkix.CertificateList{}
883+
for _, revocation := range ordererOrg.RevocationList {
884+
crl, err := utils.ParseCRL([]byte(revocation))
885+
if err != nil {
886+
return configtx.Channel{}, err
887+
}
888+
revocationList = append(revocationList, crl)
889+
}
890+
ordererOrgs = append(ordererOrgs, r.mapOrdererOrg(ordererOrg.MSPID, ordererOrg.OrdererEndpoints, caCert, tlsCACert, revocationList))
869891
}
870892
etcdRaftOptions := orderer.EtcdRaftOptions{
871893
TickInterval: "500ms",
@@ -1160,7 +1182,8 @@ func (r *FabricMainChannelReconciler) mapPolicy(
11601182
}
11611183
return policiesMap
11621184
}
1163-
func (r *FabricMainChannelReconciler) mapOrdererOrg(mspID string, ordererEndpoints []string, caCert *x509.Certificate, tlsCACert *x509.Certificate) configtx.Organization {
1185+
1186+
func (r *FabricMainChannelReconciler) mapOrdererOrg(mspID string, ordererEndpoints []string, caCert *x509.Certificate, tlsCACert *x509.Certificate, revocationList []*pkix.CertificateList) configtx.Organization {
11641187
return configtx.Organization{
11651188
Name: mspID,
11661189
Policies: map[string]configtx.Policy{
@@ -1206,7 +1229,7 @@ func (r *FabricMainChannelReconciler) mapOrdererOrg(mspID string, ordererEndpoin
12061229
},
12071230
Admins: []*x509.Certificate{},
12081231
IntermediateCerts: []*x509.Certificate{},
1209-
RevocationList: []*pkix.CertificateList{},
1232+
RevocationList: revocationList,
12101233
OrganizationalUnitIdentifiers: []membership.OUIdentifier{},
12111234
CryptoConfig: membership.CryptoConfig{},
12121235
TLSIntermediateCerts: []*x509.Certificate{},
@@ -1336,13 +1359,14 @@ func updateApplicationChannelConfigTx(currentConfigTX configtx.ConfigTx, newConf
13361359
}
13371360
}
13381361
if !found {
1339-
log.Infof("Adding organization %s", organization.Name)
1362+
log.Infof("Adding organization %v", organization)
13401363
err = currentConfigTX.Application().SetOrganization(organization)
13411364
if err != nil {
13421365
return errors.Wrapf(err, "failed to set organization %s", organization.Name)
13431366
}
13441367
}
13451368
}
1369+
13461370
err = currentConfigTX.Application().SetPolicies(
13471371
newConfigTx.Application.Policies,
13481372
)
@@ -1438,20 +1462,20 @@ func updateOrdererChannelConfigTx(currentConfigTX configtx.ConfigTx, newConfigTx
14381462
deleted := true
14391463
needsUpdate := false
14401464
var matchingNewConsenter orderer.Consenter
1441-
1465+
14421466
for _, newConsenter := range newConfigTx.Orderer.EtcdRaft.Consenters {
14431467
if newConsenter.Address.Host == consenter.Address.Host && newConsenter.Address.Port == consenter.Address.Port {
14441468
deleted = false
14451469
matchingNewConsenter = newConsenter
14461470
// Check if TLS certs are different
1447-
if !bytes.Equal(newConsenter.ClientTLSCert.Raw, consenter.ClientTLSCert.Raw) ||
1448-
!bytes.Equal(newConsenter.ServerTLSCert.Raw, consenter.ServerTLSCert.Raw) {
1471+
if !bytes.Equal(newConsenter.ClientTLSCert.Raw, consenter.ClientTLSCert.Raw) ||
1472+
!bytes.Equal(newConsenter.ServerTLSCert.Raw, consenter.ServerTLSCert.Raw) {
14491473
needsUpdate = true
14501474
}
14511475
break
14521476
}
14531477
}
1454-
1478+
14551479
if deleted {
14561480
log.Infof("Removing consenter %s:%d", consenter.Address.Host, consenter.Address.Port)
14571481
err = currentConfigTX.Orderer().RemoveConsenter(consenter)
@@ -1645,6 +1669,12 @@ func updateOrdererChannelConfigTx(currentConfigTX configtx.ConfigTx, newConfigTx
16451669
return errors.Wrapf(err, "failed to add endpoint %s", endpoint)
16461670
}
16471671
}
1672+
1673+
ordConfig.MSP.RevocationList = organization.MSP.RevocationList
1674+
err = currentConfigTX.Orderer().Organization(organization.Name).SetMSP(ordConfig.MSP)
1675+
if err != nil {
1676+
return errors.Wrapf(err, "failed to set organization %s", organization.Name)
1677+
}
16481678
} else {
16491679
log.Infof("Adding organization %s", organization.Name)
16501680
err = currentConfigTX.Orderer().SetOrganization(organization)

pkg/apis/hlf.kungfusoftware.es/v1alpha1/hlf_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,11 @@ type FabricMainChannelExternalOrdererOrganization struct {
26882688
SignRootCert string `json:"signRootCert"`
26892689
// Orderer endpoints for the organization in the channel configuration
26902690
OrdererEndpoints []string `json:"ordererEndpoints"`
2691+
// +optional
2692+
// +nullable
2693+
// +kubebuilder:validation:Optional
2694+
// +kubebuilder:default:={}
2695+
RevocationList []string `json:"revocationList"`
26912696
}
26922697
type OrgCertsRef struct {
26932698
}
@@ -2720,6 +2725,11 @@ type FabricMainChannelOrdererOrganization struct {
27202725
// +optional
27212726
// Root certificate authority for signing
27222727
SignCACert string `json:"signCACert"`
2728+
// +optional
2729+
// +nullable
2730+
// +kubebuilder:validation:Optional
2731+
// +kubebuilder:default:={}
2732+
RevocationList []string `json:"revocationList"`
27232733
// Orderer endpoints for the organization in the channel configuration
27242734
OrdererEndpoints []string `json:"ordererEndpoints"`
27252735
// Orderer nodes within the kubernetes cluster to be added to the channel

pkg/apis/hlf.kungfusoftware.es/v1alpha1/zz_generated.deepcopy.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)