core icon indicating copy to clipboard operation
core copied to clipboard

[DEFECT] Secrets during automated workflow action not resolving as expected

Open ihoffmann-dot opened this issue 8 months ago • 3 comments

Problem Statement

We have an issue when the SecretTool is invoked outside of a standard HTTP request context (such as during a scheduled job or an automated workflow action). In this scenario the system fails to correctly resolve secrets. This happens because the permission evaluation for accessing secrets defaults to an anonymous user when no user is found in the current HTTP request, even if a valid system user is present in the execution context.

Technical Root Cause

The issue is located in the canUserEvaluate method of SecretTool. The logic strictly relies on WebAPILocator.getUserWebAPI().getUser(this.request) to identify the performing user.

  • HTTP Context: When triggered via a web request, the user is correctly retrieved from the request object.
  • Job Context: When triggered via a background job (e.g., a scheduled publication), this.request does not contain a logged-in user, and getUser() returns an anonymous user.
  • The Mismatch: Even though the background execution context often carries the "System User" within the Velocity context object, SecretTool was not looking there. Since the anonymous user typically lacks the SCRIPTING_DEVELOPER role, the evaluation fails with a SecurityException, preventing the secret from being resolved.

Steps to Reproduce

  1. Ensure a System User exists in the instance.
  2. Create a secret in the Secrets App (e.g., Key: mySecret, Value: secretValue).
  3. Go to Workflows -> System Workflow and edit the Publish action.
  4. Add a Velocity Action Script sub-action that attempts to access the secret:
    #set($val = $dotsecrets.get("mySecret"))
    $logger.info("Secret value: $val")
    
  5. Create a new Content Type with a text field and a Date/Time field. Enable the System Indexed option for the Date/Time field.
  6. Edit the Content Type and set the newly created Date/Time field as the Publish Date field.
  7. Create a new Contentlet of this type. Set the Publish Date to a few minutes in the future.
  8. Click Publish. A notification should indicate the content is scheduled for future publication.
  9. Wait for the scheduled job to run.
  10. Actual Scenario: The content status changes to Published, but the secret is not resolved. Checking the logs reveals: Failed to evaluate Scripting Role presence: External scripting is disabled in your dotcms instance.
  11. Expected Scenario: The job should execute, the system user from the context should be recognized, and the secret should be resolved and logged correctly without security exceptions.

Acceptance Criteria

To resolve this issue, the following objective criteria must be met:

  • [ ] SecretTool must attempt to retrieve the user from the Velocity context if the user retrieved from the HttpServletRequest is null or anonymous.
  • [ ] The fallback mechanism should specifically look for the "user" key within the Velocity context.
  • [ ] If a valid user (e.g., System User) is found in the context, it must be used to validate the SCRIPTING_DEVELOPER role.
  • [ ] Existing behavior for standard HTTP requests must remain unchanged.
  • [ ] Automated tasks (like scheduled publishing) utilizing SecretTool must be able to resolve secrets successfully.

dotCMS Version

main

Severity

Medium - Some functionality impacted

Links

Freshdesk ticket #35344

ihoffmann-dot avatar Mar 06 '26 21:03 ihoffmann-dot

QA Failed The fix works partially. For secrets stored under the System Host, it works fine and the secret is retrieved as expected. However, for contentlets that belongs to a specific site, secrets stored for that specific host are not retrieved.

Steps to replicate the failed scenario:

  1. Create a new secret in the Dot Velocity Secrets app, and save the secret for a specific site different from the system host (for example use "default" site).
  2. Create a site field for the content type.
  3. Create a new contentlet and set the field site to point to the site that contains the stored secret(default site).
  4. Set the Publish Date for the new contentlet a few minutes in the future and save the content.
  5. Wait for the auto publish job to run.
  6. The secret stored for the site assigned to the contentlet wasn't retrieved as expected.

dsolistorres avatar Mar 13 '26 16:03 dsolistorres

QA Passed It works as expected now: the secret is retrieved from the config for the site that the content belongs.

dsolistorres avatar Apr 09 '26 01:04 dsolistorres