almenscorner / IntuneCD

Tool to backup, update and document configurations in Intune
MIT License
277 stars 35 forks source link

[FEATURE] Add support for Azure DevOps Federating identity authentication #186

Closed ztrhgf closed 5 months ago

ztrhgf commented 5 months ago

Is your feature request related to a problem? Please describe. I don't want to use service principal because of secret/certificate maintenance. Federating identity is just much more secure and maintainable.

Describe the solution you'd like Please option to authenticate using Azure DevOps federating identity as described here https://gotoguy.blog/2023/09/15/connect-to-microsoft-graph-in-azure-devops-pipelines-using-workload-identity-federation/

In general we need to be able to pass token that will be used like Connect-MgGraph -AccessToken $token

Thanks!

almenscorner commented 5 months ago

So what you really want to do here is pass the token as an argument during run time?

ztrhgf commented 5 months ago

Yes :) Instead of SP id and secret.

almenscorner commented 5 months ago

Added the option to pass a token in 2.3.0 beta4 and was able to use it like this

trigger:
- none

pool:
  vmImage: windows-latest

steps:
- task: AzureCLI@2
  displayName: 'Get Graph Token for Workload Federated Credential'
  inputs:
    azureSubscription: 'test'
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    inlineScript: |
      $token = az account get-access-token --resource-type ms-graph
      $accessToken = ($token | ConvertFrom-Json).accessToken
      Write-Host "##vso[task.setvariable variable=secretToken;issecret=true]$accessToken"

- task: PowerShell@2
  displayName: 'Install IntuneCD'
  inputs:
    targetType: 'inline'
    script: |
      pip3 install IntuneCD==2.3.0b4

    pwsh: true

- task: PowerShell@2
  displayName: 'Run IntuneCD with token'
  inputs:
    targetType: 'inline'
    script: |
      IntuneCD-startbackup -t $(secretToken) -p $(Build.SourcesDirectory)

    pwsh: true
ztrhgf commented 5 months ago

Amazing! Will try it right now.

ztrhgf commented 5 months ago

Working like a charm!

almenscorner commented 5 months ago

Cool, I'll make it a part of 2.3.0!

ztrhgf commented 5 months ago

Looking forward to it, thanks again!

ztrhgf commented 5 months ago

Please update the docs too.

almenscorner commented 5 months ago

Docs updated