Skip to content

Commit

Permalink
fix: missing persister when initializing without network (#1525)
Browse files Browse the repository at this point in the history
* fix: missing persister when initializing without network

* chore: ignore CVE-2024-3154
  • Loading branch information
alnr authored Apr 30, 2024
1 parent 4d06291 commit e675d5b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .grype.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ ignore:
# see https://github.com/anchore/grype/issues/558
- vulnerability: CVE-2015-5237
- vulnerability: CVE-2021-22570
# https://github.com/opencontainers/runc/issues/4233
- vulnerability: CVE-2024-3154
- package:
name: github.com/opencontainers/runc
version: v1.1.12
2 changes: 2 additions & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Temp ignore, as 2.36-9+deb12u6 is not yet available in debian
CVE-2024-2961
# opencontainers/runc 1.2.0-rc.1 is incompatible with Go 1.22: https://github.com/opencontainers/runc/issues/4233
CVE-2024-3154
63 changes: 35 additions & 28 deletions internal/driver/registry_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ type (
mapper *relationtuple.Mapper
readOnlyMapper *relationtuple.Mapper

initialized sync.Once
init1, init2 sync.Once
init1err, init2err error

healthH *healthx.Handler
healthServer *health.Server
handlers []Handler
Expand Down Expand Up @@ -310,42 +312,47 @@ func (r *RegistryDefault) DetermineNetwork(ctx context.Context) (*networkx.Netwo
}

func (r *RegistryDefault) InitWithoutNetworkID(ctx context.Context) error {
if dbal.IsMemorySQLite(r.Config(ctx).DSN()) {
mb, err := r.MigrationBox(ctx)
if err != nil {
return err
r.init1.Do(func() {
if dbal.IsMemorySQLite(r.Config(ctx).DSN()) {
mb, err := r.MigrationBox(ctx)
if err != nil {
r.init1err = err
return
}

if err := mb.Up(ctx); err != nil {
r.init1err = err
return
}
}

if err := mb.Up(ctx); err != nil {
return err
p, err := sql.NewPersister(ctx, r, uuid.Nil)
if err != nil {
r.init1err = err
return
}
}
return nil
r.p = p
r.traverser = sql.NewTraverser(p)
})
return r.init1err
}

func (r *RegistryDefault) Init(ctx context.Context) (err error) {
r.initialized.Do(func() {
err = func() error {
if err := r.InitWithoutNetworkID(ctx); err != nil {
return err
}

network, err := r.DetermineNetwork(ctx)
if err != nil {
return err
}
r.init2.Do(func() {
if err := r.InitWithoutNetworkID(ctx); err != nil {
r.init2err = err
return
}

p, err := sql.NewPersister(ctx, r, network.ID)
if err != nil {
return err
}
r.p = p
r.traverser = sql.NewTraverser(p)
network, err := r.DetermineNetwork(ctx)
if err != nil {
r.init2err = err
return
}

return nil
}()
r.p.SetNetwork(network.ID)
})
return
return r.init2err
}

var _ x.TransactorProvider = (*RegistryDefault)(nil)
Expand Down
1 change: 1 addition & 0 deletions internal/persistence/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type (

Connection(ctx context.Context) *pop.Connection
NetworkID(ctx context.Context) uuid.UUID
SetNetwork(nid uuid.UUID)
Transaction(ctx context.Context, f func(ctx context.Context) error) error
}
Migrator interface {
Expand Down
4 changes: 4 additions & 0 deletions internal/persistence/sql/persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func (p *Persister) NetworkID(ctx context.Context) uuid.UUID {
return p.d.Contextualizer().Network(ctx, p.nid)
}

func (p *Persister) SetNetwork(nid uuid.UUID) {
p.nid = nid
}

func internalPaginationFromOptions(opts ...x.PaginationOptionSetter) (*internalPagination, error) {
xp := x.GetPaginationOptions(opts...)
ip := &internalPagination{
Expand Down
2 changes: 0 additions & 2 deletions internal/persistence/sql/traverser.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type (
Traverser struct {
conn *pop.Connection
d dependencies
nid uuid.UUID
p *Persister
}

Expand Down Expand Up @@ -195,7 +194,6 @@ func NewTraverser(p *Persister) *Traverser {
return &Traverser{
conn: p.conn,
d: p.d,
nid: p.nid,
p: p,
}
}

0 comments on commit e675d5b

Please sign in to comment.