@@ -73,7 +73,7 @@ type Authority struct {
73
73
sshCAUserFederatedCerts []ssh.PublicKey
74
74
sshCAHostFederatedCerts []ssh.PublicKey
75
75
76
- // Do not re-initialize
76
+ // If true, do not re-initialize
77
77
initOnce bool
78
78
startTime time.Time
79
79
@@ -91,8 +91,11 @@ type Authority struct {
91
91
92
92
adminMutex sync.RWMutex
93
93
94
- // Do Not initialize the authority
94
+ // If true, do not initialize the authority
95
95
skipInit bool
96
+
97
+ // If true, does not output initialization logs
98
+ quietInit bool
96
99
}
97
100
98
101
// Info contains information about the authority.
@@ -600,10 +603,9 @@ func (a *Authority) init() error {
600
603
return admin .WrapErrorISE (err , "error loading provisioners to initialize authority" )
601
604
}
602
605
if len (provs ) == 0 && ! strings .EqualFold (a .config .AuthorityConfig .DeploymentType , "linked" ) {
603
-
604
606
var firstJWKProvisioner * linkedca.Provisioner
605
607
if len (a .config .AuthorityConfig .Provisioners ) > 0 {
606
- log . Printf ("Starting migration of provisioners" )
608
+ a . initLogf ("Starting migration of provisioners" )
607
609
// Existing provisioners detected; try migrating them to DB storage
608
610
for _ , p := range a .config .AuthorityConfig .Provisioners {
609
611
lp , err := ProvisionerToLinkedca (p )
@@ -619,9 +621,9 @@ func (a *Authority) init() error {
619
621
// Mark the first JWK provisioner, so that it can be used for administration purposes
620
622
if firstJWKProvisioner == nil && lp .Type == linkedca .Provisioner_JWK {
621
623
firstJWKProvisioner = lp
622
- log . Printf ("Migrated JWK provisioner %q with admin permissions" , p .GetName ()) // TODO(hs): change the wording?
624
+ a . initLogf ("Migrated JWK provisioner %q with admin permissions" , p .GetName ()) // TODO(hs): change the wording?
623
625
} else {
624
- log . Printf ("Migrated %s provisioner %q" , p .GetType (), p .GetName ())
626
+ a . initLogf ("Migrated %s provisioner %q" , p .GetType (), p .GetName ())
625
627
}
626
628
}
627
629
@@ -630,7 +632,12 @@ func (a *Authority) init() error {
630
632
// every error. The next time the CA runs, it won't have perform the migration,
631
633
// because there'll be at least a JWK provisioner.
632
634
633
- log .Printf ("Finished migrating provisioners" )
635
+ // 1. check if prerequisites for writing files look OK (user/group, permission bits, etc)
636
+ // 2. update the configuration to write (internal representation; do a deep copy first?)
637
+ // 3. try writing the new ca.json
638
+ // 4. on failure, perform rollback of the write (restore original in internal representation)
639
+
640
+ a .initLogf ("Finished migrating provisioners" )
634
641
}
635
642
636
643
// Create first JWK provisioner for remote administration purposes if none exists yet
@@ -639,7 +646,7 @@ func (a *Authority) init() error {
639
646
if err != nil {
640
647
return admin .WrapErrorISE (err , "error creating first provisioner" )
641
648
}
642
- log . Printf ("Created JWK provisioner %q with admin permissions" , firstJWKProvisioner .GetName ()) // TODO(hs): change the wording?
649
+ a . initLogf ("Created JWK provisioner %q with admin permissions" , firstJWKProvisioner .GetName ()) // TODO(hs): change the wording?
643
650
}
644
651
645
652
// Create first super admin, belonging to the first JWK provisioner
@@ -652,7 +659,7 @@ func (a *Authority) init() error {
652
659
return admin .WrapErrorISE (err , "error creating first admin" )
653
660
}
654
661
655
- log . Printf ("Created super admin %q for JWK provisioner %q" , firstSuperAdminSubject , firstJWKProvisioner .GetName ())
662
+ a . initLogf ("Created super admin %q for JWK provisioner %q" , firstSuperAdminSubject , firstJWKProvisioner .GetName ())
656
663
}
657
664
}
658
665
@@ -702,6 +709,14 @@ func (a *Authority) init() error {
702
709
return nil
703
710
}
704
711
712
+ // initLogf is used to log initialization information. The output
713
+ // can be disabled by starting the CA with the `--quiet` flag.
714
+ func (a * Authority ) initLogf (format string , v ... any ) {
715
+ if ! a .quietInit {
716
+ log .Printf (format , v ... )
717
+ }
718
+ }
719
+
705
720
// GetID returns the define authority id or a zero uuid.
706
721
func (a * Authority ) GetID () string {
707
722
const zeroUUID = "00000000-0000-0000-0000-000000000000"
0 commit comments