Skip to content

Commit

Permalink
Merge pull request #171 from cybozu-go/robust
Browse files Browse the repository at this point in the history
sabakan-cryptsetup: retry sabakan API calls.
  • Loading branch information
Hiroshi Muraoka authored Aug 23, 2019
2 parents dc35e02 + 9cf9021 commit 8c1db06
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 15 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [2.4.6] - 2019-08-23

### Changed
- Update etcd to 3.3.15 and etcdutil to 1.3.3 (#171).
- sabakan-cryptsetup: retry sabakan API calls (#171).

### Changed

## [2.4.5] - 2019-08-19

### Changed
Expand All @@ -15,7 +23,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Added

- [sabakan-cryptsetup] TPM 2.0 support (#164).
- sabakan-cryptsetup: TPM 2.0 support (#164).

## [2.4.3] - 2019-07-04

Expand Down Expand Up @@ -134,7 +142,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

See [CHANGELOG-0](./CHANGELOG-0.md).

[Unreleased]: https://github.com/cybozu-go/sabakan/compare/v2.4.5...HEAD
[Unreleased]: https://github.com/cybozu-go/sabakan/compare/v2.4.6...HEAD
[2.4.6]: https://github.com/cybozu-go/sabakan/compare/v2.4.5...v2.4.6
[2.4.5]: https://github.com/cybozu-go/sabakan/compare/v2.4.4...v2.4.5
[2.4.4]: https://github.com/cybozu-go/sabakan/compare/v2.4.3...v2.4.4
[2.4.3]: https://github.com/cybozu-go/sabakan/compare/v2.4.2...v2.4.3
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ require (
github.com/99designs/gqlgen v0.9.3
github.com/agnivade/levenshtein v1.0.2 // indirect
github.com/ajeddeloh/go-json v0.0.0-20170920214419-6a2fe990e083 // indirect
github.com/coreos/etcd v0.0.0-20190816232144-5cf5d88a18ae
github.com/coreos/etcd v3.3.15+incompatible
github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 // indirect
github.com/coreos/ignition v0.30.0
github.com/cybozu-go/etcdutil v1.3.2
github.com/cybozu-go/etcdutil v1.3.3
github.com/cybozu-go/log v1.5.0
github.com/cybozu-go/netutil v1.2.0
github.com/cybozu-go/well v1.8.1
Expand All @@ -17,6 +17,7 @@ require (
github.com/google/subcommands v0.0.0-20181012225330-46f0354f6315
github.com/hashicorp/go-version v1.0.0
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
Expand Down
35 changes: 33 additions & 2 deletions pkg/sabakan-cryptsetup/cmd/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
sabakan "github.com/cybozu-go/sabakan/v2/client"
)

const maxRetry = 10

// Driver setup crypt devices.
type Driver struct {
serial string
Expand Down Expand Up @@ -139,6 +141,8 @@ func (d *Driver) setupDisk(ctx context.Context, disk Disk, tpmKek []byte) error
return d.formatDisk(ctx, disk, f, tpmKek)
}

var retries int
RETRY:
ek, err := d.sabakan.CryptsGet(ctx, d.serial, md.HexID())
if err == nil {
log.Info("encryption key is found. run cryptsetup", map[string]interface{}{
Expand All @@ -152,7 +156,18 @@ func (d *Driver) setupDisk(ctx context.Context, disk Disk, tpmKek []byte) error
})
return d.formatDisk(ctx, disk, f, tpmKek)
}
return err

log.Error("failed to retrieve key from sabakan", map[string]interface{}{
log.FnError: err,
"disk": disk.Name(),
"try": retries + 1,
})
if retries == maxRetry {
return err
}
retries++
time.Sleep(time.Duration(retries) * time.Second * 2)
goto RETRY
}

func (d *Driver) formatDisk(ctx context.Context, disk Disk, f *os.File, tpmKek []byte) error {
Expand Down Expand Up @@ -183,5 +198,21 @@ func (d *Driver) formatDisk(ctx context.Context, disk Disk, f *os.File, tpmKek [
return err
}

return d.sabakan.CryptsPut(ctx, d.serial, md.HexID(), ek)
var retries int
RETRY:
err = d.sabakan.CryptsPut(ctx, d.serial, md.HexID(), ek)
if err == nil {
return nil
}
log.Error("failed to send key to sabakan", map[string]interface{}{
log.FnError: err,
"disk": disk.Name(),
"try": retries + 1,
})
if retries == maxRetry {
return err
}
retries++
time.Sleep(time.Duration(retries) * time.Second * 2)
goto RETRY
}
7 changes: 6 additions & 1 deletion vendor/github.com/cybozu-go/etcdutil/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/github.com/cybozu-go/etcdutil/flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion vendor/github.com/cybozu-go/etcdutil/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ github.com/99designs/gqlgen/handler
github.com/99designs/gqlgen/complexity
# github.com/agnivade/levenshtein v1.0.2
github.com/agnivade/levenshtein
# github.com/coreos/etcd v0.0.0-20190816232144-5cf5d88a18ae
# github.com/coreos/etcd v3.3.15+incompatible
github.com/coreos/etcd/clientv3
github.com/coreos/etcd/clientv3/clientv3util
github.com/coreos/etcd/clientv3/concurrency
Expand Down Expand Up @@ -37,7 +37,7 @@ github.com/coreos/ignition/config/shared/validations
github.com/coreos/ignition/config/validate/report
# github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f
github.com/coreos/pkg/capnslog
# github.com/cybozu-go/etcdutil v1.3.2
# github.com/cybozu-go/etcdutil v1.3.3
github.com/cybozu-go/etcdutil
# github.com/cybozu-go/log v1.5.0
github.com/cybozu-go/log
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sabakan

// Version is sabakan version
const Version = "2.4.5"
const Version = "2.4.6"

// SchemaVersion is the schema version
const SchemaVersion = "3"

0 comments on commit 8c1db06

Please sign in to comment.