Files
backstage/docs/auth/auth-backend-classes.md
T
Esteban Barrios 8f53351a32 Rebase from master (#19)
* Fix client reference

* Fix CatalogClient reference in create-app too

* Move catalog-client dep to create-app

* Add catalog-client dep again..

* Use RequestOptions

* tsc

* Backwards compatible scaffolder

* Fix test

* Avoid importing core

* Use request options

* Increase code coverage

* Type those variables

* use the second mock

* Trying to make tests work on Github too

* Get clean yarn from master

* Only add authorization header if token exists

* Use request options

* Forward authorization header token

* Refactor to use context argument

* Allow the registration of optional locations via the catalog-client

* Make EntityRefLink a React.forwardRef in order to use it as root component in other components like ListItem

* Rework the user flow of the catalog-import plugin

* Update the create-app template

* Add luxon and remove moment

* Port moment to luxon

* Add change set

* Split the step label and content to be able to refactor the stepper from vertical to horizontal in the future

* Fix tsc, prettier and import issues

* Update .changeset/strange-olives-unite.md

Co-authored-by: Himanshu Mishra <himanshu@orkohunter.net>

* Update plugins/auth-backend/src/identity/TokenFactory.ts

Co-authored-by: Himanshu Mishra <himanshu@orkohunter.net>

* Change from minor to patch

* Update DatabaseKeyStore.ts

* feat: added a test for running a simple cypress server

* Add luxon and remove moment

* Port from moment to Luxon

* Add changeset

* Fixes following CR

* Rebased and reinstalled yarn.lock

* Changed to fromSQL

* Fix prettier formatting

* chore: reworking the lock file for the cypress deps

* chore: adding cypress.config

* chore: reworking some more examples

* chore: added some more simple stuff for e2e tests with cypress

* chore: reworking again

* chore: making cypress nice

* chore: added a sample test that works

* chore: reworking tests to use he cypress github-action instead

* chore: reconfigure Cypress run

* chore: don't install - we have deps

* chore: dump video recordings too

* chore: slimming down install script a little

* chore: make pretty

* chore: fixing syntax

* chore: fixing syntax again

* Align card elements with list

* Align card elements with List

* Add changeset

* Removed unused import

* chore: archive video footage with the correct path

* chore: fix lint warnings

* chore: fix prettier again

* chore: move files around for ease

* Added pattern for component name

* Add changeset

* stash: push to stash

* Return AboutCard title to group name

* Refactor children to use shared function

* TechDocs: Add visbility to migrate away from basic setup

* bugfix: [3310] Favoriting a component resets interface to your owned components

update changeset

remove unused import

fix changeset message

fix vale errors?

* Create utc DateTime object directly

* integration: update the gitlab config mandatory fields to match reality

* Resolve review comments

* Remove shadowed variables

* generateEntityDefinitions should return a PartialEntity

* Update roadmap with Backstage Community Sessions

* Make sure that SidebarItems are also active when on sub route

* Add whitespace around variable

* Add changeset

* Add word to dictionary

* Smater duration display

* Add changeset

* chore(deps-dev): bump @graphql-codegen/typescript from 1.18.1 to 1.20.2

Bumps [@graphql-codegen/typescript](https://github.com/dotansimha/graphql-code-generator/tree/HEAD/packages/plugins/typescript/typescript) from 1.18.1 to 1.20.2.
- [Release notes](https://github.com/dotansimha/graphql-code-generator/releases)
- [Changelog](https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/typescript/typescript/CHANGELOG.md)
- [Commits](https://github.com/dotansimha/graphql-code-generator/commits/@graphql-codegen/typescript@1.20.2/packages/plugins/typescript/typescript)

Signed-off-by: dependabot[bot] <support@github.com>

* chore: reworking folder structure to move cypress outside of the project

* chore: updating workflow to point at the right folder now

* chore: fixing cypress build

* microsite: Fix color contrast for pre tags

* Add package name to lockfile.ts error

* Create new-mangos-tap.md

* Changed changeset bump to be patch

* Pass registered Logger in ServiceBuilderImpl to requestLoggingHandler

`requestLoggingHandler` takes an optional `logger` parameter that it can use
to log incoming requests. The `ServiceBuilderImpl` was not passing  on this logger, if
set, to `requestLoggingHandler` middleware

* Add indices on columns referring location(id)

* Add changeset

* Catch catalog errors

* Add changeset

* Fixed parseUrl to output catalogPaths beginning with '/'

* Add configurable OAuth 2.0 scopes

- Add oauth2 config for optional scopes
- Document oauth2 config keys
- Add OAuth2 to demo app list of identity providers

* incorrectly added callbackUrl

* chore: added a simple readme to run some simple tests against a backstage instance

* chore(deps): bump @svgr/plugin-jsx from 5.4.0 to 5.5.0

Bumps [@svgr/plugin-jsx](https://github.com/gregberge/svgr) from 5.4.0 to 5.5.0.
- [Release notes](https://github.com/gregberge/svgr/releases)
- [Changelog](https://github.com/gregberge/svgr/blob/main/CHANGELOG.md)
- [Commits](https://github.com/gregberge/svgr/compare/v5.4.0...v5.5.0)

Signed-off-by: dependabot[bot] <support@github.com>

* chore(deps): bump @types/cors from 2.8.6 to 2.8.9

Bumps [@types/cors](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/cors) from 2.8.6 to 2.8.9.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/cors)

Signed-off-by: dependabot[bot] <support@github.com>

* fix: removing test e2e-test tsconfig.json file

* TechDocs: Preparers will take and return an etag for cache invalidation

* TechDocs: Implement etag based caching for url preparer

Signed-off-by: Himanshu Mishra <himanshu@orkohunter.net>

* TechDocs: Implement etag based caching for git preparer

Signed-off-by: Himanshu Mishra <himanshu@orkohunter.net>

* TechDocs: Warn when using legacy git preparer and dir preparer in backstage.io/techdocs-ref

Context: https://github.com/backstage/backstage/issues/4409

* TechDocs: Update tests for proper url preparer caching

* TechDocs: Deduplicate git clone for cache check

Signed-off-by: Himanshu Mishra <himanshu@orkohunter.net>

* TechDocs: Add changesets for deprecation and proper caching

* TechDocs: Implement caching for dir preparer

* Update the changesets

* scaffolder-backend: remove auth-backend dependency

* catalog-client: rename ApiContext to CatalogRequestOptions + avoid export

* refactor existing usage of ApiContext

* techdocs: don't swallow errors other than NotModifiedError

* catalog-import: removed bonus code

* techdocs: meaningful logs when readTree starts

* Flatten the options of the CatalogImportPage

* inline optional id token auth headers

* Define relationship to software catalog and loose coupling by convention.

* Clarify intentions around bulk vs. incremental index management.

* Break apart backend plugins & clarify indexer/plugin relationship.

* update changeset bump levels

* [Search] documentation update (#4459)

* delete link to issue as it is closed

* replace usage of easy as its very subjective

* Update docs/features/search/architecture.md

Co-authored-by: Adam Harvey <adam.harvey@dxc.com>

* prettier....:

Co-authored-by: Adam Harvey <adam.harvey@dxc.com>

* Own it.

* scaffolder: include backstage identity token in requests

* review feedback tweaks

* docs/apis: update to use named plugin var

* sentry: update plugin instance export name

* clear other field when toggling reason

* changeset

* fix(pagerduty): use the luxon date library

* Don't pass default as a scope to OIDC providers

* docs(TechDocs): Add GitHub Actions CI example with AWS S3

* tech-radar: migrated to new composability API

* cost-insights: migrate to new composability API

* Changeset

* Fix line endings

* Prettier

* Remove unnecessary scopes from OIDC defaultApi

* Bump plugin-auth-backend to a minor change,
add documentation for fixing it

* Fix md syntax error

* Fix Vale spelling error

* Remove defaultScopes from OIDC api

* [ImgBot] Optimize images

/plugins/catalog-import/docs/catalog-import-screenshot.png -- 613.39kb -> 356.48kb (41.88%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>

* github/workflows: use lax config checks

* Use commented-out example value for scope

* feat(pagerduty): add changeset

* Apply suggestions from code review

Co-authored-by: Rémi Doreau <32459935+ayshiff@users.noreply.github.com>

* feat(catalog): add entity links card component

* update entity links changeset

* Fix prettier

* chore(deps-dev): bump @types/http-proxy from 1.17.4 to 1.17.5

Bumps [@types/http-proxy](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/http-proxy) from 1.17.4 to 1.17.5.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/http-proxy)

Signed-off-by: dependabot[bot] <support@github.com>

* Revert "Merge pull request #3953 from ayshiff/feature/techdocs-aws-sdkv3"

This reverts commit 1c7771871e, reversing
changes made to 65d5c8e6fe.

* Revert "Merge pull request #4035 from ayshiff/feature/catalog-backend-aws-sdk-v3"

This reverts commit 1df9134648, reversing
changes made to d45a510069.

* Add changeset

* feat: support custom app icons

* backend-common: implement UrlReader.search for the other providers too

* Remove changeset

* docs(TechDocs): Improvements to the CI example

Signed-off-by: Himanshu Mishra <himanshu@orkohunter.net>

* fix(catalog): entity links incorrect wrapping

* Remove unused functions and luxon

* Removed old imports

* Fix broken links in documentation (#4418)

* Update IdentityApi.md

* Update docs/reference/utility-apis/IdentityApi.md

* Update docs/reference/utility-apis/IdentityApi.md

* ran yarn docgen

* Use JS Date instead of Datetime

* Add line

* Prettier fix

* Move parseDate function

* Version Packages

* chore: fix the create-app version

* Limit the props that are forwarded to the Link component in the EntityRefLink

* Use routed tabs to link to every settings page

* fix up yarn after release

* chore: add lockfile to words

* catalog-info: add links

* Export Select component from core

I saw the Select component on storybook and went
to use it but it seems it's not exported. Any chance
it could be exported?

* bug: filepath can be returned as undefined from `git-url-parse` let's default to empty

* chore: might as well do this for all parsing

* chore: changeset

* Add changeset for fixing requestLoggingHandler

* chore(deps-dev): bump @storybook/addon-actions from 6.1.11 to 6.1.17

Bumps [@storybook/addon-actions](https://github.com/storybookjs/storybook/tree/HEAD/addons/actions) from 6.1.11 to 6.1.17.
- [Release notes](https://github.com/storybookjs/storybook/releases)
- [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md)
- [Commits](https://github.com/storybookjs/storybook/commits/v6.1.17/addons/actions)

Signed-off-by: dependabot[bot] <support@github.com>

* Port AboutCard

* Fix tests

* Revert EntityPage changes

* docs: Merge auth glossary with main glossary

* Remove the "Move repository" menu entry from the catalog page, as it's just a placeholder

It will be easy to bring it back later, but for now it just confuses users that it's not doing anything. It's also hard to remove for integrators.

* make the template cards conform to mui standard

Co-authored-by: Erik Larsson <erik.larsson@schibsted.com>
Co-authored-by: Dominik Henneke <dominik.henneke@sda-se.com>
Co-authored-by: Nils Streijffert <nstreijffert@spotify.com>
Co-authored-by: Nils Streijffert <nils.streijffert@gmail.com>
Co-authored-by: Himanshu Mishra <himanshu@orkohunter.net>
Co-authored-by: blam <ben@blam.sh>
Co-authored-by: Nir Gazit <nir.gzt@gmail.com>
Co-authored-by: Adam Harvey <adam.harvey@dxc.com>
Co-authored-by: NHI TRAN <nhid@ntran.io>
Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Oliver Sand <oliver.sand@sda-se.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Debajyoti Halder <rondebajyoti@gmail.com>
Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Gowind <petrovgovind@gmail.com>
Co-authored-by: Alan Crosswell <alan@columbia.edu>
Co-authored-by: Eric Peterson <ericpeterson@spotify.com>
Co-authored-by: Emma Indal <emma.indahl@gmail.com>
Co-authored-by: Ryan Vazquez <ryanv@spotify.com>
Co-authored-by: Ryan Vazquez <ryanmvazquez@gmail.com>
Co-authored-by: Remi <remi.d45@gmail.com>
Co-authored-by: Ryan Manny <rmanny@apptio.com>
Co-authored-by: ImgBotApp <ImgBotHelp@gmail.com>
Co-authored-by: Rémi Doreau <32459935+ayshiff@users.noreply.github.com>
Co-authored-by: Andrew Thauer <6507159+andrewthauer@users.noreply.github.com>
Co-authored-by: Joel Low <joel@joelsplace.sg>
Co-authored-by: Eric Peterson <iamEAP@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Iain Billett <iain@roadie.io>
2021-02-12 16:08:46 +01:00

8.5 KiB
Raw Blame History

id, title, description
id title description
auth-backend-classes Auth backend classes Documentation on Auth backend classes

How Does Authentication Work?

The Backstage application can use various external authentication providers for authentication. An external provider is wrapped using an AuthProviderRouteHandlers interface for handling authentication. This interface consists of four methods. Each of these methods is hosted at an endpoint (by default) /api/auth/[provider]/method, where method performs a certain operation as follows:

  /auth/[provider]/start -> Initiate a login from the web page
  /auth/[provider]/handler/frame -> Handle a finished authentication operation
  /auth/[provider]/refresh -> Refresh the validity of a login
  /auth/[provider]/logout -> Log out a logged-in user

The flow is as follows:

  1. A user attempts to sign in.
  2. A popup window is opened, pointing to the auth endpoint. That endpoint does initial preparations and then re-directs the user to an external authenticator, still inside the popup.
  3. The authenticator validates the user and returns the result of the validation (success OR failure), to the wrapper's endpoint (handler/frame).
  4. The handler/frame rendered b´webpage will issue the appropriate response to the webpage that opened the popup window, and the popup is closed.
  5. The user signs out by clicking on a UI interface and the webpage makes a request to logout the user.

There are currently two different classes for two authentication mechanisms that implement this interface: an OAuthAdapter for OAuth based mechanisms and a SAMLAuthProvider for SAML.

If you do not have an OAuth2 or SAML based authentication provider, look in the section below.

OAuth Mechanisms

For more information on how these methods are used and for which purpose, refer to the OAuth documentation.

Currently OAuth is assumed to be the de facto authentication mechanism for Backstage based applications.

Backstage comes with a "batteries-included" set of supported commonly used OAuth providers: Okta, GitHub, Google, GitLab, and a generic OAuth2 provider. For a list of available providers, look at the available wrappers in backstage/plugins/auth-backend/src/providers/.

All of these use the authorization flow of OAuth2 to implement authentication.

If your authentication provider is any of the above mentioned providers, you can configure them by setting the right variables in app-config.yaml under the auth section.

SAML

The SAML Provider is currently under development. Additional validation and profile handling is still required before use in production.

To configure the SAML Auth provider, look at the configuration parameters supported by Passport-SAML under the auth.providers.saml key

For security reasons, validate that the response from the IdP is indeed signed by also providing the cert configuration.

Configuration

Each authentication provider (except SAML) needs six parameters: an OAuth client ID, a client secret, an authorization endpoint, a token endpoint, an optional list of scopes (as a string separated by spaces) that may be required by the OAuth2 Server to enable end-user sign-on, and an app origin. The app origin is the URL at which the frontend of the application is hosted, and it is read from the app.baseUrl config. This is required because the application opens a popup window to perform the authentication, and once the flow is completed, the popup window sends a postMessage to the frontend application to indicate the result of the operation. Also this URL is used to verify that authentication requests are coming from only this endpoint.

These values are configured via the app-config.yaml present in the root of your app folder.

auth:
  providers:
    google:
      development:
        clientId:
          $env: AUTH_GOOGLE_CLIENT_ID
        clientSecret:
          $env: AUTH_GOOGLE_CLIENT_SECRET
    github:
      development:
        clientId:
          $env: AUTH_GITHUB_CLIENT_ID
        clientSecret:
          $env: AUTH_GITHUB_CLIENT_SECRET
        enterpriseInstanceUrl:
          $env: AUTH_GITHUB_ENTERPRISE_INSTANCE_URL
    gitlab:
      development:
        clientId:
          $env:
    oauth2:
      development:
        clientId:
          $env: AUTH_OAUTH2_CLIENT_ID
        clientSecret:
          $env: AUTH_OAUTH2_CLIENT_SECRET
        authorizationUrl:
          $env: AUTH_OAUTH2_AUTH_URL
        tokenUrl:
          $env: AUTH_OAUTH2_TOKEN_URL
        scope:
          $env: AUTH_OAUTH2_SCOPE
    saml:
      entryPoint:
        $env: AUTH_SAML_ENTRY_POINT
      issuer:
        $env: AUTH_SAML_ISSUER
            ...

Implementing Your Own Auth Wrapper

The core interface of any auth wrapper is the AuthProviderRouteHandlers interface. This interface has four methods corresponding to the API described in the initial section. Any auth wrapper will have to implement this interface.

When initiating a login, a pop-up window is created by the frontend, to allow the user to initiate a login. This login request is done to the /start endpoint which is handled by the start method.

The start method re-directs to the external auth provider who authenticates the request and re-directs the request to the /frame/handler endpoint, which is handled by the frameHandler method.

The frameHandler returns an HTML response, containing a script that does a postMessage to the frontend's window, containing the result of the request. The WebMessageResponse type is the message sent by the postMessage to the frontend.

A postMessageResponse utility function wraps the logic of generating a postMessage response that ensures that CORS is successfully handled. This function takes an express.Response, a WebMessageResponse and the URL of the frontend (appOrigin) as parameters and return an HTML page with the script and the message.

OAuth Wrapping Interfaces.

Each OAuth external provider is supported by a corresponding Passport strategy. For a generic OAuth2 provider, passport has a passport-oauth2 strategy. The strategy class handles the implementation details of working with each provider.

Each strategy is wrapped by an OAuthHandlers interface.

This interface cannot be directly used as an Express HTTP request handler. To do so, OAuthHandlers are wrapped in an OAuthAdapter, which implements the AuthProviderRouterHandlers interface.

Env

The concept of an env is core to the way the auth backend works. It uses an env query parameter to identify the environment in which the application is running (development, staging, production, etc). Each runtime can simultaneously support multiple environments at the same time and the right handler for each request is identified and dispatched to, based on the env parameter.

OAuthEnvironmentHandler is a utility wrapper for an OAuthHandlers that implements the AuthProviderRouteHandlers interface while supporting multiple envs.

To instantiate OAuth providers (the same but for different environments), use OAuthEnvironmentHandler.mapConfig. It's a helper to iterate over a configuration object that is a map of environments to configurations. See one of the existing OAuth providers for an example of how it is used.

Given the following configuration:

development:
  clientId: abc
  clientSecret: secret
production:
  clientId: xyz
  clientSecret: supersecret

The OAuthEnvironmentHandler.mapConfig(config, envConfig => ...) call will split the config by the top level development and production keys, and pass on each block as envConfig.

For convenience, the AuthProviderFactory is a factory function that has to be implemented which can then generate a AuthProviderRouteHandlers for a given provider.

All of the supported providers provide an AuthProviderFactory that returns an OAuthEnvironmentHandler, capable of handling authentication for multiple environments.

OAuth2 Provider

The oauth2 provider abstracts a generic OAuth2 + OIDC based authentication provider. What this means is that after the application has been given permission by the user, the authorization code will be exchanged for an access_token, a refresh_token and an id_token. This id_token is used to obtain an email id of the user, which is then used for creating the session.