Wednesday, May 10, 2017

Azure Automation Runbooks: Who ran me?

One of the interesting challenges with Azure automation is enforcing security throughout the runbook process.  As I have mentioned in previous posts, permissions within the system are not super granular and automation jobs execute in a service account context.

It turns out there is a way to at determine who actually executed a particular runbook.  You could use this identity in authorization/authentication decisions within the runbook as required.  It is important to note that this is a string reference to the email address of the person running the runbook.  This is set by the system, so trust it if you wish!

The first part is to get the job id of the currently running job.  You can accomplish this by looking at the $PSPrivateMetadata object which contains a JobId.  For example,


$jobId = $PSPrivateMetadata.JobId.Guid
$jobId

The second part is using this job ID and the Get-AzureRMAutomationJob cmdlet to determine who ran the runbook.  For example,


$job = Get-AzureRmAutomationJob -Id $jobId -ResourceGroupName "resourceGroup" -AutomationAccountName "automationAccount"
$job 

Keep in mind that you do need to log in to Azure to run the above command.  After this, the output looks like this:





As you can see, there is a StartedBy property that contains my email address.  You can now use that string to make decisions in your automation runbooks.

One interesting thing to note is that "StartBy" appears blank when you use the "Test Draft In Azure" functionality of the Automation Authoring Toolkit.

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Looking for wire crimping machine ? Then we are the best for you, who suit your expectations. We have huge experience on this field. We are 100% dedicated to find you wire crimping machine.
    We are dedicated to manufacturing and sales of a wide range of wire crimping machines including pneumatic crimping tool for crimp clamps.
    You can find here your best one.
    If you want to know more, Please check out Cheers Electronic Technical Co., LTD: https://www.terminal-crimping.com/

    ReplyDelete
  3. I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! Feedback Analytics

    ReplyDelete
  4. I have completed my all projects about Azure automation with the help of Buy Dissertation Online which is the best place for taking assistance online.

    ReplyDelete
  5. The retail business is feeling the squeeze. The business edges are focused, there are consistently increasing costs, rising requests from the providers to pass on more crude materials, high speculation to remain ahead in the opposition. With the cost pressure ever on the ascent, retailers have turned towards automation to reinforce and uphold their edge pressures. material handling automatic cart

    ReplyDelete