1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
Commit Graph

1070 Commits

Author SHA1 Message Date
Christopher Kolstad
3acb116ab2
feat: Separate api token roles (#4019)
## What
As part of the move to enable custom-root-roles, our permissions model
was found to not be granular enough to allow service accounts to only be
allowed to create read-only tokens (client, frontend), but not be
allowed to create admin tokens to avoid opening up a path for privilege
escalation.

## How
This PR adds 12 new roles, a CRUD set for each of the three token types
(admin, client, frontend). To access the `/api/admin/api-tokens`
endpoints you will still need the existing permission (CREATE_API_TOKEN,
DELETE_API_TOKEN, READ_API_TOKEN, UPDATE_API_TOKEN). Once this PR has
been merged the token type you're modifying will also be checked, so if
you're trying to create a CLIENT api-token, you will need
`CREATE_API_TOKEN` and `CREATE_CLIENT_API_TOKEN` permissions. If the
user performing the create call does not have these two permissions or
the `ADMIN` permission, the creation will be rejected with a `403 -
FORBIDDEN` status.


### Discussion points
The test suite tests all operations using a token with
operation_CLIENT_API_TOKEN permission and verifies that it fails trying
to do any of the operations against FRONTEND and ADMIN tokens. During
development the operation_FRONTEND_API_TOKEN and
operation_ADMIN_API_TOKEN permission has also been tested in the same
way. I wonder if it's worth it to re-add these tests in order to verify
that the permission checker works for all operations, or if this is
enough. Since we're running them using e2e tests, I've removed them for
now, to avoid hogging too much processing time.
2023-06-20 14:21:14 +02:00
Christopher Kolstad
fa081e9014
task: Make keepalive configurable via an environment variable (#4015)
As requested in
[Linear](https://linear.app/unleash/issue/2-1147/unleash-cloud-make-keepalive-configurable)
this PR makes the serverKeepAliveTimeout configurable via the
SERVER_KEEPALIVE_TIMEOUT environment variable. This was already
configurable when starting Unleash programmatically, but it's nice to
have as an env variable as well
2023-06-20 12:10:05 +02:00
Jaanus Sellin
9c8651879f
fix: filter out usage for export (#4006) 2023-06-19 13:42:55 +03:00
Nuno Góis
eb8f16da8d
feat: roles unification (#3999)
https://linear.app/unleash/issue/2-1137/roles-unification-on-the-ui

Root and project roles should be managed in a similar manner, which
means using the same roles route and tab for both.

Additionally, this includes a big revamp to the project roles to align
them more closely with the modern and standardized custom root roles
that were recently developed. They mostly use the same components.

There are still more things we want to improve and unify, but we've left
some of that out of this PR due to PR size concerns.
2023-06-19 09:41:40 +01:00
David Leek
4cc1505308
feat: add support for turning telemetry off with environment variable (#3987)
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

Adds an environment variable for switching off feature telemetry in
version check
2023-06-15 15:11:58 +02:00
Jaanus Sellin
6986534ed8
fix: fix sort order for environments (#3992) 2023-06-15 13:27:15 +03:00
andreas-unleash
650f6cc857
feat: Advanced playground table (#3978)
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
Implements the Advanced Playground Table

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #
[1-1007](https://linear.app/unleash/issue/1-1007/env-aware-results-table)

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


![Screenshot 2023-06-14 at 15 04
08](https://github.com/Unleash/unleash/assets/104830839/2f76d6f5-f92b-4586-bb4b-265f26eeb836)

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
2023-06-15 09:29:31 +00:00
Jaanus Sellin
a066d7888d
feat: add max order to environments (#3988)
Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com>
2023-06-15 12:21:35 +03:00
Thomas Heartman
2be143a64e
docs: mark 'yes' and no as required, add more details to variants (#3984)
This change adds a little more detail to the client metrics schema. The
description for variants felt a
little unclear.

---------

Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
2023-06-15 07:14:17 +00:00
Nuno Góis
bb026c0ba1
feat: custom root roles (#3975)
## About the changes
Implements custom root roles, encompassing a lot of different areas of
the project, and slightly refactoring the current roles logic. It
includes quite a clean up.

This feature itself is behind a flag: `customRootRoles`

This feature covers root roles in:
 - Users;
 - Service Accounts;
 - Groups;

Apologies in advance. I may have gotten a bit carried away 🙈 

### Roles

We now have a new admin tab called "Roles" where we can see all root
roles and manage custom ones. We are not allowed to edit or remove
*predefined* roles.

![image](https://github.com/Unleash/unleash/assets/14320932/1ad8695c-8c3f-440d-ac32-39746720d588)
This meant slightly pushing away the existing roles to `project-roles`
instead. One idea we want to explore in the future is to unify both
types of roles in the UI instead of having 2 separate tabs. This
includes modernizing project roles to fit more into our current design
and decisions.

Hovering the permissions cell expands detailed information about the
role:

![image](https://github.com/Unleash/unleash/assets/14320932/81c4aae7-8b4d-4cb4-92d1-8f1bc3ef1f2a)

### Create and edit role

Here's how the role form looks like (create / edit):

![image](https://github.com/Unleash/unleash/assets/14320932/85baec29-bb10-48c5-a207-b3e9a8de838a)
Here I categorized permissions so it's easier to visualize and manage
from a UX perspective.

I'm using the same endpoint as before. I tried to unify the logic and
get rid of the `projectRole` specific hooks. What distinguishes custom
root roles from custom project roles is the extra `root-custom` type we
see on the payload. By default we assume `custom` (custom project role)
instead, which should help in terms of backwards compatibility.

### Delete role

When we delete a custom role we try to help the end user make an
informed decision by listing all the entities which currently use this
custom root role:

![image](https://github.com/Unleash/unleash/assets/14320932/352ed529-76be-47a8-88da-5e924fb191d4)
~~As mentioned in the screenshot, when deleting a custom role, we demote
all entities associated with it to the predefined `Viewer` role.~~
**EDIT**: Apparently we currently block this from the API
(access-service deleteRole) with a message:

![image](https://github.com/Unleash/unleash/assets/14320932/82a8e50f-8dc5-4c18-a2ba-54e2ae91b91c)
What should the correct behavior be?

### Role selector

I added a new easy-to-use role selector component that is present in:
 - Users 

![image](https://github.com/Unleash/unleash/assets/14320932/76953139-7fb6-437e-b3fa-ace1d9187674)
 - Service Accounts

![image](https://github.com/Unleash/unleash/assets/14320932/2b80bd55-9abb-4883-b715-15650ae752ea)
- Groups

![image](https://github.com/Unleash/unleash/assets/14320932/ab438f7c-2245-4779-b157-2da1689fe402)

### Role description

I also added a new role description component that you can see below the
dropdown in the selector component, but it's also used to better
describe each role in the respective tables:

![image](https://github.com/Unleash/unleash/assets/14320932/a3eecac1-2a34-4500-a68c-e3f62ebfa782)

I'm not listing all the permissions of predefined roles. Those simply
show the description in the tooltip:

![image](https://github.com/Unleash/unleash/assets/14320932/7e5b2948-45f0-4472-8311-bf533409ba6c)

### Role badge

Groups is a bit different, since it uses a list of cards, so I added yet
another component - Role badge:

![image](https://github.com/Unleash/unleash/assets/14320932/1d62c3db-072a-4c97-b86f-1d8ebdd3523e)

I'm using this same component on the profile tab:

![image](https://github.com/Unleash/unleash/assets/14320932/214272db-a828-444e-8846-4f39b9456bc6)

## Discussion points
- Are we being defensive enough with the use of the flag? Should we
cover more?
 - Are we breaking backwards compatibility in any way?
 - What should we do when removing a role? Block or demote?
- Maybe some existing permission-related issues will surface with this
change: Are we being specific enough with our permissions? A lot of
places are simply checking for `ADMIN`;
- We may want to get rid of the API roles coupling we have with the
users and SAs and instead use the new hooks (e.g. `useRoles`)
explicitly;
 - We should update the docs;
- Maybe we could allow the user to add a custom role directly from the
role selector component;

---------

Co-authored-by: Gastón Fournier <gaston@getunleash.io>
2023-06-14 14:40:40 +01:00
Christopher Kolstad
b8da1ce2a9
docs: OpenAPI Client tag (#3979)
### What
Adds documentation for open api endpoints tagged with `Client`.

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2023-06-14 12:19:00 +00:00
Mateusz Kwasniewski
6ae4fe2085
test: meta schema rules should not check description on ref (#3980) 2023-06-14 12:29:09 +02:00
Mateusz Kwasniewski
8bddbd80f6
feat: advanced playground openapi (#3972) 2023-06-14 11:05:08 +02:00
Mateusz Kwasniewski
edd67f7046
test: advanced playground (#3968) 2023-06-14 08:23:36 +02:00
Gastón Fournier
30b16bef84
chore: set unleash version to be either the enterprise version or OSS (#3974)
## About the changes
Unleash version should be the one best representing its runtime. In this
regard, enterpriseVersion trumps unleash-server version.

This version is the one that's sent as part of our metrics.
2023-06-13 19:39:49 +02:00
David Leek
98d315e062
feat: add instance stats to version check (#3835)
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

Adds feature usage info and custom strategy counters to the version
check object.

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->
2023-06-13 15:54:20 +02:00
Christopher Kolstad
5f3e5729b9
docs: Instance admin (#3961)
### What
Adds the documentation for the instance admin endpoints.

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2023-06-13 12:10:21 +00:00
Mateusz Kwasniewski
555f77463d
feat: draft branch playground evaluation (#3967) 2023-06-13 13:56:26 +02:00
Mateusz Kwasniewski
7d69750f3b
refactor: Extract playground steps (#3966) 2023-06-13 11:26:10 +02:00
Mateusz Kwasniewski
32ae15741c
refactor: read project ids in memory (#3965) 2023-06-13 10:12:14 +02:00
Gastón Fournier
818b8e7813
fix: feature not found in project yields 404 (#3958)
## About the changes
When a feature is not found in a project we should fail with a NotFound
error. If the feature belongs to a different project, it should not be a
permission issue, because the user might not be aware (lack of
permissions/visibility) of that other project, so even in this case the
error should be NotFound (this also works if we ever allow the same
feature name in different projects)

Fixes #3726

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2023-06-12 15:07:18 +02:00
Christopher Kolstad
7003351b35
docs: Health check endpoint (#3959)
### What
Adds documentation for the health check endpoint.

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2023-06-12 12:56:45 +00:00
Mateusz Kwasniewski
7b8b6bceaf
feat: walking skeleton of the advanced playground (#3949) 2023-06-12 11:01:52 +02:00
Gastón Fournier
4e0678dfb1
fix: allow empty appName as it may come in the url (#3953)
## About the changes
Edit application under
https://app.unleash-hosted.com/demo/applications/test-app is currently
not working as the appName is expected to come in the request body, but
it's actually part of the url. We have two options here:
1. We change the UI to adapt to the expectations of the request by
adding appName to the request body (and eventually removing appName from
the URL, which would be a breaking change)
2. We remove the restriction of only sending the appName in the body and
take the one that comes in the URL. We have a validation that verifies
that at least one of the two sets the appName
([here](e376088668/src/lib/services/client-metrics/instance-service.ts (L208))
we validate using [this
schema](e376088668/src/lib/services/client-metrics/schema.ts (L55-L70)))

In terms of REST API, we can assume that the appName will be present in
the resource `/api/admin/metrics/applications` (an endpoint we don't
have), but when we're updating an application we should refer to that
application by its URL: `/api/admin/metrics/applications/<appName>` and
the presence of an appName in the body might indicate that we're trying
to change the name of the application (something we currently not
support)

Based on the above, I believe going with the second option is best, as
it adheres to REST principles and does not require a breaking change.
Despite that, we only support updating applications as the creation is
done from metrics ingestion

Fixes: #3580
2023-06-12 10:15:00 +02:00
Jaanus Sellin
9f0d94287e
feat: context field usage frontend (#3938) 2023-06-12 10:55:58 +03:00
Ivar Conradi Østhus
1bc130b7f0
fix: add createdAt in projects API response (#3929)
This PR adds the "createdAt" field to the /api/projects response, so
that we are compliant with the schema.
2023-06-09 14:18:38 +00:00
Jaanus Sellin
ea21c753bd
fix: fix variant metrics (#3947) 2023-06-09 12:48:32 +00:00
Mateusz Kwasniewski
0101491a83
refactor: playground in feature oriented architecture (#3942) 2023-06-09 12:55:54 +02:00
Jaanus Sellin
ec6e4d70b5
feat: context field usage backend (#3921) 2023-06-09 12:00:17 +03:00
Thomas Heartman
51d73f67a3
fix: propagate http-errors as they are (#3922)
This PR aims to handle the increased log alarm volume seen by the SREs.

It appears that we get a large number of alarms because a client
disconnects early from the front-end API. These errors are then
converted into 500s because of missing handling. These errors appear to
be caused by the `http-errors` library in a dependency.

We also introduced a log line whenever we see errors now a while back,
and I don't think we need this logging (I was also the one who
introduced it).

The changes in this PR are specifically:
- When converting from arbitrary errors, give `BadRequestError` a 400
status code, not a 500.
- Add a dependency on `http-errors` (which is already a transitive
dependency because of the body parser) and use that to check whether an
error is an http-error.
- If an error is an http error, then propagate it to the user with the
status code and message.
- Remove warning logs when an error occurs. This was introduced to make
it easier to correlate an API error and the logs, but the system hasn't
been set up for that (yet?), so it's just noise now.
- When logging errors as errors, only do that if their status code would
be 500.
2023-06-08 13:14:53 +02:00
Mateusz Kwasniewski
3d344509a8
feat: generate object combinations (#3920) 2023-06-07 15:51:44 +00:00
Thomas Heartman
03dd7b6863
chore: clarify error logs (#3915)
This change makes the logs that happen when we encounter an error a
little bit clearer. It logs the error message before the error ID and
also logs the full serialized message just in case.
2023-06-07 12:11:34 +00:00
Thomas Heartman
24aea5f00e
chore: improve joi errors (#3836)
This PR improves our handling of internal Joi errors, to make them more
sensible to the end user. It does that by providing a better description
of the errors and by telling the user what they value they provided was.

Previous conversion:
```json
{
  "id": "705a8dc0-1198-4894-9015-f1e5b9992b48",
  "name": "BadDataError",
  "message": "\"value\" must contain at least 1 items",
  "details": [
    {
      "message": "\"value\" must contain at least 1 items",
      "description": "\"value\" must contain at least 1 items"
    }
  ]
}
```

New conversion:
```json
{
  "id": "87fb4715-cbdd-48bb-b4d7-d354e7d97380",
  "name": "BadDataError",
  "message": "Request validation failed: your request body contains invalid data. Refer to the `details` list for more information.",
  "details": [
    {
      "description": "\"value\" must contain at least 1 items. You provided [].",
      "message": "\"value\" must contain at least 1 items. You provided []."
    }
  ]
}
```

## Restructuring

This PR moves some code out of `unleash-error.ts` and into a new file.
The purpose of this is twofold:
1. avoid circular dependencies (we need imports from both UnleashError
and BadDataError)
2. carve out a clearer separation of concerns, keeping `unleash-error` a
little more focused.
2023-06-07 08:29:36 +00:00
Thomas Heartman
08834a7250
chore: lower log-level for unexpected errors (#3837)
This change lowers the log level from warning to debug for when we see
unexpected error types.

Right now this triggers for Joi errors, which we still rely on pretty
heavily. Lowering this should clear up logs for most users.
2023-06-07 09:37:40 +02:00
Jaanus Sellin
0efaa346c4
feat: usage on context fields in list (#3906) 2023-06-06 13:59:41 +03:00
Mateusz Kwasniewski
5ec59c6e92
feat: change own password confirmation (#3894) 2023-06-05 11:58:25 +02:00
Mateusz Kwasniewski
b0a003ea58
feat: disable notifications flag (#3874) 2023-05-29 08:28:47 +02:00
Mateusz Kwasniewski
5534e4deeb
fix: remove consecutive slashes (#3882)
A small middleware who will rewrite potential dual slashes to a single slash.
2023-05-27 16:16:51 +00:00
Christopher Kolstad
52904ee038
fix: reject unauthorized client requests (#3881)
If apiTokens are enabled breaks middleware chain with a 401 if no token
is found for requests to client and frontend apis. Previously the
middleware allowed the chain to process.

Removes the regex search for multiple slashes, and instead configures
the apiTokenMiddleware to reject unauthorized requests.
2023-05-27 16:29:54 +02:00
Christopher Kolstad
3d872cf7a2
security: Reject multiple successive slashes in path (#3880) 2023-05-27 14:31:44 +02:00
Jaanus Sellin
f73d36fda3
feat: add usage of segment in list (#3853) 2023-05-26 14:37:00 +03:00
Ivar Conradi Østhus
49722d5c48
fix: use correct event type for maxRevisionId (#3870)
We had a small typo where we looked for `segment-update` event instead
of `segment-updated`. Changed to use the event constant.
2023-05-25 23:00:08 +02:00
Christopher Kolstad
3409b0c5a0
task: Add Unit test result check task (#3695)
After a Team Retro, one of our squads felt like we needed more data on
our test suites. This is the first effort to make our test results
easier to grab. It uses the test-reporter action to add a github check
to our main build and PR builds with our test results.

This at least should make it easier to parse which tests are failing.
However, it does not give us trends. So it does not yet make it easier
to decide which tests are flaky just from a quick view.

---------

Co-authored-by: Gastón Fournier <gaston@getunleash.io>
2023-05-25 11:03:54 +00:00
Mateusz Kwasniewski
78715e3374
docs: maintanance mode impact (#3858) 2023-05-25 08:28:05 +02:00
Mateusz Kwasniewski
5ac575389e
feat: maintenance mode disables scheduler (#3854) 2023-05-24 12:26:54 +02:00
Nuno Góis
ab4ff29407
fix: hide password login when it's disabled (#3851)
https://linear.app/unleash/issue/2-1085/bug-password-based-login-still-shows-on-the-login-page-even-if

Fixes a regression introduced with the changes related with #3633 where
we still show the password login even though it's disabled.

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.io>
2023-05-24 09:39:24 +01:00
Nuno Góis
c0bcc50b28
fix: add confirmation to disable password login (#3829)
https://linear.app/unleash/issue/2-1071/prevent-users-from-disabling-password-authentication-when-there-are-no

Improves the behavior of disabling password based login by adding some
relevant information and a confirmation dialog with a warning. This felt
better than trying to disable the toggle, by still allowing the end
users to make the decision, except now it should be a properly informed
decision with confirmation.


![image](https://github.com/Unleash/unleash/assets/14320932/2ca754d8-cfa2-4fda-984d-0c34b89750f3)

- **Password based administrators**: Admin accounts that have a password
set;
- **Other administrators**: Other admin users that do not have a
password. May be SSO, but may also be users that did not set a password
yet;
- **Admin service accounts**: Service accounts that have the admin root
role. Depending on how you're using the SA this may not necessarily mean
locking yourself out of an admin account, especially if you secured its
token beforehand;
- **Admin API tokens**: Similar to the above. If you secured an admin
API token beforehand, you still have access to all features through the
API;

Each one of them link to the respective page inside Unleash (e.g. users
page, service accounts page, tokens page...);

If you try to disable and press "save", and only in that scenario, you
are presented with the following confirmation dialog:


![image](https://github.com/Unleash/unleash/assets/14320932/5ad6d105-ad47-4d31-a1df-04737aed4e00)
2023-05-23 15:56:34 +01:00
Mateusz Kwasniewski
1dba9d092b
fix: move application logic to service (#3846) 2023-05-23 16:41:52 +02:00
Mateusz Kwasniewski
840ca275cf
feat: disable bulk update env var (#3828) 2023-05-22 13:12:45 +00:00
Mateusz Kwasniewski
e34c9bc0bf
feat: disable bulk toggles flag (#3827) 2023-05-22 13:31:31 +02:00