Skip to content

Commit

Permalink
Fix unable to create roles under Stack Management (#156381)
Browse files Browse the repository at this point in the history
Resolves #156249

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
thomheymann and kibanamachine committed May 2, 2023
1 parent 296b05a commit de0498d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,49 @@ describe('Put payload schema', () => {
}
`);
});

test('passes through remote_indices when specified', () => {
expect(
getPutPayloadSchema(() => basePrivilegeNamesMap).validate({
elasticsearch: {
remote_indices: [
{
clusters: ['remote_cluster'],
names: ['remote_index'],
privileges: ['all'],
},
],
},
})
).toMatchInlineSnapshot(`
Object {
"elasticsearch": Object {
"remote_indices": Array [
Object {
"clusters": Array [
"remote_cluster",
],
"names": Array [
"remote_index",
],
"privileges": Array [
"all",
],
},
],
},
}
`);
});

// This is important for backwards compatibility
test('does not set default value for remote_indices when not specified', () => {
expect(getPutPayloadSchema(() => basePrivilegeNamesMap).validate({})).toMatchInlineSnapshot(`
Object {
"elasticsearch": Object {},
}
`);
});
});

describe('validateKibanaPrivileges', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const transformPutPayloadToElasticsearchRole = (
metadata: rolePayload.metadata,
cluster: elasticsearch.cluster || [],
indices: elasticsearch.indices || [],
remote_indices: elasticsearch.remote_indices || [],
remote_indices: elasticsearch.remote_indices,
run_as: elasticsearch.run_as || [],
applications: [
...transformPrivilegesToElasticsearchPrivileges(application, kibana),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ describe('PUT role', () => {
body: {
cluster: [],
indices: [],
remote_indices: [],
remote_indices: undefined,
run_as: [],
applications: [],
},
Expand Down Expand Up @@ -359,7 +359,7 @@ describe('PUT role', () => {
body: {
cluster: [],
indices: [],
remote_indices: [],
remote_indices: undefined,
run_as: [],
applications: [
{
Expand Down Expand Up @@ -402,7 +402,7 @@ describe('PUT role', () => {
body: {
cluster: [],
indices: [],
remote_indices: [],
remote_indices: undefined,
run_as: [],
applications: [
{
Expand Down Expand Up @@ -443,7 +443,7 @@ describe('PUT role', () => {
body: {
cluster: [],
indices: [],
remote_indices: [],
remote_indices: undefined,
run_as: [],
applications: [
{
Expand Down Expand Up @@ -480,6 +480,18 @@ describe('PUT role', () => {
query: `{ "match": { "title": "foo" } }`,
},
],
remote_indices: [
{
field_security: {
grant: ['test-field-security-grant-1', 'test-field-security-grant-2'],
except: ['test-field-security-except-1', 'test-field-security-except-2'],
},
clusters: ['test-cluster-name-1', 'test-cluster-name-2'],
names: ['test-index-name-1', 'test-index-name-2'],
privileges: ['test-index-privilege-1', 'test-index-privilege-2'],
query: `{ "match": { "title": "foo" } }`,
},
],
run_as: ['test-run-as-1', 'test-run-as-2'],
},
kibana: [
Expand Down Expand Up @@ -539,7 +551,18 @@ describe('PUT role', () => {
query: `{ "match": { "title": "foo" } }`,
},
],
remote_indices: [],
remote_indices: [
{
field_security: {
grant: ['test-field-security-grant-1', 'test-field-security-grant-2'],
except: ['test-field-security-except-1', 'test-field-security-except-2'],
},
clusters: ['test-cluster-name-1', 'test-cluster-name-2'],
names: ['test-index-name-1', 'test-index-name-2'],
privileges: ['test-index-privilege-1', 'test-index-privilege-2'],
query: `{ "match": { "title": "foo" } }`,
},
],
metadata: { foo: 'test-metadata' },
run_as: ['test-run-as-1', 'test-run-as-2'],
},
Expand Down Expand Up @@ -661,7 +684,7 @@ describe('PUT role', () => {
query: `{ "match": { "title": "foo" } }`,
},
],
remote_indices: [],
remote_indices: undefined,
metadata: { foo: 'test-metadata' },
run_as: ['test-run-as-1', 'test-run-as-2'],
},
Expand Down Expand Up @@ -765,7 +788,7 @@ describe('PUT role', () => {
privileges: ['test-index-privilege-1', 'test-index-privilege-2'],
},
],
remote_indices: [],
remote_indices: undefined,
metadata: { foo: 'test-metadata' },
run_as: ['test-run-as-1', 'test-run-as-2'],
},
Expand Down Expand Up @@ -803,7 +826,7 @@ describe('PUT role', () => {
body: {
cluster: [],
indices: [],
remote_indices: [],
remote_indices: undefined,
run_as: [],
applications: [
{
Expand Down Expand Up @@ -848,7 +871,7 @@ describe('PUT role', () => {
body: {
cluster: [],
indices: [],
remote_indices: [],
remote_indices: undefined,
run_as: [],
applications: [
{
Expand Down Expand Up @@ -893,7 +916,7 @@ describe('PUT role', () => {
body: {
cluster: [],
indices: [],
remote_indices: [],
remote_indices: undefined,
run_as: [],
applications: [
{
Expand Down

0 comments on commit de0498d

Please sign in to comment.