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

[RCM-432] fix(remote-config): Clean remote state on error & use fixed fork of go-tuf #13517

Merged
merged 3 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ replace (
github.com/lxn/walk => github.com/lxn/walk v0.0.0-20180521183810-02935bac0ab8
github.com/mholt/archiver => github.com/mholt/archiver v2.0.1-0.20171012052341-26cf5bb32d07+incompatible
github.com/spf13/cast => github.com/DataDog/cast v1.3.1-0.20190301154711-1ee8c8bd14a3
github.com/theupdateframework/go-tuf => github.com/DataDog/go-tuf v0.3.0--fix-localmeta
github.com/ugorji/go => github.com/ugorji/go v1.1.7
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum

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

20 changes: 17 additions & 3 deletions pkg/config/remote/uptane/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

rdata "github.com/DataDog/datadog-agent/pkg/config/remote/data"
"github.com/DataDog/datadog-agent/pkg/proto/pbgo"
"github.com/DataDog/datadog-agent/pkg/util/log"
)

// Client is an uptane client
Expand Down Expand Up @@ -69,17 +70,28 @@ func NewClient(cacheDB *bbolt.DB, cacheKey string, orgID int64) (*Client, error)
return c, nil
}

func (c *Client) rollback(err error) {
c.transactionalStore.rollback()
if err != nil {
c.configRemoteStore = newRemoteStoreConfig(c.targetStore)
c.directorRemoteStore = newRemoteStoreDirector(c.targetStore)
c.configTUFClient = client.NewClient(c.configLocalStore, c.configRemoteStore)
c.directorTUFClient = client.NewClient(c.directorLocalStore, c.directorRemoteStore)
}
}

// Update updates the uptane client
func (c *Client) Update(response *pbgo.LatestConfigsResponse) error {
c.Lock()
defer c.Unlock()
c.cachedVerify = false
var err error

// in case the commit is successful it is a no-op.
// the defer is present to be sure a transaction is never left behind.
defer c.transactionalStore.rollback()
defer func() { c.rollback(err) }()

err := c.updateRepos(response)
err = c.updateRepos(response)
if err != nil {
return err
}
Expand All @@ -91,8 +103,10 @@ func (c *Client) Update(response *pbgo.LatestConfigsResponse) error {
if err != nil {
return err
}
log.Infof("committing")
BaptisteFoy marked this conversation as resolved.
Show resolved Hide resolved

return c.transactionalStore.commit()
err = c.transactionalStore.commit()
return err
}

// TargetsCustom returns the current targets custom of this uptane client
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/remote/uptane/remote_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *remoteStore) latestVersion(r role) uint64 {
return latestVersion
}

// GetMeta implements go-tuf's RemoteStore.GetMeta
// GetMeta implements go-tuf's RemoteStore.<
BaptisteFoy marked this conversation as resolved.
Show resolved Hide resolved
// See https://pkg.go.dev/github.com/theupdateframework/go-tuf/client#RemoteStore
func (s *remoteStore) GetMeta(path string) (io.ReadCloser, int64, error) {
metaPath, err := parseMetaPath(path)
Expand Down