Newsletter #4 – Worthwhile gifts, MFA / password managers, and books

TinyLetter-4-1

Worthwhile gifts

Before I start, Christmas / birthdays / anniversaries / other important events != giving gifts as the primary focus in our house.  With that said, my wife and I have been reflecting on the gifts that we give to each other or other people.  For our kids we’ve been looking into more “experience” type gifts.  This could be a bowling night out, art classes, tickets to a kids musical, etc.  So far this is working well and helps our kids not to become consumed with “things” but instead making memories.  It helps that we take lots of pictures and then upload them to a digital frame that rotates through pictures from past years.

For my wife and I we’ve been looking into gifts that give both of us more time to spend with each other or help keep us in the moment.  I’ll share some examples.

  • Smart home garage door opener – auto-closes at night if accidentally left open, provides peace of mind when going to bed.
  • Cordless Dyson vacuum – can move from room to room and vacuum in half the time it used to take with corded, heavy canister-style vacuum we previously had.
  • WeMo smart switches for lights – we are slowly helping our 2 older kids learn to turn off lights when they leave a room.  In the meantime the ability to turn off all the basement lights without needing to go up and down the stairs while cooking dinner / feeding baby / doing ten other things is a big help.  I think I’ll be adding more of these over time to other rooms.

 

MFA / password managers

Another worth-while gift that you can give to your family / friends / coworkers / etc. is the (strong) encouragement to turn on multi-factor authentication (MFA) and use a password manager.  I’ve recently read two interesting articles online that highlight the need to secure your digital / online accounts:

  1. Your Pa$$word doesn’t matter
    • In majority of credential theft scenarios, password doesn’t matter as bad actor can obtain them
    • Don’t focus on password limitations, instead implement MFA and threat detection processes
    • If using password manager, then max out the length of password
    • Use of MFA reduces credential theft by 99.9% [this was enough to cement my thoughts]
  2. All your creds are belong to us!

Regarding a password manager, I registered the majority of the accounts that my wife and I share (Netflix, banking, mortgage, retirement plan, etc.)  If she needs to access them (heaven forbid if I were in a coma, passed away unexpectedly, or similar) she would need to access them.  By using a shared password manager (currently Lastpass family plan) those shared accounts can be accessed by either of us.  For any accounts that aren’t shared (personal email, etc.) my wife is also the emergency contact who can gain admin access in the event that would be needed.  Overall this gives both of us more peace of mind about planning for the future.

 

Books

Reading (blogs, online magazines, books, etc.) can introduce you to new ideas and keep your brain active to help you boost your creativity (see newsletter #2).  In the past few months I’ve had the pleasure to read (still in progress on the 3rd one) 3 books that have had a profound impact on me.  I want to share these with you in the hopes that you read them, incorporate their ideas into your own life, and if you feel moved to do so pass them along to others.

  • Leadership and Self-Deception: Getting Out of the Box
    • We “put ourselves into a box” when we let our own emotions or thoughts obscure our view of other people.  We can get out of this box and see others clearly when we shift our attitudes.  The applications of these concepts can apply to family, work, and other relationships / environments.  I highly recommend this book and I plan to re-read this again in the future.
  • Bullshit Jobs: A Theory
    • Excuse the language in the title of this book, but this book has profoundly changed the way I see my own work and the work of others.  As we as a human race move towards more automation and less reliance on manual labor the rise of BS jobs has increased.  This book goes into the history and current state of jobs, how people as a whole value their job / life, and ways to address the changing nature of jobs in the future.  I’m still internalizing many of the ideas brought up in this book but can see this making large changes to my life / work.
  • Be the Master (4th edition)
    • I am 2/3 of the way through this book but wanted to list it as well.  Be the Master focuses on how to become a master (does not mean a “know it all” or “expert in everything“) in your career and also how to share that with the next generation of workers.  You may have heard of many of the concepts discussed in this book, but Don does an excellent job of succinctly reviewing them and sharing stories / analogies to illustrate all of the points.

Do you have any worthwhile gifts (or books) that have made an impact for you?  Please share back if so.

-Frog Out

Creating a C# Azure Function to Call Microsoft Graph

This post is a part of The Third Annual C# Advent.

Building on my “Introduction to Calling Microsoft Graph from a C# .Net Core Application” post from the 2018 C# Advent event, this year we’ll take what we learned and adapt that code to run in an Azure Function.  I recommend reading that post (and the linked resources in it) first to get the background on creating and authenticating an Azure AD application.

Prerequisites

Background

Azure Functions is one of the serverless options within Azure (read here for more about Azure serverless solutions).  Azure Functions consist of a trigger (HTTP, timer, storage event, etc.) and optionally one or more input / output bindings.  I especially appreciate how triggers and input / output bindings reduce, or even completely remove, the need to write what I call “internal plumbing” code.  “Internal plumbing” code is the code required to connect to an Azure storage account, monitor for a webhook request, or similar event based functionality.  Having that functionality taken care of allows you as the developer to focus on writing the core business logic where the most value can be provided.

Speaking of bindings, you may notice on the Azure Functions documentation that there are Microsoft Graph bindings for Azure Functions as of version 2+.  I’m not on the product group but as far as I’m aware these bindings have been in preview for over 2 years and are not planned to move past preview.  As such this blog post will walk through calling Microsoft Graph using the Microsoft Graph .Net SDK.

The below steps can be seen in the sample repo at BTJ.CSAdvent.AZFunc on GitHub. Additionally the Develop Azure Functions by using Visual Studio Code documentation gives a good overview of the VS Code development process.

Create Azure Function

Open Visual Studio Code and open the Command Pallete (⇧⌘P or F1 on Mac, Ctrl+Shift+P or F1 on Windows).

  1. Search for “Azure Functions: Create New Project…” and select it.CSAdvent-MSGAZFunc1
  2. Choose a folder to create the project in (preferably not in a Visual Studio Code workspace).
  3. Select the language of the project as C#.
    CSAdvent-MSGAZFunc2
  4. Create an empty function project by selecting “Skip for now” when prompted for the trigger type.
    CSAdvent-MSGAZFunc3
  5. Open the Command Palette again and search for “Azure Functions: Create Function…” and select it.
    CSAdvent-MSGAZFunc4
  6. Select a TimerTrigger.
  7. Name the function “GetUserMicrosoftGraph” (or any name you wish, but later references will be impacted).
    CSAdvent-MSGAZFunc5
  8. Provide a namespace for the function.
  9. Use the default timer schedule “0 */5 * * * *” which is the CRON representation of running every 5 minutes.
  10. On the terminal at the root of the project run “dotnet build” to build the project.
    • If you are prompted to choose a storage account and are using Windows, select “Use local emulator”.
    • If you are on Mac / Linux, select “Select storage account” and specify a cloud Azure storage account.CSAdvent-MSGAZFunc6

At this point you should have an Azure Function project that should build successfully.

Add NuGet Packages

Since we’ll be calling Microsoft Graph and the MSAL .Net SDK libraries we’ll add the supporting NuGet packages with the following:

  1. Run “dotnet add package Microsoft.Graph” from the terminal.
  2. Run “dotnet add package Microsoft.Identity.Client” from the terminal.

Add Azure AD App Authentication

Open the local.settings.json file.  It should look similar to the following (AzureWebJobStorage may be different depending on choices above for storage).

CSAdvent-MSGAZFunc7

Add the following key/value pairs to the Values section.  Use the values from the Azure AD application that was created using the references in the linked articles above.

   "timerSchedule": "0 */5 * * * *",
   "AzureADAppTenantId": "YOUR_TENANT_ID_HERE",
   "AzureADAppClientId": "YOUR_CLIENT_ID_HERE",
   "AzureADAppClientSecret": "YOUR_CLIENT_SECRET_HERE",
   "AzureADAppRedirectUri": "YOUR_REDIRECT_URI_HERE"

Implement the sample code (link here) from last year’s post as helper classes to the project.  See AuthHandler.cs and MsalAuthenticationProvider.cs from the example repo.

CSAdvent-MSGAZFunc11

Call Microsoft Graph

Implement the following code (adapted from last year’s post, link here) inside the GetUserMicrosoftGraph.cs file.

 public static class GetUserMicrosoftGraph
    {
        private static GraphServiceClient _graphServiceClient;

        [FunctionName("GetUserMicrosoftGraph")]
        public static void Run([TimerTrigger("%timerSchedule%")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            //Query using Graph SDK (preferred when possible)
            GraphServiceClient graphClient = GetAuthenticatedGraphClient();
            List<QueryOption> options = new List<QueryOption>
            {
                new QueryOption("$top", "1")
            };

            var graphResult = graphClient.Users.Request(options).GetAsync().Result;
            log.LogInformation("Graph SDK Result");
            log.LogInformation(graphResult[0].DisplayName);
        }

        private static GraphServiceClient GetAuthenticatedGraphClient()
        {
            var authenticationProvider = CreateAuthorizationProvider();
            _graphServiceClient = new GraphServiceClient(authenticationProvider);
            return _graphServiceClient;
        }

        private static IAuthenticationProvider CreateAuthorizationProvider()
        {
            var clientId = System.Environment.GetEnvironmentVariable("AzureADAppClientId", EnvironmentVariableTarget.Process);
            var clientSecret = System.Environment.GetEnvironmentVariable("AzureADAppClientSecret", EnvironmentVariableTarget.Process);
            var redirectUri = System.Environment.GetEnvironmentVariable("AzureADAppRedirectUri", EnvironmentVariableTarget.Process);
            var tenantId = System.Environment.GetEnvironmentVariable("AzureADAppTenantId", EnvironmentVariableTarget.Process);
            var authority = $"https://login.microsoftonline.com/{tenantId}/v2.0";

            //this specific scope means that application will default to what is defined in the application registration rather than using dynamic scopes
            List<string> scopes = new List<string>();
            scopes.Add("https://graph.microsoft.com/.default");

            var cca = ConfidentialClientApplicationBuilder.Create(clientId)
                                              .WithAuthority(authority)
                                              .WithRedirectUri(redirectUri)
                                              .WithClientSecret(clientSecret)
                                              .Build();

            return new MsalAuthenticationProvider(cca, scopes.ToArray());;
        }
    }

Test Azure Function

Test out the Azure Function by doing the following:

  1. Run “dotnet build” from the terminal.
  2. Assuming the build is successful you can then execute the Azure Function locally by pressing the F5 key.

See below for sample output.

CSAdvent-MSGAZFunc12

Deploy Azure Function

The Azure Functions extension for Visual Studio Code makes the deployment process much easier.  Search for “Azure Functions: Deploy to Function App…” and select it.

CSAdvent-MSGAZFunc9

I already have a consumption based, Windows hosted Function App deployed in my Azure subscription but you can also create a new one if needed.  Select the subscription and Function App to deploy to.

Upload App Settings

When you develop the Azure Function locally you make use of the local.settings.json file which is automatically loaded as environment variables.  In Azure though you will need to create those configuration values as app settings on the Function App.  Rather than manually add / edit those values, search for “Azure Functions: Upload Local Settings…” and select it.  This will upload any values you have in your local.settings.json as app settings on the Function App.

IMPORTANT: If you specified the AzureWebJobsStorage key to use local storage, do not overwrite that value in Azure.  Instead use the cloud Azure storage account already specified.

CSAdvent-MSGAZFunc10

(Bonus) Add Key Vault Integration for Client Secret

While it is possible to specify the Azure AD app secret in the Function App configuration settings (stored encrypted), anyone with read / edit access to the Function App will be able to view that value as plain text through the Azure portal.  As such it is recommended to store the value in Azure Key Vault or similar location.  To specify a location in Azure Key Vault following the documentation on Use Key Vault references for App Service and Azure Functions.

The reference in your Function App configuration will now look something like the following:

@Microsoft.KeyVault(SecretUri=https://yourvault.vault.azure.net/secrets/yoursecret/ec96f02080254f109c51a1f14cdb1931)

 

Conclusion

In this blog post we walked through the process to create, test, and deploy a C# compiled Azure Function that calls Microsoft Graph.  The sample repo can be found on GitHub at BTJ.CSAdvent.AZFunc.  Thank you for reading along and please open an issue on GitHub repo if you run into any issues with the sample project.  Enjoy the rest of The Third Annual C# Advent.

-Frog Out

Newsletter #3 – Tools / automation and the right song

Tools / Automation

I’m not an anthropologist or kinesiologist, but using a broad definition tools can be thought of as an extension of the human body.

  • A hammer allows you to swing your arm and impart more force than your hand could
  • A knife / scissors lets you cut apart materials with more precision than tearing with your bear hands
  • A bicycle lets you travel faster / more distance than your feet can carry you

I like to apply similar logic to computers, automation tools, etc.

  • PowerShell / Bash / can automate processes or tests rather than needing to manually run them
  • Automated alerting / bill pay keeps my financial accounts in check without needing to manually monitor them
  • My blog engine (WordPress at the current time) handles cross posting to Twitter and LinkedIn as well notifying any followers instead of my manually taking those actions
  • Azure DevOps allows my customer to create build and release pipelines to automate the tedious work of building and deploying an application with little to no manual steps

There is (almost) always an upfront investment in configuring, purchasing, etc. these types of tools or automating processes but the end result is generally an improvement in productivity / time to complete / etc.  Well-defined and / or simplistic processes are great targets for automation, but be careful that you don’t fall into the trap of automating the wrong things or spending more time building the automation than you’ll gain.  When in doubt check XKCD for funny examples like below.

Don Jones has a good article on “What’s not worth automating?” if you are interested in reading more on this topic.

The right tool (song) for the job

My dad is an electrical engineer who moved into sales many years ago.  He is also very handy around the house and likes to help me with house projects when he visits.  On many occasion a part, a bolt, or some other thing will get stuck.  Rather than trying to force what we are working on he always seems to know the right tool, compound, etc. to solve the problem with the least amount of effort needed.

Since I personally work with computers more than I do with my hands I find it helpful to get in the right mindset when I have a task to complete.  The task could be a blog post to write, some code to review, a set of screenshots to edit, etc.  Rather than fighting with myself (i.e. forcing it too much), I find it better to tune out my brain and let the words, code, or ideas flow more easily.

In order to help tune out my brain I have a playlist (called “Repeat All Songs”, link here) that I’ve moved with me from music service to service (now Spotify).  This playlist contains dozens of songs that I can (and frequently do) listen to on single-song repeat over and over.  These span classic rock, techno / house, instrumental, and other genres.  I don’t categorize the songs on my playlist but when I need inspiration or help getting into a specific mindset I browse through there, find a song that fits what I’m looking for, and hit play.

For those looking for some new songs to listen to on repeat here are a few from my recent rotation:

  • Achilles Last Stand – Led Zeppelin (rock)
  • In My Mind – Dynoro (electronica / dance)
  • Fly – Ludovico Einaudi (contemporary piano)
  • Nostos – Jean-Michael Blais (contemporary piano)
  • Lazy Eye – Silversun Pickups (rock, one of my fav bands)
  • Amsterdam – Guster (alternative / rock)
  • Brighton Rock – Queen (rock)
  • This World [Westworld Season 1] – Ramin Djawadi (instrumental)

How about you, do you have any favorite songs for single-song repeat?  Feel free to share back a link or recommendation.

-Frog Out

Newsletter #2 – Creativity, Times of Day, and Email Productivity Hack

If you saw my post yesterday “Starting a New Tiny Newsletter“, I’m starting up a new way to share out my smaller, more “informal” thoughts, articles, and other topics.  It’s called “Frog Pond Thoughts” and I’m publishing the 2nd one below.  I haven’t decided if I want to cross-post on my blog long term or keep them separate in TinyLetter.com / Twitter.  If you have any feedback or suggestions please do share in the comments, email, or on Twitter @BrianTJackett as I’m listening.  For now though enjoy this 2nd one as I expect it will be after the USA holiday of Thanksgiving before then next is published.


#2 – Creativity, Times of Day, and Email Productivity Hack

Creativity

How do I become more creative?

    1. Do creative things.
    2. Share with others.

 

  • Repeat #1 and #2 on a regular / scheduled basis.

 

Yes at first these sounds silly or simplistic but I’ve found them to be true (for me personally at least).  What does “do creative things” mean though?  It might be drawing in a notebook, writing a blog post, creating a new presentation, building blocks with my kids (see pictures below), playing a musical instrument, learning a new language (computer or spoken), etc.  Just as exercising your muscles during a workout needs variety, so do you need variety in the creative things you do.  Additionally doing something creative on a regular basis (once a week, once a month, or whatever works for you) ensures that it isn’t a “once and done” type of activity.

“Thanks Brian but what does sharing with others have to do with creativity?”  Glad you / I asked.  Have you ever had a friend, coworker, or family member who told you about a new TV show / game / restaurant / etc. and your first reaction is “that’s cool, have you heard about…?”  By sharing more not only do you become someone that people rely on finding out new things from but they may reciprocate by sharing their own things to you.

Times of Day

Semi-related to creativity, I find that I am more productive with specific categories of tasks at different times of the day.  Every day is different with   I don’t have anything written down or a routine (perhaps I should) but the following is a rough order for my day:

  • 7am
    • Plan out day, create tasks or to-do list, review day’s meetings, send out meeting agendas if needed
  • 8am
    • Write up documentation, blog post, or other creative writing
  • 9am
    • Deep focus on code, prototyping, etc.
  • noon
    • Read up on blogs / Twitter / LinkedIn from the previous day
  • 1pm
    • Deep focus on code, prototyping, etc.
  • 3pm
    • Emails and other communication

Schedules will always be changing depending on meetings, customer questions, etc. but knowing what types of activities I will be most productive at during different times helps me plan out when I should schedule those tasks.  If you open your email first thing in the morning, blink, and then it is suddenly 3 hours later then that is a good indication that you should either time box how long you spend on email and / or schedule it for a different time of day.

Email Productivity Hack

Speaking of email, I don’t like to send email after 5pm local time.  It’s my own personal guideline.  After 5pm is family / me time and if I’m sending emails to peers, customers, etc. it sets the expectation that they should also be reading and responding to emails “after hours”.

Instead of sending emails in the evening, if I have open time after my kids and wife go to bed I’ll draft up a number of emails that I need to write or respond to and then use the “delay delivery” feature of Outlook
(desktop version).  I then specify not to deliver those emails until at least 7am the following morning.  This way when I open my laptop in the morning, usually around 7:15-7:45am, all of those emails will be sent then.  This helps reinforce my personal rule that email is only for during business hours and also clears those emails off my plate to focus on other tasks that I’m more productive at (see above section).



Do you have any productivity hacks that you use?

-Frog Out

Starting a New Tiny Newsletter

If you’re reading this post (thanks to the handful of you out there), I wanted to let you know I’m starting something new.  I’ve been publishing my blog for over 10 years now but there are times I’d like to post something more informal.  It deserves more than a tweet but a full blog post is too much.  I found out about a service called TinyLetter from my friend Jeff Blankenburg.  I plan to write a tiny letter 2-3 times a month.  In it I’ll share interesting articles I’ve read, thoughts on various topics, or projects I’m following.  Think of it as a way to find out what is ticking in my brain that week.  Feel free to subscribe to Frog Pond Thoughts and share with others.  I’m posting the first letter to my blog for now as well.  Enjoy!


#1: Is this mic on? Starting something new…and why frogs?

Why write a tiny newsletter?

When someone does something new I like to think about “why did they do that?”.  I’ll share my own answer for why I’m starting up this tiny newsletter.  Over the past 6+ months I’ve been tossing around the idea of having some way to share out the various articles, topics, and thoughts I explore on a weekly basis.  During my 1:1 meetings with my mentor (you should have at least 1 mentor, topic for another day) I send him half a dozen or more links, stories, projects, etc. that I store in a OneNote (see example below).

While it is great discussing these items with my mentor I’d love to share them out to a broader audience.  I looked into a number of platforms.  I could extend my existing blog or share posts on LinkedIn but each of those didn’t feel like the right platform.  After seeing my friend and fellow Stir Trek Conference board planner Jeff Blankenburg starting up his Tiny Letter again (Blankenthoughts) I thought this would be a great experiment to see how easy it was for composing, distributing, and engaging with others.  Look for a new newsletter at least 2 times a month.

Why frogs?

If you’ve ever read my blog https://briantjackett.com/ (“The Frog Pond of Technology”) you may be asking “Brian what’s the deal with frogs?”.  Glad you asked.

For all of my life I’ve always liked the color green.  I also like to do new things on a regular basis which also means.  I liken this to frogs who are amphibious and able to live in many environments.  In the water, on land, in trees, and more.  Frogs are traditionally green and the change of scenery for frogs’ environments led to me have a natural liking of frogs.  That’s the short and simple answer.

Conclusion

I’m keeping this first newsletter short so that is all for now.  Please subscribe and share with your friends, coworkers, or anyone else who might be interested.

-Frog Out

Query Office 365 and Azure AD Logs with Azure Sentinel / Log Analytics and KQL

A few months ago I shared a tweet with a few quick links for learning about Kusto Query Language (KQL) and Azure Log Analytics.  Since that time Azure Sentinel (which sits of top of Azure Log Analytics) has been released to general availability (GA).  In this post I’ll build on that tweet and share a number of resources for starting out with Azure Sentinel / Azure Log Analytics and KQL.

Before you continue with this post I highly recommend reading MVP Tobias Zimmergren’s post on Monitoring Office 365 tenants with Azure Sentinel.

Monitoring Office 365 tenants with Azure Sentinel
https://zimmergren.net/use-azure-sentinel-to-digest-office-365-audit-logs/

Background

Most Microsoft cloud services emit logs for audit, operational, etc. purposes.  These logs are useful for gaining insights into who is using the service and how they are using it but sometimes it is not always easy to query these services.  You might be restricted to only a few thousands records at a time, a limited set of filters, or other constraints.  Azure Log Analytics and KQL make it possible to query a large number of records (in my experience millions to hundreds of millions) in a short time period (seconds in most cases instead of minutes or hours).

Kusto Query Language (KQL)

Over the years I’ve used T-SQL to query SQL Server when needed, but I am by no means an expert in the T-SQL language or concepts.  Having a basic understanding of T-SQL did make it easier for me to understand the entry level concepts of KQL such as filtering, ordering, grouping, and more.  Intermediate to advanced concepts like time based aggregations or self referential queries took a little more time to understand but my Data & AI PFE peer Ken Kilty provided a lot of good advice in this space.

Kusto Query Language overview
https://docs.microsoft.com/en-us/azure/kusto/query/

SQL to Kusto query translation
https://docs.microsoft.com/en-us/azure/kusto/query/sqlcheatsheet

Limiting Costs

Azure Sentinel (and by proxy Azure Log Analytics) is charged in 2 ways:

  • Ingestion of data
    • Reserved capacity
    • -or-
    • Per GB
  • Retention of data

Azure Sentinel pricing
https://azure.microsoft.com/en-us/pricing/details/azure-sentinel/

For all Office 365 data the ingestion of data is free.  Azure AD audit logs and sign-in logs will be charged according to the reserved capacity or pay-as-you-go per GB model.

Retention of data in an Azure Sentinel enabled workspace is free for the first 90 days.  Beyond the first 90 days pricing is per GB per month.

Ex. Storing Office 365 logs for 9 months, a customer would only be charged for (9 months – 3 free months) = 6 paid months.

Azure Monitor pricing
https://azure.microsoft.com/en-us/pricing/details/monitor/

If you are looking to test out the service “for free” it is possible to configure an Azure Sentinel enabled workspace to ingest Office 365 data and limit the retention of data to < 90 days.  Once you get comfortable with the data schema and writing queries you can increase the retention period.

Sample Queries

In the course of working with customers on monitoring their Office 365 environments I and my teammates have developed a number of KQL queries to find “interesting” data points.  I’ve shared these queries in the following GitHub repo.  Note that these sample queries are provided as-is with no warranty.  If you have any queries of your own that you would like to contribute feel free to submit a pull request (or open an issue) to the repo for review.

Office 365 and Azure AD sample KQL Queries
https://github.com/BrianTJackett/log-analytics-samples

Conclusion

Last year I had never heard of Log Analytics, Azure Sentinel, or KQL.  This year I am seeing it pop up in so many places inside and outside of Microsoft.  I am very eager to see where these technologies go and spread the word about them.  I truly see interesting problems that can be solved with enough data and the right query.  Hopefully this post will give you a nudge in the right direction to start (or continue) looking at these technologies.

-Frog Out