Add changeset and docs.

Signed-off-by: Joon Park <joonp@spotify.com>
This commit is contained in:
Joon Park
2021-12-07 15:47:19 +00:00
parent f786dc8140
commit abb7616345
4 changed files with 20 additions and 9 deletions
+8
View File
@@ -0,0 +1,8 @@
---
'@backstage/backend-common': minor
'example-app': patch
'example-backend': patch
'@backstage/plugin-permission-node': patch
---
Integrate permission framework into example app
+6 -6
View File
@@ -22,13 +22,14 @@ resulting value.
node -p 'require("crypto").randomBytes(24).toString("base64")'
```
**NOTE**: For ease of development, we auto-generate a key for you if you haven't
configured a secret in dev mode. You _must set your own secret_ in order for
backend-to-backend authentication to work in production.
Requests originating from a backend plugin can be authenticated by decorating
them with a backend token. Backend tokens can be generated using a
`TokenManager`, which can be passed to plugin backends via the
`PluginEnvironment`. The `TokenManager` provided in new Backstage instances
generated by `create-app` is a stub, which returns empty tokens and accepts any
input string as valid. To enable backend-to-backend authentication, you'll need
to instantiate a new one using the secret from your config instead:
`PluginEnvironment`.
```diff
// packages/backend/src/index.ts
@@ -42,8 +43,7 @@ function makeCreateEnv(config: Config) {
const cacheManager = CacheManager.fromConfig(config);
const databaseManager = DatabaseManager.fromConfig(config);
- const tokenManager = ServerTokenManager.noop();
+ const tokenManager = ServerTokenManager.fromConfig(config);
+ const tokenManager = ServerTokenManager.default({ config, logger: root });
```
With this `tokenManager`, you can then generate a server token for requests:
+1 -3
View File
@@ -126,9 +126,7 @@ export type PolicyDecision =
}
| ConditionalPolicyDecision;
// Warning: (ae-missing-release-tag) "ServerPermissionClient" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export class ServerPermissionClient extends PermissionClient {
constructor(options: {
discoveryApi: DiscoveryApi;
@@ -25,6 +25,11 @@ import {
PermissionClient,
} from '@backstage/plugin-permission-common';
/**
* A server side {@link @backstage/plugin-permission-common#PermissionClient}
* that allows all backend-to-backend requests.
* @public
*/
export class ServerPermissionClient extends PermissionClient {
private readonly serverTokenManager: ServerTokenManager;