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

webpack build breaks aio-lib-ims in runtime actions #55

Closed
moritzraho opened this issue Aug 11, 2020 · 14 comments · Fixed by #56
Closed

webpack build breaks aio-lib-ims in runtime actions #55

moritzraho opened this issue Aug 11, 2020 · 14 comments · Fixed by #56
Assignees
Labels
bug

Comments

@moritzraho
Copy link
Member

moritzraho commented Aug 11, 2020

Relates to #33

Description

When invoking an action that use the lateset aio-lib-ims and was deployed via aio app deloy (built with webpack) we get the following error:

    "result": {
      "error": "Initialization has failed due to: Error: Cannot find module '/package.json'\n    at webpackEmptyContext (/nodejsAction/ov9Ltpr6/index.js:126097:10)\n    at checkNodeVersion (/nodejsAction/ov9Ltpr6/index.js:52777:43)\n    at Object.<anonymous> (/nodejsAction/ov9Ltpr6/index.js:52783:1)\n    at Object.module.exports.Object.defineProperty.value (/nodejsAction/ov9Ltpr6/index.js:52793:30)\n    at __webpack_require__ (/nodejsAction/ov9Ltpr6/index.js:21:30)\n    at Object.module.exports.webpackEmptyContext.keys (/nodejsAction/ov9Ltpr6/index.js:125795:19)\n    at __webpack_require__ (/nodejsAction/ov9Ltpr6/index.js:21:30)\n    at Object.module.exports.Object.defineProperty.value (/nodejsAction/ov9Ltpr6/index.js:51875:36)\n    at __webpack_require__ (/nodejsAction/ov9Ltpr6/index.js:21:30)\n    at Object.<anonymous> (/nodejsAction/ov9Ltpr6/index.js:49883:17)"
    },

The same error appears if we unzip dist/myaction.zip and import the index.js in a node REPL

Reproduce

  • aio app init -> select only actions
  • npm install @adobe/aio-lib-ims
  • require the lib in the action
  • aio app deploy
  • invoke the action => ERROR

Workaround (partial)

use aio-lib-ims 4.0.1 to access the Ims object, getToken won't work because of #33

What causes the error

In 4.0.1...4.1.0diff-d8c50dc3673a2b383c6c1a0a0c19799fR17-R19, removing the import to const imsCliPlugin = require('@adobe/aio-lib-ims-oauth/src/ims-cli') and const imsOAuthPlugin = require('@adobe/aio-lib-ims-oauth') fixes the problem

@moritzraho
Copy link
Member Author

moritzraho commented Aug 11, 2020

cc @shazron

@moritzraho moritzraho added the bug label Aug 12, 2020
@aiojbot
Copy link
Collaborator

aiojbot commented Aug 12, 2020

JIRA issue created: https://jira.corp.adobe.com/browse/ACNA-892

@davidjgonzalez
Copy link

davidjgonzalez commented Aug 25, 2020

Is there an ETA on when this will be released?

@meryllblanchet
Copy link
Contributor

meryllblanchet commented Aug 26, 2020

@davidjgonzalez , we are currently prioritizing the issues and enhancement requests that are open.
Could you provide more input about your use case? Thanks!

@davidjgonzalez
Copy link

davidjgonzalez commented Aug 26, 2020

Update: After an offline conversation with @meryllblanchet (thank you for explaining!) -- So, no ETA required for me anymore :)

It is against Adobe Firefly (which is my use-case) best practices to have the runtime action obtain the Adobe IO Access Token.

Instead, I need to have the service that INVOKES my Firefly app (Runtime action) to obtain/keep-fresh the Adobe IO access token, and PASS it to my Firefly app, for use within my action!

You can read on this pattern at: https://github.com/AdobeDocs/project-firefly/blob/master/guides/security_overview.md

@meryllblanchet
Copy link
Contributor

meryllblanchet commented Aug 26, 2020

Thanks for the great summary and discussion @davidjgonzalez ! On our side we are evaluating options to fix this issue and will provide an update soon.

cc @sandeep-paliwal @shazron

@sandeep-paliwal sandeep-paliwal self-assigned this Aug 27, 2020
@sandeep-paliwal
Copy link
Contributor

sandeep-paliwal commented Aug 28, 2020

We should be able to address this issue by having a different webpack builds (one for CLI and one for deployed action).
Refer to https://webpack.js.org/plugins/define-plugin/#root for more details.
Right now aio-app-scripts and aio-cli-plugin-app repos which will get impacted by the fix are going through refactoring. So will wait for these changes to be made before implementing the suggested fix.

@UrsBoller
Copy link

UrsBoller commented Sep 1, 2020

Update: After an offline conversation with @meryllblanchet (thank you for explaining!) -- So, no ETA required for me anymore :)

It is against Adobe Firefly (which is my use-case) best practices to have the runtime action obtain the Adobe IO Access Token.

Instead, I need to have the service that INVOKES my Firefly app (Runtime action) to obtain/keep-fresh the Adobe IO access token, and PASS it to my Firefly app, for use within my action!

You can read on this pattern at: https://github.com/AdobeDocs/project-firefly/blob/master/guides/security_overview.md

@davidjgonzalez our use case where we need the action to generate the access token is triggered by whisk/alarms package. as far as I know I can't pass any access token to the action - means I need some solution to generate the access token on tuntime.
since the action is not exposed to web/UI I think there should not be any security risks.

@meryllblanchet
Copy link
Contributor

meryllblanchet commented Sep 1, 2020

@UrsBoller thanks for the feedback about your use-case! In both SPA and headless scenarios, the application should not bake the token for its own usage, as documented in the guidelines above.

We'll follow-up to give you the most appropriate recommendation in order to enable your use-case.
cc @sarahxxu

@UrsBoller
Copy link

UrsBoller commented Sep 1, 2020

@meryllblanchet the problem is that my headless action get's triggered only by whisk/alarms. I just need a way to access adobe products (especially adobe analytics) somehow - I just try to figure out a way to get a valid token ... happy to hear any possible solution apart from using auo-lib-ims...

@meryllblanchet
Copy link
Contributor

meryllblanchet commented Sep 2, 2020

@UrsBoller we will sync-up with @duynguyen to review the app solution design and provide the appropriate recommendations.

About this issue itself: we are wrapping up the preliminary Runtime / App plugins refactoring this week (to follow here: adobe/aio-cli-plugin-runtime#191).

We will then be able to work towards a resolution.

@sandeep-paliwal
Copy link
Contributor

sandeep-paliwal commented Sep 14, 2020

Added PR to fix this - #56

@alexkli
Copy link

alexkli commented Sep 15, 2020

Same issue here. (And yes I know it should not be used that way, but I have a temporary special case.)

Workaround: use patch-package with this patch file in patches/@adobe+aio-lib-ims+4.1.0.patch:

diff --git a/node_modules/@adobe/aio-lib-ims/src/token-helper.js b/node_modules/@adobe/aio-lib-ims/src/token-helper.js
index 2206a58..12b0019 100644
--- a/node_modules/@adobe/aio-lib-ims/src/token-helper.js
+++ b/node_modules/@adobe/aio-lib-ims/src/token-helper.js
@@ -14,9 +14,9 @@ const { Ims, ACCESS_TOKEN, REFRESH_TOKEN } = require('./ims')
 const debug = require('debug')('@adobe/aio-lib-ims/token-helper')
 const { getContext } = require('./context')
 
-const imsCliPlugin = require('@adobe/aio-lib-ims-oauth/src/ims-cli')
+const imsCliPlugin = undefined
 const imsJwtPlugin = require('@adobe/aio-lib-ims-jwt')
-const imsOAuthPlugin = require('@adobe/aio-lib-ims-oauth')
+const imsOAuthPlugin = undefined
 
 /**
  * This is the default list of NPM packages used as plugins to create tokens

Thanks @moritzraho's hint in the OP.

@meryllblanchet
Copy link
Contributor

meryllblanchet commented Sep 15, 2020

We expect to release the fix within the next two weeks - see #56.

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

Successfully merging a pull request may close this issue.

8 participants