r/PowerShell • • Nov 20 '19

Opinion - The Microsoft Partner Center Powershell Module is not fit for purpose for delegated administration

For those who don't know, a number of months ago Microsoft enforced a number of security requirements on MS Partners to enforce two-factor security.

Two-factor authentication is an absolute must for partners AND our users/clients - this is something I will openly champion. Unfortunately, Microsoft rushed in to this head first without appropriately preparing their own Powershell modules for delegated administration. Upon implementation we were left in a position where we had to scramble to re-write existing scripts to make them work. We completely lost all of our centralised security monitoring for clients Exchange tenants because Microsoft had zero way at the time of performing delegated administration through Powershell.

I know outside of our own experience that huge vendors struggled to implement the model too with some of their Office 365 integrations that relied on Powershell.

I am not a Powershell pro, but I am not a Powershell noob either but I find the Secure App Model extremely difficult to implement in Powershell. I know others do too because the Microsoft Partner Community Forums is full of MS Partners who are having the same difficulties in consuming it.

To get an indication of the difficulty in consuming it, see here for a script on how to start setting it up. https://www.cyberdrain.com/connect-to-exchange-online-automated-when-mfa-is-enabled-using-the-secureapp-model/ . The methods that partners have to go through are not intuitive in the slightest.

To make it even harder the Refresh Token that you eventually get that allows you to perform delegated administration expires every 90 days and there are only two ways to get a new one:

  1. It generates a new refresh token each time you request a new token, leaving you with two tokens which means you need to find a way to update the existing token that you have stored somewhere

  2. If for whatever reason that initial token expires you need to request a new one - that's an interactive process that you need to go through each time with no way to automate it.

To outline how ridiculous it is, look at what steps are required for me as a partner to get some mailbox information out for my clients using Powershell.

  1. Generate a new App in Azure with explicit permissions

  2. Generate and then store credentials that can then interact with the app, an AppID and a Key which is essentially the password

  3. Request a token from the PartnerCenter Module that then becomes a refresh token for that Partner App (this requires an interactive login)

  4. Request a different token that becomes your Exchange Refresh token (this requires an interactive login)

  5. Store all of the above securely on the machine you are running these on

  6. Get an Azure Active Directory graph token using the credentials generated in step 2 and the refresh token generated in step 3

  7. Get a standard MS Graph token using the credentials generated in step 2 and the refresh token generated in step 3

  8. Connect to the MSOnline Powershell module to get a list of your clients and their tenant IDs using the aadGraphToken and the MsGraphToken.

  9. Loop through each customer and then...

  10. For each customer request a specific Exchange Refresh Token for that particular customer using the Partner Center Module Powershell

  11. Manipulate the token to be able to facilitate generating a New-PSSession for which you need to send in your manipulated token that you've had to prefix and manipulate with Bearer to get to work

  12. Get-Mailbox

  13. Remove the session and loop back to 9.

To keep this running automated too, in the main commands each time a refresh token is issued you need to update any existing tokens you get stored. If you are storing the credentials appropriately and want to run this on different machines you have to go through the entire process on each machine because it's a different refreshtoken each time.

In my opinion this is FAR too difficult and short of providing better security for partners it will simply encourage the ones that care a bit less to adopt security practices that are FAR worse like embedding credentials. I'd never do that, but there are plenty of crappy MSPs that will.

To top this off, a number of these cmdlets don't even work properly. I have two Github issues open right now for inherent problems that exist in the modules. Imagine how hard this is when you are requesting tokens and it only provides a refresh token 10% of the time you run the Cmdlet. Imagine the difficulty when certain commands that you run with your delegated tokens just error out, not with reasonable errors but with errors that represent the module is actually crashing. Imagine them changing how the Partner Center Module worked from 1.5 to 2 with them implementing changes that break existing scripts.

But hey, they released V2 of the Exchange Online Powershell Module! Great! https://docs.microsoft.com/en-gb/powershell/module/exchange/powershell-v2-module/connect-exchangeonline?view=exchange-ps Oh wait... it doesn't work with Delegated Administration at all at the moment.

I apologise if this comes across a bit ranty, but I wanted to draw attention to how messed up the situation is at present.

116 Upvotes

20 comments sorted by

11

u/jupiter-88 Nov 21 '19

I stopped at step 1, then wrote a module using Invoke-WebRequest and the XML based EWS API with a username and password that are hashed and stored using DPAPI.

3

u/TNTGav Nov 21 '19

That's fine if you've got one tenant to do that on.

I'd have to do that for literally hundreds of Office 365 tenants.

4

u/roll_for_initiative_ Nov 21 '19

Sadly this is how we're doing it for many tenants, just using a for-each loop to run single tenant scripts against multiple tenants

8

u/nh5x Nov 21 '19

And I just had a thread about this 3 weeks back. This situation is a joke and It's extremely agitating that we can't do what we want to with it currently.

" To top this off, a number of these cmdlets don't even work properly. I have two Github issues open right now for inherent problems that exist in the modules. Imagine how hard this is when you are requesting tokens and it only provides a refresh token 10% of the time you run the Cmdlet. Imagine the difficulty when certain commands that you run with your delegated tokens just error out, not with reasonable errors but with errors that represent the module is actually crashing. Imagine them changing how the Partner Center Module worked from 1.5 to 2 with them implementing changes that break existing scripts. "

We're having the same exact ****ing issue.

2

u/TNTGav Nov 21 '19

It absolutely is. If you manage to make progress on these issues please do update me!

26

u/Er4smus Nov 21 '19

This is the first time I've seen someone say anything about this and you're right it's so stupid but no one seems to care.

16

u/weakhamstrings Nov 21 '19

This is exactly the kind of thing that's been happening throughout their ecosystems.

Product changes and moves.

Very short software support cycles.

Inconsistent policies across platforms.

Mislabeled packages that don't even include what they say (I'm looking at you, Intune in M365...)

It's caused us to just stay at the edges of their platforms whenever possible, using pieced together solutions.

Yes, Mr. Customer - your secure email system, PC, and email account have separate passwords with separate MFA. Why? Because Microsoft's overpriced subscription trash is often a support nightmare and isn't supported for long enough for me to implement anything in your business that I can promise will work for more than 3 years.

I'm sick of it. And now I'm looking to find non-Windows and non-Microsoft solutions for my clients when I can and in some rare cases, touching exactly 0 of their products.

5

u/[deleted] Nov 21 '19

This issue goes back to when Microsoft got rid of their independent QA engineers.

I have to live with MS software in the workplace. At home it's Linux.

1

u/Aznflipfoo Nov 21 '19

Okay that’s a bit of an overreaction there. The guys post is correct but I have no clue what you’re talking about

5

u/thingandstuff Nov 21 '19 edited Nov 21 '19

Microsoft's implementation of XaaS seems to be exclusively aimed at carving out space in the parts of the market which compete with Apple and Google ecosystems when it comes to "mobility" and access control and AWS when it comes to platform/hosting whatever. The ball Microsoft is chained to, the ball that these other companies don't have to worry about, is legacy support or, frankly, reliability. This pivot is understandable, Apple mints money while Microsoft is begging for change even though they have significant majority of of non-mobile devices, but so is the trouble it is causing.

As far as I can tell, everything we're complaining about is being shoved down our throats. For my part, you know how many conversations I've had about the exciting new Windows 10 features? None, ever; not one. Nobody cares. No one in my team cares, no one in my department cares, none of the end users care or are ever aware. Actually nobody caring would be an improvement. Everyone just hates everything about all of this.

Unless your org is restructuring and adding restructured 5 years ago and added staff for the increased overhead caused by this constantly upheaval this is not at all an over-reaction. This stuff is supposed to make things easier, and it often does when done by the book, but the ceaselessness and pace in the evolution of that book is a new challenge in this field that, from where I sit, doesn't even begin to settle the organizational debts it's creating. Maybe I'm just in my bubble...

4

u/fbsau Nov 21 '19

Yeah I completely agree. I had a guide up on setting it up that worked for about a month until they updated the partner Center module with a breaking change.

The method to retrieve and manage the refresh token is so much more difficult than it needs to be.

3

u/nerddtvg Nov 21 '19

This has been the same issue for Exchange Online, as you mention, for over two years. You'd imagine they'd solve this issue by now and use something like the device login method for even interactive sessions, but no. I wouldn't expect a fix anytime soon.

3

u/olavrb Nov 21 '19

Agree with OP.

Something thats at least as stupid is the partner center security score for api and sdk requests. We reach 1% compliance, Ms contacts us almost daily to tell us we'll loose our business if that score does not go to 100%. Yet, with two open asfp tickets for over a week, Ms still havent been able to tell us what integration is causing our 99% noncompliance. I suspect it's Cloudyn, but we can't just shut it down to see if it makes a difference.

3

u/Analytiks Nov 21 '19 edited Nov 21 '19

You can skip a lot of those steps tbh with some automation and service pricipals, generating application credentials are best practice.

Yeah you have to interactively login every so often but that's literally what MFA is. 90 days is so infrequent and you can set reminders.

I do think that it's not particularly intuitive for an MSP without DevOps engineers to automate which leads to this kind of upset.

But the model itself where you use application credentials does make a lot of sense.

2

u/hailGunslinger9 Nov 21 '19

Check this person out, they're along the correct path. I'll be testing it more soon.

https://www.reddit.com/r/msp/comments/dwhbet/exchange_online_with_mfa_secure_app_model_with/

Edit: I've had multiple tickets open with premier support on it.

2

u/bvierra Nov 21 '19

To make it even harder the Refresh Token that you eventually get that allows you to perform delegated administration expires every 90 days and there are only two ways to get a new one:

It generates a new refresh token each time you request a new token, leaving you with two tokens which means you need to find a way to update the existing token that you have stored somewhere

If for whatever reason that initial token expires you need to request a new one - that's an interactive process that you need to go through each time with no way to automate it.

So standard OAuth?

1

u/orourkean Nov 21 '19

I'm having trouble right now trying to insure our api apps are connecting to mcp with mfa. The API vendor won't work with me. Microsoft provided the guids and only one lines up with an API user. To say this was rushed is a bit of an understatement.

1

u/jake_theadmin Nov 21 '19

You got a script which can work unattended for partner tenant. What about non-partner tenants? Microsoft is pushing everyone for modernAuth & MFA, but it breaks in-house scripts.

1

u/TotesMessenger Nov 20 '19

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)