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

Feat - RBAC Implementation and Non-OSS Feature Removal #1236

Merged
merged 114 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
e049ba3
Add models for RBAC
devgenix Jan 11, 2024
d3efdf4
Add Workspace to Database Engine
devgenix Jan 12, 2024
a92cdce
Set description to be optional
devgenix Jan 12, 2024
c706346
Define CreateOrganization
devgenix Jan 12, 2024
0a0b6e0
Create pydantic basemodel for Workspace
devgenix Jan 12, 2024
f990e6b
Feat: create workspace
devgenix Jan 12, 2024
7de5b35
Add new permissions and method to check for role access
devgenix Jan 12, 2024
a978d3f
include user id in get_user_and_org_id
devgenix Jan 12, 2024
fb514ce
define fine-grained rbac function check
devgenix Jan 12, 2024
b755b01
Add Workspace when creating dm_manager objects
devgenix Jan 12, 2024
3bd8c71
define function to get workspace and organization id
devgenix Jan 12, 2024
0de3b88
add methods to get member roles and permissions
devgenix Jan 14, 2024
4f1c7ac
Add workspace
devgenix Jan 14, 2024
3ef2fb7
Define Workspace Pydantic Models
devgenix Jan 14, 2024
a680b01
define get organization default workspace
devgenix Jan 14, 2024
53ff76e
add workspace to evaluations
devgenix Jan 14, 2024
23f49e1
define check_user_workspace_access
devgenix Jan 14, 2024
545ee3c
Define RBAC Permission for App Router
devgenix Jan 14, 2024
c131e52
format
devgenix Jan 14, 2024
557bf10
fix bugs with creating an app from workspace assignment
devgenix Jan 14, 2024
be72158
register models for both oss and cloud
devgenix Jan 18, 2024
f211f95
Feat [ draft ]: remove Organization features, refactor and conditiona…
devgenix Jan 18, 2024
145ab68
Feat: complete refactoring of moving cloud features and adding rbac
devgenix Jan 19, 2024
fc1d712
Improvements and fix bugs with refactor
devgenix Jan 19, 2024
6b81444
Merge branch 'main' into oss/rbac
devgenix Jan 19, 2024
6748ee0
import converters
devgenix Jan 19, 2024
d9579fa
import db_manager from source
devgenix Jan 19, 2024
a94ade6
Merge branch 'oss/rbac' of https://github.com/Agenta-AI/agenta into o…
devgenix Jan 19, 2024
4075294
fix imports
devgenix Jan 19, 2024
62b41fc
fix circular imports
devgenix Jan 19, 2024
d115137
update docstring
devgenix Jan 19, 2024
3215d40
fix bugs with imports and naming
devgenix Jan 22, 2024
49a3f81
merge
devgenix Jan 22, 2024
2203990
Change Output to Response in api Models
devgenix Jan 23, 2024
d85ea2c
Ran format
devgenix Jan 23, 2024
2add1fc
Merge branch 'main' into oss/rbac
devgenix Jan 23, 2024
51a5476
fix feature flag mispelling
devgenix Jan 23, 2024
9f3569b
Merge branch 'oss/rbac' of https://github.com/agenta-ai/agenta into o…
devgenix Jan 23, 2024
4372df8
fix closing square bracket
devgenix Jan 23, 2024
01d6dbb
fix closing square brackets
devgenix Jan 23, 2024
a2369e2
cleanup
devgenix Jan 23, 2024
22427ca
rbac improvements
devgenix Jan 23, 2024
d1e51b9
bug fixes and removed org id from everywhere
MohammedMaaz Jan 24, 2024
495ede5
Fix for non-org use in oss
devgenix Jan 24, 2024
da862e2
format black
devgenix Jan 24, 2024
b209a90
fix bugs
devgenix Jan 25, 2024
44c9a97
add org & workspace in cloud
devgenix Jan 25, 2024
2c27771
Refactor tests in line with RBAC: remove organizations
devgenix Jan 25, 2024
c35864d
permission denied modal and minor fixes
MohammedMaaz Jan 25, 2024
c424049
set rbac error status code to 403
devgenix Jan 25, 2024
33a9727
Merge branch 'oss/rbac' of https://github.com/agenta-ai/agenta into HEAD
devgenix Jan 25, 2024
b72261e
apps fetching separation for cloud and oss
MohammedMaaz Jan 25, 2024
a011fb7
fix delete testet permission
devgenix Jan 25, 2024
5aca614
dynamic modules | pass org id when creating app
MohammedMaaz Jan 30, 2024
b571730
Merge branch 'oss/rbac' of https://github.com/Agenta-AI/agenta into o…
MohammedMaaz Jan 30, 2024
8626664
require workspace and org id when creation app from template in cloud
devgenix Jan 30, 2024
73ba802
pass workspace_id when creating an app
MohammedMaaz Jan 30, 2024
d515f51
merge oss/rbac_migrations
devgenix Jan 30, 2024
9cec946
cleanup
devgenix Jan 30, 2024
b0b5968
refactor use of Feature Flag
devgenix Jan 30, 2024
515e85f
remove session
devgenix Jan 30, 2024
9de7346
fix paranthesis
devgenix Jan 30, 2024
530d978
fixed fe comflicts
MohammedMaaz Jan 30, 2024
ab23ee3
remove paranthesis for imports
devgenix Jan 30, 2024
4e8abff
Merge branch 'main' of https://github.com/Agenta-AI/agenta into oss/r…
MohammedMaaz Jan 30, 2024
251d2a9
rename rbac migration folder
devgenix Jan 30, 2024
9d1a281
remove oss/cloud folder
devgenix Jan 30, 2024
8d93ab4
merge main & resolve merge conflicts
devgenix Jan 30, 2024
7408275
update migration with current db schema
devgenix Jan 30, 2024
4a87164
refactor from merge: use object in check_action_access and
devgenix Jan 30, 2024
740a5d2
Feat: complete merge and fix merge bugs
devgenix Jan 31, 2024
6512a5c
rename migration folder
devgenix Jan 31, 2024
713bd1c
fix bugs and format
devgenix Jan 31, 2024
f7b23c4
[draft]: fix tests failing
devgenix Jan 31, 2024
24f5408
add new field from prompt_versioning
devgenix Jan 31, 2024
dd37d98
fixed import issues for dynamicComponent
MohammedMaaz Jan 31, 2024
70266b6
Add mongo_express to docker test compose file
devgenix Jan 31, 2024
730af41
Merge branch 'main' into oss/rbac
devgenix Jan 31, 2024
0c05e7b
import re to fix failing tests
devgenix Jan 31, 2024
e4d9e30
format black
devgenix Jan 31, 2024
6ea2806
format after upgrading pip
devgenix Jan 31, 2024
f0ce13d
Allow none for variant revision
devgenix Jan 31, 2024
aa8f8dc
removed session commit
devgenix Jan 31, 2024
261a121
Refactor - remove redundant code in modes_revamp in oss rbac migratio…
aybruhm Feb 3, 2024
6b5a81b
Merge branch 'main' into oss/rbac
aybruhm Feb 3, 2024
147db53
Merge branch 'main' into oss/rbac
aybruhm Feb 3, 2024
b9f9f12
fix removing app
aakrem Feb 6, 2024
380ca57
Update - resolve 500 error in getting app container_url
aybruhm Feb 6, 2024
1d58daa
Merge branch 'main' into oss/rbac
aybruhm Feb 6, 2024
8bd3767
Update - resolve breaking endpoint page in agenta web
aybruhm Feb 6, 2024
26dba6a
Update - fix failing deploy endpoint and update deploy_to_environment…
aybruhm Feb 6, 2024
0b4f8b8
Refactor - modified construct_app_container_url endpoint
aybruhm Feb 6, 2024
281dccc
Update - resolve failing endpoints in human evaluation router
aybruhm Feb 6, 2024
79f62b2
:art: Format - ran black
aybruhm Feb 6, 2024
a086de4
:art: Format - ran prettier
aybruhm Feb 6, 2024
6fb5b78
Update - remove redundant testcases for deployment versioning in oss
aybruhm Feb 6, 2024
488f62c
Update - change database mode to test
aybruhm Feb 6, 2024
41bd10a
Update - added environment output to app router and converters base o…
aybruhm Feb 7, 2024
6782e30
Update - allow workspace members with DELETE_EVALUATION permission to…
aybruhm Feb 8, 2024
10fb341
Update - added permission check to ensure only users with the right r…
aybruhm Feb 9, 2024
0219468
Update - added logic to check apikey action access for rbac
aybruhm Feb 11, 2024
7382580
Update - fix unbound error
aybruhm Feb 11, 2024
b0f06a6
Update - added logic to allow organization selection for cloud
aybruhm Feb 11, 2024
886be34
fixed double loading issue on apps page | fixed missing workspace_id …
MohammedMaaz Feb 12, 2024
754168f
Refactor - update list_apps router
aybruhm Feb 12, 2024
e9dedca
fixes | single role selection
MohammedMaaz Feb 12, 2024
df19dc7
Update - change permission from view_application to read_system
aybruhm Feb 12, 2024
25e10f6
Refactor - remove redundant rbac check
aybruhm Feb 12, 2024
efc22ff
Update - make use of right status code (403)
aybruhm Feb 12, 2024
7f002a9
Merged 'main' into 'oss/rbac' branch
aybruhm Feb 12, 2024
5331ddc
:art: Format - ran black
aybruhm Feb 12, 2024
b7eabcb
Refactor - remove redundant selectedOrg
aybruhm Feb 12, 2024
3fbcbf0
hardcode black version
aakrem Feb 13, 2024
494769b
format web
aakrem Feb 13, 2024
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ agenta-web/cypress/screenshots/
agenta-web/cypress/videos/
.nextjs_cache/

rabbitmq_data
rabbitmq_data

# docker compose override
docker-compose.*override.yaml
4 changes: 0 additions & 4 deletions agenta-backend/agenta_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
human_evaluation_router,
evaluators_router,
observability_router,
organization_router,
testset_router,
user_profile,
variants_router,
Expand Down Expand Up @@ -102,9 +101,6 @@ async def lifespan(application: FastAPI, cache=True):
app.include_router(
observability_router.router, prefix="/observability", tags=["Observability"]
)
app.include_router(
organization_router.router, prefix="/organizations", tags=["Organizations"]
)
app.include_router(bases_router.router, prefix="/bases", tags=["Bases"])
app.include_router(configs_router.router, prefix="/configs", tags=["Configs"])

Expand Down
24 changes: 1 addition & 23 deletions agenta-backend/agenta_backend/models/api/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class VariantAction(BaseModel):

class CreateApp(BaseModel):
app_name: str
organization_id: Optional[str] = None


class CreateAppOutput(BaseModel):
Expand All @@ -57,7 +56,6 @@ class AppVariant(BaseModel):
variant_name: str
parameters: Optional[Dict[str, Any]]
previous_variant_name: Optional[str]
organization_id: Optional[str] = None
base_name: Optional[str]
config_name: Optional[str]

Expand All @@ -66,14 +64,13 @@ class AppVariantFromImagePayload(BaseModel):
variant_name: str


class AppVariantOutput(BaseModel):
class AppVariantResponse(BaseModel):
app_id: str
app_name: str
variant_id: str
variant_name: str
parameters: Optional[Dict[str, Any]]
previous_variant_name: Optional[str]
organization_id: str
user_id: str
base_name: str
base_id: str
Expand Down Expand Up @@ -106,7 +103,6 @@ class AppVariantFromImage(BaseModel):
variant_name: str
parameters: Optional[Dict[str, Any]]
previous_variant_name: Optional[str]
organization_id: Optional[str] = None


class RestartAppContainer(BaseModel):
Expand All @@ -117,7 +113,6 @@ class Image(BaseModel):
type: Optional[str]
docker_id: str
tags: str
organization_id: Optional[str] = None


class AddVariantFromImagePayload(BaseModel):
Expand Down Expand Up @@ -170,23 +165,13 @@ class CreateAppVariant(BaseModel):
app_name: str
template_id: str
env_vars: Dict[str, str]
organization_id: Optional[str] = None


class InviteRequest(BaseModel):
email: str


class InviteToken(BaseModel):
token: str


class Environment(BaseModel):
name: str
deployed_app_variant: Optional[str]
deployed_base_name: Optional[str]
deployed_config_name: Optional[str]
organization_id: Optional[str] = None


class DeployToEnvironmentPayload(BaseModel):
Expand All @@ -210,13 +195,6 @@ class PostVariantConfigPayload(BaseModel):
overwrite: bool


class ListAPIKeysOutput(BaseModel):
prefix: str
created_at: datetime
last_used_at: datetime = None
expiration_date: datetime = None


class BaseOutput(BaseModel):
base_id: str
base_name: str
29 changes: 0 additions & 29 deletions agenta-backend/agenta_backend/models/api/organization_models.py

This file was deleted.

130 changes: 87 additions & 43 deletions agenta-backend/agenta_backend/models/converters.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,86 @@
"""Converts db models to pydantic models
"""
import os
import json
import logging
from typing import List
from agenta_backend.services import db_manager
from agenta_backend.models.api.user_models import User
from agenta_backend.models.db_models import (
AppVariantDB,
EvaluationScenarioResult,
EvaluatorConfigDB,
HumanEvaluationDB,
HumanEvaluationScenarioDB,
ImageDB,
TemplateDB,
AppDB,
AppEnvironmentDB,
TestSetDB,
SpanDB,
TraceDB,
Feedback as FeedbackDB,
EvaluationDB,
EvaluationScenarioDB,
VariantBaseDB,
UserDB,
AggregatedResult,
)
from agenta_backend.models.api.api_models import (
AppVariant,
ImageExtended,
Template,
TemplateImageInfo,
AppVariantOutput,
App,
EnvironmentOutput,
TestSetOutput,
BaseOutput,
)

from agenta_backend.models.api.observability_models import (
Span,
Trace,
Feedback as FeedbackOutput,
)
from agenta_backend.models.api.evaluation_model import (
HumanEvaluation,
HumanEvaluationScenario,
SimpleEvaluationOutput,
EvaluationScenario,
Evaluation,
HumanEvaluation,
EvaluatorConfig,
EvaluationScenario,
SimpleEvaluationOutput,
EvaluationScenarioInput,
HumanEvaluationScenario,
EvaluationScenarioOutput,
)

import logging
FEATURE_FLAG = os.environ["FEATURE_FLAG"]
if FEATURE_FLAG in ["cloud", "ee"]:
devgenix marked this conversation as resolved.
Show resolved Hide resolved
from agenta_backend.commons.models.db_models import (
AppDB_ as AppDB,
devgenix marked this conversation as resolved.
Show resolved Hide resolved
UserDB_ as UserDB,
ImageDB_ as ImageDB,
TestSetDB_ as TestSetDB,
EvaluationDB_ as EvaluationDB,
AppVariantDB_ as AppVariantDB,
VariantBaseDB_ as VariantBaseDB,
AppEnvironmentDB_ as AppEnvironmentDB,
EvaluatorConfigDB_ as EvaluatorConfigDB,
HumanEvaluationDB_ as HumanEvaluationDB,
EvaluationScenarioDB_ as EvaluationScenarioDB,
HumanEvaluationScenarioDB_ as HumanEvaluationScenarioDB,
)
from agenta_backend.commons.models.api.api_models import (
AppVariant_ as AppVariant,
ImageExtended_ as ImageExtended,
AppVariantResponse_ as AppVariantResponse,
)
else:
from agenta_backend.models.db_models import (
AppDB,
UserDB,
ImageDB,
TestSetDB,
EvaluationDB,
AppVariantDB,
VariantBaseDB,
AppEnvironmentDB,
EvaluatorConfigDB,
HumanEvaluationDB,
EvaluationScenarioDB,
HumanEvaluationScenarioDB,
)
from agenta_backend.models.api.api_models import (
AppVariant,
ImageExtended,
AppVariantResponse,
)

from agenta_backend.models.db_models import (
SpanDB,
TraceDB,
TemplateDB,
AggregatedResult,
Feedback as FeedbackDB,
EvaluationScenarioResult,
)
from agenta_backend.models.api.api_models import (
App,
Template,
BaseOutput,
TestSetOutput,
TemplateImageInfo,
EnvironmentOutput,
)

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -192,19 +221,24 @@ def evaluation_scenario_db_to_pydantic(
def app_variant_db_to_pydantic(
app_variant_db: AppVariantDB, previous_variant_name: str = None
) -> AppVariant:
return AppVariant(
app_variant = AppVariant(
app_id=str(app_variant_db.app.id),
app_name=app_variant_db.app.app_name,
variant_name=app_variant_db.variant_name,
parameters=app_variant_db.config.parameters,
previous_variant_name=app_variant_db.previous_variant_name,
organization_id=str(app_variant_db.organization.id),
base_name=app_variant_db.base_name,
config_name=app_variant_db.config_name,
)

if FEATURE_FLAG in ["cloud", "ee"]:
app_variant.organization_id = str(app_variant_db.organization.id)
app_variant.workspace_id = str(app_variant_db.workspace.id)

async def app_variant_db_to_output(app_variant_db: AppVariantDB) -> AppVariantOutput:
return app_variant


async def app_variant_db_to_output(app_variant_db: AppVariantDB) -> AppVariantResponse:
if app_variant_db.base.deployment:
deployment = await db_manager.get_deployment_by_objectid(
app_variant_db.base.deployment
Expand All @@ -214,13 +248,12 @@ async def app_variant_db_to_output(app_variant_db: AppVariantDB) -> AppVariantOu
deployment = None
uri = None
logger.info(f"uri: {uri} deployment: {app_variant_db.base.deployment} {deployment}")
return AppVariantOutput(
variant_response = AppVariantResponse(
app_id=str(app_variant_db.app.id),
app_name=str(app_variant_db.app.app_name),
variant_name=app_variant_db.variant_name,
variant_id=str(app_variant_db.id),
user_id=str(app_variant_db.user.id),
organization_id=str(app_variant_db.organization.id),
parameters=app_variant_db.config.parameters,
previous_variant_name=app_variant_db.previous_variant_name,
base_name=app_variant_db.base_name,
Expand All @@ -230,6 +263,12 @@ async def app_variant_db_to_output(app_variant_db: AppVariantDB) -> AppVariantOu
uri=uri,
)

if FEATURE_FLAG in ["cloud", "ee"]:
variant_response.organization_id = str(app_variant_db.organization.id)
variant_response.workspace_id = str(app_variant_db.workspace.id)

return variant_response


async def environment_db_to_output(
environment_db: AppEnvironmentDB,
Expand Down Expand Up @@ -262,13 +301,18 @@ def app_db_to_pydantic(app_db: AppDB) -> App:


def image_db_to_pydantic(image_db: ImageDB) -> ImageExtended:
return ImageExtended(
organization_id=str(image_db.organization.id),
image = ImageExtended(
docker_id=image_db.docker_id,
tags=image_db.tags,
id=str(image_db.id),
)

if FEATURE_FLAG in ["cloud", "ee"]:
image.organization_id = str(image_db.organization.id)
image.workspace_id = str(image_db.workspace.id)

return image


def templates_db_to_pydantic(templates_db: List[TemplateDB]) -> List[Template]:
return [
Expand Down
Loading
Loading