Skip to content

Commit dae0ac7

Browse files
authored
fix(api): permission on worker that are no more linked to an hatchery (#5303)
1 parent c6150a2 commit dae0ac7

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

engine/api/ascode/pull_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func UpdateAsCodeResult(ctx context.Context, db *gorp.DbMap, store cache.Store,
5151
if err != nil {
5252
globalErr = err
5353
}
54-
sdk.GoRoutine(context.Background(), fmt.Sprintf("UpdateAsCodeResult-pusblish-as-code-event-%s", asCodeEvent.ID), func(ctx context.Context) {
54+
sdk.GoRoutine(context.Background(), fmt.Sprintf("UpdateAsCodeResult-pusblish-as-code-event-%d", asCodeEvent.ID), func(ctx context.Context) {
5555
event.PublishAsCodeEvent(ctx, proj.Key, workflowHolder.Name, *asCodeEvent, u)
5656
})
5757
}

engine/api/worker.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,11 @@ func (api *API) disableWorkerHandler() service.Handler {
153153
if err != nil {
154154
return sdk.WrapError(sdk.ErrForbidden, "Cannot disable a worker from this hatchery: %v", err)
155155
}
156-
if wk.HatcheryID != nil && *wk.HatcheryID != hatcherySrv.ID {
157-
return sdk.WrapError(sdk.ErrForbidden, "Cannot disable a worker from hatchery (expected: %d/actual: %d)", wk.HatcheryID, hatcherySrv.ID)
156+
if wk.HatcheryID == nil {
157+
return sdk.WrapError(sdk.ErrForbidden, "hatchery %d cannot disable worker %s started by %s that is no more linked to an hatchery", hatcherySrv.ID, wk.ID, wk.HatcheryName)
158+
}
159+
if *wk.HatcheryID != hatcherySrv.ID {
160+
return sdk.WrapError(sdk.ErrForbidden, "cannot disable a worker from hatchery (expected: %d/actual: %d)", *wk.HatcheryID, hatcherySrv.ID)
158161
}
159162
}
160163

engine/cdn/cdn_log.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,15 @@ func (s *Service) handleServiceLog(ctx context.Context, hatcheryID int64, hatche
213213
_, ok = logCache.Get(workerCacheKey)
214214
if !ok {
215215
// Verify that the worker has been spawn by this hatchery
216-
w, err := worker.LoadWorkerByName(ctx, s.Db, workerName)
216+
wk, err := worker.LoadWorkerByName(ctx, s.Db, workerName)
217217
if err != nil {
218218
return err
219219
}
220-
if w.HatcheryID != nil && *w.HatcheryID != signature.Service.HatcheryID {
221-
return sdk.WrapError(sdk.ErrWrongRequest, "hatchery and worker does not match")
220+
if wk.HatcheryID == nil {
221+
return sdk.WrapError(sdk.ErrWrongRequest, "hatchery %d cannot send service log for worker %s started by %s that is no more linked to an hatchery", signature.Service.HatcheryID, wk.ID, wk.HatcheryName)
222+
}
223+
if *wk.HatcheryID != signature.Service.HatcheryID {
224+
return sdk.WrapError(sdk.ErrWrongRequest, "cannot send service log for worker %s from hatchery (expected: %d/actual: %d)", wk.ID, *wk.HatcheryID, signature.Service.HatcheryID)
222225
}
223226
logCache.Set(workerCacheKey, true, gocache.DefaultExpiration)
224227
}

0 commit comments

Comments
 (0)