@backstage/backend-defaults 0.4.4 → 0.5.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +104 -12
  2. package/auth/package.json +1 -1
  3. package/cache/package.json +1 -1
  4. package/config.d.ts +221 -0
  5. package/database/package.json +1 -1
  6. package/discovery/package.json +1 -1
  7. package/dist/auth.cjs.js +16 -45
  8. package/dist/auth.cjs.js.map +1 -1
  9. package/dist/auth.d.ts +1 -1
  10. package/dist/cache.cjs.js +22 -3
  11. package/dist/cache.cjs.js.map +1 -1
  12. package/dist/cache.d.ts +1 -1
  13. package/dist/database.cjs.js +4 -2
  14. package/dist/database.cjs.js.map +1 -1
  15. package/dist/database.d.ts +1 -1
  16. package/dist/discovery.d.ts +1 -1
  17. package/dist/httpAuth.d.ts +1 -1
  18. package/dist/httpRouter.d.ts +1 -1
  19. package/dist/index.cjs.js +118 -2
  20. package/dist/index.cjs.js.map +1 -1
  21. package/dist/index.d.ts +22 -1
  22. package/dist/lifecycle.d.ts +1 -1
  23. package/dist/logger.d.ts +1 -1
  24. package/dist/permissions.cjs.js +3 -5
  25. package/dist/permissions.cjs.js.map +1 -1
  26. package/dist/permissions.d.ts +1 -1
  27. package/dist/rootConfig.cjs.js +1 -1
  28. package/dist/rootConfig.cjs.js.map +1 -1
  29. package/dist/rootHealth.d.ts +1 -1
  30. package/dist/rootHttpRouter.cjs.js +1 -1
  31. package/dist/rootHttpRouter.cjs.js.map +1 -1
  32. package/dist/rootLifecycle.d.ts +1 -1
  33. package/dist/rootLogger.d.ts +1 -1
  34. package/dist/scheduler.d.ts +1 -1
  35. package/dist/urlReader.cjs.js +2 -1
  36. package/dist/urlReader.cjs.js.map +1 -1
  37. package/dist/urlReader.d.ts +1 -1
  38. package/dist/userInfo.d.ts +1 -1
  39. package/httpAuth/package.json +1 -1
  40. package/httpRouter/package.json +1 -1
  41. package/lifecycle/package.json +1 -1
  42. package/logger/package.json +1 -1
  43. package/package.json +11 -10
  44. package/permissions/package.json +1 -1
  45. package/rootConfig/package.json +1 -1
  46. package/rootHealth/package.json +1 -1
  47. package/rootHttpRouter/package.json +1 -1
  48. package/rootLifecycle/package.json +1 -1
  49. package/rootLogger/package.json +1 -1
  50. package/scheduler/package.json +1 -1
  51. package/urlReader/package.json +1 -1
  52. package/userInfo/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,23 +1,115 @@
1
1
  # @backstage/backend-defaults
2
2
 
3
- ## 0.4.4
3
+ ## 0.5.0-next.0
4
4
 
5
- ### Patch Changes
5
+ ### Minor Changes
6
6
 
7
- - Updated dependencies
8
- - @backstage/backend-common@0.24.1
9
- - @backstage/backend-app-api@0.9.3
10
- - @backstage/plugin-auth-node@0.5.1
11
- - @backstage/plugin-events-node@0.3.10
12
- - @backstage/plugin-permission-node@0.8.2
13
- - @backstage/backend-plugin-api@0.8.1
14
- - @backstage/config-loader@1.9.0
7
+ - 359fcd7: **BREAKING**: The backwards compatibility with plugins using legacy auth through the token manager service has been removed. This means that instead of falling back to using the old token manager, requests towards plugins that don't support the new auth system will simply fail. Please make sure that all plugins in your deployment are hosted within a backend instance from the new backend system.
8
+ - d425fc4: **BREAKING**: The return values from `createBackendPlugin`, `createBackendModule`, and `createServiceFactory` are now simply `BackendFeature` and `ServiceFactory`, instead of the previously deprecated form of a function that returns them. For this reason, `createServiceFactory` also no longer accepts the callback form where you provide direct options to the service. This also affects all `coreServices.*` service refs.
9
+
10
+ This may in particular affect tests; if you were effectively doing `createBackendModule({...})()` (note the parentheses), you can now remove those extra parentheses at the end. You may encounter cases of this in your `packages/backend/src/index.ts` too, where you add plugins, modules, and services. If you were using `createServiceFactory` with a function as its argument for the purpose of passing in options, this pattern has been deprecated for a while and is no longer supported. You may want to explore the new multiton patterns to achieve your goals, or moving settings to app-config.
11
+
12
+ As part of this change, the `IdentityFactoryOptions` type was removed, and can no longer be used to tweak that service. The identity service was also deprecated some time ago, and you will want to [migrate to the new auth system](https://backstage.io/docs/tutorials/auth-service-migration) if you still rely on it.
13
+
14
+ - 19ff127: **BREAKING**: The default backend instance no longer provides implementations for the identity and token manager services, which have been removed from `@backstage/backend-plugin-api`.
15
+
16
+ If you rely on plugins that still require these services, you can add them to your own backend by re-creating the service reference and factory.
15
17
 
16
- ## 0.4.3
18
+ The following can be used to implement the identity service:
19
+
20
+ ```ts
21
+ import {
22
+ coreServices,
23
+ createServiceFactory,
24
+ createServiceRef,
25
+ } from '@backstage/backend-plugin-api';
26
+ import {
27
+ DefaultIdentityClient,
28
+ IdentityApi,
29
+ } from '@backstage/plugin-auth-node';
30
+
31
+ backend.add(
32
+ createServiceFactory({
33
+ service: createServiceRef<IdentityApi>({ id: 'core.identity' }),
34
+ deps: {
35
+ discovery: coreServices.discovery,
36
+ },
37
+ async factory({ discovery }) {
38
+ return DefaultIdentityClient.create({ discovery });
39
+ },
40
+ }),
41
+ );
42
+ ```
43
+
44
+ The following can be used to implement the token manager service:
45
+
46
+ ```ts
47
+ import { ServerTokenManager, TokenManager } from '@backstage/backend-common';
48
+ import { createBackend } from '@backstage/backend-defaults';
49
+ import {
50
+ coreServices,
51
+ createServiceFactory,
52
+ createServiceRef,
53
+ } from '@backstage/backend-plugin-api';
54
+
55
+ backend.add(
56
+ createServiceFactory({
57
+ service: createServiceRef<TokenManager>({ id: 'core.tokenManager' }),
58
+ deps: {
59
+ config: coreServices.rootConfig,
60
+ logger: coreServices.rootLogger,
61
+ },
62
+ createRootContext({ config, logger }) {
63
+ return ServerTokenManager.fromConfig(config, {
64
+ logger,
65
+ allowDisabledTokenManager: true,
66
+ });
67
+ },
68
+ async factory(_deps, tokenManager) {
69
+ return tokenManager;
70
+ },
71
+ }),
72
+ );
73
+ ```
17
74
 
18
75
  ### Patch Changes
19
76
 
20
- - 91e78c3: `auth.externalAccess` should be optional in the config schema
77
+ - 7f779c7: `auth.externalAccess` should be optional in the config schema
78
+ - 7a72ec8: Exports the `discoveryFeatureLoader` as a replacement for the deprecated `featureDiscoveryService`.
79
+ The `discoveryFeatureLoader` is a new backend system [feature loader](https://backstage.io/docs/backend-system/architecture/feature-loaders/) that discovers backend features from the current `package.json` and its dependencies.
80
+ Here is an example using the `discoveryFeatureLoader` loader in a new backend instance:
81
+
82
+ ```ts
83
+ import { createBackend } from '@backstage/backend-defaults';
84
+ import { discoveryFeatureLoader } from '@backstage/backend-defaults';
85
+ //...
86
+
87
+ const backend = createBackend();
88
+ //...
89
+ backend.add(discoveryFeatureLoader);
90
+ //...
91
+ backend.start();
92
+ ```
93
+
94
+ - 66dbf0a: Allow the cache service to accept the human duration format for TTL
95
+ - 5a8fcb4: Added the option to skip database migrations by setting `skipMigrations: true` in config. This can be done globally in the database config or by plugin id.
96
+ - 0b2a402: Updates to the config schema to match reality
97
+ - Updated dependencies
98
+ - @backstage/backend-app-api@0.10.0-next.0
99
+ - @backstage/backend-plugin-api@0.9.0-next.0
100
+ - @backstage/plugin-permission-node@0.8.3-next.0
101
+ - @backstage/backend-common@0.25.0-next.0
102
+ - @backstage/plugin-events-node@0.4.0-next.0
103
+ - @backstage/plugin-auth-node@0.5.2-next.0
104
+ - @backstage/backend-dev-utils@0.1.5
105
+ - @backstage/cli-common@0.1.14
106
+ - @backstage/cli-node@0.2.7
107
+ - @backstage/config@1.2.0
108
+ - @backstage/config-loader@1.9.0
109
+ - @backstage/errors@1.2.4
110
+ - @backstage/integration@1.14.0
111
+ - @backstage/integration-aws-node@0.1.12
112
+ - @backstage/types@1.1.1
21
113
 
22
114
  ## 0.4.2
23
115
 
package/auth/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults__auth",
3
- "version": "0.4.4",
3
+ "version": "0.5.0-next.0",
4
4
  "main": "../dist/auth.cjs.js",
5
5
  "types": "../dist/auth.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults__cache",
3
- "version": "0.4.4",
3
+ "version": "0.5.0-next.0",
4
4
  "main": "../dist/cache.cjs.js",
5
5
  "types": "../dist/cache.d.ts"
6
6
  }
package/config.d.ts CHANGED
@@ -14,8 +14,51 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ import { HumanDuration } from '@backstage/types';
18
+
17
19
  export interface Config {
20
+ app: {
21
+ baseUrl: string; // defined in core, but repeated here without doc
22
+ };
23
+
18
24
  backend?: {
25
+ /**
26
+ * The full base URL of the backend, as seen from the browser's point of
27
+ * view as it makes calls to the backend.
28
+ */
29
+ baseUrl: string;
30
+
31
+ /** Address that the backend should listen to. */
32
+ listen?:
33
+ | string
34
+ | {
35
+ /** Address of the interface that the backend should bind to. */
36
+ host?: string;
37
+ /** Port that the backend should listen to. */
38
+ port?: string | number;
39
+ };
40
+
41
+ /**
42
+ * HTTPS configuration for the backend. If omitted the backend will serve HTTP.
43
+ *
44
+ * Setting this to `true` will cause self-signed certificates to be generated, which
45
+ * can be useful for local development or other non-production scenarios.
46
+ */
47
+ https?:
48
+ | true
49
+ | {
50
+ /** Certificate configuration */
51
+ certificate?: {
52
+ /** PEM encoded certificate. Use $file to load in a file */
53
+ cert: string;
54
+ /**
55
+ * PEM encoded certificate key. Use $file to load in a file.
56
+ * @visibility secret
57
+ */
58
+ key: string;
59
+ };
60
+ };
61
+
19
62
  /**
20
63
  * Options used by the default auth, httpAuth and userInfo services.
21
64
  */
@@ -353,4 +396,182 @@ export interface Config {
353
396
  plugins: string[];
354
397
  }>;
355
398
  };
399
+
400
+ /** Database connection configuration, select base database type using the `client` field */
401
+ database: {
402
+ /** Default database client to use */
403
+ client: 'better-sqlite3' | 'sqlite3' | 'pg';
404
+ /**
405
+ * Base database connection string, or object with individual connection properties
406
+ * @visibility secret
407
+ */
408
+ connection:
409
+ | string
410
+ | {
411
+ /**
412
+ * Password that belongs to the client User
413
+ * @visibility secret
414
+ */
415
+ password?: string;
416
+ /**
417
+ * Other connection settings
418
+ */
419
+ [key: string]: unknown;
420
+ };
421
+ /** Database name prefix override */
422
+ prefix?: string;
423
+ /**
424
+ * Whether to ensure the given database exists by creating it if it does not.
425
+ * Defaults to true if unspecified.
426
+ */
427
+ ensureExists?: boolean;
428
+ /**
429
+ * Whether to ensure the given database schema exists by creating it if it does not.
430
+ * Defaults to false if unspecified.
431
+ *
432
+ * NOTE: Currently only supported by the `pg` client when pluginDivisionMode: schema
433
+ */
434
+ ensureSchemaExists?: boolean;
435
+ /**
436
+ * How plugins databases are managed/divided in the provided database instance.
437
+ *
438
+ * `database` -> Plugins are each given their own database to manage their schemas/tables.
439
+ *
440
+ * `schema` -> Plugins will be given their own schema (in the specified/default database)
441
+ * to manage their tables.
442
+ *
443
+ * NOTE: Currently only supported by the `pg` client.
444
+ *
445
+ * @default database
446
+ */
447
+ pluginDivisionMode?: 'database' | 'schema';
448
+ /** Configures the ownership of newly created schemas in pg databases. */
449
+ role?: string;
450
+ /**
451
+ * Arbitrary config object to pass to knex when initializing
452
+ * (https://knexjs.org/#Installation-client). Most notable is the debug
453
+ * and asyncStackTraces booleans
454
+ */
455
+ knexConfig?: object;
456
+ /** Skip running database migrations. */
457
+ skipMigrations?: boolean;
458
+ /** Plugin specific database configuration and client override */
459
+ plugin?: {
460
+ [pluginId: string]: {
461
+ /** Database client override */
462
+ client?: 'better-sqlite3' | 'sqlite3' | 'pg';
463
+ /**
464
+ * Database connection string or Knex object override
465
+ * @visibility secret
466
+ */
467
+ connection?: string | object;
468
+ /**
469
+ * Whether to ensure the given database exists by creating it if it does not.
470
+ * Defaults to base config if unspecified.
471
+ */
472
+ ensureExists?: boolean;
473
+ /**
474
+ * Whether to ensure the given database schema exists by creating it if it does not.
475
+ * Defaults to false if unspecified.
476
+ *
477
+ * NOTE: Currently only supported by the `pg` client when pluginDivisionMode: schema
478
+ */
479
+ ensureSchemaExists?: boolean;
480
+ /**
481
+ * Arbitrary config object to pass to knex when initializing
482
+ * (https://knexjs.org/#Installation-client). Most notable is the
483
+ * debug and asyncStackTraces booleans.
484
+ *
485
+ * This is merged recursively into the base knexConfig
486
+ */
487
+ knexConfig?: object;
488
+ /** Configures the ownership of newly created schemas in pg databases. */
489
+ role?: string;
490
+ /** Skip running database migrations. */
491
+ skipMigrations?: boolean;
492
+ };
493
+ };
494
+ };
495
+
496
+ /** Cache connection configuration, select cache type using the `store` field */
497
+ cache?:
498
+ | {
499
+ store: 'memory';
500
+ /** An optional default TTL (in milliseconds). */
501
+ defaultTtl?: number | HumanDuration;
502
+ }
503
+ | {
504
+ store: 'redis';
505
+ /**
506
+ * A redis connection string in the form `redis://user:pass@host:port`.
507
+ * @visibility secret
508
+ */
509
+ connection: string;
510
+ /** An optional default TTL (in milliseconds). */
511
+ defaultTtl?: number | HumanDuration;
512
+ /**
513
+ * Whether or not [useRedisSets](https://github.com/jaredwray/keyv/tree/main/packages/redis#useredissets) should be configured to this redis cache.
514
+ * Defaults to true if unspecified.
515
+ */
516
+ useRedisSets?: boolean;
517
+ }
518
+ | {
519
+ store: 'memcache';
520
+ /**
521
+ * A memcache connection string in the form `user:pass@host:port`.
522
+ * @visibility secret
523
+ */
524
+ connection: string;
525
+ /** An optional default TTL (in milliseconds). */
526
+ defaultTtl?: number | HumanDuration;
527
+ };
528
+
529
+ cors?: {
530
+ origin?: string | string[];
531
+ methods?: string | string[];
532
+ allowedHeaders?: string | string[];
533
+ exposedHeaders?: string | string[];
534
+ credentials?: boolean;
535
+ maxAge?: number;
536
+ preflightContinue?: boolean;
537
+ optionsSuccessStatus?: number;
538
+ };
539
+
540
+ /**
541
+ * Content Security Policy options.
542
+ *
543
+ * The keys are the plain policy ID, e.g. "upgrade-insecure-requests". The
544
+ * values are on the format that the helmet library expects them, as an
545
+ * array of strings. There is also the special value false, which means to
546
+ * remove the default value that Backstage puts in place for that policy.
547
+ */
548
+ csp?: { [policyId: string]: string[] | false };
549
+
550
+ /**
551
+ * Configuration related to URL reading, used for example for reading catalog info
552
+ * files, scaffolder templates, and techdocs content.
553
+ */
554
+ reading?: {
555
+ /**
556
+ * A list of targets to allow outgoing requests to. Users will be able to make
557
+ * requests on behalf of the backend to the targets that are allowed by this list.
558
+ */
559
+ allow?: Array<{
560
+ /**
561
+ * A host to allow outgoing requests to, being either a full host or
562
+ * a subdomain wildcard pattern with a leading `*`. For example `example.com`
563
+ * and `*.example.com` are valid values, `prod.*.example.com` is not.
564
+ * The host may also contain a port, for example `example.com:8080`.
565
+ */
566
+ host: string;
567
+
568
+ /**
569
+ * An optional list of paths. In case they are present only targets matching
570
+ * any of them will are allowed. You can use trailing slashes to make sure only
571
+ * subdirectories are allowed, for example `/mydir/` will allow targets with
572
+ * paths like `/mydir/a` but will block paths like `/mydir2`.
573
+ */
574
+ paths?: string[];
575
+ }>;
576
+ };
356
577
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults__database",
3
- "version": "0.4.4",
3
+ "version": "0.5.0-next.0",
4
4
  "main": "../dist/database.cjs.js",
5
5
  "types": "../dist/database.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults__discovery",
3
- "version": "0.4.4",
3
+ "version": "0.5.0-next.0",
4
4
  "main": "../dist/discovery.cjs.js",
5
5
  "types": "../dist/discovery.d.ts"
6
6
  }
package/dist/auth.cjs.js CHANGED
@@ -11,15 +11,13 @@ var luxon = require('luxon');
11
11
  var fs = require('fs');
12
12
 
13
13
  class DefaultAuthService {
14
- constructor(userTokenHandler, pluginTokenHandler, externalTokenHandler, tokenManager, pluginId, disableDefaultAuthPolicy, pluginKeySource, logger) {
14
+ constructor(userTokenHandler, pluginTokenHandler, externalTokenHandler, pluginId, disableDefaultAuthPolicy, pluginKeySource) {
15
15
  this.userTokenHandler = userTokenHandler;
16
16
  this.pluginTokenHandler = pluginTokenHandler;
17
17
  this.externalTokenHandler = externalTokenHandler;
18
- this.tokenManager = tokenManager;
19
18
  this.pluginId = pluginId;
20
19
  this.disableDefaultAuthPolicy = disableDefaultAuthPolicy;
21
20
  this.pluginKeySource = pluginKeySource;
22
- this.logger = logger;
23
21
  }
24
22
  async authenticate(token, options) {
25
23
  const pluginResult = await this.pluginTokenHandler.verifyToken(token);
@@ -85,45 +83,25 @@ class DefaultAuthService {
85
83
  if (type === "none" && this.disableDefaultAuthPolicy) {
86
84
  return { token: "" };
87
85
  }
88
- const targetSupportsNewAuth = await this.pluginTokenHandler.isTargetPluginSupported(targetPluginId);
89
86
  switch (type) {
90
87
  case "service":
91
- if (targetSupportsNewAuth) {
92
- return this.pluginTokenHandler.issueToken({
93
- pluginId: this.pluginId,
94
- targetPluginId
95
- });
96
- }
97
- this.logger.warn(
98
- `DEPRECATION WARNING: A call to the '${targetPluginId}' plugin had to fall back to using deprecated auth via the token manager service. Please migrate all plugins to the new auth service, see https://backstage.io/docs/tutorials/auth-service-migration for more information`
99
- );
100
- return this.tokenManager.getToken().catch((error) => {
101
- throw new errors.ForwardedError(
102
- `Unable to generate legacy token for communication with the '${targetPluginId}' plugin. You will typically encounter this error when attempting to call a plugin that does not exist, or is deployed with an old version of Backstage`,
103
- error
104
- );
88
+ return this.pluginTokenHandler.issueToken({
89
+ pluginId: this.pluginId,
90
+ targetPluginId
105
91
  });
106
92
  case "user": {
107
93
  const { token } = internalForward;
108
94
  if (!token) {
109
95
  throw new Error("User credentials is unexpectedly missing token");
110
96
  }
111
- if (targetSupportsNewAuth) {
112
- const onBehalfOf = await this.userTokenHandler.createLimitedUserToken(
113
- token
114
- );
115
- return this.pluginTokenHandler.issueToken({
116
- pluginId: this.pluginId,
117
- targetPluginId,
118
- onBehalfOf
119
- });
120
- }
121
- if (this.userTokenHandler.isLimitedUserToken(token)) {
122
- throw new errors.AuthenticationError(
123
- `Unable to call '${targetPluginId}' plugin on behalf of user, because the target plugin does not support on-behalf-of tokens or the plugin doesn't exist`
124
- );
125
- }
126
- return { token };
97
+ const onBehalfOf = await this.userTokenHandler.createLimitedUserToken(
98
+ token
99
+ );
100
+ return this.pluginTokenHandler.issueToken({
101
+ pluginId: this.pluginId,
102
+ targetPluginId,
103
+ onBehalfOf
104
+ });
127
105
  }
128
106
  default:
129
107
  throw new errors.AuthenticationError(
@@ -622,7 +600,7 @@ class PluginTokenHandler {
622
600
  }
623
601
  if (!await this.isTargetPluginSupported(pluginId)) {
624
602
  throw new errors.AuthenticationError(
625
- `Received a plugin token where the source '${pluginId}' plugin unexpectedly does not have a JWKS endpoint`
603
+ `Received a plugin token where the source '${pluginId}' plugin unexpectedly does not have a JWKS endpoint. The target plugin needs to be migrated to be installed in an app using the new backend system.`
626
604
  );
627
605
  }
628
606
  const newClient = new JwksClient(async () => {
@@ -980,14 +958,9 @@ const authServiceFactory = backendPluginApi.createServiceFactory({
980
958
  logger: backendPluginApi.coreServices.rootLogger,
981
959
  discovery: backendPluginApi.coreServices.discovery,
982
960
  plugin: backendPluginApi.coreServices.pluginMetadata,
983
- database: backendPluginApi.coreServices.database,
984
- // Re-using the token manager makes sure that we use the same generated keys for
985
- // development as plugins that have not yet been migrated. It's important that this
986
- // keeps working as long as there are plugins that have not been migrated to the
987
- // new auth services in the new backend system.
988
- tokenManager: backendPluginApi.coreServices.tokenManager
961
+ database: backendPluginApi.coreServices.database
989
962
  },
990
- async factory({ config, discovery, plugin, tokenManager, logger, database }) {
963
+ async factory({ config, discovery, plugin, logger, database }) {
991
964
  const disableDefaultAuthPolicy = config.getOptionalBoolean(
992
965
  "backend.auth.dangerouslyDisableDefaultAuthPolicy"
993
966
  ) ?? false;
@@ -1017,11 +990,9 @@ const authServiceFactory = backendPluginApi.createServiceFactory({
1017
990
  userTokens,
1018
991
  pluginTokens,
1019
992
  externalTokens,
1020
- tokenManager,
1021
993
  plugin.getId(),
1022
994
  disableDefaultAuthPolicy,
1023
- keySource,
1024
- logger
995
+ keySource
1025
996
  );
1026
997
  }
1027
998
  });