Skip to content

Commit

Permalink
Fetch users from supabase
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-asriyan committed Jan 11, 2025
1 parent d462bb5 commit 18b7969
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 82 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/CD-production-frontman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
run: |
echo "$SERVERS" > config/servers.yml
- name: Render USERS secret into config/users.yml
- name: Render SUPABASE secret into config/supabase.yml
env:
USERS: ${{ secrets.USERS }}
SUPABASE: ${{ secrets.SUPABASE }}
shell: bash
run: |
echo "$USERS" > config/users.yml
echo "$SUPABASE" > config/supabase.yml
- name: Run playbook
shell: bash
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/CD-production-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ jobs:
run: |
echo "$SERVERS" > config/servers.yml
- name: Render USERS secret into config/users.yml
- name: Render SUPABASE secret into config/supabase.yml
env:
USERS: ${{ secrets.USERS }}
SUPABASE: ${{ secrets.SUPABASE }}
shell: bash
run: |
echo "$USERS" > config/users.yml
echo "$SUPABASE" > config/supabase.yml
- name: Run playbook
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ id_rsa.pub
config/users-configs.yml
config/metrics.yml
config/servers.yml
config/users.yml
config/supabase.yml
config/hosts.yml
static
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ hosts_encrypt:
hosts_decrypt:
ansible-vault decrypt $(HOSTS_FILE)

render_users_csv:
ansible-playbook $(PLAYBOOK_FILE_USERS_CSV)

render_users_configs:
ansible-playbook $(PLAYBOOK_FILE_USERS_CONFIGS)

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ https://hiddify.com#app
# Architecture
![digram](./diagram.svg)

There are 3 types of componets: **GH Pages**, **metrics** and **proxy**. GH Actions that must be configured for this repository.
There are 4 componets: **GH Pages**, **[Supabase](https://supabase.com) instance**, **metrics** and **proxy**. GH Actions that must be configured for this repository.
Metrics should be deployed as a single instance (sharding is not allowed). Proxies could be deployed as many instances as needed,
each instance should have dedicated IP address and DNS record (if exists). All hosts should be Debian hosts with public IPs.

# [Supabase](https://supabase.com)
Stores list of user configs. Users may generate new user configs (my means of HTML website). Deploymemnt fetch records from there
to render configs for xrays and other components. _The repository with Supabas is not open-source at the moment. It will becore
open-source later_.

## GH Pages
Serves static content:
* static html pages with installation instructions which is being developed in a separate repository:
Expand Down Expand Up @@ -93,11 +98,6 @@ The following GitHub secrets are required for CD:
make deploy_proxies deploy_metrics
```

### Generate user list table
```commandline
make -e DOMAIN=<domain where GH pages are deployed> render_users_csv
```

### Generate UUID for a new user
```commandline
make generate_uuid
Expand Down
5 changes: 5 additions & 0 deletions config/supabase.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# supabase `service_role` key (`secret` API key)
config_supabase_api_key:

# supabase project id
config_supabase_project_id:
9 changes: 0 additions & 9 deletions config/users.example.yml

This file was deleted.

2 changes: 1 addition & 1 deletion diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 19 additions & 2 deletions proxies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@
- proxies
no_log: true
vars_files:
- ./config/users.yml
- ./config/supabase.yml
- ./config/servers.yml
vars:
# do not worry. these ports are local
config_local_xray_metrics_port: 8081
config_local_node_exporter_metrics_port: 8082
config_local_xray_exporter_metrics_port: 8080
pre_tasks:
- name: Fetch user UUIDs from Supabase
delegate_to: localhost
uri:
url: "https://{{ config_supabase_project_id }}.supabase.co/rest/v1/configs?select=uuid"
method: GET
headers:
apikey: "{{ config_supabase_api_key }}"
Authorization: "Bearer {{ config_supabase_api_key }}"
register: supabase_response

- name: Set user UUIDs fact
delegate_to: localhost
set_fact:
config_local_users: "{{ supabase_response.json | map(attribute='uuid') | list }}"
roles:
- role: xray
vars:
xray_server_uuid: "{{ hosts_server_uuid }}"
xray_server: "{{ config_servers[xray_server_uuid] }}"
xray_users: "{{ config_users }}"
xray_users: "{{ config_local_users }}"
xray_metrics_port: "{{ config_local_xray_metrics_port }}"
xray_supabase_api_key: "{{ supabase_api_key }}"
xray_supabase_project_id: "{{ supabase_project_id }}"
- role: node-exporter
vars:
node_exporter_port: "{{ config_local_node_exporter_metrics_port }}"
Expand Down
4 changes: 2 additions & 2 deletions roles/users-configs/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
dest: "{{ users_configs_static_root_local }}/robots.txt"

- name: Render configs
with_items: "{{ users_configs_users | dict2items }}"
with_items: "{{ users_configs_users }}"
loop_control:
index_var: loop_index
vars:
users_configs_user_uuid: "{{ item.key }}"
users_configs_user_uuid: "{{ item }}"
include_tasks: render_users_configs.yml
5 changes: 0 additions & 5 deletions roles/users-csv/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions roles/users-csv/defaults/main.yml

This file was deleted.

16 changes: 0 additions & 16 deletions roles/users-csv/tasks/main.yml

This file was deleted.

4 changes: 0 additions & 4 deletions roles/users-csv/templates/users.csv.j2

This file was deleted.

6 changes: 3 additions & 3 deletions roles/xray/templates/config.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"protocol": "vless",
"settings": {
"clients": [
{% for user in xray_users | dict2items %}
{% for user in xray_users %}
{
"email": "{{ user.value.name }}",
"email": "{{ user }}",
"flow": "{{ xray_server.flow }}",
"id": "{{ user.key }}"
"id": "{{ user }}"
}
{% if not loop.last %}
,
Expand Down
5 changes: 2 additions & 3 deletions tasks/assert-users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
- name: Ensure servers variable is defined correctly
assert:
that:
- item.value.name is string
- item.value.preferred_server_uuid is not defined or item.value.preferred_server_uuid is string
with_items: "{{ users | dict2items }}"
- item is string
with_items: "{{ users }}"
19 changes: 17 additions & 2 deletions users-configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@
vars_files:
- ./config/users-configs.yml
- ./config/servers.yml
- ./config/users.yml
- ./config/supabase.yml
pre_tasks:
- name: Fetch user UUIDs from Supabase
delegate_to: localhost
uri:
url: "https://{{ config_supabase_project_id }}.supabase.co/rest/v1/configs?select=uuid"
method: GET
headers:
apikey: "{{ config_supabase_api_key }}"
Authorization: "Bearer {{ config_supabase_api_key }}"
register: supabase_response

- name: Set user UUIDs fact
delegate_to: localhost
set_fact:
config_local_users: "{{ supabase_response.json | map(attribute='uuid') | list }}"
roles:
- role: users-configs
vars:
users_configs_default_redirect: "{{ config_users_configs_default_redirect }}"
users_configs_servers: "{{ config_servers }}"
users_configs_users: "{{ config_users }}"
users_configs_users: "{{ config_local_users }}"
users_configs_static_directory_filename: static
users_configs_title: "{{ config_users_title }}"
users_configs_support_url: "{{ config_users_support_url }}"
11 changes: 0 additions & 11 deletions users-csv.yml

This file was deleted.

0 comments on commit 18b7969

Please sign in to comment.