Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unable to create roles under Stack Management #156381

Merged
merged 5 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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