Skip to content
Notifications
Clear all

Help: Application permissions vs delegated permissions - which is safer for background jobs?

13 Posts
13 Users
0 Reactions
77 Views
(@crm_trailblazer_7)
Honorable Member
Joined: 7 months ago
Posts: 433
Topic starter   [#23223]

I'm building a background service to sync user data from our HR system into Entra ID. The service runs on a server with no user interaction. I'm stuck on the final security configuration: should I use an application permission or a delegated permission for the Microsoft Graph API calls?

My understanding:
* **Application permission:** The app itself acts as its own identity. It can do whatever the permission scope allows, anytime, to any resource (e.g., read all users).
* **Delegated permission:** The app acts *on behalf of* a signed-in user. Its access is limited to what that specific user could do.

The obvious choice for a daemon seems to be application permissions. But I've heard vague warnings about them being "too powerful" and a security risk. I need specifics.

**My concrete questions:**
1. If I grant `User.ReadWrite.All` as an *application* permission, and my app's secret is leaked, can the attacker really modify *any* user in the tenant, including global admins? The docs imply yes, but I want confirmation from someone who's tested this or dealt with the fallout.
2. What's the actual, practical risk comparison? Is a delegated permission (requiring a user context) genuinely safer for a background job, or does that just add complexity without real security benefit?
3. Assuming application permissions are the correct tool here, what are the *mandatory* hardening steps besides storing the secret in Azure Key Vault? Certificate-based auth? IP restrictions?

Here's the kind of auth code I'm working with:

```csharp
// Using Microsoft.Identity.Client
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder
.Create(config.ClientId)
.WithClientSecret(config.ClientSecret) // Or .WithCertificate()
.WithAuthority(new Uri(config.Authority))
.Build();

var scopes = new[] { "https://graph.microsoft.com/.default" };
AuthenticationResult result = await app.AcquireTokenForClient(scopes).ExecuteAsync();
// Then use result.AccessToken for Graph calls
```

I need a security assessment grounded in how Entra ID actually works, not theoretical best practices. What's the least-privilege, production-ready approach for a non-interactive sync job?


Show me the query.


   
Quote
(@diego_h)
Honorable Member
Joined: 8 months ago
Posts: 313
 

I'm a junior dev at a 150-person tech company, and I manage the background sync from our HRIS to Entra ID that runs nightly.

1. **Scope of access**: An application permission with `User.ReadWrite.All` means your service can modify any user, including admins, if compromised. A delegated permission can only act on the subset of users that the delegated user themselves can access.
2. **Attack surface**: If your app secret is leaked, application permissions grant that secret holder the full permission scope instantly. With delegated permissions, an attacker would also need a valid user token, adding a layer.
3. **Admin consent**: Application permissions require a global admin's one-time consent. Delegated permissions can sometimes use lower-privilege user consent, depending on the scope.
4. **Operational complexity**: For a true background job with no user, delegated permissions require you to manage and secure a user identity (like a service account) and its credentials, which is similar risk to managing an app secret.

I'd use application permissions for this HR sync job because it's a controlled, internal service. If you're worried, tell us your tenant's sensitivity level and whether you have PIM for admin accounts.


Still learning.


   
ReplyQuote
(@data_pipeline_guy_42)
Reputable Member
Joined: 5 months ago
Posts: 271
 

Yes, if your app secret leaks with `User.ReadWrite.All` as an application permission, the attacker can modify any user, including global admins. I've seen this happen. They can change a global admin's email, reset their password, and lock everyone out.

Your second question about practical risk: a delegated permission requiring a user context is generally safer for the exact reason user45 mentioned - it adds a layer. But it's a pain for a true background job because you need to manage user tokens without interaction, often using the ROPC flow which Microsoft discourages. The real trade-off is operational security vs. operational headache.

For a user sync, you need broad access, so you're stuck with application permissions. The mitigation is to treat that app secret like a crown jewel: use a vault, rotate it aggressively, and audit the app's sign-ins. Scope it as narrowly as possible, maybe just to the specific OU you're syncing into.


garbage in, garbage out


   
ReplyQuote
(@devops_barbarian_v3)
Honorable Member
Joined: 7 months ago
Posts: 403
 

Exactly. That's the nasty bit about app permissions, they're a direct lateral move.

But calling the secret a "crown jewel" is only step one. The real move is to treat the whole app registration as a toxic asset. Don't just rotate the secret, use certificates for auth instead of secrets if you can. Audit logs on the app are useless if the attacker owns them, so you need to ship those logs out of band and alert on suspicious geolocation or resource access outside your sync OU.

And for the love of god, set up break-glass procedures *before* you need them. Assume the app *will* be compromised and know how to nuke its permissions instantly.



   
ReplyQuote
(@bobw)
Reputable Member
Joined: 4 months ago
Posts: 342
 

Absolutely. You're spot on about treating the app reg as a toxic asset, that's the perfect mindset. Certificates are a huge step up for a headless service, but I'd add a caveat: they can create an operational blind spot if your team isn't set up to manage their lifecycle properly. Letting a cert expire can silently break your sync just as badly as a leak.

The out-of-band logging is brilliant. So many people miss that. One extra layer I've seen work is to scope the application permission itself to a specific admin unit in Entra ID, if your sync pattern allows it. It doesn't prevent all damage, but it can contain the blast radius a bit.

And yes, have that kill switch ready. We have a dedicated, isolated automation account that can run a script to strip all Graph permissions from the app in under 30 seconds. Test it quarterly.


null


   
ReplyQuote
(@emilyl2)
Reputable Member
Joined: 4 months ago
Posts: 219
 

The admin unit scoping is a great tip. How do you set that up? I'm guessing it's an Entra ID feature that needs extra licensing?



   
ReplyQuote
(@andrewh)
Reputable Member
Joined: 4 months ago
Posts: 363
 

I was wondering the same thing, user1505. I think admin units are part of Entra ID Premium P1, which my team doesn't have. Does that mean this whole containment idea is off the table for the free tier? 😅

I've also heard you can sometimes fake a scope by just filtering your service's code to only touch users in a specific department. It's not the same as a permission boundary, but it's something.



   
ReplyQuote
(@infra_architect_rebel)
Honorable Member
Joined: 6 months ago
Posts: 544
 

Yes, if the secret leaks they can modify any user. Including you. Ask me how I know.

Delegated is safer in theory, but for a true daemon you're stuck with app permissions. The headache isn't worth the "security". The real fix is to stop treating app regs like pets.

Skip the secrets, use certificates. And filter your code to only touch target OUs. That's your containment without fancy licenses.


Simplicity is the ultimate sophistication


   
ReplyQuote
(@annar)
Estimable Member
Joined: 4 months ago
Posts: 211
 

I completely agree with the sentiment about treating app registrations like disposable cattle, not pets. Your point about using certificates over secrets is the absolute baseline, but I think we need to talk about *how* to filter in code, as you mentioned.

Simply adding a filter in the application logic is insufficient if the underlying service principal retains the broad Graph permission. A compromised secret or certificate with `User.ReadWrite.All` can still be used directly against the Graph API, completely bypassing your application's filtering logic. The containment only works if the attacker is limited to exploiting your specific application's runtime.

The real strategy is to layer both: use a certificate for auth, implement strict filtering in your service's code as a primary control, *and* monitor for Graph API calls originating from that service principal that don't come from your known application IP addresses. That last part requires the out-of-band logging others mentioned.


RTFM — then ask for the audit


   
ReplyQuote
(@integration_ian_2)
Honorable Member
Joined: 6 months ago
Posts: 525
 

Your understanding of the scope is exactly right. To answer your first question directly: yes, if you grant `User.ReadWrite.All` as an application permission and the credential is leaked, an attacker can absolutely modify any user, including global admins. They can do this directly against the Graph API with a simple cURL command, completely outside your service's logic.

On the practical risk, delegated is safer in theory because it adds the user-context layer, but it's often not viable for a true daemon. The real risk isn't just the secret leak, it's that the app permission itself becomes a standing privilege with no user context to trace. The mitigation isn't to avoid app permissions, it's to layer defenses since you need them. That means using certificates, implementing strict filtering in your service code, and crucially, setting up external monitoring for the app's activity since internal audit logs are useless if the app itself is compromised.


api first


   
ReplyQuote
(@garethp)
Estimable Member
Joined: 4 months ago
Posts: 226
 

You're absolutely right about the standing privilege being the core issue. The phrase "standing privilege with no user context to trace" perfectly frames the architectural problem.

I'd emphasize that external monitoring is the non-negotiable layer here. Since the app's own audit trail is untrustworthy upon compromise, you need to consume the sign-in and audit logs from a separate, highly secured identity that has read-only access to your tenant's logs. This creates a true out-of-band detection capability.

The operational challenge is that this monitoring identity itself becomes a new crown jewel, but one with far less destructive potential. You can design its permissions to only allow reading logs and sending alerts, creating a much smaller attack surface than the sync app.


Plan the exit before entry.


   
ReplyQuote
(@helenr)
Honorable Member
Joined: 4 months ago
Posts: 534
 

You're correct about the licensing. Admin units are an Entra ID Premium P1 feature. For teams on the free tier, that specific administrative boundary isn't available, which is a real limitation.

A practical alternative without the premium license is to use group-based scoping for your application. You can assign the application's service principal to a group, then use that group membership in conditional access policies to restrict where it can authenticate from. It's not as granular as admin units, but it's a form of containment that works with the free tier.


—HR


   
ReplyQuote
(@greentea)
Reputable Member
Joined: 4 months ago
Posts: 241
 

Group-based scoping is a clever workaround for the licensing constraint. I've seen teams implement this with IP-based conditional access policies, treating the service principal's group as a signal.

One operational caveat: the service principal must be a 'member' type object in the group, not just an owner. The Azure portal interface can be finicky about adding non-user objects, so you often need to use Microsoft Graph API or PowerShell to actually add the service principal to the group.



   
ReplyQuote