Moderate severityNVD Advisory· Published Oct 2, 2024· Updated Oct 2, 2024
CVE-2024-7558
CVE-2024-7558
Description
JUJU_CONTEXT_ID is a predictable authentication secret. On a Juju machine (non-Kubernetes) or Juju charm container (on Kubernetes), an unprivileged user in the same network namespace can connect to an abstract domain socket and guess the JUJU_CONTEXT_ID value. This gives the unprivileged user access to the same information and tools as the Juju charm.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
github.com/juju/jujuGo | < 0.0.0-20240826044107-ecd7e2d0e986 | 0.0.0-20240826044107-ecd7e2d0e986 |
Affected products
1- Range: 3.5
Patches
1ecd7e2d0e986fix: use cryptographic random suffix for context id
2 files changed · +39 −11
worker/uniter/runner/context/contextfactory.go+22 −11 modified@@ -4,9 +4,9 @@ package context import ( + "crypto/rand" + "encoding/hex" "fmt" - "math/rand" - "time" "github.com/juju/charm/v8/hooks" "github.com/juju/errors" @@ -88,9 +88,6 @@ type contextFactory struct { // Callback to get relation state snapshot. getRelationInfos RelationsFunc relationCaches map[int]*RelationCache - - // For generating "unique" context ids. - rand *rand.Rand } // FactoryConfig contains configuration values @@ -149,7 +146,6 @@ func NewContextFactory(config FactoryConfig) (ContextFactory, error) { machineTag: machineTag, getRelationInfos: config.GetRelationInfos, relationCaches: map[int]*RelationCache{}, - rand: rand.New(rand.NewSource(time.Now().Unix())), clock: config.Clock, zone: zone, principal: principal, @@ -160,8 +156,14 @@ func NewContextFactory(config FactoryConfig) (ContextFactory, error) { // newId returns a probably-unique identifier for a new context, containing the // supplied string. -func (f *contextFactory) newId(name string) string { - return fmt.Sprintf("%s-%s-%d", f.unit.Name(), name, f.rand.Int63()) +func (f *contextFactory) newId(name string) (string, error) { + randomData := [16]byte{} + _, err := rand.Read(randomData[:]) + if err != nil { + return "", fmt.Errorf("cannot generate id for hook context: %w", err) + } + randomComponent := hex.EncodeToString(randomData[:]) + return fmt.Sprintf("%s-%s-%s", f.unit.Name(), name, randomComponent), nil } // coreContext creates a new context with all unspecialised fields filled in. @@ -214,7 +216,10 @@ func (f *contextFactory) ActionContext(actionData *ActionData) (*HookContext, er return nil, errors.Trace(err) } ctx.actionData = actionData - ctx.id = f.newId(actionData.Name) + ctx.id, err = f.newId(actionData.Name) + if err != nil { + return nil, errors.Trace(err) + } return ctx, nil } @@ -264,7 +269,10 @@ func (f *contextFactory) HookContext(hookInfo hook.Info) (*HookContext, error) { if hookInfo.Kind == hooks.PreSeriesUpgrade { ctx.seriesUpgradeTarget = hookInfo.SeriesUpgradeTarget } - ctx.id = f.newId(hookName) + ctx.id, err = f.newId(hookName) + if err != nil { + return nil, errors.Trace(err) + } ctx.hookName = hookName return ctx, nil } @@ -282,7 +290,10 @@ func (f *contextFactory) CommandContext(commandInfo CommandInfo) (*HookContext, } ctx.relationId = relationId ctx.remoteUnitName = remoteUnitName - ctx.id = f.newId("run-commands") + ctx.id, err = f.newId("run-commands") + if err != nil { + return nil, errors.Trace(err) + } return ctx, nil }
worker/uniter/runner/context/contextfactory_test.go+17 −0 modified@@ -4,7 +4,9 @@ package context_test import ( + "encoding/hex" "os" + "strings" "time" "github.com/juju/charm/v8/hooks" @@ -193,6 +195,21 @@ func (s *ContextFactorySuite) TestNewActionContextLeadershipContext(c *gc.C) { }) } +func (s *ContextFactorySuite) TestHookContextID(c *gc.C) { + hi := hook.Info{ + Kind: hooks.Install, + } + ctx, err := s.factory.HookContext(hi) + c.Assert(err, jc.ErrorIsNil) + + v := strings.Split(ctx.Id(), "-") + c.Assert(v, gc.HasLen, 3) + + randomComponent, err := hex.DecodeString(v[2]) + c.Assert(err, jc.ErrorIsNil) + c.Assert(randomComponent, gc.HasLen, 16) +} + func (s *ContextFactorySuite) TestRelationHookContext(c *gc.C) { hi := hook.Info{ Kind: hooks.RelationBroken,
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
6- github.com/advisories/GHSA-mh98-763h-m9v4ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2024-7558ghsaADVISORY
- github.com/juju/juju/commit/ecd7e2d0e9867576b9da04871e22232f06fa0cc7ghsaWEB
- github.com/juju/juju/security/advisories/GHSA-mh98-763h-m9v4ghsaissue-trackingWEB
- pkg.go.dev/vuln/GO-2024-3173ghsaWEB
- www.cve.org/CVERecordmitreissue-tracking
News mentions
0No linked articles in our index yet.