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

Initial support for Microsoft Graph with opt-in beta #373

Merged
merged 62 commits into from
May 19, 2021

Conversation

manicminer
Copy link
Contributor

@manicminer manicminer commented Dec 14, 2020

This PR introduces support for Microsoft Graph using https://github.com/manicminer/hamilton, alongside the existing Azure Active Directory Graph API implementation, and aims to maintain forward and backward compatibility. Users can opt-in to using MS Graph by setting the use_microsoft_graph provider attribute or the AAD_USE_MICROSOFT_GRAPH environment variable.

This is broken into multiple commits to aid review.

Authentication

  • Authentication for MS Graph is handled by hamilton/auth similarly to go-azure-helpers. Different auth methods can be configured and are tried in order, until one succeeds.

    • Service principal auth is always tried first, if configured
    • If managed identity is enabled, it will raise an error on failure (current behavior)
    • Azure CLI is the last attempted method and serves as a fallback
  • Authentication via hamilton/auth is only performed when MS Graph is enabled, to avoid erroring if no API permissions are granted to the principal.

  • Authentication via go-azure-helpers is always performed, even when MS Graph is enabled. Both methods must work for provider configuration to succeed. This will be removed in v2.0.

  • Client configuration is sourced from the AuthConfig supplied by go-azure-helpers. This will be switched in v2.0.

  • All national clouds are supported

  • The US Gov cloud is now two clouds in MS Graph - L4 and L5.

Resources

  • All resource CRUD functions have been replaced with temporary shim functions to conditionally call the corresponding aadgraph or msgraph function.
  • A number of resource.StateChangeConf{}.WaitForState() method usages have been removed since MS Graph has been observed to be consistent in most cases.
  • Lots of deprecations and new fields to accommodate new API schema and nomenclature

Documentation

  • Several documentation fixes, deprecations added
  • Upgrade guide for v2.0 and Microsoft Graph, with section explaining the MS Graph Beta

@manicminer manicminer added this to the v1.2.0 milestone Dec 14, 2020
@manicminer manicminer force-pushed the feature/enable-microsoft-graph branch 4 times, most recently from 66a9a37 to 33946d2 Compare December 14, 2020 11:42
@manicminer manicminer marked this pull request as ready for review December 15, 2020 14:59
@manicminer manicminer requested a review from a team December 15, 2020 14:59
@manicminer manicminer force-pushed the feature/enable-microsoft-graph branch from 0d4a908 to e06f028 Compare December 15, 2020 15:33
@manicminer manicminer force-pushed the feature/resource-packages branch from 7e061a3 to 3a9c0a4 Compare December 16, 2020 15:11
@manicminer manicminer force-pushed the feature/enable-microsoft-graph branch from 34c6ac0 to 14b1fa8 Compare December 16, 2020 15:14
@manicminer manicminer force-pushed the feature/resource-packages branch 2 times, most recently from d690b7a to 9225d08 Compare December 16, 2020 17:45
@manicminer manicminer force-pushed the feature/enable-microsoft-graph branch 3 times, most recently from c505e72 to 6f7c4d8 Compare December 16, 2020 17:50
@manicminer manicminer force-pushed the feature/resource-packages branch from 9225d08 to 5dc0f38 Compare January 11, 2021 18:05
@manicminer manicminer force-pushed the feature/enable-microsoft-graph branch from 6f7c4d8 to 6ea7423 Compare January 11, 2021 18:05
@manicminer manicminer force-pushed the feature/resource-packages branch 2 times, most recently from 439ac7f to 8e0e9c2 Compare January 13, 2021 23:23
Base automatically changed from feature/resource-packages to main January 14, 2021 19:32
@manicminer manicminer modified the milestones: v1.2.0, v1.3.0 Jan 14, 2021
@hashicorp hashicorp deleted a comment Jan 14, 2021
@manicminer manicminer force-pushed the feature/enable-microsoft-graph branch 2 times, most recently from f228887 to 1ab05ac Compare January 16, 2021 00:25
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

a few minor comments but this otherwise LGTM 👍

docs/resources/application.md Outdated Show resolved Hide resolved
Comment on lines +44 to +48
## Attributes Reference

In addition to all arguments above, the following attributes are exported:

*No additional attributes are exported*
Copy link
Contributor

Choose a reason for hiding this comment

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

The ID will be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried to avoid mentioning the resource ID too much as it's a frequent source of confusion - instead there are contextual attributes like scope_id in this case.

internal/tf/import.go Outdated Show resolved Hide resolved
var status int
for _, owner := range *group.Owners {
// don't fail if an owner already exists
checkOwnerAlreadyExists := func(resp *http.Response, o *odata.OData) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't this indicate a bug?

Copy link
Contributor Author

@manicminer manicminer May 17, 2021

Choose a reason for hiding this comment

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

This mostly helps to work around API inconsistency where newly created groups (and other objects) sometimes inherit an owner but sometimes don't. Also the group read operation has inconsistencies where owners sometimes take awhile to show up after adding, this helps work around that without excessive/fruitless retry logic in the calling app.

}

// despite the above check, sometimes owners are just gone
checkOwnerGone := func(resp *http.Response, o *odata.OData) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) wouldn't this indicate a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similarly sometimes the read operation on a group indicates the presence of an owner when it's actually already been removed, so you end up with a GET showing an owner, but DELETEing that owner gets you a 403.

if err := json.Unmarshal(data, &e); err != nil {
return err
}
for _, k := range []string{"error", "odata.error"} {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this also be in @odata.error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't seen that but maybe? AFAICT @odata.error isn't in the odata standard, although I think i'd probably expect it to have astring value if it showed up anywhere.

manicminer added 10 commits May 17, 2021 12:51
…ice_principal_password

For both resources:

- Since `value` is to be removed, generate a value for AAD Graph if one
  is not specified in configuration, mimicking characteristics of
  msgraph-generated passwords
- As `end_date` / `end_date_relative` are also being removed, default
  `end_date_relative` to 17520h (2 years) which mimics MS Graph
@manicminer
Copy link
Contributor Author

Test Results

Applications - AAD Graph

Screenshot 2021-05-19 at 20 50 55

Applications - MS Graph

Screenshot 2021-05-19 at 21 00 44

Domains - AAD Graph

Screenshot 2021-05-19 at 21 01 45

Domains - MS Graph

Screenshot 2021-05-19 at 21 02 23

Groups - AAD Graph

Screenshot 2021-05-19 at 21 02 55

Groups - MS Graph

Screenshot 2021-05-19 at 21 03 24

Service Principals - AAD Graph

Screenshot 2021-05-19 at 21 04 10

Service Principals - MS Graph

Screenshot 2021-05-19 at 21 04 42

Users - AAD Graph

Screenshot 2021-05-19 at 21 05 17

Users - MS Graph

Screenshot 2021-05-19 at 21 05 46

@manicminer manicminer force-pushed the feature/enable-microsoft-graph branch from c70a8bc to ebaf2ab Compare May 19, 2021 21:24
@manicminer manicminer force-pushed the feature/enable-microsoft-graph branch from ebaf2ab to b2de421 Compare May 19, 2021 21:42
@manicminer manicminer merged commit e9f389f into main May 19, 2021
@manicminer manicminer deleted the feature/enable-microsoft-graph branch May 19, 2021 23:23
@manicminer manicminer restored the feature/enable-microsoft-graph branch May 20, 2021 01:03
@manicminer manicminer deleted the feature/enable-microsoft-graph branch May 20, 2021 01:04
@ken5scal
Copy link

Great work!

@simongottschlag
Copy link

😁🎉🚀💐🥇⭐️🙌🥳

@ghost
Copy link

ghost commented May 20, 2021

This has been released in version 1.5.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azuread" {
    version = "~> 1.5.0"
}
# ... other configuration ...

@JonZeolla
Copy link

Awesome work!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants