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 for ManagedIdentity #71

Closed
mbfaay opened this issue Apr 3, 2023 · 10 comments
Closed

Support for ManagedIdentity #71

mbfaay opened this issue Apr 3, 2023 · 10 comments

Comments

@mbfaay
Copy link

mbfaay commented Apr 3, 2023

It would be nice to have support for ManagedIdentityCredential.
e.g. for case where Strapi is running in Azure App Service and media is stored in Azure Storage Account with shared keys disabled.

@mbfaay
Copy link
Author

mbfaay commented Apr 3, 2023

Have a suggested solution available for you.
Based on:
https://learn.microsoft.com/en-us/answers/questions/760656/using-managedidentity-with-node-js-web-app-to-acce

@@ -1,5 +1,6 @@
 import {
     AnonymousCredential,
+    ManagedIdentityCredential,
     BlobServiceClient,
     newPipeline,
     StorageSharedKeyCredential,
@@ -14,6 +15,7 @@ type Config = {
     containerName: string;
     defaultPath: string;
     cdnBaseURL?: string;
+    managedIdentity?: boolean;
 };

 type StrapiFile = File & {
@@ -44,12 +46,18 @@ function makeBlobServiceClient(config: Config) {
     const account = trimParam(config.account);
     const accountKey = trimParam(config.accountKey);
     const sasToken = trimParam(config.sasToken);
+    const managedIdentity = config.managedIdentity;
     const serviceBaseURL = getServiceBaseUrl(config);
-    // if accountKey doesn't contain value return below line
+    // if sasToken contains value return below line
     if (sasToken != '') {
         const anonymousCredential = new AnonymousCredential();
         return new BlobServiceClient(`${serviceBaseURL}${sasToken}`, anonymousCredential);
     }
+    // if managedIdentity is true return below line
+    if (managedIdentity) {
+        const aadCredentials = new ManagedIdentityCredential();
+        return new BlobServiceClient(serviceBaseURL, aadCredentials);
+    }
     const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
     const pipeline = newPipeline(sharedKeyCredential);
     return new BlobServiceClient(serviceBaseURL, pipeline);

@jakeFeldman
Copy link
Owner

Hello @mbfaay, I'm okay supporting other connection types. Would you like to issue a PR?

@mbfaay
Copy link
Author

mbfaay commented Apr 6, 2023

Hi @jakeFeldman, I can issue a PR for supporting managed identity.
Can you give me the rights to create a branch for this?

@mbfaay
Copy link
Author

mbfaay commented Apr 13, 2023

Hi @jakeFeldman, I can issue a PR for supporting managed identity. Can you give me the rights to create a branch for this?

Gentle reminder

@jakeFeldman
Copy link
Owner

Hey @mbfaay thanks for the reminder. You should be able to fork the repo and open a PR from your fork. Let me know if you have any issues doing so.

@nmartin5
Copy link

nmartin5 commented Jul 3, 2023

@jakeFeldman I see that #72 has been approved. Is this still on the roadmap? I would love to start using this feature.
Thanks!

@Jeinhaus
Copy link

Jeinhaus commented Oct 25, 2023

@jakeFeldman This would be awesome to have. Is there anything needed beside the open #72 to get this working?

@jakeFeldman
Copy link
Owner

Hi @Jeinhaus, I haven't looked at #72 in a while and would need testing. If you would like to take ownership on the PR and make sure everything is good to go, I'd be happy to get it merged in

@Jeinhaus
Copy link

@jakeFeldman thank you for responding so quickly.
To be honest, I'm a total Azure, strapi and js noob, but I might give it a try to test #72.
Maybe @mbfaay is still around and have a look at it as well?

@fardarter
Copy link
Contributor

Can be closed now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants