@backstage-community/plugin-vault 0.1.30

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.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @backstage-community/plugin-vault
2
+
3
+ A frontend for [Vault](https://www.vaultproject.io/), this plugin allows you to display a list of secrets in a certain path inside your vault instance. There are also some useful links to edit and/or view them using the official UI.
4
+
5
+ ![Screenshot of the vault plugin table](images/vault-table.png)
6
+
7
+ ## Introduction
8
+
9
+ Vault is an identity-based secrets and encryption management system. A secret is anything that you want to tightly control access to, such as API encryption keys, passwords, or certificates. Vault provides encryption services that are gated by authentication and authorization methods.
10
+
11
+ This plugins allows you to view all the available secrets at a certain location, and redirect you to the official UI so backstage can rely on LIST permissions, which is safer.
12
+
13
+ ## Getting started
14
+
15
+ To get started, first you need a running instance of Vault. You can follow [this tutorial](https://learn.hashicorp.com/tutorials/vault/getting-started-intro?in=vault/getting-started) to install vault and start your server locally.
16
+
17
+ 1. When your Vault instance is up and running, then you will need to install the plugin into your app:
18
+
19
+ ```bash
20
+ # From your Backstage root directory
21
+ yarn --cwd packages/app add @backstage-community/plugin-vault
22
+ ```
23
+
24
+ 2. Add the Vault card to the overview tab on the EntityPage:
25
+
26
+ ```typescript
27
+ // In packages/app/src/components/catalog/EntityPage.tsx
28
+ import { EntityVaultCard } from '@backstage-community/plugin-vault';
29
+
30
+ const overviewContent = (
31
+ <Grid container spacing={3} alignItems="stretch">
32
+ {/* ...other content */}
33
+ <Grid item md={6} xs={12}>
34
+ <EntityVaultCard />
35
+ </Grid>
36
+ );
37
+ ```
38
+
39
+ 3. Add some extra configurations in your [`app-config.yaml`](https://github.com/backstage/backstage/blob/master/app-config.yaml).
40
+
41
+ ```yaml
42
+ vault:
43
+ baseUrl: http://your-vault-url
44
+ token: <VAULT_TOKEN>
45
+ secretEngine: 'customSecretEngine' # Optional. By default it uses 'secrets'. Can be overwritten by the annotation of the entity
46
+ kvVersion: <kv-version> # Optional. The K/V version that your instance is using. The available options are '1' or '2'
47
+ ```
48
+
49
+ 4. Get a `VAULT_TOKEN` with **LIST** permissions, as it's enough for the plugin. You can check [this tutorial](https://learn.hashicorp.com/tutorials/vault/tokens) for more info.
50
+
51
+ 5. If you also want to use the `renew` functionality, you need to attach the following block to your custom policy, so that Backstage can perform a token-renew:
52
+ ```
53
+ # Allow tokens to renew themselves
54
+ path "auth/token/renew-self" {
55
+ capabilities = ["update"]
56
+ }
57
+ ```
58
+
59
+ ## Integration with the Catalog
60
+
61
+ The plugin can be integrated into each Component in the catalog. To allow listing the available secrets a new annotation must be added to the `catalog-info.yaml`:
62
+
63
+ ```yaml
64
+ apiVersion: backstage.io/v1alpha1
65
+ kind: Component
66
+ metadata:
67
+ # ...
68
+ annotations:
69
+ vault.io/secrets-path: path/to/secrets
70
+ vault.io/secrets-engine: customSecretEngine # Optional. By default it uses the 'secretEngine' value from your app-config.
71
+ ```
72
+
73
+ The path is relative to your secrets engine folder. So if you want to get the secrets for backstage and you have the following directory structure:
74
+
75
+ .
76
+ ├── ...
77
+ ├── secrets # Your secret engine name (usually it is `secrets`)
78
+ │ ├── test # Folder with test secrets
79
+ │ │ ├── backstage # In this folder there are secrets for Backstage
80
+ │ ├── other # Other folder with more secrets inside
81
+ │ └── folder # And another folder
82
+ └── ...
83
+
84
+ You will set the `vault.io/secret-path` to `test/backstage`. If the folder `backstage` contains other sub-folders, the plugin will fetch the secrets inside them and adapt the **View** and **Edit** URLs to point to the correct place.
85
+
86
+ If the annotation is missing for a certain component, then the card will show some information to the user:
87
+
88
+ ![Screenshot of the vault plugin with missing annotation](images/annotation-missing.png)
89
+
90
+ In case you need to support different secret engines for entities of the catalog you can provide optional annotation to the entity in `catalog-info.yaml`:
91
+
92
+ ```diff
93
+ apiVersion: backstage.io/v1alpha1
94
+ kind: Component
95
+ metadata:
96
+ # ...
97
+ annotations:
98
+ vault.io/secrets-path: path/to/secrets
99
+ + vault.io/secrets-engine: customSecretEngine # Optional. By default it uses 'secertEngine' value from configuration.
100
+ ```
101
+
102
+ That will overwrite the default secret engine from the configuration.
103
+
104
+ ## Features
105
+
106
+ - List the secrets present in a certain path
107
+ - Use different secret engines for different components
108
+ - Open a link to view the secret
109
+ - Open a link to edit the secret
110
+ - Renew the token automatically with a defined periodicity
111
+
112
+ The secrets cannot be edited/viewed from within Backstage to make it more secure. Backstage will only have permissions to LIST data from Vault. And the user who wants to edit/view a certain secret needs the correct permissions to do so.
@@ -0,0 +1,90 @@
1
+ import { createApiRef, createPlugin, createApiFactory, discoveryApiRef, fetchApiRef, createComponentExtension } from '@backstage/core-plugin-api';
2
+ import { NotFoundError, ResponseError } from '@backstage/errors';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => {
7
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ return value;
9
+ };
10
+ const vaultApiRef = createApiRef({
11
+ id: "plugin.vault.service"
12
+ });
13
+ class VaultClient {
14
+ constructor({
15
+ discoveryApi,
16
+ fetchApi
17
+ }) {
18
+ __publicField(this, "discoveryApi");
19
+ __publicField(this, "fetchApi");
20
+ this.discoveryApi = discoveryApi;
21
+ this.fetchApi = fetchApi;
22
+ }
23
+ async callApi(path, query) {
24
+ const apiUrl = `${await this.discoveryApi.getBaseUrl("vault")}`;
25
+ const response = await this.fetchApi.fetch(
26
+ `${apiUrl}/${path}?${new URLSearchParams(query).toString()}`,
27
+ {
28
+ headers: {
29
+ Accept: "application/json"
30
+ }
31
+ }
32
+ );
33
+ if (response.ok) {
34
+ return await response.json();
35
+ } else if (response.status === 404) {
36
+ throw new NotFoundError(`No secrets found in path '${path}'`);
37
+ }
38
+ throw await ResponseError.fromResponse(response);
39
+ }
40
+ async listSecrets(secretPath, options) {
41
+ const query = {};
42
+ const { secretEngine } = options || {};
43
+ if (secretEngine) {
44
+ query.engine = secretEngine;
45
+ }
46
+ const result = await this.callApi(
47
+ `v1/secrets/${encodeURIComponent(secretPath)}`,
48
+ query
49
+ );
50
+ return result.items;
51
+ }
52
+ }
53
+
54
+ const vaultPlugin = createPlugin({
55
+ id: "vault",
56
+ apis: [
57
+ createApiFactory({
58
+ api: vaultApiRef,
59
+ deps: { discoveryApi: discoveryApiRef, fetchApi: fetchApiRef },
60
+ factory: ({
61
+ discoveryApi,
62
+ fetchApi
63
+ }) => new VaultClient({
64
+ discoveryApi,
65
+ fetchApi
66
+ })
67
+ })
68
+ ]
69
+ });
70
+ const EntityVaultCard = vaultPlugin.provide(
71
+ createComponentExtension({
72
+ name: "EntityVaultCard",
73
+ component: {
74
+ lazy: () => import('./index-_ZTGu21U.esm.js').then((m) => m.EntityVaultCard)
75
+ }
76
+ })
77
+ );
78
+
79
+ const VAULT_SECRET_ENGINE_ANNOTATION = "vault.io/secrets-engine";
80
+ const VAULT_SECRET_PATH_ANNOTATION = "vault.io/secrets-path";
81
+
82
+ function isVaultAvailable(entity) {
83
+ var _a;
84
+ return Boolean(
85
+ (_a = entity.metadata.annotations) == null ? void 0 : _a.hasOwnProperty(VAULT_SECRET_PATH_ANNOTATION)
86
+ );
87
+ }
88
+
89
+ export { EntityVaultCard as E, VAULT_SECRET_PATH_ANNOTATION as V, VAULT_SECRET_ENGINE_ANNOTATION as a, vaultPlugin as b, isVaultAvailable as i, vaultApiRef as v };
90
+ //# sourceMappingURL=index-C3tCbIvC.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-C3tCbIvC.esm.js","sources":["../../src/api.ts","../../src/plugin.ts","../../src/constants.ts","../../src/conditions.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n DiscoveryApi,\n createApiRef,\n FetchApi,\n} from '@backstage/core-plugin-api';\nimport { NotFoundError, ResponseError } from '@backstage/errors';\n\n/**\n * @public\n */\nexport const vaultApiRef = createApiRef<VaultApi>({\n id: 'plugin.vault.service',\n});\n\n/**\n * Object containing the secret name and some links.\n * @public\n */\nexport type VaultSecret = {\n name: string;\n path: string;\n showUrl: string;\n editUrl: string;\n};\n\n/**\n * Interface for the VaultApi.\n * @public\n */\nexport interface VaultApi {\n /**\n * Returns a list of secrets used to show in a table.\n * @param secretPath - The path where the secrets are stored in Vault\n * @param options - Additional options to be passed to the Vault API, allows to override vault default settings in app config file\n */\n listSecrets(\n secretPath: string,\n options?: {\n secretEngine?: string;\n },\n ): Promise<VaultSecret[]>;\n}\n\n/**\n * Default implementation of the VaultApi.\n * @public\n */\nexport class VaultClient implements VaultApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n\n constructor({\n discoveryApi,\n fetchApi,\n }: {\n discoveryApi: DiscoveryApi;\n fetchApi: FetchApi;\n }) {\n this.discoveryApi = discoveryApi;\n this.fetchApi = fetchApi;\n }\n\n private async callApi<T>(\n path: string,\n query: { [key in string]: any },\n ): Promise<T> {\n const apiUrl = `${await this.discoveryApi.getBaseUrl('vault')}`;\n const response = await this.fetchApi.fetch(\n `${apiUrl}/${path}?${new URLSearchParams(query).toString()}`,\n {\n headers: {\n Accept: 'application/json',\n },\n },\n );\n if (response.ok) {\n return (await response.json()) as T;\n } else if (response.status === 404) {\n throw new NotFoundError(`No secrets found in path '${path}'`);\n }\n throw await ResponseError.fromResponse(response);\n }\n\n async listSecrets(\n secretPath: string,\n options?: {\n secretEngine?: string;\n },\n ): Promise<VaultSecret[]> {\n const query: { [key in string]: any } = {};\n const { secretEngine } = options || {};\n if (secretEngine) {\n query.engine = secretEngine;\n }\n\n const result = await this.callApi<{ items: VaultSecret[] }>(\n `v1/secrets/${encodeURIComponent(secretPath)}`,\n query,\n );\n return result.items;\n }\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n createApiFactory,\n createComponentExtension,\n createPlugin,\n DiscoveryApi,\n discoveryApiRef,\n FetchApi,\n fetchApiRef,\n} from '@backstage/core-plugin-api';\n\nimport { vaultApiRef, VaultClient } from './api';\n\n/**\n * The vault plugin.\n * @public\n */\nexport const vaultPlugin = createPlugin({\n id: 'vault',\n apis: [\n createApiFactory({\n api: vaultApiRef,\n deps: { discoveryApi: discoveryApiRef, fetchApi: fetchApiRef },\n factory: ({\n discoveryApi,\n fetchApi,\n }: {\n discoveryApi: DiscoveryApi;\n fetchApi: FetchApi;\n }) =>\n new VaultClient({\n discoveryApi,\n fetchApi,\n }),\n }),\n ],\n});\n\n/**\n * Card used to show the list of Vault secrets.\n * @public\n */\nexport const EntityVaultCard = vaultPlugin.provide(\n createComponentExtension({\n name: 'EntityVaultCard',\n component: {\n lazy: () =>\n import('./components/EntityVaultCard').then(m => m.EntityVaultCard),\n },\n }),\n);\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @public\n */\nexport const VAULT_SECRET_ENGINE_ANNOTATION = 'vault.io/secrets-engine';\n/**\n * @public\n */\nexport const VAULT_SECRET_PATH_ANNOTATION = 'vault.io/secrets-path';\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Entity } from '@backstage/catalog-model';\nimport { VAULT_SECRET_PATH_ANNOTATION } from './constants';\n\n/**\n * Checks if an entity contains the annotation for Vault.\n * @param entity - The entity to check if the annotation exists\n * @returns If the annotation exists or not\n * @public\n */\nexport function isVaultAvailable(entity: Entity): boolean {\n return Boolean(\n entity.metadata.annotations?.hasOwnProperty(VAULT_SECRET_PATH_ANNOTATION),\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAyBO,MAAM,cAAc,YAAuB,CAAA;AAAA,EAChD,EAAI,EAAA,sBAAA;AACN,CAAC,EAAA;AAmCM,MAAM,WAAgC,CAAA;AAAA,EAI3C,WAAY,CAAA;AAAA,IACV,YAAA;AAAA,IACA,QAAA;AAAA,GAIC,EAAA;AATH,IAAiB,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AASf,IAAA,IAAA,CAAK,YAAe,GAAA,YAAA,CAAA;AACpB,IAAA,IAAA,CAAK,QAAW,GAAA,QAAA,CAAA;AAAA,GAClB;AAAA,EAEA,MAAc,OACZ,CAAA,IAAA,EACA,KACY,EAAA;AACZ,IAAA,MAAM,SAAS,CAAG,EAAA,MAAM,KAAK,YAAa,CAA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AAAA,IACJ,gBAAiB,CAAA;AAAA,MACf,GAAK,EAAA,WAAA;AAAA,MACL,IAAM,EAAA,EAAE,YAAc,EAAA,eAAA,EAAiB,UAAU,WAAY,EAAA;AAAA,MAC7D,SAAS,CAAC;AAAA,QACR,YAAA;AAAA,QACA,QAAA;AAAA,OACF,KAIE,IAAI,WAAY,CAAA;AAAA,QACd,YAAA;AAAA,QACA,QAAA;AAAA,OACD,CAAA;AAAA,KACJ,CAAA;AAAA,GACH;AACF,CAAC,EAAA;AAMM,MAAM,kBAAkB,WAAY,CAAA,OAAA;AAAA,EACzC,wBAAyB,CAAA;AAAA,IACvB,IAAM,EAAA,iBAAA;AAAA,IACN,SAAW,EAAA;AAAA,MACT,IAAA,EAAM,MACJ,OAAO,yBAA8B,EAAE,IAAK,CAAA,CAAA,CAAA,KAAK,EAAE,eAAe,CAAA;AAAA,KACtE;AAAA,GACD,CAAA;AACH;;AC7CO,MAAM,8BAAiC,GAAA,0BAAA;AAIvC,MAAM,4BAA+B,GAAA;;ACCrC,SAAS,iBAAiB,MAAyB,EAAA;AAxB1D,EAAA,IAAA,EAAA,CAAA;AAyBE,EAAO,OAAA,OAAA;AAAA,IAAA,CACL,EAAO,GAAA,MAAA,CAAA,QAAA,CAAS,WAAhB,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAA6B,cAAe,CAAA,4BAAA,CAAA;AAAA,GAC9C,CAAA;AACF;;;;"}
@@ -0,0 +1,91 @@
1
+ import React from 'react';
2
+ import { useEntity, MissingAnnotationEmptyState } from '@backstage/plugin-catalog-react';
3
+ import { v as vaultApiRef, V as VAULT_SECRET_PATH_ANNOTATION, a as VAULT_SECRET_ENGINE_ANNOTATION, i as isVaultAvailable } from './index-C3tCbIvC.esm.js';
4
+ import { Link, Table } from '@backstage/core-components';
5
+ import { useApi } from '@backstage/core-plugin-api';
6
+ import Box from '@material-ui/core/Box';
7
+ import Typography from '@material-ui/core/Typography';
8
+ import Edit from '@material-ui/icons/Edit';
9
+ import Visibility from '@material-ui/icons/Visibility';
10
+ import Alert from '@material-ui/lab/Alert';
11
+ import useAsync from 'react-use/esm/useAsync';
12
+ import '@backstage/errors';
13
+
14
+ const vaultSecretConfig = (entity) => {
15
+ var _a, _b;
16
+ const secretPath = (_a = entity.metadata.annotations) == null ? void 0 : _a[VAULT_SECRET_PATH_ANNOTATION];
17
+ const secretEngine = (_b = entity.metadata.annotations) == null ? void 0 : _b[VAULT_SECRET_ENGINE_ANNOTATION];
18
+ return { secretPath, secretEngine };
19
+ };
20
+ const EntityVaultTable = ({ entity }) => {
21
+ const vaultApi = useApi(vaultApiRef);
22
+ const { secretPath, secretEngine } = vaultSecretConfig(entity);
23
+ if (!secretPath) {
24
+ throw Error(
25
+ `The secret path is undefined. Please, define the annotation ${VAULT_SECRET_PATH_ANNOTATION}`
26
+ );
27
+ }
28
+ const { value, loading, error } = useAsync(async () => {
29
+ return vaultApi.listSecrets(secretPath, { secretEngine });
30
+ }, []);
31
+ const columns = [
32
+ { title: "Secret", field: "secret", highlight: true },
33
+ { title: "View URL", field: "view", width: "10%" },
34
+ { title: "Edit URL", field: "edit", width: "10%" }
35
+ ];
36
+ const data = (value || []).map((secret) => {
37
+ const secretName = `${secret.path.replace(`${secretPath}/`, "")}/${secret.name}`;
38
+ return {
39
+ secret: secretName,
40
+ view: /* @__PURE__ */ React.createElement(
41
+ Link,
42
+ {
43
+ "aria-label": "View",
44
+ title: `View ${secretName}`,
45
+ to: secret.showUrl
46
+ },
47
+ /* @__PURE__ */ React.createElement(Visibility, { style: { fontSize: 16 } })
48
+ ),
49
+ edit: /* @__PURE__ */ React.createElement(
50
+ Link,
51
+ {
52
+ "aria-label": "Edit",
53
+ title: `Edit ${secretName}`,
54
+ to: secret.editUrl
55
+ },
56
+ /* @__PURE__ */ React.createElement(Edit, { style: { fontSize: 16 } })
57
+ )
58
+ };
59
+ });
60
+ if (error) {
61
+ return /* @__PURE__ */ React.createElement(Alert, { severity: "error" }, "Unexpected error while fetching secrets from path '", secretPath, "':", " ", error.message);
62
+ }
63
+ return /* @__PURE__ */ React.createElement(
64
+ Table,
65
+ {
66
+ title: "Vault",
67
+ subtitle: `Secrets for ${entity.metadata.name} in ${secretPath}`,
68
+ columns,
69
+ data,
70
+ isLoading: loading,
71
+ options: {
72
+ padding: "dense",
73
+ pageSize: 10,
74
+ emptyRowsWhenPaging: false,
75
+ search: false
76
+ },
77
+ emptyContent: /* @__PURE__ */ React.createElement(Box, { style: { textAlign: "center", padding: "15px" } }, /* @__PURE__ */ React.createElement(Typography, { variant: "body1" }, "No secrets found for ", entity.metadata.name, " in ", secretPath))
78
+ }
79
+ );
80
+ };
81
+
82
+ const EntityVaultCard = () => {
83
+ const { entity } = useEntity();
84
+ if (isVaultAvailable(entity)) {
85
+ return /* @__PURE__ */ React.createElement(EntityVaultTable, { entity });
86
+ }
87
+ return /* @__PURE__ */ React.createElement(MissingAnnotationEmptyState, { annotation: VAULT_SECRET_PATH_ANNOTATION });
88
+ };
89
+
90
+ export { EntityVaultCard };
91
+ //# sourceMappingURL=index-_ZTGu21U.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-_ZTGu21U.esm.js","sources":["../../src/components/EntityVaultTable/EntityVaultTable.tsx","../../src/components/EntityVaultCard/EntityVaultCard.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\nimport { Entity } from '@backstage/catalog-model';\nimport { Link, Table, TableColumn } from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\nimport Box from '@material-ui/core/Box';\nimport Typography from '@material-ui/core/Typography';\nimport Edit from '@material-ui/icons/Edit';\nimport Visibility from '@material-ui/icons/Visibility';\nimport Alert from '@material-ui/lab/Alert';\nimport useAsync from 'react-use/esm/useAsync';\nimport { VaultSecret, vaultApiRef } from '../../api';\nimport {\n VAULT_SECRET_ENGINE_ANNOTATION,\n VAULT_SECRET_PATH_ANNOTATION,\n} from '../../constants';\n\nexport const vaultSecretConfig = (entity: Entity) => {\n const secretPath =\n entity.metadata.annotations?.[VAULT_SECRET_PATH_ANNOTATION];\n const secretEngine =\n entity.metadata.annotations?.[VAULT_SECRET_ENGINE_ANNOTATION];\n\n return { secretPath, secretEngine };\n};\n\nexport const EntityVaultTable = ({ entity }: { entity: Entity }) => {\n const vaultApi = useApi(vaultApiRef);\n const { secretPath, secretEngine } = vaultSecretConfig(entity);\n if (!secretPath) {\n throw Error(\n `The secret path is undefined. Please, define the annotation ${VAULT_SECRET_PATH_ANNOTATION}`,\n );\n }\n\n const { value, loading, error } = useAsync(async (): Promise<\n VaultSecret[]\n > => {\n return vaultApi.listSecrets(secretPath, { secretEngine });\n }, []);\n\n const columns: TableColumn[] = [\n { title: 'Secret', field: 'secret', highlight: true },\n { title: 'View URL', field: 'view', width: '10%' },\n { title: 'Edit URL', field: 'edit', width: '10%' },\n ];\n\n const data = (value || []).map(secret => {\n const secretName = `${secret.path.replace(`${secretPath}/`, '')}/${\n secret.name\n }`;\n\n return {\n secret: secretName,\n view: (\n <Link\n aria-label=\"View\"\n title={`View ${secretName}`}\n to={secret.showUrl}\n >\n <Visibility style={{ fontSize: 16 }} />\n </Link>\n ),\n edit: (\n <Link\n aria-label=\"Edit\"\n title={`Edit ${secretName}`}\n to={secret.editUrl}\n >\n <Edit style={{ fontSize: 16 }} />\n </Link>\n ),\n };\n });\n\n if (error) {\n return (\n <Alert severity=\"error\">\n Unexpected error while fetching secrets from path '{secretPath}':{' '}\n {error.message}\n </Alert>\n );\n }\n\n return (\n <Table\n title=\"Vault\"\n subtitle={`Secrets for ${entity.metadata.name} in ${secretPath}`}\n columns={columns}\n data={data}\n isLoading={loading}\n options={{\n padding: 'dense',\n pageSize: 10,\n emptyRowsWhenPaging: false,\n search: false,\n }}\n emptyContent={\n <Box style={{ textAlign: 'center', padding: '15px' }}>\n <Typography variant=\"body1\">\n No secrets found for {entity.metadata.name} in {secretPath}\n </Typography>\n </Box>\n }\n />\n );\n};\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\nimport {\n useEntity,\n MissingAnnotationEmptyState,\n} from '@backstage/plugin-catalog-react';\nimport { isVaultAvailable } from '../../conditions';\nimport { VAULT_SECRET_PATH_ANNOTATION } from '../../constants';\nimport { EntityVaultTable } from '../EntityVaultTable';\n\nexport const EntityVaultCard = () => {\n const { entity } = useEntity();\n\n if (isVaultAvailable(entity)) {\n return <EntityVaultTable entity={entity} />;\n }\n return (\n <MissingAnnotationEmptyState annotation={VAULT_SECRET_PATH_ANNOTATION} />\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AA+Ba,MAAA,iBAAA,GAAoB,CAAC,MAAmB,KAAA;AA/BrD,EAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAgCE,EAAA,MAAM,UACJ,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,QAAS,CAAA,WAAA,KAAhB,IAA8B,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,4BAAA,CAAA,CAAA;AAChC,EAAA,MAAM,YACJ,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,QAAS,CAAA,WAAA,KAAhB,IAA8B,GAAA,KAAA,CAA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V;AAAA,MACA,YAAA,sCACG,GAAI,EAAA,EAAA,KAAA,EAAO,EAAE,SAAW,EAAA,QAAA,EAAU,SAAS,MAAO,EAAA,EAAA,sCAChD,UAAW,EAAA,EAAA,OAAA,EAAQ,WAAQ,uBACJ,EAAA,MAAA,CAAO,SAAS,IAAK,EAAA,MAAA,EAAK,UAClD,CACF,CAAA;AAAA,KAAA;AAAA,GAEJ,CAAA;AAEJ,CAAA;;AC/FO,MAAM,kBAAkB,MAAM;AACnC,EAAM,MAAA,EAAE,MAAO,EAAA,GAAI,SAAU,EAAA,CAAA;AAE7B,EAAI,IAAA,gBAAA,CAAiB,MAAM,CAAG,EAAA;AAC5B,IAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,oBAAiB,MAAgB,EAAA,CAAA,CAAA;AAAA,GAC3C;AACA,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,2BAA4B,EAAA,EAAA,UAAA,EAAY,4BAA8B,EAAA,CAAA,CAAA;AAE3E;;;;"}
@@ -0,0 +1,59 @@
1
+ /// <reference types="react" />
2
+ import * as react from 'react';
3
+ import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
4
+ import { Entity } from '@backstage/catalog-model';
5
+
6
+ /**
7
+ * The vault plugin.
8
+ * @public
9
+ */
10
+ declare const vaultPlugin: _backstage_core_plugin_api.BackstagePlugin<{}, {}, {}>;
11
+ /**
12
+ * Card used to show the list of Vault secrets.
13
+ * @public
14
+ */
15
+ declare const EntityVaultCard: () => react.JSX.Element;
16
+
17
+ /**
18
+ * Checks if an entity contains the annotation for Vault.
19
+ * @param entity - The entity to check if the annotation exists
20
+ * @returns If the annotation exists or not
21
+ * @public
22
+ */
23
+ declare function isVaultAvailable(entity: Entity): boolean;
24
+
25
+ /**
26
+ * @public
27
+ */
28
+ declare const VAULT_SECRET_PATH_ANNOTATION = "vault.io/secrets-path";
29
+
30
+ /**
31
+ * @public
32
+ */
33
+ declare const vaultApiRef: _backstage_core_plugin_api.ApiRef<VaultApi>;
34
+ /**
35
+ * Object containing the secret name and some links.
36
+ * @public
37
+ */
38
+ type VaultSecret = {
39
+ name: string;
40
+ path: string;
41
+ showUrl: string;
42
+ editUrl: string;
43
+ };
44
+ /**
45
+ * Interface for the VaultApi.
46
+ * @public
47
+ */
48
+ interface VaultApi {
49
+ /**
50
+ * Returns a list of secrets used to show in a table.
51
+ * @param secretPath - The path where the secrets are stored in Vault
52
+ * @param options - Additional options to be passed to the Vault API, allows to override vault default settings in app config file
53
+ */
54
+ listSecrets(secretPath: string, options?: {
55
+ secretEngine?: string;
56
+ }): Promise<VaultSecret[]>;
57
+ }
58
+
59
+ export { EntityVaultCard, VAULT_SECRET_PATH_ANNOTATION, type VaultApi, type VaultSecret, isVaultAvailable, vaultApiRef, vaultPlugin };
@@ -0,0 +1,4 @@
1
+ export { E as EntityVaultCard, V as VAULT_SECRET_PATH_ANNOTATION, i as isVaultAvailable, v as vaultApiRef, b as vaultPlugin } from './esm/index-C3tCbIvC.esm.js';
2
+ import '@backstage/core-plugin-api';
3
+ import '@backstage/errors';
4
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@backstage-community/plugin-vault",
3
+ "version": "0.1.30",
4
+ "description": "A Backstage plugin that integrates towards Vault",
5
+ "backstage": {
6
+ "role": "frontend-plugin"
7
+ },
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "main": "dist/index.esm.js",
11
+ "types": "dist/index.d.ts"
12
+ },
13
+ "keywords": [
14
+ "backstage",
15
+ "vault"
16
+ ],
17
+ "homepage": "https://backstage.io",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/backstage/community-plugins",
21
+ "directory": "workspaces/vault/plugins/vault"
22
+ },
23
+ "license": "Apache-2.0",
24
+ "sideEffects": false,
25
+ "main": "dist/index.esm.js",
26
+ "types": "dist/index.d.ts",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "scripts": {
31
+ "build": "backstage-cli package build",
32
+ "clean": "backstage-cli package clean",
33
+ "lint": "backstage-cli package lint",
34
+ "prepack": "backstage-cli package prepack",
35
+ "postpack": "backstage-cli package postpack",
36
+ "start": "backstage-cli package start",
37
+ "test": "backstage-cli package test"
38
+ },
39
+ "dependencies": {
40
+ "@backstage/catalog-model": "^1.4.5",
41
+ "@backstage/core-components": "^0.14.4",
42
+ "@backstage/core-plugin-api": "^1.9.2",
43
+ "@backstage/errors": "^1.2.4",
44
+ "@backstage/plugin-catalog-react": "^1.11.3",
45
+ "@material-ui/core": "^4.12.2",
46
+ "@material-ui/icons": "^4.9.1",
47
+ "@material-ui/lab": "4.0.0-alpha.61",
48
+ "@types/react": "^16.13.1 || ^17.0.0 || ^18.0.0",
49
+ "react-use": "^17.2.4"
50
+ },
51
+ "devDependencies": {
52
+ "@backstage/cli": "^0.26.3",
53
+ "@backstage/core-app-api": "^1.12.4",
54
+ "@backstage/dev-utils": "^1.0.31",
55
+ "@backstage/test-utils": "^1.5.4",
56
+ "@testing-library/dom": "^10.0.0",
57
+ "@testing-library/jest-dom": "^6.0.0",
58
+ "@testing-library/react": "^15.0.0",
59
+ "@types/react-dom": "^18.2.19",
60
+ "canvas": "^2.11.2",
61
+ "msw": "^1.0.0",
62
+ "react": "^16.13.1 || ^17.0.0 || ^18.0.0",
63
+ "react-dom": "^16.13.1 || ^17.0.0 || ^18.0.0",
64
+ "react-router-dom": "6.0.0-beta.0 || ^6.3.0"
65
+ },
66
+ "peerDependencies": {
67
+ "react": "^16.13.1 || ^17.0.0 || ^18.0.0",
68
+ "react-dom": "^16.13.1 || ^17.0.0 || ^18.0.0",
69
+ "react-router-dom": "6.0.0-beta.0 || ^6.3.0"
70
+ },
71
+ "module": "./dist/index.esm.js"
72
+ }