diff --git a/go.mod b/go.mod index d9f03797eff3a..9b5ac513a3a32 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 2371b1a54f06d..2dbd97aa66b4c 100644 --- a/go.sum +++ b/go.sum @@ -148,6 +148,8 @@ github.com/DataDog/ebpf-manager v0.0.0-20220627174516-12adb97b679e h1:MsSGtI99s8 github.com/DataDog/ebpf-manager v0.0.0-20220627174516-12adb97b679e/go.mod h1:8bqjDI64T80GHECNIJp9nY4+0mgX4Tc+Kcdk3p0NeIA= github.com/DataDog/extendeddaemonset v0.7.1-0.20220530183123-9c60ea5abbc6 h1:XDD6SEIEpe5CAa7esIWlgdXLQgLKN4hvPw+Wd8pJQFU= github.com/DataDog/extendeddaemonset v0.7.1-0.20220530183123-9c60ea5abbc6/go.mod h1:YxkO6rhI37nstfxBAdk4fVi5kheKJRMk9AtqDdl/mSQ= +github.com/DataDog/go-tuf v0.3.0--fix-localmeta h1:lM/fRQNIaJpsnLU7edjV3jYHylCym0Ah+kvoJWRTzsk= +github.com/DataDog/go-tuf v0.3.0--fix-localmeta/go.mod h1:E5XP0wXitrFUHe4b8cUcAAdxBW4LbfnqF4WXXGLgWNo= github.com/DataDog/gohai v0.0.0-20220823152657-b201b8a4ebec h1:BB0E2Ij4/rO6RANy91r9ND27PtPLcdrwUJJ27B2CbIY= github.com/DataDog/gohai v0.0.0-20220823152657-b201b8a4ebec/go.mod h1:oyPC4jWHHjVVNjslDAKp8EqfQBaSmODjHt4HCX+C+9Q= github.com/DataDog/gopsutil v0.0.0-20200624212600-1b53412ef321/go.mod h1:tGQp6XG4XpOyy67WG/YWXVxzOY6LejK35e8KcQhtRIQ= @@ -1649,8 +1651,6 @@ github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00 h1:mujcChM89zOHwgZBBN github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0= github.com/tedsuo/rata v1.0.0 h1:Sf9aZrYy6ElSTncjnGkyC2yuVvz5YJetBIUKJ4CmeKE= github.com/tedsuo/rata v1.0.0/go.mod h1:X47ELzhOoLbfFIY0Cql9P6yo3Cdwf2CMX3FVZxRzJPc= -github.com/theupdateframework/go-tuf v0.3.0 h1:od2sc5+BSkKZhmUG2o2rmruy0BGSmhrbDhCnpxh87X8= -github.com/theupdateframework/go-tuf v0.3.0/go.mod h1:E5XP0wXitrFUHe4b8cUcAAdxBW4LbfnqF4WXXGLgWNo= github.com/tidwall/assert v0.1.0/go.mod h1:QLYtGyeqse53vuELQheYl9dngGCJQ+mTtlxcktb+Kj8= github.com/tidwall/btree v0.3.0/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8= github.com/tidwall/btree v1.1.0/go.mod h1:TzIRzen6yHbibdSfK6t8QimqbUnoxUSrZfeW7Uob0q4= diff --git a/pkg/config/remote/uptane/client.go b/pkg/config/remote/uptane/client.go index 33a35b0827fdd..a5bbb4010a28a 100644 --- a/pkg/config/remote/uptane/client.go +++ b/pkg/config/remote/uptane/client.go @@ -69,7 +69,7 @@ func NewClient(cacheDB *bbolt.DB, cacheKey string, orgID int64) (*Client, error) return c, nil } -// Update updates the uptane client +// Update updates the uptane client and rollbacks in case of error func (c *Client) Update(response *pbgo.LatestConfigsResponse) error { c.Lock() defer c.Unlock() @@ -79,20 +79,28 @@ func (c *Client) Update(response *pbgo.LatestConfigsResponse) error { // the defer is present to be sure a transaction is never left behind. defer c.transactionalStore.rollback() - err := c.updateRepos(response) + err := c.update(response) 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) return err } - err = c.pruneTargetFiles() + return c.transactionalStore.commit() +} + +// update updates the uptane client +func (c *Client) update(response *pbgo.LatestConfigsResponse) error { + err := c.updateRepos(response) if err != nil { return err } - err = c.verify() + err = c.pruneTargetFiles() if err != nil { return err } - - return c.transactionalStore.commit() + return c.verify() } // TargetsCustom returns the current targets custom of this uptane client