backstage: šŸ› Bug Report: Trying to add custom SCMAUTH for GHE. Documentation not so clear

šŸ“œ Description

Hello,

We were able to build and deploy backstage in an OpenShift cluster, but now we want to use the user token for the user currently logged in backstage.

We configured the authentication and user/groups for GHE and is working properly. The user can authenticate with corporate GHE user and we can see the user details in the settings page. Also we can ā€œchooseā€ a template that publish a repo in the organization.

But we also wanted to use the

        requestUserCredentials:
          secretsKey: USER_OAUTH_TOKEN

in a template to allow the user to publish in his own GHE account. So we tried to follow

this https://backstage.io/docs/auth/#scaffolder-configuration-software-templates

If you want to use the authentication capabilities of the [Repository Picker](https://backstage.io/docs/features/software-templates/writing-templates#the-repository-picker) inside your software templates you will need to configure the [ScmAuthApi](https://backstage.io/docs/reference/integration-react.scmauthapi) alongside your authentication provider. It is an API used to authenticate towards different SCM systems in a generic way, based on what resource is being accessed.

and https://backstage.io/docs/auth/#custom-scmauthapi-implementation

to implement a new ScmAuthAPI for GHE, but we can’t build the image in Openshift in Dockerfile. We are getting compile errors

šŸ‘ Expected behavior

A correct build

šŸ‘Ž Actual Behavior with Screenshots

[2/3] STEP 14/15: RUN --mount=type=cache,target=/opt/app-root/src/.cache/yarn,uid=1001,gid=0 yarn tsc && yarn --cwd packages/backend build yarn run v1.22.21 $ tsc packages/app/src/apis.ts:39:29 - error TS2304: Cannot find name ā€˜ApiRef’.

39 export const gheAuthApiRef: ApiRef<OAuthApi & ProfileInfoApi & SessionApi> =    ~~~~~~

packages/app/src/apis.ts:39:29 - error TS4025: Exported variable ā€˜gheAuthApiRef’ has or is using private name ā€˜ApiRef’.

39 export const gheAuthApiRef: ApiRef<OAuthApi & ProfileInfoApi & SessionApi> =    ~~~~~~

packages/app/src/apis.ts:39:36 - error TS2304: Cannot find name ā€˜OAuthApi’.

39 export const gheAuthApiRef: ApiRef<OAuthApi & ProfileInfoApi & SessionApi> =    ~~~~~~~~

packages/app/src/apis.ts:39:36 - error TS4025: Exported variable ā€˜gheAuthApiRef’ has or is using private name ā€˜OAuthApi’.

39 export const gheAuthApiRef: ApiRef<OAuthApi & ProfileInfoApi & SessionApi> =    ~~~~~~~~

packages/app/src/apis.ts:39:47 - error TS2304: Cannot find name ā€˜ProfileInfoApi’.

39 export const gheAuthApiRef: ApiRef<OAuthApi & ProfileInfoApi & SessionApi> =    ~~~~~~~~~~~~~~

packages/app/src/apis.ts:39:47 - error TS4025: Exported variable ā€˜gheAuthApiRef’ has or is using private name ā€˜ProfileInfoApi’.

39 export const gheAuthApiRef: ApiRef<OAuthApi & ProfileInfoApi & SessionApi> =    ~~~~~~~~~~~~~~

packages/app/src/apis.ts:39:64 - error TS2304: Cannot find name ā€˜SessionApi’.

39 export const gheAuthApiRef: ApiRef<OAuthApi & ProfileInfoApi & SessionApi> =    ~~~~~~~~~~

packages/app/src/apis.ts:39:64 - error TS4025: Exported variable ā€˜gheAuthApiRef’ has or is using private name ā€˜SessionApi’.

39 export const gheAuthApiRef: ApiRef<OAuthApi & ProfileInfoApi & SessionApi> =    ~~~~~~~~~~

packages/app/src/apis.ts:59:7 - error TS2304: Cannot find name ā€˜GithubAuth’.

59 GithubAuth.create({    ~~~~~~~~~~

packages/app/src/apis.ts:77:27 - error TS2345: Argument of type ā€˜unknown’ is not assignable to parameter of type ā€˜OAuthApi’.

77 ScmAuth.forGithub(gheAuthApi, {    ~~~~~~~~~~

packages/backend/src/plugins/kubernetes.ts:10:60 - error TS2345: Argument of type ā€˜{ logger: winston.Logger; config: Config; catalogApi: CatalogClient; }’ is not assignable to parameter of type ā€˜KubernetesEnvironment’. Property ā€˜permissions’ is missing in type ā€˜{ logger: winston.Logger; config: Config; catalogApi: CatalogClient; }’ but required in type ā€˜KubernetesEnvironment’.

 10 const { router } = await KubernetesBuilder.createBuilder({    ~  11 logger: env.logger,   ~~~~~~~ …  13 catalogApi,   ~  14 }).build();   ~

node_modules/@backstage/plugin-kubernetes-backend/dist/index.d.ts:272:5 272 permissions: PermissionEvaluator;    ~~~~~~~~~~~ ā€˜permissions’ is declared here.

Found 11 errors in 2 files.

Errors Files 10 packages/app/src/apis.ts:39 1 packages/backend/src/plugins/kubernetes.ts:10

šŸ‘Ÿ Reproduction steps

yarn install --verbose --frozen-lockfile --network-timeout 600000

šŸ“ƒ Provide the context for the Bug.

No response

šŸ–„ļø Your Environment

OS: Linux 4.4.0-19041-Microsoft - linux/x64 node: v18.14.0 yarn: 1.22.19 cli: 0.25.1 (installed) backstage: 1.22.1

Dependencies: @backstage/app-defaults 1.4.7 @backstage/backend-app-api 0.5.10 @backstage/backend-common 0.20.1 @backstage/backend-dev-utils 0.1.3 @backstage/backend-openapi-utils 0.1.2 @backstage/backend-plugin-api 0.6.9 @backstage/backend-tasks 0.5.14 @backstage/catalog-client 1.5.2 @backstage/catalog-model 1.4.3 @backstage/cli-common 0.1.13 @backstage/cli-node 0.2.2 @backstage/cli 0.25.1 @backstage/config-loader 1.6.1 @backstage/config 1.1.1 @backstage/core-app-api 1.11.3 @backstage/core-compat-api 0.1.1 @backstage/core-components 0.13.10 @backstage/core-plugin-api 1.8.2 @backstage/errors 1.2.3 @backstage/eslint-plugin 0.1.4 @backstage/frontend-plugin-api 0.5.0 @backstage/integration-aws-node 0.1.8 @backstage/integration-react 1.1.23 @backstage/integration 1.8.0 @backstage/plugin-api-docs 0.10.3 @backstage/plugin-app-backend 0.3.57 @backstage/plugin-app-node 0.1.9 @backstage/plugin-auth-backend-module-atlassian-provider 0.1.1 @backstage/plugin-auth-backend-module-gcp-iap-provider 0.2.3 @backstage/plugin-auth-backend-module-github-provider 0.1.6 @backstage/plugin-auth-backend-module-gitlab-provider 0.1.6 @backstage/plugin-auth-backend-module-google-provider 0.1.6 @backstage/plugin-auth-backend-module-oauth2-provider 0.1.6 @backstage/plugin-auth-backend-module-oauth2-proxy-provider 0.1.1 @backstage/plugin-auth-backend-module-okta-provider 0.0.2 @backstage/plugin-auth-backend 0.20.3 @backstage/plugin-auth-node 0.4.3 @backstage/plugin-catalog-backend-module-github 0.4.7 @backstage/plugin-catalog-backend-module-scaffolder-entity-model 0.1.6 @backstage/plugin-catalog-backend 1.16.1 @backstage/plugin-catalog-common 1.0.20 @backstage/plugin-catalog-graph 0.3.3 @backstage/plugin-catalog-import 0.10.5 @backstage/plugin-catalog-node 1.6.1 @backstage/plugin-catalog-react 1.9.3 @backstage/plugin-catalog 1.16.1 @backstage/plugin-events-node 0.2.18 @backstage/plugin-github-actions 0.6.10 @backstage/plugin-kubernetes-backend 0.14.1 @backstage/plugin-kubernetes-common 0.7.3 @backstage/plugin-kubernetes-node 0.1.3 @backstage/plugin-kubernetes-react 0.2.1 @backstage/plugin-kubernetes 0.11.4 @backstage/plugin-org 0.6.19 @backstage/plugin-permission-common 0.7.12 @backstage/plugin-permission-node 0.7.20 @backstage/plugin-permission-react 0.4.19 @backstage/plugin-proxy-backend 0.4.7 @backstage/plugin-scaffolder-backend-module-azure 0.1.1 @backstage/plugin-scaffolder-backend-module-bitbucket 0.1.1 @backstage/plugin-scaffolder-backend-module-gerrit 0.1.1 @backstage/plugin-scaffolder-backend-module-github 0.1.1 @backstage/plugin-scaffolder-backend-module-gitlab 0.2.12 @backstage/plugin-scaffolder-backend 1.20.0 @backstage/plugin-scaffolder-common 1.4.5 @backstage/plugin-scaffolder-node 0.2.10 @backstage/plugin-scaffolder-react 1.7.1 @backstage/plugin-scaffolder 1.17.1 @backstage/plugin-search-backend-module-catalog 0.1.13 @backstage/plugin-search-backend-module-pg 0.5.18 @backstage/plugin-search-backend-module-techdocs 0.1.13 @backstage/plugin-search-backend-node 1.2.13 @backstage/plugin-search-backend 1.4.9 @backstage/plugin-search-common 1.2.10 @backstage/plugin-search-react 1.7.5 @backstage/plugin-search 1.4.5 @backstage/plugin-tech-radar 0.6.12 @backstage/plugin-techdocs-backend 1.9.2 @backstage/plugin-techdocs-module-addons-contrib 1.1.4 @backstage/plugin-techdocs-node 1.11.1 @backstage/plugin-techdocs-react 1.1.15 @backstage/plugin-techdocs 1.9.3 @backstage/plugin-user-settings 0.8.0 @backstage/release-manifests 0.0.11 @backstage/test-utils 1.4.7 @backstage/theme 0.5.0 @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, I don’t have time to work on this right now

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Hi @benjdlambert

More info…

In local it’s working correctly, I’ve created an OAuth App for local development with

Homepage URL: http://localhost:3000
Authorization callback URL: http://localhost:7007/api/auth/github/handler/frame

and another OAuth App for Openshift with

Homepage URL: https://openshift-internal-domain
Authorization callback URL: https://openshift-internal-domain/api/auth/github/handler/frame

With backstage in local I receive a popup request to do the login, for this permission

image

Then, when requesting the location from template

    - title: Choose a location
      required:
        - repoUrl
      properties:
        repoUrl:
          title: Repository Location
          type: string
          ui:field: RepoUrlPicker
          ui:options:
            requestUserCredentials:
              secretsKey: USER_OAUTH_TOKEN
              additionalScopes:
                github: 
                  - workflow          
            allowedHosts:
              - github.ourcompany.com

I’m getting another logging

image

and requesting more permissions

image

and I’m not getting the error

No auth provider available for 'https://github.ourcompany.com/user-account/testRepo', see https://backstage.io/link?scm-auth

And I can create the repo in a personal GHE account.

But the same code, in Openshift, I’m only getting the first login, and for the location I’m receiving the

No auth provider available for 'https://github.ourcompany.com/user-account/testRepo', see https://backstage.io/link?scm-auth

The only difference between local and Openshift is in app-config.yaml, the baseUrl for app and backend

app:
  title: Backstage GO
  #baseUrl: https://openshift-internal-domain
  baseUrl: http://localhost:3000

organization:
  name: Our Company

backend:
  # Used for enabling authentication, secret is shared by all backend plugins
  # See https://backstage.io/docs/auth/service-to-service-auth for
  # information on the format
  # auth:
  #   keys:
  #     - secret: ${BACKEND_SECRET}
  #baseUrl: https://openshift-internal-domain
  baseUrl: http://localhost:7007