Skip to content

Commit 680e5b5

Browse files
Merge remote-tracking branch 'remotes/from/ce/main'
2 parents 56c9f61 + 6c4e6a5 commit 680e5b5

File tree

7 files changed

+87
-10
lines changed

7 files changed

+87
-10
lines changed

changelog/_10371.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:bug
2+
ui (enterprise): Fix KV v2 not displaying secrets in namespaces.
3+
```
4+
5+
```release-note:bug
6+
ui: Fix KV v2 metadata list request failing for policies without a trailing slash in the path.
7+
```

ui/app/components/console/ui-panel.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<p class="console-ui-panel-intro is-font-mono">
3636
<span aria-hidden="true">→ </span>Read a kv v2 secret: kv-get &lt;mount&gt;/secret-path</p>
3737
<p class="console-ui-panel-intro is-font-mono">
38-
<span aria-hidden="true">→ </span>Read a kv v2 secret's metadata: kv-get &lt;mount&gt;/secret-path-metadata</p>
38+
<span aria-hidden="true">→ </span>Read a kv v2 secret's metadata: kv-get &lt;mount&gt;/secret-path -metadata</p>
3939
</div>
4040
<Console::OutputLog @outputLog={{this.cliLog}} />
4141
<Console::CommandInput

ui/lib/core/addon/components/kv-suggestion-input.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export default class KvSuggestionInputComponent extends Component<Args> {
7474
const backend = keyIsFolder(mountPath) ? mountPath.slice(0, -1) : mountPath;
7575
const parentDirectory = parentKeyForKey(this.args.value);
7676
this.pathToSecret = this.isDirectory ? this.args.value : parentDirectory;
77+
// kvV2List => GET /:secret-mount-path/metadata/:secret_path/?list=true
78+
// This request can either list secrets at the mount root or for a specified :secret_path.
79+
// Since :secret_path already contains a trailing slash, e.g. /metadata/my-secret//
80+
// the request URL is sanitized by the api service to remove duplicate slashes.
7781
const { keys } = await this.api.secrets.kvV2List(this.pathToSecret, backend, KvV2ListListEnum.TRUE);
7882
// this will be used to filter the existing result set when the search term changes within the same path
7983
this._cachedSecrets = keys || [];

ui/lib/kv/addon/routes/list-directory.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export default class KvSecretsListRoute extends Route {
2626

2727
async fetchMetadata(backend, pathToSecret, params) {
2828
try {
29+
// kvV2List => GET /:secret-mount-path/metadata/:secret_path/?list=true
30+
// This request can either list secrets at the mount root or for a specified :secret_path.
31+
// Since :secret_path already contains a trailing slash, e.g. /metadata/my-secret//
32+
// the request URL is sanitized by the api service to remove duplicate slashes.
2933
const { keys } = await this.api.secrets.kvV2List(pathToSecret, backend, true);
3034
return paginate(keys, { page: Number(params.page) || 1, filter: params.pageFilter });
3135
} catch (error) {

ui/tests/acceptance/secrets/backend/kv/kv-v2-workflow-edge-cases-test.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import codemirror, { getCodeEditorValue, setCodeEditorValue } from 'vault/tests/
3939
import { personas } from 'vault/tests/helpers/kv/policy-generator';
4040
import { capabilitiesStub } from 'vault/tests/helpers/stubs';
4141
import { setupMirage } from 'ember-cli-mirage/test-support';
42+
import { selectChoose } from 'ember-power-select/test-support';
43+
import { DASHBOARD } from 'vault/tests/helpers/components/dashboard/dashboard-selectors';
4244

4345
/**
4446
* This test set is for testing edge cases, such as specific bug fixes or reported user workflows
@@ -66,7 +68,7 @@ module('Acceptance | kv-v2 workflow | edge cases', function (hooks) {
6668
return;
6769
});
6870

69-
module('persona with read and list access on the secret level', function (hooks) {
71+
module('persona with glob (*) read and list access on the secret level', function (hooks) {
7072
// see github issue for more details https://github.com/hashicorp/vault/issues/5362
7173
hooks.beforeEach(async function () {
7274
const secretPath = `${this.rootSecret}/*`; // user has LIST and READ access within this root secret directory
@@ -228,6 +230,62 @@ module('Acceptance | kv-v2 workflow | edge cases', function (hooks) {
228230
});
229231
});
230232

233+
module('persona with list access on a secret path', function (hooks) {
234+
// test coverage for this regression: https://github.com/hashicorp/vault/issues/31606
235+
hooks.beforeEach(async function () {
236+
const secretPath = this.rootSecret;
237+
const capabilities = ['list'];
238+
const backend = this.backend;
239+
const token = await runCmd([
240+
createPolicyCmd(
241+
`secret-lister-${this.backend}`,
242+
metadataPolicy({ backend, secretPath, capabilities })
243+
),
244+
createTokenCmd(`secret-lister-${this.backend}`),
245+
]);
246+
await login(token);
247+
});
248+
249+
test('it lists secrets within the root directory from the kv engine list', async function (assert) {
250+
assert.expect(4);
251+
const backend = this.backend;
252+
const [root, subdirectory] = this.fullSecretPath.split('/');
253+
254+
await visit(`/vault/secrets-engines/${backend}/kv/list`);
255+
assert.strictEqual(
256+
currentURL(),
257+
`/vault/secrets-engines/${backend}/kv/list`,
258+
'lands on secrets list page'
259+
);
260+
261+
await typeIn(PAGE.list.overviewInput, `${root}/`);
262+
await click(GENERAL.submitButton);
263+
assert.strictEqual(
264+
currentURL(),
265+
`/vault/secrets-engines/${backend}/kv/list/${root}/`,
266+
'it navigates to secret list'
267+
);
268+
assert.dom(PAGE.list.filter).hasValue(`${root}/`);
269+
assert.dom(PAGE.list.item(`${subdirectory}/`)).exists('it renders nested secret');
270+
});
271+
272+
test('it lists secrets within the root directory from the quick actions card', async function (assert) {
273+
assert.expect(2);
274+
const backend = this.backend;
275+
const [root, subdirectory] = this.fullSecretPath.split('/');
276+
277+
await visit(`/vault`);
278+
await selectChoose(DASHBOARD.searchSelect('secrets-engines'), backend);
279+
await fillIn(DASHBOARD.selectEl, 'Find KV secrets');
280+
await typeIn(GENERAL.kvSuggestion.input, `${root}/`);
281+
await click(GENERAL.kvSuggestion.input);
282+
assert
283+
.dom(GENERAL.searchSelect.options)
284+
.hasText(`${subdirectory}/`)
285+
.exists({ count: 1 }, 'expected options render');
286+
});
287+
});
288+
231289
module('destruction without read', function (hooks) {
232290
hooks.beforeEach(async function () {
233291
const backend = this.backend;

ui/tests/integration/components/console/ui-panel-test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,24 @@ module('Integration | Component | console/ui panel', function (hooks) {
1616
setupRenderingTest(hooks);
1717

1818
test('it renders', async function (assert) {
19-
await render(hbs`{{console/ui-panel}}`);
20-
19+
await render(hbs`<div class="panel-open"><Console::UiPanel /></div>`);
2120
assert.ok(component.hasInput);
21+
assert
22+
.dom(this.element)
23+
.hasText(
24+
"The Vault Web REPL provides an easy way to execute common Vault CLI commands, such as write, read, delete, and list. It does not include KV version 2 write or put commands. For guidance, type `help`. For more detailed documentation, see the HashiCorp Developer site. Examples: → Write secrets to kv v1: write <mount>/my-secret foo=bar → List kv v1 secret keys: list <mount>/ → Read a kv v1 secret: read <mount>/my-secret → Mount a kv v2 secret engine: write sys/mounts/<mount> type=kv options=version=2 → Read a kv v2 secret: kv-get <mount>/secret-path → Read a kv v2 secret's metadata: kv-get <mount>/secret-path -metadata"
25+
);
2226
});
2327

2428
test('it clears console input on enter', async function (assert) {
25-
await render(hbs`{{console/ui-panel}}`);
29+
await render(hbs`<Console::UiPanel />`);
2630
await component.runCommands('list this/thing/here', false);
2731
await settled();
2832
assert.strictEqual(component.consoleInputValue, '', 'empties input field on enter');
2933
});
3034

3135
test('it clears the log when using clear command', async function (assert) {
32-
await render(hbs`{{console/ui-panel}}`);
36+
await render(hbs`<Console::UiPanel />`);
3337
await component.runCommands(
3438
['list this/thing/here', 'list this/other/thing', 'read another/thing'],
3539
false
@@ -50,7 +54,7 @@ module('Integration | Component | console/ui panel', function (hooks) {
5054
});
5155

5256
test('it adds command to history on enter', async function (assert) {
53-
await render(hbs`{{console/ui-panel}}`);
57+
await render(hbs`<Console::UiPanel />`);
5458

5559
await component.runCommands('list this/thing/here', false);
5660
await settled();
@@ -67,7 +71,7 @@ module('Integration | Component | console/ui panel', function (hooks) {
6771
});
6872

6973
test('it cycles through history with more than one command', async function (assert) {
70-
await render(hbs`{{console/ui-panel}}`);
74+
await render(hbs`<Console::UiPanel />`);
7175
await component.runCommands(['list this/thing/here', 'read that/thing/there', 'qwerty'], false);
7276
await settled();
7377
await component.up();

ui/yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,8 +2752,8 @@ __metadata:
27522752

27532753
"@hashicorp/vault-client-typescript@hashicorp/vault-client-typescript":
27542754
version: 0.0.0
2755-
resolution: "@hashicorp/vault-client-typescript@https://github.com/hashicorp/vault-client-typescript.git#commit=192d6367eca00c22e887e5de00586b394a0be03f"
2756-
checksum: eed9bcd9c37377337a7a5e378f807c949926b39b8c2b36b8a442a2b9727a152cf73370a396f868a82d3318d69532089e25b2dc27f1072e0a709b06fe4c49b0f6
2755+
resolution: "@hashicorp/vault-client-typescript@https://github.com/hashicorp/vault-client-typescript.git#commit=a3dda25d161198fe514ad37f8ecc11820b281916"
2756+
checksum: cc3ddde3e03906c308e5049b01b28c7d9c22e541772b4a1f07dddf5a82879bd3fb691b92543f25b2cee71461ec8c6226438ee1cc88d7686fc4122a9b45930c5f
27572757
languageName: node
27582758
linkType: hard
27592759

0 commit comments

Comments
 (0)