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

Support Azure AD auth for Cosmos DB #1104

Merged
merged 8 commits into from Sep 1, 2021
Merged

Support Azure AD auth for Cosmos DB #1104

merged 8 commits into from Sep 1, 2021

Conversation

ItalyPaleAle
Copy link
Contributor

Description

Updated the bindings/azure/cosmosdb and state/azure/cosmosdb components to support auth via Azure AD.

If masterKey is present in the metadata, that's used first. Otherwise, it tries authenticating using Azure AD, including using a service principal (azureClientId and azureClientSecret), a certificate, or MSI.

Issue reference

See #1103

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
    • I cannot do this because I do not have access to the Azure account used by dapr developers
  • Extended the documentation / Created issue in the https://github.com/dapr/docs/ repo: dapr/docs#[issue number]

@daixiang0
Copy link
Member

@ItalyPaleAle happy to see it, please fix CI.

@ItalyPaleAle
Copy link
Contributor Author

@daixiang0 the failed CI is not due to this PR, as I did not touch MQTT. Not sure if it's a previous commit that caused the error or just some flakiness in the test.

@daixiang0
Copy link
Member

For this case, you can re-commit to trigger CI re-run :)

Copy link
Contributor

@CodeMonkeyLeet CodeMonkeyLeet left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding this support, it's much appreciated!

Per the PR template, can you also open an issue in dapr/docs to track documenting the additional support for AD auth in the bindings & state cosmosdb components?

bindings/azure/cosmosdb/cosmosdb.go Outdated Show resolved Hide resolved
@ItalyPaleAle
Copy link
Contributor Author

@CodeMonkeyLeet I was thinking this could be tracked as part of the umbrella issue #1103. Do you want me to create a separate issue for each one?

@CodeMonkeyLeet
Copy link
Contributor

@CodeMonkeyLeet I was thinking this could be tracked as part of the umbrella issue #1103. Do you want me to create a separate issue for each one?

#1103 tracks the general issue to be fixed in dapr/components-contrib, I'm asking for an issue in dapr/docs (or better yet, the documentation PR in dapr/docs) per:

The PR template includes this item because Dapr would like the documentation to be up-to-date with the new features included in each release (in this case, the ability to use Azure AD auth with the CosmosDB) and that's at the granularity of what has been merged into the release.

@ItalyPaleAle
Copy link
Contributor Author

Sorry I missed the part where you were referring to docs. I will open an issue.

Copy link
Contributor

@CodeMonkeyLeet CodeMonkeyLeet left a comment

Choose a reason for hiding this comment

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

LGTM, thanks again for the contribution!

@artursouza artursouza added this to the v1.4 milestone Sep 1, 2021
@codecov
Copy link

codecov bot commented Sep 1, 2021

Codecov Report

Merging #1104 (78f0c3c) into master (253ef85) will decrease coverage by 0.74%.
The diff coverage is 21.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1104      +/-   ##
==========================================
- Coverage   34.53%   33.78%   -0.75%     
==========================================
  Files         132      136       +4     
  Lines       10870    11400     +530     
==========================================
+ Hits         3754     3852      +98     
- Misses       6736     7155     +419     
- Partials      380      393      +13     
Impacted Files Coverage Δ
authentication/azure/storage.go 0.00% <0.00%> (ø)
bindings/azure/cosmosdb/cosmosdb.go 22.78% <0.00%> (-2.93%) ⬇️
bindings/azure/eventhubs/eventhubs.go 17.32% <0.00%> (-0.14%) ⬇️
...indings/azure/servicebusqueues/servicebusqueues.go 15.06% <0.00%> (-0.21%) ⬇️
bindings/gcp/pubsub/pubsub.go 5.26% <0.00%> (-0.15%) ⬇️
bindings/postgres/postgres.go 6.66% <0.00%> (-0.38%) ⬇️
pubsub/jetstream/jetstream.go 0.00% <0.00%> (ø)
pubsub/rocketmq/rocketmq.go 0.00% <ø> (ø)
pubsub/rocketmq/settings.go 86.66% <ø> (ø)
state/azure/cosmosdb/cosmosdb.go 16.03% <0.00%> (-0.28%) ⬇️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e05c8d...78f0c3c. Read the comment docs.

@dapr-bot dapr-bot merged commit a992cd1 into dapr:master Sep 1, 2021
CodeMonkeyLeet pushed a commit to CodeMonkeyLeet/components-contrib that referenced this pull request Sep 2, 2021
PR dapr#1104 introduced a regression in cosmosdb state component `Init()`
by creating a `NewConfig()` which sets a new DefaultIdentificationHydrator,
which causes a panic later when invoked.

Patch this by restoring the configuration setting to use a struct with
`nil` `IdentificationHydrator`.
artursouza pushed a commit that referenced this pull request Sep 2, 2021
PR #1104 introduced a regression in cosmosdb state component `Init()`
by creating a `NewConfig()` which sets a new DefaultIdentificationHydrator,
which causes a panic later when invoked.

Patch this by restoring the configuration setting to use a struct with
`nil` `IdentificationHydrator`.
CodeMonkeyLeet pushed a commit to CodeMonkeyLeet/components-contrib that referenced this pull request Sep 3, 2021
Follow-up to dapr#1104 to support AD Auth codepath as well.

`NewConfig()` and `NewConfigWithServicePrincipal()` both set the
`Config.IdentificationHydrator` to the `DefaultIdentificationHydrator`
in the underlying a8m/documentdb library. That implementation ends up
calling `reflect.Value.Elem.FieldByName()`, which requires that the
value passed to it is an interface or pointer, otherwise the Elem()
call fails to dereference which causes a panic.

cosmosdb.go passes the input to `UpsertDocument` by value today,
which is eventually passed to the `DefaultIdentificationHydrator`,
so changing the value passed to a pointer resolves the failure.
dapr-bot added a commit that referenced this pull request Sep 3, 2021
)

Follow-up to #1104 to support AD Auth codepath as well.

`NewConfig()` and `NewConfigWithServicePrincipal()` both set the
`Config.IdentificationHydrator` to the `DefaultIdentificationHydrator`
in the underlying a8m/documentdb library. That implementation ends up
calling `reflect.Value.Elem.FieldByName()`, which requires that the
value passed to it is an interface or pointer, otherwise the Elem()
call fails to dereference which causes a panic.

cosmosdb.go passes the input to `UpsertDocument` by value today,
which is eventually passed to the `DefaultIdentificationHydrator`,
so changing the value passed to a pointer resolves the failure.

Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
amimimor pushed a commit to amimimor/components-contrib that referenced this pull request Dec 9, 2021
* Support Azure AD auth for Cosmos DB

* Fixed linting errors

* Tidying go.sum

* Removed the need for nolint:shadow

Co-authored-by: Simon Leet <31784195+CodeMonkeyLeet@users.noreply.github.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
amimimor pushed a commit to amimimor/components-contrib that referenced this pull request Dec 9, 2021
PR dapr#1104 introduced a regression in cosmosdb state component `Init()`
by creating a `NewConfig()` which sets a new DefaultIdentificationHydrator,
which causes a panic later when invoked.

Patch this by restoring the configuration setting to use a struct with
`nil` `IdentificationHydrator`.
amimimor pushed a commit to amimimor/components-contrib that referenced this pull request Dec 9, 2021
…pr#1121)

Follow-up to dapr#1104 to support AD Auth codepath as well.

`NewConfig()` and `NewConfigWithServicePrincipal()` both set the
`Config.IdentificationHydrator` to the `DefaultIdentificationHydrator`
in the underlying a8m/documentdb library. That implementation ends up
calling `reflect.Value.Elem.FieldByName()`, which requires that the
value passed to it is an interface or pointer, otherwise the Elem()
call fails to dereference which causes a panic.

cosmosdb.go passes the input to `UpsertDocument` by value today,
which is eventually passed to the `DefaultIdentificationHydrator`,
so changing the value passed to a pointer resolves the failure.

Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
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.

None yet

5 participants