backstage: ๐Ÿ› Bug Report: Backstage 1.24. breaks scaffolder

๐Ÿ“œ Description

Iโ€™ve upgraded backstage to version 1.24 and if I try to execute a template 401 unauthorized is displayed.

๐Ÿ‘ Expected behavior

It should run the template as it was in previous versions.

๐Ÿ‘Ž Actual Behavior with Screenshots

When clicking on create the scaffolder shows an error 401 Unauthorized. No Description or anything.

image

๐Ÿ‘Ÿ Reproduction steps

Go to Scaffolder and run any template.

๐Ÿ“ƒ Provide the context for the Bug.

I think this occurence of the bug comes from the update in the auth system of backstage. After debugging a little bit, I could not find the exact location where the unauthorized request is made. But adding the following code to permissions plugin fixes this error.

http.addAuthPolicy({
    path: "/",
    allow: "unauthenticated"
 });

I think the request must be made by the scaffolder-backend-plugin somewhere, as no errors are shown in the network tab.

๐Ÿ–ฅ๏ธ Your Environment

OS: Darwin 23.4.0 - darwin/arm64 node: v18.17.1 yarn: 3.7.0 cli: 0.26.0 (installed) backstage: 1.24.0

Dependencies: @backstage/app-defaults 1.5.1 @backstage/backend-app-api 0.5.14, 0.6.0 @backstage/backend-common 0.19.10, 0.21.4 @backstage/backend-defaults 0.2.14 @backstage/backend-dev-utils 0.1.4 @backstage/backend-openapi-utils 0.1.7 @backstage/backend-plugin-api 0.6.14 @backstage/backend-tasks 0.5.19 @backstage/backend-test-utils 0.3.4 @backstage/catalog-client 1.6.1 @backstage/catalog-model 1.4.5 @backstage/cli-common 0.1.13 @backstage/cli-node 0.2.4 @backstage/cli 0.26.0 @backstage/config-loader 1.7.0 @backstage/config 1.2.0 @backstage/core-app-api 1.12.1 @backstage/core-compat-api 0.2.1 @backstage/core-components 0.13.10, 0.14.1 @backstage/core-plugin-api 1.9.1 @backstage/dev-utils 1.0.28 @backstage/errors 1.2.4 @backstage/eslint-plugin 0.1.6 @backstage/frontend-plugin-api 0.6.1 @backstage/integration-aws-node 0.1.10 @backstage/integration-react 1.1.25 @backstage/integration 1.9.1 @backstage/plugin-api-docs 0.11.1 @backstage/plugin-app-backend 0.3.62 @backstage/plugin-app-node 0.1.14 @backstage/plugin-auth-backend-module-atlassian-provider 0.1.6 @backstage/plugin-auth-backend-module-aws-alb-provider 0.1.5 @backstage/plugin-auth-backend-module-gcp-iap-provider 0.2.9 @backstage/plugin-auth-backend-module-github-provider 0.1.11 @backstage/plugin-auth-backend-module-gitlab-provider 0.1.11 @backstage/plugin-auth-backend-module-google-provider 0.1.11 @backstage/plugin-auth-backend-module-microsoft-provider 0.1.9 @backstage/plugin-auth-backend-module-oauth2-provider 0.1.11 @backstage/plugin-auth-backend-module-oauth2-proxy-provider 0.1.7 @backstage/plugin-auth-backend-module-oidc-provider 0.1.4 @backstage/plugin-auth-backend-module-okta-provider 0.0.7 @backstage/plugin-auth-backend 0.22.0 @backstage/plugin-auth-node 0.4.9 @backstage/plugin-auth-react 0.0.1 @backstage/plugin-catalog-backend-module-gitlab 0.3.11 @backstage/plugin-catalog-backend-module-openapi 0.1.31 @backstage/plugin-catalog-backend-module-scaffolder-entity-model 0.1.11 @backstage/plugin-catalog-backend-module-unprocessed 0.4.0 @backstage/plugin-catalog-backend 1.18.0 @backstage/plugin-catalog-common 1.0.22 @backstage/plugin-catalog-graph 0.4.1 @backstage/plugin-catalog-import 0.10.7 @backstage/plugin-catalog-node 1.8.0 @backstage/plugin-catalog-react 1.11.0 @backstage/plugin-catalog-unprocessed-entities-common 0.0.1 @backstage/plugin-catalog 1.18.0 @backstage/plugin-events-backend-module-gitlab 0.2.0 @backstage/plugin-events-backend-test-utils 0.1.24 @backstage/plugin-events-backend 0.3.0 @backstage/plugin-events-node 0.3.0 @backstage/plugin-explore-common 0.0.2 @backstage/plugin-github-actions 0.6.12 @backstage/plugin-home-react 0.1.9 @backstage/plugin-home 0.7.0 @backstage/plugin-kubernetes-backend 0.16.0 @backstage/plugin-kubernetes-common 0.7.5 @backstage/plugin-kubernetes-node 0.1.8 @backstage/plugin-kubernetes-react 0.3.1 @backstage/plugin-kubernetes 0.11.6 @backstage/plugin-org 0.6.21 @backstage/plugin-permission-backend-module-allow-all-policy 0.1.11 @backstage/plugin-permission-backend 0.5.37 @backstage/plugin-permission-common 0.7.13 @backstage/plugin-permission-node 0.7.25 @backstage/plugin-permission-react 0.4.21 @backstage/plugin-proxy-backend 0.4.12 @backstage/plugin-scaffolder-backend-module-azure 0.1.6 @backstage/plugin-scaffolder-backend-module-bitbucket-cloud 0.1.4 @backstage/plugin-scaffolder-backend-module-bitbucket-server 0.1.4 @backstage/plugin-scaffolder-backend-module-bitbucket 0.2.4 @backstage/plugin-scaffolder-backend-module-gerrit 0.1.6 @backstage/plugin-scaffolder-backend-module-gitea 0.1.4 @backstage/plugin-scaffolder-backend-module-github 0.2.4 @backstage/plugin-scaffolder-backend-module-gitlab 0.3.0 @backstage/plugin-scaffolder-backend 1.22.0 @backstage/plugin-scaffolder-common 1.5.1 @backstage/plugin-scaffolder-node-test-utils 0.1.0 @backstage/plugin-scaffolder-node 0.4.0 @backstage/plugin-scaffolder-react 1.8.1 @backstage/plugin-scaffolder 1.19.0 @backstage/plugin-search-backend-module-catalog 0.1.18 @backstage/plugin-search-backend-module-explore 0.1.18 @backstage/plugin-search-backend-module-pg 0.5.23 @backstage/plugin-search-backend-module-techdocs 0.1.18 @backstage/plugin-search-backend-node 1.2.18 @backstage/plugin-search-backend 1.5.4 @backstage/plugin-search-common 1.2.11 @backstage/plugin-search-react 1.7.7 @backstage/plugin-search 1.4.7 @backstage/plugin-techdocs-backend 1.10.0 @backstage/plugin-techdocs-module-addons-contrib 1.1.6 @backstage/plugin-techdocs-node 1.12.0 @backstage/plugin-techdocs-react 1.2.0 @backstage/plugin-techdocs 1.10.1 @backstage/plugin-user-settings 0.8.2 @backstage/release-manifests 0.0.11 @backstage/test-utils 1.5.1 @backstage/theme 0.4.4, 0.5.2 @backstage/types 1.1.1 @backstage/version-bridge 1.0.7

๐Ÿ‘€ Have you spent some time to check if this bug has been raised before?

  • I checked and didnโ€™t find similar issue

๐Ÿข Have you read the Code of Conduct?

Are you willing to submit PR?

No, but Iโ€™m happy to collaborate on a PR with someone else

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Reactions: 5
  • Comments: 37 (19 by maintainers)

Most upvoted comments

Apologies - weโ€™ve noticed that there was some issues with the previous patch releases thatโ€™s causing us some headaches with another patch release, so I think weโ€™re going to hold off on both the -next release and the patch release until tomorrow just to make sure weโ€™re in a good state. Sorry for any inconveniences.

Great - expect some releases coming your way later today ๐ŸŽ‰

Works for me ๐Ÿ‘

A new release is hot off the press. Gonna close this issue as it should be fixed in 1.25.0 ๐ŸŽ‰ Nice little bonus release just in time for Easter holidays. ๐Ÿ˜…

My guess is that https://github.com/backstage/backstage/pull/23827 should fix this. Weโ€™re gonna be doing a -next release today, wondering if it makes sense to try with that -next release and then we can ship that as a patch.

Also going to throw together a quick yarn patch to try locally to see if the fix in the PR works which might be a bit quicker than waiting for the -next release.

Some more context: we have migrated to the new backend system, including the new auth services (following these docs). We require an authenticated user everywhere, and do not allow guest access.

Might be able to debug myself a bit more later today

We encounter the same error. After upgrading to 1.24 and moving to Backstageโ€™s built-in authentication, software templates fail with the exact same error as reported above. There is no info in the logs, nor any more output in the UI.

We also use a custom policy, however I see in the network console that the /api/permission/authorize comes back with 200 and { "id": "...", "result": "ALLOW" }. Furthermore our policy only restricts specific actions (mostly related to catalog), but none related to the scaffolder. Any unhandled permission is allowed by default. Therefore I doubt that the permission handling is related to this issue.

Itโ€™s the same for all templates, it does not even start the first step of the template but immediately errors with the 401.

@drodil, I think thatโ€™s because youโ€™ll need to pass an Authorization header to actually see the event stream response. My guess is that once you pass that Authorization token you will see something like @fstoerkle

event: log
data: {"id":5,"taskId":"292f074f-866f-4a9f-b622-0bd74ae7c3df","body":{"message":"Starting up task with 2 steps"},"type":"log","createdAt":"2024-03-26T13:53:46.183Z"}

event: completion
data: {"id":6,"taskId":"292f074f-866f-4a9f-b622-0bd74ae7c3df","body":{"message":"Run completed with status: failed","error":{"name":"ResponseError","message":"Request failed with 401 Unauthorized"}},"type":"completion","createdAt":"2024-03-26T13:53:46.196Z"}

Can confirm ๐Ÿ‘

@freben actually there is no 401 network calls, the message just appears out of nowhere. The tasks endpoint even returns the task as processing but itโ€™s actually failed. No communication at all in the eventstream.

image

Occurs after clicking on the create button after filling out all input steps, right as the scaffolder tasks starts.

Upgraded to 1.24.2, issue still persists.

If it makes a difference, our permission policy has this structure:

async handle(
  request: PolicyQuery,
  user?: BackstageIdentityResponse,
): Promise<PolicyDecision> {
  if (!user) {
    // we require authentication, so we always need a valid user here
    return { result: AuthorizeResult.DENY };
  }

  if (isPermission(...)) {
    ...
    return { result: AuthorizeResult.DENY };
  }

  if (isPermission(...)) {
    ...
    return { result: AuthorizeResult.DENY };
  }

  return { result: AuthorizeResult.ALLOW };
}

Edit: we donโ€™t import/use @backstage/plugin-permission-backend-module-allow-all-policy

@freben thanks, just upgraded to 1.24.1, the issue still persists for us (as expected, as weโ€™re not using the unprocessed module)