Do not use InheritedThreadLocal for SecurityRequestContext

Description

Using InheritedThreadLocal with any kind of executor pool is dangerous because executor pools spin up threads on-demand when a job is submitted; they do not necessarily warm up the pool. Since those executors may be reused, this can cause the SecurityRequestContext (i.e. user ID and credentials) to be transferred to a different request.

This specifically happens in the /run endpoint of system workers; the call eventually gets sent to a downstream ScheduledExecutorService which will inherit the first tasks’s SecurityRequestContext, but following tasks will continue to use the previous SecurityRequestContext since it is not reset.

This is also demonstrated in the below code; specifically, the second task is forced to spawn a new thread because the first task is in an infinite while loop. However, the third task will print test 2 instead of the expected test 3 because it inherits the threadlocal set before the second task:

Release Notes

Fixed an error in security-enabled instances which caused pipeline launch to fail and return `token expired` to the user when evaluating secure macros in provisioner properties.

Activity

Show:

kullai test1 February 24, 2023 at 1:49 PM

fdsfsfsd

Dennis Li February 23, 2023 at 7:59 PM

Validated the fix in both 6.7.3 and 6.8.1.

Pandiyan Appavu January 13, 2023 at 12:13 AM

Dennis, please update the status on this.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Affects versions

Triaged

No

Components

Fix versions

Due date

Priority

Created November 29, 2022 at 10:09 PM
Updated February 24, 2023 at 1:49 PM
Resolved February 10, 2023 at 6:01 AM