Commit Graph
42 Commits
Author SHA1 Message Date
Hengfei Yang 871f954fe2 feat: add new ENV to set token for root user (#6438) 2025-04-01 12:27:11 +08:00
+2 8cd0683a0b feat: ws v2 (#6404)
# WebSocket v2 Architecture

## NOTE: Open Issues:
- [ ] `session_drain` from server is experimental and not ready for
prod. Instead, the client maintains ongoing `trace_id`'s and when cookie
expires it will retry search for all the ongoing searches.

## Overview
Implements websocket v2 with the main goal to establish `Client-Router`
connections `per tab` and `Router-Querier` `persistent` connections.

## New Env (Default):
```sh
ZO_WEBSOCKET_CHECK_COOKIE_EXPIRY=true
ZO_WEBSOCKET_HEALTH_CHECK_INTERVAL_SECS=60
ZO_WEBSOCKET_IS_SESSION_DRAIN_ENABLED=false # This is experimental, not meant for prod
```

## High-Level Flow

1. Client establishes WebSocket connection with the router.  
2. Router creates a session.  
3. Router maintains persistent connections to all queriers.  
4. Client requests are routed to the appropriate querier using
consistent hashing.
5. Responses are routed back using `trace_id` mappings.  
6. Health checks maintain connection validity.  
7. Failed connections trigger automatic cleanup and reconnection.  
8. **Internal Communication Validation Using:**  
   - **8a.** Internal gRPC tokens  
   - **8b.** IP validation  
   - **8c.** WebSocket upgrade headers  

## Connection Lifecycle
```mermaid
sequenceDiagram
    participant Client
    participant Router
    participant ConnectionPool
    participant QuerierConn
    participant Querier
    participant Cluster

    Client->>Router: WS Connection Request
    Router->>SessionManager: register_client(client_id)
    
    Note over Router,SessionManager: Creates channels:<br/>response_tx/rx<br/>disconnect_tx/rx

    par Handle Incoming Messages
        Router->>Router: spawn handle_incoming task
    and Handle Outgoing Messages
        Router->>Router: spawn handle_outgoing task
    end

    Client->>Router: WS Client Event
    Router->>SessionManager: get_querier_for_trace(trace_id)
    
    alt No Existing Mapping
        Router->>Cluster: get_node_from_consistent_hash(trace_id)
        Router->>ConnectionPool: get_or_create_connection(querier)
        
        alt No Existing Connection
            ConnectionPool->>QuerierConn: create_connection
            QuerierConn->>Querier: WS Connection Request
            
            par Connection Tasks
                QuerierConn->>QuerierConn: spawn listen_to_querier_response
                QuerierConn->>QuerierConn: spawn health_check
            end
            
            Querier-->>QuerierConn: Connection Established
        end
        
        Router->>SessionManager: set_querier_for_trace(trace_id, querier)
    end

    Router->>QuerierConn: register_request(trace_id)
    Router->>QuerierConn: send_message(event)
    Querier-->>QuerierConn: Response
    QuerierConn->>Router: Route Response via response_tx
    Router->>Client: Forward Response

    Note over Router,Client: On Disconnect/Error:<br/>1. Send disconnect signal<br/>2. Clean up sessions<br/>3. Drain if needed
```

## Connections
```mermaid
graph TB
    subgraph "Client Layer"
        UI1[UI Client 1]
        UI2[UI Client 2]
        UI3[UI Client 3]
    end

    subgraph "Router Layer"
        R1[Router 1]
        R2[Router 2]
        
        subgraph "Router 1 Connection Pool"
            CP1[Connection Pool]
            QC11[Querier1 Conn]
            QC12[Querier2 Conn]
            QC13[Querier3 Conn]
            CP1 --- QC11
            CP1 --- QC12
            CP1 --- QC13
        end
        
        subgraph "Router 2 Connection Pool"
            CP2[Connection Pool]
            QC21[Querier1 Conn]
            QC22[Querier2 Conn]
            QC23[Querier3 Conn]
            CP2 --- QC21
            CP2 --- QC22
            CP2 --- QC23
        end
        
        R1 --- CP1
        R2 --- CP2
    end

    subgraph "Querier Layer"
        Q1[Querier 1]
        Q2[Querier 2]
        Q3[Querier 3]
    end

    UI1 -.->|WS| R1
    UI2 -.->|WS| R1
    UI3 -.->|WS| R2

    QC11 ===|Persistent WS| Q1
    QC12 ===|Persistent WS| Q2
    QC13 ===|Persistent WS| Q3
    QC21 ===|Persistent WS| Q1
    QC22 ===|Persistent WS| Q2
    QC23 ===|Persistent WS| Q3

    classDef client fill:#f9f,stroke:#333,stroke-width:2px
    classDef router fill:#bbf,stroke:#333,stroke-width:2px
    classDef querier fill:#bfb,stroke:#333,stroke-width:2px
    classDef pool fill:#ffd,stroke:#333,stroke-width:2px
    
    class UI1,UI2,UI3 client
    class R1,R2 router
    class Q1,Q2,Q3 querier
    class CP1,CP2 pool
```

## Components
```mermaid
classDiagram
    class WsHandler {
        +session_manager: Arc<SessionManager>
        +connection_pool: Arc<QuerierConnectionPool>
        +handle_connection()
        +remove_querier_connection()
        +_shutdown()
    }

    class SessionManager {
        +sessions: RwAHashMap<ClientId, SessionInfo>
        +mapped_queriers: RwAHashMap<QuerierName, HashSet<TraceId>>
        +register_client()
        +update_session_activity()
        +remove_trace_id()
        +unregister_client()
        +set_querier_for_trace()
        +get_querier_for_trace()
    }

    class QuerierConnectionPool {
        +connections: RwAHashMap<QuerierName, Arc<QuerierConnection>>
        +get_or_create_connection()
        +remove_querier_connection()
        +maintain_connections()
        +get_active_connection()
    }

    class QuerierConnection {
        +querier_name: QuerierName
        +write: Arc<Mutex<Option<SplitSink>>>
        +response_router: Arc<ResponseRouter>
        +is_connected: Arc<AtomicBool>
        +connect()
        +disconnect()
        +send_message()
        +register_request()
        +unregister_request()
    }

    class ResponseRouter {
        +routes: RwAHashMap<TraceId, Sender<WsServerEvents>>
        +route_response()
        +flush()
        +spawn_cleanup_task()
    }

    WsHandler --> SessionManager
    WsHandler --> QuerierConnectionPool
    QuerierConnectionPool --> QuerierConnection
    QuerierConnection --> ResponseRouter
```


Related Issues: #6396

---------

Co-authored-by: Taiming Liu <liutaiming3@gmail.com>
Co-authored-by: Hengfei Yang <hengfei.yang@gmail.com>
Co-authored-by: Abhay Padamani <141122205+ktx-abhay@users.noreply.github.com>
Co-authored-by: Ashish Kolhe <35160958+oasisk@users.noreply.github.com>
Co-authored-by: udev <uddhav@openobserve.ai>
Co-authored-by: omkark06 <omkar@zinclabs.io>
Co-authored-by: ktx-abhay <abhay.padamani@kiara.tech>
Co-authored-by: Omkar Kesarkhane <127078473+omkarK06@users.noreply.github.com>
Co-authored-by: udev <uddhavdave1@gmail.com>
Co-authored-by: Subhra264 <chakrabortysubhradeep556@gmail.com>
Co-authored-by: ktx-vaidehi <134508096+ktx-vaidehi@users.noreply.github.com>
2025-03-26 11:43:40 -07:00
Subhra264 caf798e5c2 fix: Alert folder rbac migration issues (#6338) 2025-03-20 11:48:47 +05:30
Hengfei Yang 595490ea33 ci: update rust to nightly-2025-03-02 (#6145) 2025-03-02 17:27:10 +08:00
Patrick Sullivan 0111124a15 refactor: Split openfga and dex modules into their own crates (#5876)
Note: This PR has an [accompanying
PR](https://github.com/openobserve/o2-enterprise/pull/331) in the
enterprise repo

This splits the `openfga` and `dex` modules into their own crates,
`o2_openfga` and `o2_dex`.

**Why?** 
We want to be able to reference the `o2_enterprise::openfga` module from
within the `infra::table` module so that we can perform OpenFGA data
migrations as part of data transformation migrations in the
`openobserve` app. However, the `o2_enterprise` module references the
`infra::table` module in various places (eg: inside
`o2_enterprise::enterprise::actions::action_manager`). Therefore we
cannot reference `o2_enterprise::enterprise::openfga` from
`infra::table` without introducing a circular dependency.

The solution presented by this PR is to move the `openfga` module into
its own crate, so that `infra::table` can reference the new create
without creating a circular dependency. As part of this PR we also move
the `dex` module into its own crate since the `openfga` module depends
on the `dex` module, and we do not want the new `o2_openfga` crate to
depend on the `o2_enterprise` crate.

![Captura de pantalla 2025-02-04 a la(s) 3 53 42 p
m](https://github.com/user-attachments/assets/bb2b748c-e40c-470f-a295-90087f4ed989)

![Captura de pantalla 2025-02-04 a la(s) 3 51 14 p
m](https://github.com/user-attachments/assets/3237aa75-fc31-4821-bf80-3ec83e9c39bc)
2025-02-06 08:35:18 -06:00
Hengfei Yang 2c7f4dff53 fix: aws ingestion (#5660) 2025-01-10 18:53:44 +08:00
Hengfei Yanganddomyway 39c44de0e5 fix: debug the RUM deadlock (#5558)
for debug the #5398

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **Configuration**
  - Added new configuration option to disable keep-alive connections
  - Adjusted HTTP server connection timeout settings

- **Authentication**
  - Enhanced token validation with improved traceability
- Updated authentication methods to support more detailed request
tracking

- **Performance**
  - Optimized client lock management in MaxMind database downloader
  - Refined request handling in RUM ingestion APIs

- **Logging**
  - Improved logging for authentication and request processing
  - Added trace ID support for better request tracking
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: domyway <weizhao029@gmail.com>
2025-01-06 10:58:08 +08:00
Ashish Kolhe fb0241a368 feat: introduce root only login (#5505)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
	- Enhanced enterprise-level access control for user authentication.
- Added stricter login requirements for non-root users when
`root_only_login` is enabled.

- **Bug Fixes**
- Improved authentication validation process to prevent unauthorized
access.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-12-31 10:09:37 +05:30
0c728df972 feat: service accounts for api access (#5212)
This PR introduces the service accounts with tokens

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced a new module for managing service accounts, including
functionalities for listing, creating, updating, and deleting service
accounts.
- Added a new tab for "Service Accounts" in the Identity Access
Management interface.
- Enhanced user management interfaces to support service account
operations, including the ability to add and edit service accounts.
- Implemented a new component for managing service accounts within
groups and roles.
- Added new API endpoints for service account management, including
token operations.
- Introduced a comprehensive Vue component for managing service accounts
with enhanced features, including filtering, searching, and token
management.
- Enhanced permission checks and error handling for service accounts
across various functions.
- Added support for external user permissions in service account
operations.
- Enhanced error handling for various components to prevent unnecessary
notifications on permission-related issues.
- Added localization support for service account functionalities,
providing necessary labels for user interface elements.

- **Bug Fixes**
- Improved error handling and validation across user management and
service account functionalities.

- **Documentation**
- Updated localization files to support new service account features and
labels.

- **Style**
- Adjusted styles in various components to enhance usability and
consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: oasisk <ashish.j.kolhe@gmail.com>
Co-authored-by: Subhradeep Chakraborty <chakrabortysubhradeep556@gmail.com>
2024-12-10 21:41:21 +05:30
Hengfei Yang 3955ed02f2 feat: add jobs for compact old data (#4952) 2024-10-31 00:33:09 +08:00
Prabhat Sharma f39a3de5a1 fix: rename zinc labs to OpenObserve (#4822)
Rename Zinc Labs to OpenObserve
2024-10-18 13:11:52 +08:00
Hengfei Yang 3256b97d4e feat: add reload config for ent (#4801) 2024-10-16 13:13:25 +08:00
Subhra264 aac7025008 fix: Short url fixes (#4773) 2024-10-14 15:24:34 +08:00
Loakesh Indiranandoasisk 0825839f3d fix: short_url auth, redirect to /web if auth fails (#4750) (#4754)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a new `RedirectResponse` struct for improved HTTP
redirection handling.
- Enhanced authentication validation with a new redirect mechanism for
`/short/` requests.
- Updated the `retrieve` function to improve logging and response
handling.

- **Bug Fixes**
	- Improved error management for authentication failures.

- **Refactor**
- Restructured route configurations to integrate new authentication
middleware and enhance service management.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: oasisk <ashish.j.kolhe@gmail.com>
2024-10-10 19:54:17 +05:30
Subhra264 974a61bb6f fix: include org_id in list_objects for rbac (#3841)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced authentication and authorization handling for user requests
with more efficient token validation.
- **Bug Fixes**
- Improved error handling and response based on user permissions and
authorization status.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-07-04 12:46:33 +05:30
Ankur Srivastava b6a4009ac4 feat: basic auth header support in GET requests (#3792)
Support basic-auth header parsing and login for enterprise-GET requests

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
  - Improved logging for user validation to aid in debugging.

- **New Features**
- Enhanced authentication process with better handling of headers and
tokens.
- Introduced new cookie preparation functionality to streamline cookie
management during authentication.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-07-01 08:48:26 +02:00
Hengfei Yang 6a17c42e83 feat: support user level search work group (#3790) 2024-06-23 00:59:52 +08:00
Subhra264 6e38089e97 fix: include login calls into auditing (#3758)
- [x] Includes the following APIs endpoints in auditing -
- `/auth/login` - If the login is successful, the user email along with
the event data (such as response code, path, method, query params and
the timestamp) and if it is unsuccessful, it still audits the event, but
username will be present only if available.
- `/auth/presigned-url`
- `/auth/login` - `GET` request. Similar to the first `login` endpoint.
- `/config/reload` - Audits this event, but as this is not a protected
route, the username will not be present in the audit record.
- `/config/redirect` - Similar to the first `login` endpoint.
- `/config/logout`

- [x] Audit Cron job is run on all the nodes including the router. The
interval can be set through `O2_AUDIT_PUBLISH_INTERVAL` env (in
seconds).
- [x] In case of remote usage reporing, print the error if response from
remote usage url is unsuccessful


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced enhanced auditing functionalities for user authentication
and authorization in the enterprise version.
- Added asynchronous task for auditing and publishing tasks within job
module.

- **Improvements**
- Refined error handling in usage data ingestion to better manage
success and failure responses.
  
- **Conditional Compilation**
- Multiple new functionalities and auditing enhancements are now
conditionally compiled based on the "enterprise" feature.


<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-06-20 18:13:35 +05:30
Ankur Srivastava ba3b27d780 fix: ensure that dashmap isnt getting deadlocked + more logs (#3747) 2024-06-17 10:46:00 +08:00
04b7df63be feat: support presigned GET URLS (#3667)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced user authentication by adding extended password fields and
support for generating presigned login URLs.
- Improved user management with new functions for handling user data and
authentication tokens.

- **Bug Fixes**
- Fixed issues with user data handling by passing references instead of
values in database operations.

- **Refactor**
- Streamlined authentication and user management code for better
maintainability and performance.

- **Tests**
- Added new test cases to validate password hashing and presigned URL
generation functionalities.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: oasisk <ashish.j.kolhe@gmail.com>
Co-authored-by: Bhargav <BJP232004@GMAIL.COM>
2024-06-07 14:20:21 +02:00
Ankur SrivastavaandHengfei Yang 8f3df9e7a1 feat: support reloading config vars using an API (#3623)
The new endpoint `/config/reload` will refresh the
environment variables.

There are a bunch of env-vars which will not be reloaded
for e.g. HTTP_PORT etc. these will need a restart.

---------

Co-authored-by: Hengfei Yang <hengfei.yang@gmail.com>
2024-05-30 08:23:27 +08:00
Ashish Kolhe 2417102f97 fix: ofga disable native user bug (#3431) 2024-05-08 19:34:52 +05:30
gaetan-craftandTaiming Liu 360e13790a fix(auth): fix password with colons (#3402)
Fix #3401

---------

Co-authored-by: Taiming Liu <90490946+taimingl@users.noreply.github.com>
2024-05-03 06:25:16 -07:00
Ashish Kolhe 8a1cfddcc7 fix: RBAC for native users (#3404) 2024-05-03 12:44:32 +05:30
Ashish Kolhe a7222f7d65 fix: id token length issue (#3360) 2024-04-28 15:16:05 +05:30
Ankur Srivastavaandomkark06 3826f87640 fix: ensure that rum proxy endpoint uses cookies (#3210)
Due to changes in the current architecture the access-token is being
sent as a cookie - `access_token` so this change facilitates accessing
the proxy url via the same mechanism

---------

Co-authored-by: omkark06 <omkar@zinclabs.io>
2024-04-11 18:13:21 +02:00
Hengfei Yang d4ff1888e4 feat: super cluster (#3039) 2024-04-11 10:01:56 +08:00
7c52e0ea7a fix: schema versions as separate key (#3021)
To enable row per schema version use:
ZO_ENTRY_PER_SCHEMA_VERSION_ENABLED = true.

One can migrate schemas from single row to row per schema version using
: migrate-schemas command

Before migration :

- DROP INDEX meta_module_key2_idx ON meta
- ALTER TABLE meta ADD COLUMN start_dt BIGINT NOT NULL DEFAULT 0;
- CREATE UNIQUE INDEX meta_module_start_dt_idx ON meta (start_dt, key2,
key1, module);

---------

Co-authored-by: Hengfei Yang <hengfei.yang@gmail.com>
Co-authored-by: Ankur Srivastava <ansrivas@users.noreply.github.com>
Co-authored-by: Huaijin <haohuaijin@gmail.com>
Co-authored-by: ktx-abhay <141122205+ktx-abhay@users.noreply.github.com>
Co-authored-by: Subhra264 <chakrabortysubhradeep556@gmail.com>
Co-authored-by: Bhargav <BJP232004@GMAIL.COM>
Co-authored-by: ktx-vaidehi <vaidehi.akhani@kiara.tech>
Co-authored-by: Omkar Kesarkhane <127078473+omkarK06@users.noreply.github.com>
Co-authored-by: Kirtan Thakkar <kirtan@kiara.tech>
2024-03-24 21:25:06 +05:30
Ashish Kolhe 0f5f97f42a fix: root user should have access to everything (#2993) 2024-03-15 13:15:03 +05:30
Ashish Kolhe 5bc9d93e23 fix: list should return only allowed objects (#2785) 2024-02-26 22:08:54 +05:30
Ashish Kolheandomkark06 d9e022bc04 fix: support native users in rbac (#2683)
Co-authored-by: omkark06 <omkar@zinclabs.io>
2024-02-11 10:43:01 +05:30
Ashish Kolhe eed6625097 chore: refactor rbac code (#2668) 2024-02-07 17:18:11 +05:30
Ashish Kolhe 1947bca6d2 fix: ReBAC issues (#2659) 2024-02-06 07:24:45 +05:30
Hengfei Yang 79682120f0 feat: search queue management (#2621) 2024-02-01 11:54:01 +08:00
Ashish Kolhe 98c9af0356 fix: report user email as part of usage reporting (#2610) 2024-01-31 15:31:08 +05:30
Ashish KolheandBhargav 99ec2221d8 feat: rebac with openfga (#2454)
Co-authored-by: Bhargav <BJP232004@GMAIL.COM>
2024-01-24 10:13:59 +05:30
Ashish Kolhe da08a7f5e8 feat: rebac with openfga (#2452) 2024-01-11 20:40:17 +05:30
Ashish Kolhe 7db25f01d6 feat: rebac with open fga (#2445) 2024-01-11 14:56:37 +05:30
Ashish Kolhe 52c02feeac chore: dex integration changes (#2360) 2024-01-05 13:04:02 +05:30
Hengfei Yang a4bae1a584 feat: Implement memtable + wal (#2261) 2023-12-28 07:40:22 +08:00
Ashish Kolhe 3cc141d778 fix: user api checks (#2294)
- [x] Check role during User Creation
- [x] Added checks during User Deletion/removal from org
2023-12-23 22:48:59 +05:30
Ashish Kolhe 122d5d52c4 feat: dex integration (#2277) 2023-12-22 09:05:46 +05:30