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

[Fleet] Allow readonly user to access /agent_policies_spaces API #203434

Merged
merged 5 commits into from
Dec 10, 2024
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
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/routes/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
path: APP_API_ROUTES.AGENT_POLICIES_SPACES,
access: 'internal',
fleetAuthz: {
fleet: { allAgentPolicies: true },
fleet: { readAgentPolicies: true },
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default function (providerContext: FtrProviderContext) {
username: testUsers.fleet_all_int_all.username,
password: testUsers.fleet_all_int_all.password,
});
const apiClientReadOnly = new SpaceTestApiClient(supertestWithoutAuth, {
username: testUsers.fleet_read_only.username,
password: testUsers.fleet_read_only.password,
});

let defaultSpacePolicy1: CreateAgentPolicyResponse;
let spaceTest1Policy1: CreateAgentPolicyResponse;
Expand Down Expand Up @@ -113,5 +117,19 @@ export default function (providerContext: FtrProviderContext) {
expect(res.item.id).to.eql(`${TEST_SPACE_1}-fleet-server-policy`);
});
});

describe('GET /agent_policies_spaces', () => {
it('should return all spaces user can write agent policies to', async () => {
const res = await apiClient.getAgentPoliciesSpaces();

expect(res.items.map(({ id }: { id: string }) => id)).to.eql(['default', 'test1']);
});

it('should return no spaces for user with readonly access', async () => {
const res = await apiClientReadOnly.getAgentPoliciesSpaces();

expect(res.items.map(({ id }: { id: string }) => id)).to.eql([]);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ export class SpaceTestApiClient {

return res;
}

async getAgentPoliciesSpaces(spaceId?: string) {
const { body: res } = await this.supertest
.get(`${this.getBaseUrl(spaceId)}/internal/fleet/agent_policies_spaces`)
.auth(this.auth.username, this.auth.password)
.set('kbn-xsrf', 'xxxx')
.set('elastic-api-version', '1')
.expect(200);

return res;
}

// Enrollment API Keys
async getEnrollmentApiKey(
keyId: string,
Expand Down
Loading