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

Latest release 1.24.0 breaks GitHub auth #23748

Closed
2 tasks done
pogo61 opened this issue Mar 21, 2024 · 71 comments
Closed
2 tasks done

Latest release 1.24.0 breaks GitHub auth #23748

pogo61 opened this issue Mar 21, 2024 · 71 comments
Labels
bug Something isn't working

Comments

@pogo61
Copy link

pogo61 commented Mar 21, 2024

📜 Description

I've been trying for the last day to get GitHub auth working, after upgrading to the latest release, assuming it was my fault, even though my config hasn't changed.
Then I noticed that the latest release introduced braking changes to the auth providers.
I downloaded release 1.23.4 and build it and it is working as before.
It would be nice if you had made sure the auth provider plugins worked before releasing these changes.

👍 Expected behavior

Return a HTTP 200

👎 Actual Behavior with Screenshots

This is the error response gotten when trying to auth against gitHub using a GitHub App and the PAT:

"error": {
        "name": "NotFoundError",
        "message": "Unknown auth provider 'github'",
        "stack": "NotFoundError: Unknown auth provider 'github'\n    at <anonymous> (/Users/paulpog/backstage/node_modules/@backstage/plugin-auth-backend/src/service/router.ts:161:11)\n    at handleReturn (/Users/paulpog/backstage/node_modules/express-promise-router/lib/express-promise-router.js:24:23)\n    at /Users/paulpog/backstage/node_modules/express-promise-router/lib/express-promise-router.js:64:7\n    at Layer.handle [as handle_request] (/Users/paulpog/backstage/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/Users/paulpog/backstage/node_modules/express/lib/router/index.js:328:13)\n    at /Users/paulpog/backstage/node_modules/express/lib/router/index.js:286:9\n    at param (/Users/paulpog/backstage/node_modules/express/lib/router/index.js:365:14)\n    at param (/Users/paulpog/backstage/node_modules/express/lib/router/index.js:376:14)\n    at Function.process_params (/Users/paulpog/backstage/node_modules/express/lib/router/index.js:421:3)\n    at next (/Users/paulpog/backstage/node_modules/express/lib/router/index.js:280:10)\n    at /Users/paulpog/backstage/node_modules/express/lib/router/index.js:646:15\n    at next (/Users/paulpog/backstage/node_modules/express/lib/router/index.js:265:14)\n    at Function.handle (/Users/paulpog/backstage/node_modules/express/lib/router/index.js:175:3)\n    at router (/Users/paulpog/backstage/node_modules/express/lib/router/index.js:47:12)\n    at handleReturn (/Users/paulpog/backstage/node_modules/express-promise-router/lib/express-promise-router.js:24:23)\n    at router (/Users/paulpog/backstage/node_modules/express-promise-router/lib/express-promise-router.js:64:7)"
    },
    "request": {
        "method": "GET",
        "url": "/api/auth/github/refresh?optional&scope=read%3Auser&env=development"
    },
    "response": {
        "statusCode": 404
    }
} 

👟 Reproduction steps

settings->Authentication Providers -> choose GitHub->sign in

📃 Provide the context for the Bug.

No response

🖥️ Your Environment

local installation of backstage with env:development

👀 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?

None

@pogo61 pogo61 added the bug Something isn't working label Mar 21, 2024
@ryan-WORK
Copy link

ryan-WORK commented Mar 21, 2024

Hey is this the Authorization callback URL?

http://localhost:7007/api/auth/github/handler/frame?

If so try this:

http://localhost:7007/api/auth/github

@pogo61
Copy link
Author

pogo61 commented Mar 21, 2024

@ryan-WORK I take it that this is the GitHub App callback URL that needs changing?

@ryan-WORK
Copy link

@pogo61 yup thats the one:

Screenshot 2024-03-21 at 1 17 25 AM

@pogo61
Copy link
Author

pogo61 commented Mar 21, 2024

@ryan-WORK sorry, that did nothing... same response
Just to make sure we are on the same page.... I'm not using OAuth, just the basic GitHub App with the PAT

@Rugvip
Copy link
Member

Rugvip commented Mar 21, 2024

What does tour config look like? If you happen to have something like this it might disable the provider now:

auth:
  providers:
    github:

@freben
Copy link
Member

freben commented Mar 21, 2024

Hi,

I just tried this on latest master and cannot reproduce, at least so far.

Indeed I also used the callback URL http://localhost:7007/api/auth/github in the OAuth app.

Since the error says that it cannot find the provider at all, I am wondering if instead of the auth changes, maybe it could be related to #23339 . Do you have anywhere in your config a naked github: without any children? That gets interpreted as github: null by yaml. Something that might make it so that the providers.github key actually become unset and therefore the provider doesn't get loaded.

When running locally, you can check the logs at startup to see what providers get loaded.

Also you can use the yarn backstage-cli config:print command to print an actual resolved output config. You may want to add the --lax flag to that to not have to set all env vars. You may also want to pass in the same --config arguments that you use in production (in the same order too), to ensure that what gets printed is as production-like as possible. Then when you have that printout, look into the auth.providers key space to see what's in there.

EDIT: Heh, @Rugvip got in there before me as I typed this

@pogo61
Copy link
Author

pogo61 commented Mar 21, 2024

This IS NOT an OAuth App, it’s the normal GitHub App in conjunction with a PAT.
Methinks you guys have gotten tunnel vision about using OAuth, and forgotten about the other option.
also, as originally stated, the config was unchanged

@eilonash92
Copy link

eilonash92 commented Mar 21, 2024

@freben

I'm having the same issue using oAuth app -
image

This is my config print and using local config file -
What am I missing?

*[main][~/repos/aura-backstage]$ yarn backstage-cli config:print
yarn run v1.22.22
$ /Users/eilon.ashkenazi/repos/aura-backstage/node_modules/.bin/backstage-cli config:print
Loaded config from app-config.yaml, app-config.local.yaml
app:
  title: Aura Backstage
  baseUrl: http://localhost:3000
backend:
  database:
    connection:
      host: localhost
      port: 5432
      user: postgres
      password: <secret>
    client: better-sqlite3
  baseUrl: http://localhost:7007
  listen:
    port: 7007
  csp:
    connect-src:
      - "'self'"
      - "http:"
      - "https:"
  cors:
    origin: http://localhost:3000
    methods:
      - GET
      - HEAD
      - PATCH
      - POST
      - PUT
      - DELETE
    credentials: true
auth:
  environment: development
  providers:
    github:
      development:
        clientId: 17208d9d0746c9766a77
        clientSecret: <secret>
integrations:
  github:
    - host: github.com
      token: <secret>
organization:
  name: My Company
techdocs:
  builder: local
  generator:
    runIn: docker
  publisher:
    type: local
catalog:
  import:
    entityFilename: catalog-info.yaml
    pullRequestBranchName: backstage-integration
  rules:
    - allow:
        - Component
        - System
        - API
        - Resource
        - Location
  locations:
    - type: file
      target: ../../examples/entities.yaml
    - type: file
      target: ../../examples/template/template.yaml
      rules:
        - allow:
            - Template
    - type: file
      target: ../../examples/org.yaml
      rules:
        - allow:
            - User
            - Group

Error -

{
"error": {
"name": "NotFoundError",
"message": "Unknown auth provider 'github'",
"stack": "NotFoundError: Unknown auth provider 'github'\n    at <anonymous> (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/@backstage/plugin-auth-backend/src/service/router.ts:161:11)\n    at handleReturn (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express-promise-router/lib/express-promise-router.js:24:23)\n    at /Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express-promise-router/lib/express-promise-router.js:64:7\n    at Layer.handle [as handle_request] (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:328:13)\n    at /Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:286:9\n    at param (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:365:14)\n    at param (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:376:14)\n    at Function.process_params (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:421:3)\n    at next (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:280:10)\n    at /Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:646:15\n    at next (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:265:14)\n    at Function.handle (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:175:3)\n    at router (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express/lib/router/index.js:47:12)\n    at handleReturn (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express-promise-router/lib/express-promise-router.js:24:23)\n    at router (/Users/eilon.ashkenazi/repos/aura-backstage/node_modules/express-promise-router/lib/express-promise-router.js:64:7)"
},
"request": {
"method": "GET",
"url": "[/api/auth/github/start?scope=read%3Auser&origin=http%3A%2F%2Flocalhost%3A3000&flow=popup&env=development](http://localhost:7007/api/auth/github/start?scope=read%3Auser&origin=http%3A%2F%2Flocalhost%3A3000&flow=popup&env=development)"
},
"response": {
"statusCode": 404
}
}

@freben
Copy link
Member

freben commented Mar 21, 2024

Still trying to reproduce.

  1. Set up an oauth app

  2. Run npx @backstage/create-app@latest

  3. Edit app-config.yaml to add

    auth:
      environment: development
      providers:
        guest: {}
        github:
          development:
            clientId: 2da...46f
            clientSecret: 531...3ce
  4. In the app somewhere, add

    const auth = useApi(githubAuthApiRef);
    auth.getAccessToken('repo').then(
      token => console.log('success', token),
      error => console.log('failure', error),
    );

That does work fine

@eilonash92
Copy link

import React from 'react';
import { Navigate, Route } from 'react-router-dom';
import { apiDocsPlugin, ApiExplorerPage } from '@backstage/plugin-api-docs';
import {
  CatalogEntityPage,
  CatalogIndexPage,
  catalogPlugin,
} from '@backstage/plugin-catalog';
import {
  CatalogImportPage,
  catalogImportPlugin,
} from '@backstage/plugin-catalog-import';
import { ScaffolderPage, scaffolderPlugin } from '@backstage/plugin-scaffolder';
import { orgPlugin } from '@backstage/plugin-org';
import { SearchPage } from '@backstage/plugin-search';
import { TechRadarPage } from '@backstage/plugin-tech-radar';
import {
  TechDocsIndexPage,
  techdocsPlugin,
  TechDocsReaderPage,
} from '@backstage/plugin-techdocs';
import { TechDocsAddons } from '@backstage/plugin-techdocs-react';
import { ReportIssue } from '@backstage/plugin-techdocs-module-addons-contrib';
import { UserSettingsPage } from '@backstage/plugin-user-settings';
import { apis } from './apis';
import { entityPage } from './components/catalog/EntityPage';
import { searchPage } from './components/search/SearchPage';
import { Root } from './components/Root';

import {
  AlertDisplay,
  OAuthRequestDialog,
  SignInProviderConfig,
  SignInPage,
} from '@backstage/core-components';
import { createApp } from '@backstage/app-defaults';
import { AppRouter, FlatRoutes } from '@backstage/core-app-api';
import { CatalogGraphPage } from '@backstage/plugin-catalog-graph';
import { RequirePermission } from '@backstage/plugin-permission-react';
import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/alpha';
import { githubAuthApiRef } from '@backstage/core-plugin-api';

const githubProvider: SignInProviderConfig = {
  id: 'github-auth-provider',
  title: 'GitHub',
  message: 'Sign in using GitHub',
  apiRef: githubAuthApiRef,
};

const app = createApp({
  apis,
  bindRoutes({ bind }) {
    bind(catalogPlugin.externalRoutes, {
      createComponent: scaffolderPlugin.routes.root,
      viewTechDoc: techdocsPlugin.routes.docRoot,
      createFromTemplate: scaffolderPlugin.routes.selectedTemplate,
    });
    bind(apiDocsPlugin.externalRoutes, {
      registerApi: catalogImportPlugin.routes.importPage,
    });
    bind(scaffolderPlugin.externalRoutes, {
      registerComponent: catalogImportPlugin.routes.importPage,
      viewTechDoc: techdocsPlugin.routes.docRoot,
    });
    bind(orgPlugin.externalRoutes, {
      catalogIndex: catalogPlugin.routes.catalogIndex,
    });
  },
  components: {
    SignInPage: props => (
      <SignInPage
        {...props}
        auto
        provider={githubProvider}
      />
    ),
  },
});


const routes = (
  <FlatRoutes>
    <Route path="/" element={<Navigate to="catalog" />} />
    <Route path="/catalog" element={<CatalogIndexPage />} />
    <Route
      path="/catalog/:namespace/:kind/:name"
      element={<CatalogEntityPage />}
    >
      {entityPage}
    </Route>
    <Route path="/docs" element={<TechDocsIndexPage />} />
    <Route
      path="/docs/:namespace/:kind/:name/*"
      element={<TechDocsReaderPage />}
    >
      <TechDocsAddons>
        <ReportIssue />
      </TechDocsAddons>
    </Route>
    <Route path="/create" element={<ScaffolderPage />} />
    <Route path="/api-docs" element={<ApiExplorerPage />} />
    <Route
      path="/tech-radar"
      element={<TechRadarPage width={1500} height={800} />}
    />
    <Route
      path="/catalog-import"
      element={
        <RequirePermission permission={catalogEntityCreatePermission}>
          <CatalogImportPage />
        </RequirePermission>
      }
    />
    <Route path="/search" element={<SearchPage />}>
      {searchPage}
    </Route>
    <Route path="/settings" element={<UserSettingsPage />} />
    <Route path="/catalog-graph" element={<CatalogGraphPage />} />
  </FlatRoutes>
);

export default app.createRoot(
  <>
    <AlertDisplay />
    <OAuthRequestDialog />
    <AppRouter>
      <Root>{routes}</Root>
    </AppRouter>
  </>,
);

What is missing in my code? @freben

@eilonash92
Copy link

eilonash92 commented Mar 21, 2024

@freben
I added these blocks -

const githubProvider: SignInProviderConfig = {
  id: 'github-auth-provider',
  title: 'GitHub',
  message: 'Sign in using GitHub',
  apiRef: githubAuthApiRef,
};

components: {
    SignInPage: props => (
      <SignInPage
        {...props}
        auto
        provider={githubProvider}
      />
    ),
  },

@pogo61
Copy link
Author

pogo61 commented Mar 21, 2024

Hold on!
Where in the doco does it say to add those blocks and where should they be added????

@ryan-WORK
Copy link

@pogo61
Copy link
Author

pogo61 commented Mar 21, 2024

@ryan-WORK that has always been optional and it doesn’t include this
const githubProvider: SignInProviderConfig = {
id: 'github-auth-provider',
title: 'GitHub',
message: 'Sign in using GitHub',
apiRef: githubAuthApiRef,
};
so has something changed?

@freben
Copy link
Member

freben commented Mar 21, 2024

I'll keep reproducing and hopefully issue a fix tomorrow

@pogo61
Copy link
Author

pogo61 commented Mar 21, 2024

@freben Brilliant... thanks

@vinzscam
Copy link
Member

have you switched to the new backend system by changing your packages/backend/src/index.ts according to https://backstage.github.io/upgrade-helper/?from=1.23.4&to=1.24.0 ?

If yes, you might have missed adding

  // auth plugin
  backend.add(import('@backstage/plugin-auth-backend'));
  // See https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin
  backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
  // See https://github.com/backstage/backstage/blob/master/docs/auth/guest/provider.md

+ backend.add(import('@backstage/plugin-auth-backend-module-github-provider'));
  // catalog plugin
  backend.add(import('@backstage/plugin-catalog-backend/alpha'));
  backend.add(
    import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'),
  );

More info in https://backstage.io/docs/backend-system/building-backends/migrating/#the-auth-plugin

@giocolas
Copy link

just to inform that same issue I verified using Microsoft auth provider.
This is my portion in App.tsx:

const app = createApp({
  ...
  components: {
    SignInPage: props => (
      <SignInPage
        {...props}
        auto
        provider={{
          id: 'microsoft-auth-provider',
          title: 'Microsoft',
          message: 'Sign in using microsoft',
          apiRef: microsoftAuthApiRef,
        }}
      />
    ),
  },

This is my part in backend:

// auth plugin
backend.add(import('@backstage/plugin-auth-backend'));
// backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
backend.add(import('@backstage/plugin-auth-backend-module-microsoft-provider'));

This is my app-config.yaml:

auth:
  environment: development
  providers:
    microsoft:
      development:
        clientId: ${AUTH_MICROSOFT_CLIENT_ID}
        clientSecret: ${AUTH_MICROSOFT_CLIENT_SECRET}
        tenantId: ${AUTH_MICROSOFT_TENANT_ID}

and finally I tested request of refresh / access tokens by backend returns in browser's network tab correctly status code 200!

@freben
Copy link
Member

freben commented Mar 22, 2024

@giocolas Thanks - just double checking, are you saying that you do NOT have the problem anymore? Is all good on your end?

@giocolas
Copy link

No, maybe I expressed myself badly: I detect the same problem with the Microsoft auth provider!

@freben
Copy link
Member

freben commented Mar 22, 2024

It's weird, I cannot for the life of me reproduce this yet. If someone can upload a repo that exhibits the problem, that would be great

@sennyeya
Copy link
Contributor

Can you share startup logs from your backend? The auth backend will spit out some errors when it has a provider installed that isn't correctly set up.

@SeanoNET
Copy link

Same issue for me, I am new to this project. I followed the getting started guide

https://backstage.io/docs/getting-started/

and then straight into adding authentication and got the same error.

https://backstage.io/docs/getting-started/config/authentication

@Parsifal-M
Copy link
Contributor

Hey Peeps 👋

I've just upgraded my repo from 1.22.2 to 1.24.0 and I am using a GitHub oAuth App and it all seems fine to me .. so far.

Not sure if it helps at all but here is the PR I have to upgrade versions.

I know @pogo61 has mentioned they are not using the oAuth App so sadly this won't help in that case, but others above have also mentioned they have issues with oAuth.

Hopefully this helps!

Thanks!

@freben
Copy link
Member

freben commented Mar 22, 2024

@pogo61 Just to be sure even though I don't think it's related, I've installed a proper GitHub app now too (originally generated with yarn backstage-cli create-github-app <repo>) and signing in with that works just as well - both for regular sign-in-page at the start, and for negotiating ghu access tokens.

@freben
Copy link
Member

freben commented Mar 22, 2024

@eilonash92 @SeanoNET what does your packages/backend/src/index.ts look like? See the comment above

@freben
Copy link
Member

freben commented Mar 22, 2024

@giocolas Can you describe the steps you are taking and what you are seeing? Step by step and the expected vs actual outcome. Just to see exactly where in your process things fail.

Also, do check the backend log output for anomalies.

@SeanoNET
Copy link

SeanoNET commented Mar 22, 2024

@freben - I have added backend.add(import('@backstage/plugin-auth-backend-module-github-provider')); into packages/backend/src/index.ts and I am getting this error above the SIGN IN button.

The GitHub provider is not configured to support sign-in

EDIT

after doing some research it appears i need to configure a github resolver in packages/backend/src/plugins/auth.ts however my generated project doesnt contain that file or packages/backend/src/plugins folder.

@freben
Copy link
Member

freben commented Mar 22, 2024

Yeah i think the docs need to be updated now that the default is the new backend system. See this section instead:

https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin

It shows how you add the signIn key in config. There's indeed no longer a plugins folder in there

@freben
Copy link
Member

freben commented Mar 23, 2024

I responded in there. You just hadn't added the github module for the scaffolder.

@Dogacel
Copy link

Dogacel commented Mar 23, 2024

have you switched to the new backend system by changing your packages/backend/src/index.ts according to https://backstage.github.io/upgrade-helper/?from=1.23.4&to=1.24.0 ?

If yes, you might have missed adding

  // auth plugin
  backend.add(import('@backstage/plugin-auth-backend'));
  // See https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin
  backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
  // See https://github.com/backstage/backstage/blob/master/docs/auth/guest/provider.md

+ backend.add(import('@backstage/plugin-auth-backend-module-github-provider'));
  // catalog plugin
  backend.add(import('@backstage/plugin-catalog-backend/alpha'));
  backend.add(
    import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'),
  );

More info in https://backstage.io/docs/backend-system/building-backends/migrating/#the-auth-plugin

And

Thanks everyone! Confirming adding a user to examples\org.yaml fixed my problem also. I appreciated the patience as this is all new to me :)

apiVersion: backstage.io/v1alpha1
kind: User
metadata:
  name: seanonet
spec:
  memberOf: [guests]

was the answer for my problem 🙏 Thanks!

The following pages need updating (and probably other providers too)

@sivaprasadreddy
Copy link

I followed all the steps mentioned in this thread:

  1. Update app-config.yaml
  2. Update packages/app/src/App.tsx
  3. Update packages/backend/src/index.ts
  4. Update examples/org.yaml to change "guest" to my GH username.

But, still getting "The GitHub provider is not configured to support sign-in" error.

@freben
Copy link
Member

freben commented Mar 23, 2024

@sivaprasadreddy you probably forgot to add the signIn key on your provider in app-config. https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin

@sivaprasadreddy
Copy link

After adding the resolvers, it worked. @freben Thanks.

auth:
  environment: development
  providers:
    github:
      development:
        clientId: xxxxxx
        clientSecret: xxxxxxx
        signIn:
          resolvers:
            - resolver: emailMatchingUserEntityProfileEmail
            - resolver: emailLocalPartMatchingUserEntityName
            - resolver: usernameMatchingUserEntityName

@HiGein
Copy link

HiGein commented Mar 24, 2024

Having the same issue. Did all the steps as @sivaprasadreddy, now something different appeared:

Login failed, user profile does not contain an email

UPD. Fixed by making my email visible in GitHub and selecting it in settings.

@freben
Copy link
Member

freben commented Mar 26, 2024

Alright, I think we'll consider this a general "migration questions" thread at this point, rather than an actual underlying issue to be fixed. That's perfectly fine, but just noting that if I understand things correctly, there are no actionable outcomes besides docs improvements which we agree really are needed. I'll close for now, but of course it stays around and is searchable and hopefully helps others who encounter the same type of situations.

@freben freben closed this as completed Mar 26, 2024
@bluu926
Copy link

bluu926 commented Mar 27, 2024

I got this to work by adding the resolvers above and updating examples/org.yaml to my own user, but how do we add more users or can we use a github Team instead?

@freben
Copy link
Member

freben commented Mar 27, 2024

@bluu926 You are meant to add a catalog integration with some provider of actual user/group data, like ldap or whatnot. See the different "Org" sections under https://backstage.io/docs/integrations/

@vinzscam
Copy link
Member

I got this to work by adding the resolvers above and updating examples/org.yaml to my own user, but how do we add more users or can we use a github Team instead?

you probably need to use the appropriate resolved in your app-config.yaml. Depending on your use case you might want to choose between emailMatchingUserEntityProfileEmail , emailLocalPartMatchingUserEntityName or usernameMatchingUserEntityName

@Estehsan
Copy link

Estehsan commented Apr 1, 2024

I followed every step, yet I'm still encountering an error when trying to log in with Microsoft.

Login failed; caused by Error: Failed to sign-in, unable to resolve user identity

@vinzscam
Copy link
Member

vinzscam commented Apr 1, 2024

I followed every step, yet I'm still encountering an error when trying to log in with Microsoft.

Login failed; caused by Error: Failed to sign-in, unable to resolve user identity

Hi @Estehsan,
does your app-config.yaml contain the following?

auth:
  environment: development
  providers:
    microsoft:
      development:
        clientId: ${AZURE_CLIENT_ID}
        clientSecret: ${AZURE_CLIENT_SECRET}
        tenantId: ${AZURE_TENANT_ID}
        signIn:
          resolvers:
            # one of the following resolvers
            - resolver: emailMatchingUserEntityAnnotation
            - resolver: emailMatchingUserEntityProfileEmail
            - resolver: emailLocalPartMatchingUserEntityName

the error you are getting is due to the fact that either you don't have any resolver in place or none of your resolvers can match the provided user, meaning that the ingestion in the catalog isn't working as it should

cc @Sarabadu 😅

@sara4dev
Copy link

sara4dev commented Apr 11, 2024

I followed every step, yet I'm still encountering an error when trying to log in with Microsoft.

Login failed; caused by Error: Failed to sign-in, unable to resolve user identity

@Estehsan - I got into the same issue too. It turns out I need to have the user ingested into the system (via Azure integrations) that should match the user trying to login.

@paco-sparta
Copy link

paco-sparta commented Apr 11, 2024

The patch I applied is below. Note that you'll need to import the entities as I mentioned on this message: #23748 (comment)

diff --git a/app-config.yaml b/app-config.yaml
index 248cff1..416b120 100644
--- a/app-config.yaml
+++ b/app-config.yaml
@@ -66,6 +66,13 @@ auth:
   # see https://backstage.io/docs/auth/ to learn about auth providers
   providers:
     # See https://backstage.io/docs/auth/guest/provider
+    github:
+      development:
+        clientId: XXX
+        clientSecret: YYY
+        signIn:
+          resolvers:
+            - resolver: usernameMatchingUserEntityName
     guest: {}
 
 scaffolder:
diff --git a/examples/org.yaml b/examples/org.yaml
index a10e81f..2dbbda9 100644
--- a/examples/org.yaml
+++ b/examples/org.yaml
@@ -15,3 +15,12 @@ metadata:
 spec:
   type: team
   children: []
+---
+# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-user
+apiVersion: backstage.io/v1alpha1
+kind: User
+metadata:
+  name: paco-sparta
+spec:
+  memberOf: [guests]
+---
diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx
index f751cf6..51aa0e5 100644
--- a/packages/app/src/App.tsx
+++ b/packages/app/src/App.tsx
@@ -26,6 +26,8 @@ import { apis } from './apis';
 import { entityPage } from './components/catalog/EntityPage';
 import { searchPage } from './components/search/SearchPage';
 import { Root } from './components/Root';
+import { githubAuthApiRef } from '@backstage/core-plugin-api';
+import { AutoLogout } from '@backstage/core-components';
 
 import {
   AlertDisplay,
@@ -58,7 +60,21 @@ const app = createApp({
     });
   },
   components: {
-    SignInPage: props => <SignInPage {...props} auto providers={['guest']} />,
+    SignInPage: props => (
+      <SignInPage
+        {...props}
+        auto
+        providers={[
+          'guest',
+          {
+            id: 'github-auth-provider',
+            title: 'GitHub',
+            message: 'Sign in using GitHub',
+            apiRef: githubAuthApiRef,
+          },
+        ]}
+      />
+    ),
   },
 });
 
@@ -107,6 +123,7 @@ export default app.createRoot(
   <>
     <AlertDisplay />
     <OAuthRequestDialog />
+    <AutoLogout />
     <AppRouter>
       <Root>{routes}</Root>
     </AppRouter>
diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts
index 44fde69..6fdd0a9 100644
--- a/packages/backend/src/index.ts
+++ b/packages/backend/src/index.ts
@@ -17,6 +17,7 @@ backend.add(import('@backstage/plugin-techdocs-backend/alpha'));
 
 // auth plugin
 backend.add(import('@backstage/plugin-auth-backend'));
+backend.add(import('@backstage/plugin-auth-backend-module-github-provider'));
 // See https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin
 backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
 // See https://github.com/backstage/backstage/blob/master/docs/auth/guest/provider.md

@Chilinot
Copy link

The patch I applied:

diff --git a/app-config.yaml b/app-config.yaml
index 248cff1..416b120 100644
--- a/app-config.yaml
+++ b/app-config.yaml
@@ -66,6 +66,13 @@ auth:
   # see https://backstage.io/docs/auth/ to learn about auth providers
   providers:
     # See https://backstage.io/docs/auth/guest/provider
+    github:
+      development:
+        clientId: XXX
+        clientSecret: YYY
+        signIn:
+          resolvers:
+            - resolver: usernameMatchingUserEntityName
     guest: {}
 
 scaffolder:
diff --git a/examples/org.yaml b/examples/org.yaml
index a10e81f..2dbbda9 100644
--- a/examples/org.yaml
+++ b/examples/org.yaml
@@ -15,3 +15,12 @@ metadata:
 spec:
   type: team
   children: []
+---
+# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-user
+apiVersion: backstage.io/v1alpha1
+kind: User
+metadata:
+  name: paco-sparta
+spec:
+  memberOf: [guests]
+---
diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx
index f751cf6..51aa0e5 100644
--- a/packages/app/src/App.tsx
+++ b/packages/app/src/App.tsx
@@ -26,6 +26,8 @@ import { apis } from './apis';
 import { entityPage } from './components/catalog/EntityPage';
 import { searchPage } from './components/search/SearchPage';
 import { Root } from './components/Root';
+import { githubAuthApiRef } from '@backstage/core-plugin-api';
+import { AutoLogout } from '@backstage/core-components';
 
 import {
   AlertDisplay,
@@ -58,7 +60,21 @@ const app = createApp({
     });
   },
   components: {
-    SignInPage: props => <SignInPage {...props} auto providers={['guest']} />,
+    SignInPage: props => (
+      <SignInPage
+        {...props}
+        auto
+        providers={[
+          'guest',
+          {
+            id: 'github-auth-provider',
+            title: 'GitHub',
+            message: 'Sign in using GitHub',
+            apiRef: githubAuthApiRef,
+          },
+        ]}
+      />
+    ),
   },
 });
 
@@ -107,6 +123,7 @@ export default app.createRoot(
   <>
     <AlertDisplay />
     <OAuthRequestDialog />
+    <AutoLogout />
     <AppRouter>
       <Root>{routes}</Root>
     </AppRouter>
diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts
index 44fde69..6fdd0a9 100644
--- a/packages/backend/src/index.ts
+++ b/packages/backend/src/index.ts
@@ -17,6 +17,7 @@ backend.add(import('@backstage/plugin-techdocs-backend/alpha'));
 
 // auth plugin
 backend.add(import('@backstage/plugin-auth-backend'));
+backend.add(import('@backstage/plugin-auth-backend-module-github-provider'));
 // See https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin
 backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
 // See https://github.com/backstage/backstage/blob/master/docs/auth/guest/provider.md

Thanks a lot! However even after applying these exact patches on a new backstage installation i am still getting Login failed; caused by Error: Failed to sign-in, unable to resolve user identity when trying to authenticate.

@Chilinot
Copy link

Chilinot commented Apr 19, 2024

This is what my app-config.yml looks like:

auth:
  environment: development
  # see https://backstage.io/docs/auth/ to learn about auth providers
  providers:
    # See https://backstage.io/docs/auth/guest/provider
    guest: {}
    github:
      development:
        clientId: 'xxx'
        clientSecret: 'xxx'
        signIn:
          resolvers:
            - resolver: usernameMatchingUserEntityName

@Chilinot
Copy link

Turns out i missed this patch:

diff --git a/examples/org.yaml b/examples/org.yaml
index a10e81f..2dbbda9 100644
--- a/examples/org.yaml
+++ b/examples/org.yaml
@@ -15,3 +15,12 @@ metadata:
 spec:
   type: team
   children: []
+---
+# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-user
+apiVersion: backstage.io/v1alpha1
+kind: User
+metadata:
+  name: chilinot
+spec:
+  memberOf: [guests]
+---

@paco-sparta
Copy link

paco-sparta commented Apr 19, 2024

Yeah, you need another plugin to import your User + Group + Repo entities from github.

backend.add(import('@backstage/plugin-catalog-backend-module-github/alpha'));
backend.add(import('@backstage/plugin-catalog-backend-module-github-org'));
integrations:
  github:
    - host: github.com
      // Personal Access Token
      token: ghp_XXXX

....

catalog:
  import:
    entityFilename: catalog-info.yaml
    pullRequestBranchName: backstage-integration
  providers:
    github:
      your-org-gh-provider:
        organization: <yourOrg>
        schedule:
          frequency: PT30M
          timeout: PT30S
    githubOrg:
      id: <your-org>
      orgs: [<yourOrg>]
      githubUrl: https://github.com/
      schedule:
        frequency: PT30M
        timeout: PT30S

@pogo61
Copy link
Author

pogo61 commented Apr 19, 2024

Yeah, you need another plugin to import your User + Group + Repo entities from github.

backend.add(import('@backstage/plugin-catalog-backend-module-github/alpha'));

backend.add(import('@backstage/plugin-catalog-backend-module-github-org'));
integrations:

  github:

    - host: github.com

      // Personal Access Token

      token: ghp_XXXX



....



catalog:

  import:

    entityFilename: catalog-info.yaml

    pullRequestBranchName: backstage-integration

  providers:

    github:

      your-org-gh-provider:

        organization: <yourOrg>

        schedule:

          frequency: PT30M

          timeout: PT30S

    githubOrg:

      id: <your-org>

      orgs: [<yourOrg>]

      githubUrl: https://github.com/

      schedule:

        frequency: PT30M

        timeout: PT30S

I disagree.

  • Take a look at my solution further up the chain. All you need to do is add a definition of your GitHub user to the /examples/org.yaml file

@paco-sparta
Copy link

paco-sparta commented Apr 19, 2024

Obviously hardcoding the users will also work. Pulling from the org keeps it up-to-date and doesn't require redeploying whenever a dev joins or leaves the company.

@pogo61
Copy link
Author

pogo61 commented Apr 19, 2024

Obviously hardcoding the users will also work. Pulling from the org keeps it up-to-date and doesn't require redeploying whenever a dev joins or leaves the company.

There are many ways to do that, what I indicated was a way of boot strapping Backstage so that you could use it. It would totally depend on what authentication integration you have defined as to what you do after that. BYW, a change to the base configuration will result in a re-initiation of Backstage without the need to redeploy.

@shadygrove
Copy link

shadygrove commented May 1, 2024

I am going to try and summarize it all in one post for others. This is for enabling Github Auth:

Create an OAuth app in Github account under Developer Settings

Add auth section to app-config.yaml:

auth:
  # see https://backstage.io/docs/auth/ to learn about auth providers
  environment: development
  providers:
    github:
      development:
        clientId: 6cfd...9bd
        clientSecret: 7695...546c
        signIn:
          resolvers:
            # Only one of these
            - resolver: emailMatchingUserEntityProfileEmail
            - resolver: emailLocalPartMatchingUserEntityName
            - resolver: usernameMatchingUserEntityName

NOTE: the resolvers used is dependent on the auth provider being used!

Update the Frontend. Add the following to packages/app/src/App.tsx

import { githubAuthApiRef } from '@backstage/core-plugin-api';

const githubAuthCfg = {
  id: 'github-auth-provider',
  title: 'GitHub',
  message: 'Sign in using GitHub',
  apiRef: githubAuthApiRef,
} 

...

components: {
    SignInPage: props => <SignInPage {...props} auto providers={['guest', githubAuthCfg]} />,
},

Update the Backend: add github provider import in packages/backend/src/index.ts:

backend.add(import('@backstage/plugin-auth-backend-module-github-provider'))  

Make sure your Github user is defined in examples/org.yaml

# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-user
apiVersion: backstage.io/v1alpha1
kind: User
metadata:
  name: <github-username>
spec:
  memberOf: [guests]

Hope that helps the next person that comes along. This was a bit tricky to track down for this Backstage newbie that simply wanted to do a local run to explore.

@awanlin
Copy link
Collaborator

awanlin commented May 2, 2024

Hope that helps the next person that comes along. This was a bit tricky to track down for this Backstage newbie that simply wanted to do a local run to explore.

Hi @shadygrove, sorry you had issues with this, the docs for sure have not been helpful. I've been slowly working to fix this in many areas. If you are open to it would like to get some feedback: was the issue that there was no docs at all our that they were spread out in a way that made them hard to find? If you'd rather chat on the Backstage Discord that works too I'm Ahhhndre there.

@shadygrove
Copy link

@awanlin thanks for reaching out. I will follow up on Discord to prevent this issue from getting sidetracked in unrelated discussion.

@hungryengineer
Copy link

hungryengineer commented May 4, 2024

Got it working

@hungryengineer
Copy link

  • Update app-config.yaml
  • Update packages/app/src/App.tsx
  • Update packages/backend/src/index.ts
  • Update examples/org.yaml to change "guest" to my GH username.
    got it working
    Thanks

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

No branches or pull requests