SQL Agent Powershell step running as proxy 'loses' stored credential

stephen clover 1 Reputation point
2022-02-08T20:54:29.893+00:00

When I run a SQL Agent Powershell step 'as' a proxy credential (a domain service account), the credential which has been associated with the service account on the server is not accessible. The credential is for use to access an Azure fileshare.

The proxy is enabled for:

  • Operating System (CmdExec)
  • SSIS Package Execution
  • PowerShell

To reproduce (names of resources have been sanitised):

  1. Associate a stored credential for the fileshare with the proxy credential service account:
    172304-image.png
  2. Do the same for the SQL Agent service account:
    172305-image.png
  3. Set up a SQL Agent job with two steps which do the same thing, one running as the proxy credential and one as SQL Agent:
    172356-image.png
    172228-image.png
  4. Run the job.

Here's the output:
Step 1: Executed as user: DOMAIN_svc_MyCredential. domain_svc_mycredential Currently stored credentials: * NONE *. Process Exit Code 0. The step succeeded.
Step 2. Executed as user: DOMAIN_svc_SQLAgent. domain_svc_sqlagent Currently stored credentials: Target: Domain:target=azurefilesharename.file.core.windows.net Type: Domain Password User: fileshareuser. Process Exit Code 0. The step succeeded.

I can't find anything online to explain why the stored credential is not available to the step running as the proxy credential account.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rodrigo Ribeiro 27 Reputation points
    2023-02-22T01:39:42.2766667+00:00

    I guess explanation is in Credential API: https://learn.microsoft.com/en-us/windows/win32/api/wincred/nf-wincred-credreadw

    User's image

    When using Proxy, SQL Agent start process with new user credentials, and this open a new Network Logon Session for that user.

    When using SQL Server Agent Account, the process opens under service logon session type and this have a credential set.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.