ca.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. package ca
  2. import (
  3. "bytes"
  4. "context"
  5. "crypto/tls"
  6. "crypto/x509"
  7. "fmt"
  8. "log"
  9. "net"
  10. "net/http"
  11. "net/url"
  12. "reflect"
  13. "strings"
  14. "sync"
  15. "time"
  16. "github.com/go-chi/chi"
  17. "github.com/go-chi/chi/middleware"
  18. "github.com/pkg/errors"
  19. "github.com/smallstep/certificates/acme"
  20. acmeAPI "github.com/smallstep/certificates/acme/api"
  21. acmeNoSQL "github.com/smallstep/certificates/acme/db/nosql"
  22. "github.com/smallstep/certificates/api"
  23. "github.com/smallstep/certificates/authority"
  24. "github.com/smallstep/certificates/authority/admin"
  25. adminAPI "github.com/smallstep/certificates/authority/admin/api"
  26. "github.com/smallstep/certificates/authority/config"
  27. "github.com/smallstep/certificates/db"
  28. "github.com/smallstep/certificates/logging"
  29. "github.com/smallstep/certificates/monitoring"
  30. "github.com/smallstep/certificates/scep"
  31. scepAPI "github.com/smallstep/certificates/scep/api"
  32. "github.com/smallstep/certificates/server"
  33. "github.com/smallstep/nosql"
  34. "go.step.sm/cli-utils/step"
  35. "go.step.sm/crypto/x509util"
  36. )
  37. type options struct {
  38. configFile string
  39. linkedCAToken string
  40. quiet bool
  41. password []byte
  42. issuerPassword []byte
  43. sshHostPassword []byte
  44. sshUserPassword []byte
  45. database db.AuthDB
  46. }
  47. func (o *options) apply(opts []Option) {
  48. for _, fn := range opts {
  49. fn(o)
  50. }
  51. }
  52. // Option is the type of options passed to the CA constructor.
  53. type Option func(o *options)
  54. // WithConfigFile sets the given name as the configuration file name in the CA
  55. // options.
  56. func WithConfigFile(name string) Option {
  57. return func(o *options) {
  58. o.configFile = name
  59. }
  60. }
  61. // WithPassword sets the given password as the configured password in the CA
  62. // options.
  63. func WithPassword(password []byte) Option {
  64. return func(o *options) {
  65. o.password = password
  66. }
  67. }
  68. // WithSSHHostPassword sets the given password to decrypt the key used to sign
  69. // ssh host certificates.
  70. func WithSSHHostPassword(password []byte) Option {
  71. return func(o *options) {
  72. o.sshHostPassword = password
  73. }
  74. }
  75. // WithSSHUserPassword sets the given password to decrypt the key used to sign
  76. // ssh user certificates.
  77. func WithSSHUserPassword(password []byte) Option {
  78. return func(o *options) {
  79. o.sshUserPassword = password
  80. }
  81. }
  82. // WithIssuerPassword sets the given password as the configured certificate
  83. // issuer password in the CA options.
  84. func WithIssuerPassword(password []byte) Option {
  85. return func(o *options) {
  86. o.issuerPassword = password
  87. }
  88. }
  89. // WithDatabase sets the given authority database to the CA options.
  90. func WithDatabase(d db.AuthDB) Option {
  91. return func(o *options) {
  92. o.database = d
  93. }
  94. }
  95. // WithLinkedCAToken sets the token used to authenticate with the linkedca.
  96. func WithLinkedCAToken(token string) Option {
  97. return func(o *options) {
  98. o.linkedCAToken = token
  99. }
  100. }
  101. // WithQuiet sets the quiet flag.
  102. func WithQuiet(quiet bool) Option {
  103. return func(o *options) {
  104. o.quiet = quiet
  105. }
  106. }
  107. // CA is the type used to build the complete certificate authority. It builds
  108. // the HTTP server, set ups the middlewares and the HTTP handlers.
  109. type CA struct {
  110. auth *authority.Authority
  111. config *config.Config
  112. srv *server.Server
  113. insecureSrv *server.Server
  114. opts *options
  115. renewer *TLSRenewer
  116. compactStop chan struct{}
  117. }
  118. // New creates and initializes the CA with the given configuration and options.
  119. func New(cfg *config.Config, opts ...Option) (*CA, error) {
  120. ca := &CA{
  121. config: cfg,
  122. opts: new(options),
  123. compactStop: make(chan struct{}),
  124. }
  125. ca.opts.apply(opts)
  126. return ca.Init(cfg)
  127. }
  128. // Init initializes the CA with the given configuration.
  129. func (ca *CA) Init(cfg *config.Config) (*CA, error) {
  130. // Set password, it's ok to set nil password, the ca will prompt for them if
  131. // they are required.
  132. opts := []authority.Option{
  133. authority.WithPassword(ca.opts.password),
  134. authority.WithSSHHostPassword(ca.opts.sshHostPassword),
  135. authority.WithSSHUserPassword(ca.opts.sshUserPassword),
  136. authority.WithIssuerPassword(ca.opts.issuerPassword),
  137. }
  138. if ca.opts.linkedCAToken != "" {
  139. opts = append(opts, authority.WithLinkedCAToken(ca.opts.linkedCAToken))
  140. }
  141. if ca.opts.database != nil {
  142. opts = append(opts, authority.WithDatabase(ca.opts.database))
  143. }
  144. if ca.opts.quiet {
  145. opts = append(opts, authority.WithQuietInit())
  146. }
  147. webhookTransport := http.DefaultTransport.(*http.Transport).Clone()
  148. opts = append(opts, authority.WithWebhookClient(&http.Client{Transport: webhookTransport}))
  149. auth, err := authority.New(cfg, opts...)
  150. if err != nil {
  151. return nil, err
  152. }
  153. ca.auth = auth
  154. tlsConfig, clientTLSConfig, err := ca.getTLSConfig(auth)
  155. if err != nil {
  156. return nil, err
  157. }
  158. webhookTransport.TLSClientConfig = clientTLSConfig
  159. // Using chi as the main router
  160. mux := chi.NewRouter()
  161. handler := http.Handler(mux)
  162. insecureMux := chi.NewRouter()
  163. insecureHandler := http.Handler(insecureMux)
  164. // Add HEAD middleware
  165. mux.Use(middleware.GetHead)
  166. insecureMux.Use(middleware.GetHead)
  167. // Add regular CA api endpoints in / and /1.0
  168. api.Route(mux)
  169. mux.Route("/1.0", func(r chi.Router) {
  170. api.Route(r)
  171. })
  172. // Mount the CRL to the insecure mux
  173. insecureMux.Get("/crl", api.CRL)
  174. insecureMux.Get("/1.0/crl", api.CRL)
  175. // Add ACME api endpoints in /acme and /1.0/acme
  176. dns := cfg.DNSNames[0]
  177. u, err := url.Parse("https://" + cfg.Address)
  178. if err != nil {
  179. return nil, err
  180. }
  181. port := u.Port()
  182. if port != "" && port != "443" {
  183. dns = fmt.Sprintf("%s:%s", dns, port)
  184. }
  185. // ACME Router is only available if we have a database.
  186. var acmeDB acme.DB
  187. var acmeLinker acme.Linker
  188. if cfg.DB != nil {
  189. acmeDB, err = acmeNoSQL.New(auth.GetDatabase().(nosql.DB))
  190. if err != nil {
  191. return nil, errors.Wrap(err, "error configuring ACME DB interface")
  192. }
  193. acmeLinker = acme.NewLinker(dns, "acme")
  194. mux.Route("/acme", func(r chi.Router) {
  195. acmeAPI.Route(r)
  196. })
  197. // Use 2.0 because, at the moment, our ACME api is only compatible with v2.0
  198. // of the ACME spec.
  199. mux.Route("/2.0/acme", func(r chi.Router) {
  200. acmeAPI.Route(r)
  201. })
  202. }
  203. // Admin API Router
  204. if cfg.AuthorityConfig.EnableAdmin {
  205. adminDB := auth.GetAdminDatabase()
  206. if adminDB != nil {
  207. acmeAdminResponder := adminAPI.NewACMEAdminResponder()
  208. policyAdminResponder := adminAPI.NewPolicyAdminResponder()
  209. webhookAdminResponder := adminAPI.NewWebhookAdminResponder()
  210. mux.Route("/admin", func(r chi.Router) {
  211. adminAPI.Route(
  212. r,
  213. adminAPI.WithACMEResponder(acmeAdminResponder),
  214. adminAPI.WithPolicyResponder(policyAdminResponder),
  215. adminAPI.WithWebhookResponder(webhookAdminResponder),
  216. )
  217. })
  218. }
  219. }
  220. var scepAuthority *scep.Authority
  221. if ca.shouldServeSCEPEndpoints() {
  222. scepPrefix := "scep"
  223. scepAuthority, err = scep.New(auth, scep.AuthorityOptions{
  224. Service: auth.GetSCEPService(),
  225. DNS: dns,
  226. Prefix: scepPrefix,
  227. })
  228. if err != nil {
  229. return nil, errors.Wrap(err, "error creating SCEP authority")
  230. }
  231. // According to the RFC (https://tools.ietf.org/html/rfc8894#section-7.10),
  232. // SCEP operations are performed using HTTP, so that's why the API is mounted
  233. // to the insecure mux.
  234. insecureMux.Route("/"+scepPrefix, func(r chi.Router) {
  235. scepAPI.Route(r)
  236. })
  237. // The RFC also mentions usage of HTTPS, but seems to advise
  238. // against it, because of potential interoperability issues.
  239. // Currently I think it's not bad to use HTTPS also, so that's
  240. // why I've kept the API endpoints in both muxes and both HTTP
  241. // as well as HTTPS can be used to request certificates
  242. // using SCEP.
  243. mux.Route("/"+scepPrefix, func(r chi.Router) {
  244. scepAPI.Route(r)
  245. })
  246. }
  247. // helpful routine for logging all routes
  248. //dumpRoutes(mux)
  249. //dumpRoutes(insecureMux)
  250. // Add monitoring if configured
  251. if len(cfg.Monitoring) > 0 {
  252. m, err := monitoring.New(cfg.Monitoring)
  253. if err != nil {
  254. return nil, err
  255. }
  256. handler = m.Middleware(handler)
  257. insecureHandler = m.Middleware(insecureHandler)
  258. }
  259. // Add logger if configured
  260. if len(cfg.Logger) > 0 {
  261. logger, err := logging.New("ca", cfg.Logger)
  262. if err != nil {
  263. return nil, err
  264. }
  265. handler = logger.Middleware(handler)
  266. insecureHandler = logger.Middleware(insecureHandler)
  267. }
  268. // Create context with all the necessary values.
  269. baseContext := buildContext(auth, scepAuthority, acmeDB, acmeLinker)
  270. ca.srv = server.New(cfg.Address, handler, tlsConfig)
  271. ca.srv.BaseContext = func(net.Listener) context.Context {
  272. return baseContext
  273. }
  274. // only start the insecure server if the insecure address is configured
  275. // and, currently, also only when it should serve SCEP endpoints.
  276. if ca.shouldServeInsecureServer() {
  277. // TODO: instead opt for having a single server.Server but two
  278. // http.Servers handling the HTTP and HTTPS handler? The latter
  279. // will probably introduce more complexity in terms of graceful
  280. // reload.
  281. ca.insecureSrv = server.New(cfg.InsecureAddress, insecureHandler, nil)
  282. ca.insecureSrv.BaseContext = func(net.Listener) context.Context {
  283. return baseContext
  284. }
  285. }
  286. return ca, nil
  287. }
  288. // shouldServeInsecureServer returns whether or not the insecure
  289. // server should also be started. This is (currently) only the case
  290. // if the insecure address has been configured AND when a SCEP
  291. // provisioner is configured or when a CRL is configured.
  292. func (ca *CA) shouldServeInsecureServer() bool {
  293. switch {
  294. case ca.config.InsecureAddress == "":
  295. return false
  296. case ca.shouldServeSCEPEndpoints():
  297. return true
  298. case ca.config.CRL.IsEnabled():
  299. return true
  300. default:
  301. return false
  302. }
  303. }
  304. // buildContext builds the server base context.
  305. func buildContext(a *authority.Authority, scepAuthority *scep.Authority, acmeDB acme.DB, acmeLinker acme.Linker) context.Context {
  306. ctx := authority.NewContext(context.Background(), a)
  307. if authDB := a.GetDatabase(); authDB != nil {
  308. ctx = db.NewContext(ctx, authDB)
  309. }
  310. if adminDB := a.GetAdminDatabase(); adminDB != nil {
  311. ctx = admin.NewContext(ctx, adminDB)
  312. }
  313. if scepAuthority != nil {
  314. ctx = scep.NewContext(ctx, scepAuthority)
  315. }
  316. if acmeDB != nil {
  317. ctx = acme.NewContext(ctx, acmeDB, acme.NewClient(), acmeLinker, nil)
  318. }
  319. return ctx
  320. }
  321. // Run starts the CA calling to the server ListenAndServe method.
  322. func (ca *CA) Run() error {
  323. var wg sync.WaitGroup
  324. errs := make(chan error, 1)
  325. if !ca.opts.quiet {
  326. authorityInfo := ca.auth.GetInfo()
  327. log.Printf("Starting %s", step.Version())
  328. log.Printf("Documentation: https://u.step.sm/docs/ca")
  329. log.Printf("Community Discord: https://u.step.sm/discord")
  330. if step.Contexts().GetCurrent() != nil {
  331. log.Printf("Current context: %s", step.Contexts().GetCurrent().Name)
  332. }
  333. log.Printf("Config file: %s", ca.getConfigFileOutput())
  334. baseURL := fmt.Sprintf("https://%s%s",
  335. authorityInfo.DNSNames[0],
  336. ca.config.Address[strings.LastIndex(ca.config.Address, ":"):])
  337. log.Printf("The primary server URL is %s", baseURL)
  338. log.Printf("Root certificates are available at %s/roots.pem", baseURL)
  339. if len(authorityInfo.DNSNames) > 1 {
  340. log.Printf("Additional configured hostnames: %s",
  341. strings.Join(authorityInfo.DNSNames[1:], ", "))
  342. }
  343. for _, crt := range authorityInfo.RootX509Certs {
  344. log.Printf("X.509 Root Fingerprint: %s", x509util.Fingerprint(crt))
  345. }
  346. if authorityInfo.SSHCAHostPublicKey != nil {
  347. log.Printf("SSH Host CA Key: %s\n", bytes.TrimSpace(authorityInfo.SSHCAHostPublicKey))
  348. }
  349. if authorityInfo.SSHCAUserPublicKey != nil {
  350. log.Printf("SSH User CA Key: %s\n", bytes.TrimSpace(authorityInfo.SSHCAUserPublicKey))
  351. }
  352. }
  353. wg.Add(1)
  354. go func() {
  355. defer wg.Done()
  356. ca.runCompactJob()
  357. }()
  358. if ca.insecureSrv != nil {
  359. wg.Add(1)
  360. go func() {
  361. defer wg.Done()
  362. errs <- ca.insecureSrv.ListenAndServe()
  363. }()
  364. }
  365. wg.Add(1)
  366. go func() {
  367. defer wg.Done()
  368. errs <- ca.srv.ListenAndServe()
  369. }()
  370. // wait till error occurs; ensures the servers keep listening
  371. err := <-errs
  372. wg.Wait()
  373. return err
  374. }
  375. // Stop stops the CA calling to the server Shutdown method.
  376. func (ca *CA) Stop() error {
  377. close(ca.compactStop)
  378. ca.renewer.Stop()
  379. if err := ca.auth.Shutdown(); err != nil {
  380. log.Printf("error stopping ca.Authority: %+v\n", err)
  381. }
  382. var insecureShutdownErr error
  383. if ca.insecureSrv != nil {
  384. insecureShutdownErr = ca.insecureSrv.Shutdown()
  385. }
  386. secureErr := ca.srv.Shutdown()
  387. if insecureShutdownErr != nil {
  388. return insecureShutdownErr
  389. }
  390. return secureErr
  391. }
  392. // Reload reloads the configuration of the CA and calls to the server Reload
  393. // method.
  394. func (ca *CA) Reload() error {
  395. cfg, err := config.LoadConfiguration(ca.opts.configFile)
  396. if err != nil {
  397. return errors.Wrap(err, "error reloading ca configuration")
  398. }
  399. logContinue := func(reason string) {
  400. log.Println(reason)
  401. log.Println("Continuing to run with the original configuration.")
  402. log.Println("You can force a restart by sending a SIGTERM signal and then restarting the step-ca.")
  403. }
  404. // Do not allow reload if the database configuration has changed.
  405. if !reflect.DeepEqual(ca.config.DB, cfg.DB) {
  406. logContinue("Reload failed because the database configuration has changed.")
  407. return errors.New("error reloading ca: database configuration cannot change")
  408. }
  409. newCA, err := New(cfg,
  410. WithPassword(ca.opts.password),
  411. WithSSHHostPassword(ca.opts.sshHostPassword),
  412. WithSSHUserPassword(ca.opts.sshUserPassword),
  413. WithIssuerPassword(ca.opts.issuerPassword),
  414. WithLinkedCAToken(ca.opts.linkedCAToken),
  415. WithQuiet(ca.opts.quiet),
  416. WithConfigFile(ca.opts.configFile),
  417. WithDatabase(ca.auth.GetDatabase()),
  418. )
  419. if err != nil {
  420. logContinue("Reload failed because the CA with new configuration could not be initialized.")
  421. return errors.Wrap(err, "error reloading ca")
  422. }
  423. if ca.insecureSrv != nil {
  424. if err = ca.insecureSrv.Reload(newCA.insecureSrv); err != nil {
  425. logContinue("Reload failed because insecure server could not be replaced.")
  426. return errors.Wrap(err, "error reloading insecure server")
  427. }
  428. }
  429. if err = ca.srv.Reload(newCA.srv); err != nil {
  430. logContinue("Reload failed because server could not be replaced.")
  431. return errors.Wrap(err, "error reloading server")
  432. }
  433. // 1. Stop previous renewer
  434. // 2. Safely shutdown any internal resources (e.g. key manager)
  435. // 3. Replace ca properties
  436. // Do not replace ca.srv
  437. ca.renewer.Stop()
  438. ca.auth.CloseForReload()
  439. ca.auth = newCA.auth
  440. ca.config = newCA.config
  441. ca.opts = newCA.opts
  442. ca.renewer = newCA.renewer
  443. return nil
  444. }
  445. // get TLSConfig returns separate TLSConfigs for server and client with the
  446. // same self-renewing certificate.
  447. func (ca *CA) getTLSConfig(auth *authority.Authority) (*tls.Config, *tls.Config, error) {
  448. // Create initial TLS certificate
  449. tlsCrt, err := auth.GetTLSCertificate()
  450. if err != nil {
  451. return nil, nil, err
  452. }
  453. // Start tls renewer with the new certificate.
  454. // If a renewer was started, attempt to stop it before.
  455. if ca.renewer != nil {
  456. ca.renewer.Stop()
  457. }
  458. ca.renewer, err = NewTLSRenewer(tlsCrt, auth.GetTLSCertificate)
  459. if err != nil {
  460. return nil, nil, err
  461. }
  462. ca.renewer.Run()
  463. var serverTLSConfig *tls.Config
  464. if ca.config.TLS != nil {
  465. serverTLSConfig = ca.config.TLS.TLSConfig()
  466. } else {
  467. serverTLSConfig = &tls.Config{
  468. MinVersion: tls.VersionTLS12,
  469. }
  470. }
  471. // GetCertificate will only be called if the client supplies SNI
  472. // information or if tlsConfig.Certificates is empty.
  473. // When client requests are made using an IP address (as opposed to a domain
  474. // name) the server does not receive any SNI and may fallback to using the
  475. // first entry in the Certificates attribute; by setting the attribute to
  476. // empty we are implicitly forcing GetCertificate to be the only mechanism
  477. // by which the server can find it's own leaf Certificate.
  478. serverTLSConfig.Certificates = []tls.Certificate{}
  479. clientTLSConfig := serverTLSConfig.Clone()
  480. serverTLSConfig.GetCertificate = ca.renewer.GetCertificateForCA
  481. clientTLSConfig.GetClientCertificate = ca.renewer.GetClientCertificate
  482. // initialize a certificate pool with root CA certificates to trust when doing mTLS.
  483. certPool := x509.NewCertPool()
  484. // initialize a certificate pool with root CA certificates to trust when connecting
  485. // to webhook servers
  486. rootCAsPool, err := x509.SystemCertPool()
  487. if err != nil {
  488. return nil, nil, err
  489. }
  490. for _, crt := range auth.GetRootCertificates() {
  491. certPool.AddCert(crt)
  492. rootCAsPool.AddCert(crt)
  493. }
  494. // adding the intermediate CA certificates to the pool will allow clients that
  495. // do mTLS but don't send an intermediate to successfully connect. The intermediates
  496. // added here are used when building a certificate chain.
  497. intermediates := tlsCrt.Certificate[1:]
  498. for _, certBytes := range intermediates {
  499. cert, err := x509.ParseCertificate(certBytes)
  500. if err != nil {
  501. return nil, nil, err
  502. }
  503. certPool.AddCert(cert)
  504. rootCAsPool.AddCert(cert)
  505. }
  506. // Add support for mutual tls to renew certificates
  507. serverTLSConfig.ClientAuth = tls.VerifyClientCertIfGiven
  508. serverTLSConfig.ClientCAs = certPool
  509. clientTLSConfig.RootCAs = rootCAsPool
  510. return serverTLSConfig, clientTLSConfig, nil
  511. }
  512. // shouldServeSCEPEndpoints returns if the CA should be
  513. // configured with endpoints for SCEP. This is assumed to be
  514. // true if a SCEPService exists, which is true in case a
  515. // SCEP provisioner was configured.
  516. func (ca *CA) shouldServeSCEPEndpoints() bool {
  517. return ca.auth.GetSCEPService() != nil
  518. }
  519. //nolint:unused // useful for debugging
  520. func dumpRoutes(mux chi.Routes) {
  521. // helpful routine for logging all routes
  522. walkFunc := func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
  523. fmt.Printf("%s %s\n", method, route)
  524. return nil
  525. }
  526. if err := chi.Walk(mux, walkFunc); err != nil {
  527. fmt.Printf("Logging err: %s\n", err.Error())
  528. }
  529. }
  530. func (ca *CA) getConfigFileOutput() string {
  531. if ca.config.WasLoadedFromFile() {
  532. return ca.config.Filepath()
  533. }
  534. return "loaded from token"
  535. }
  536. // runCompactJob will run the value log garbage collector if the nosql database
  537. // supports it.
  538. func (ca *CA) runCompactJob() {
  539. caDB, ok := ca.auth.GetDatabase().(*db.DB)
  540. if !ok {
  541. return
  542. }
  543. compactor, ok := caDB.DB.(nosql.Compactor)
  544. if !ok {
  545. return
  546. }
  547. // Compact database at start.
  548. runCompact(compactor)
  549. // Compact database every minute.
  550. ticker := time.NewTicker(time.Minute)
  551. defer ticker.Stop()
  552. for {
  553. select {
  554. case <-ca.compactStop:
  555. return
  556. case <-ticker.C:
  557. runCompact(compactor)
  558. }
  559. }
  560. }
  561. // runCompact executes the compact job until it returns an error.
  562. func runCompact(c nosql.Compactor) {
  563. for err := error(nil); err == nil; {
  564. err = c.Compact(0.7)
  565. }
  566. }