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

Cosmos managed Identity Authentication Changes #3950

Closed
wants to merge 11 commits into from

Conversation

v-ajajvanu
Copy link
Contributor

@v-ajajvanu v-ajajvanu commented Jul 4, 2024

Description

Made changes to support Managed Identity Authentication for Cosmos DB instead of using Secrets.

Related issues

user story AB#122541

Testing

Tested by creating FHIR server instance with code running from publishing new images to ACR that contain managed identity authentication changes.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

@v-ajajvanu v-ajajvanu requested a review from a team as a code owner July 4, 2024 06:02
@v-ajajvanu v-ajajvanu added the New Feature Label for a new feature in FHIR OSS label Jul 4, 2024
@v-ajajvanu v-ajajvanu added this to the S144 milestone Jul 4, 2024
@v-ajajvanu v-ajajvanu added the Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR label Jul 4, 2024
@v-ajajvanu v-ajajvanu modified the milestones: S144, S145 Jul 9, 2024
@v-ajajvanu
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@v-ajajvanu
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Ajaj Vanu added 2 commits July 12, 2024 11:51
private Task _backgroundLoopTask;

public CosmosDbCollectionPhysicalPartitionInfo(
IAccessTokenProvider aadTokenProvider,
Copy link
Contributor

Choose a reason for hiding this comment

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

What "add" in "aadTokenProvider" stands for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abiisnn "aad" stands here for Azure Active Directory.

Copy link
Contributor

@abiisnn abiisnn left a comment

Choose a reason for hiding this comment

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

Left a couple of comments, thanks for fixing it!!

Comment on lines -95 to -112
string key = _dataStoreConfiguration.Key;

if (string.IsNullOrWhiteSpace(host))
{
if (string.IsNullOrWhiteSpace(key))
{
host = CosmosDbLocalEmulator.Host;
key = CosmosDbLocalEmulator.Key;
}
else
{
Ensure.That(host, $"{nameof(CosmosDataStoreConfiguration)}.{nameof(CosmosDataStoreConfiguration.Host)}").IsNotNullOrEmpty();
}
}
else if (string.IsNullOrWhiteSpace(key))
{
Ensure.That(key, $"{nameof(CosmosDataStoreConfiguration)}.{nameof(CosmosDataStoreConfiguration.Key)}").IsNotNullOrEmpty();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep the same behavior but using the new tokenProvider.

We might need to add a new variable called "token" in CosmosDBLocalEmuletor and make sure we clean up "key" in case it is not needed anymore. If "token" is not longer needed (because now you use new DefaultAzureCredential()), then can we clean up all key references?

I think we can keep the same structure because Ensure.That() will throw an exception in case host or token are null or white space, as now, it will just check host and not token.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need "key"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abiisnn We had removed "Key" reference from everywhere.
Also, in CosmosDBLocalEmulator class, we do not need token property as we are using DefaultAzureCredentials, and it generates token internally.

@@ -186,6 +164,23 @@ private static string GenerateAuthToken(string verb, string resourceType, string
return $"type=master&ver=1.0&sig={signature}";
}

private async Task<string> GenerateAccessToken(string host, CancellationToken cancellationToken)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we check that host is not null, empty or white space?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abiisnn We are already checking for "host" as not null and empty or white space in line number 101.
Only after the check is successful, GenerateAccessToken function will get invoked.

@v-ajajvanu
Copy link
Contributor Author

@abiisnn We had worked on the suggestions provided and changes are committed from our end. If possible, could you please review the same and provide feedbacks.

@v-ajajvanu
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@v-ajajvanu
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@v-ajajvanu
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@v-ajajvanu
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@brendankowitz
Copy link
Member

Covered by changes in #4026. The investigation/changes for CosmosDbCollectionPhysicalPartitionInfo was helpful in getting this working under MI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR New Feature Label for a new feature in FHIR OSS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants