Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement project pulling from Azure DevOps using Service Principals #14628

Merged

Conversation

puiterwijk
Copy link
Contributor

SUMMARY

This adds support for syncing a project from Azure DevOps using an Azure Service Principal.

ISSUE TYPE
  • New or Enhanced Feature
COMPONENT NAME
  • API
  • UI
  • Other
ADDITIONAL INFORMATION

In order to use this feature, create an Azure Resource Manager type secret, and assign this to the project (this PR allows attaching either an scm or azure_rm secret to projects).
The associated service principal must have Basic level access to the DevOps organization, and at least Reader level access to the Project.

Note that the current implementation uses ansible.builtin.uri to retrieve an access token.
I have submitted ansible-collections/azure#1318 to implement this as a separate Ansible module, after which this could be replaced by:

azure.azcollection.azure_rm_access_token:
  subscription_id: "{{ azure_subscription_id }}"
  client_id: "{{ azure_client_id }}"
  secret: "{{ azure_client_secret }}"
  tenant: "{{ azure_tenant }}"
  scopes:
    - 499b84ac-1321-427f-aa17-267ca6975798/.default

@puiterwijk puiterwijk force-pushed the azure_service_principal_devops branch 2 times, most recently from 7d03a68 to 725827b Compare November 5, 2023 09:10
@@ -47,6 +82,7 @@
force: "{{ scm_clean }}"
track_submodules: "{{ scm_track_submodules | default(omit) }}"
accept_hostkey: "{{ scm_accept_hostkey | default(omit) }}"
environment: "{{ git_environment | default({}) }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to do something similar in #14190, just to link it.

@thedoubl3j
Copy link
Member

@AlanCoding is there way for us to test this or is there anything we would need integration wise? I think once the collection PR merges it would be good to move to that implementation @puiterwijk. The collection is already part of the awx-ee so it is already included in base installs.

@puiterwijk puiterwijk force-pushed the azure_service_principal_devops branch from 725827b to 58f7150 Compare November 12, 2023 13:09
@puiterwijk
Copy link
Contributor Author

@thedoubl3j Yeah, I had seen that that collection is already in the EE, that's why I even put in the effort to add support for it there :).
I just updated my PR on the collection to fix the remarks (has been a busy week!), so let's hope that progresses.

Regarding testing this PR: it'll require an Azure account with DevOps and a service principal that has access (see the instructions in my commit message/github summary).

@puiterwijk puiterwijk force-pushed the azure_service_principal_devops branch from 58f7150 to 058c386 Compare November 14, 2023 06:05
@TheRealHaoLiu
Copy link
Member

cc @CFSNM

@ryankwilliams
Copy link
Member

Hey @puiterwijk!

While I was testing out these changes and creating new automated tests for this. I noticed when trying to create a project with the credential for the azure service principal, the project ends up having the credential be empty (when using awxkit).

I was going through the awxkit code that our tests repository use and in order for the tests I added to work with this credential and project creation. I had to add the following to the conditional:

                if credential.ds.credential_type.namespace not in ('scm', 'insights', 'azure_rm'):

https://github.com/ansible/awx/blob/devel/awxkit/awxkit/api/pages/projects.py#L52

Would you be able to make this change within this PR?

@puiterwijk puiterwijk force-pushed the azure_service_principal_devops branch from 058c386 to 4f5754b Compare December 22, 2023 03:44
@puiterwijk
Copy link
Contributor Author

@ryankwilliams Hi, sorry for the delayed reply, but I just pushed the change!

@ryankwilliams
Copy link
Member

@ryankwilliams Hi, sorry for the delayed reply, but I just pushed the change!

@puiterwijk Thank you for making the change!

puiterwijk added a commit to puiterwijk/awx-ee that referenced this pull request Jan 8, 2024
@puiterwijk puiterwijk force-pushed the azure_service_principal_devops branch from 4f5754b to 0bc75e1 Compare January 8, 2024 14:17
@puiterwijk
Copy link
Contributor Author

@thedoubl3j @ryankwilliams I've updated this PR to use the collection version for token retrieval.
I also filed ansible/awx-ee#229 to make sure that version 2.1 or later of the collection is used in awx-ee (although it's already in the :latest tag, so that might not be required?).

@puiterwijk puiterwijk force-pushed the azure_service_principal_devops branch from 0bc75e1 to 061b17f Compare January 8, 2024 14:50
Allow looking up a credential with one of multiple type IDs.

Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
Allow selecting an Azure Resource Manager credential for Git-based SCMs.
This is in order to enable using Azure Service Principals for project updates.

Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
This adds support for using an Azure Service Principal for project updates.

Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
@dmzoneill dmzoneill force-pushed the azure_service_principal_devops branch from 061b17f to fa1829b Compare February 21, 2024 14:54
@dmzoneill
Copy link
Member

@puiterwijk is this ready for merging?

@dmzoneill dmzoneill marked this pull request as draft February 21, 2024 15:00
@puiterwijk
Copy link
Contributor Author

puiterwijk commented Feb 21, 2024

@puiterwijk is this ready for merging?

@dmzoneill I think it is, yes. I've been waiting for review and someone to merge it or provide feedback.

@chadmf
Copy link
Collaborator

chadmf commented Mar 7, 2024

LGTM!

@TheRealHaoLiu TheRealHaoLiu marked this pull request as ready for review March 7, 2024 15:06
Copy link
Collaborator

@chadmf chadmf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@TheRealHaoLiu TheRealHaoLiu merged commit 2e2cd7f into ansible:devel Mar 7, 2024
21 checks passed
@puiterwijk puiterwijk deleted the azure_service_principal_devops branch March 7, 2024 16:35
@TheRealHaoLiu
Copy link
Member

Reverting this PR due to test failure, please open the PR again.

TheRealHaoLiu added a commit to TheRealHaoLiu/awx that referenced this pull request Mar 11, 2024
TheRealHaoLiu added a commit that referenced this pull request Mar 11, 2024
#14977)

Revert "Implement project pulling from Azure DevOps using Service Principals (#14628)"

This reverts commit 2e2cd7f.
@puiterwijk puiterwijk restored the azure_service_principal_devops branch March 11, 2024 14:26
djyasin pushed a commit to djyasin/awx that referenced this pull request Sep 16, 2024
…nsible#14628)

* Credential Lookup with multiple types
Allow looking up a credential with one of multiple type IDs.

* Allow Azure cred for SCM
Allow selecting an Azure Resource Manager credential for Git-based SCMs.
This is in order to enable using Azure Service Principals for project updates.

* Implement Azure Service Principal Git
This adds support for using an Azure Service Principal for project updates.

---------

Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
djyasin pushed a commit to djyasin/awx that referenced this pull request Sep 16, 2024
ansible#14977)

Revert "Implement project pulling from Azure DevOps using Service Principals (ansible#14628)"

This reverts commit 2e2cd7f.
djyasin pushed a commit to djyasin/awx that referenced this pull request Nov 11, 2024
…nsible#14628)

* Credential Lookup with multiple types
Allow looking up a credential with one of multiple type IDs.

* Allow Azure cred for SCM
Allow selecting an Azure Resource Manager credential for Git-based SCMs.
This is in order to enable using Azure Service Principals for project updates.

* Implement Azure Service Principal Git
This adds support for using an Azure Service Principal for project updates.

---------

Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
djyasin pushed a commit to djyasin/awx that referenced this pull request Nov 11, 2024
ansible#14977)

Revert "Implement project pulling from Azure DevOps using Service Principals (ansible#14628)"

This reverts commit 2e2cd7f.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants