-
-
Notifications
You must be signed in to change notification settings - Fork 6
Tailscale Operator & Ansible Tailscale deployment #658
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
base: main
Are you sure you want to change the base?
Changes from all commits
2b92dd8
7a069c7
47f497f
cc6588a
8054baf
c7f7c9a
847cb89
0633a2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| - linode-ips | ||
| - common | ||
| - pydis-mtls | ||
| - tailscale | ||
| - wireguard | ||
| - munin-node | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ data_directory = '/var/lib/postgresql/{{ postgres_version }}/main' | |
| hba_file = '/etc/postgresql/{{ postgres_version }}/main/pg_hba.conf' | ||
| ident_file = '/etc/postgresql/{{ postgres_version }}/main/pg_ident.conf' | ||
| external_pid_file = '/var/run/postgresql/{{ postgres_version }}-main.pid' | ||
| listen_addresses = '89.58.26.118,localhost' | ||
| listen_addresses = '89.58.26.118,lovelace.opossum-python.ts.net,localhost' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this means PostgreSQL won't start if Tailscale is not running, doesn't it? |
||
| port = 5432 | ||
| unix_socket_directories = '/var/run/postgresql' | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| tailscale_rocky_repo: "https://pkgs.tailscale.com/stable/centos/10/tailscale.repo" | ||
| tailscale_gpg_key_url: "https://pkgs.tailscale.com/stable/debian/trixie.noarmor.gpg" | ||
| tailscale_apt_repo: "https://pkgs.tailscale.com/stable/debian/trixie.tailscale-keyring.list" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| --- | ||
| - name: Add Tailscale repository (Rocky) | ||
| ansible.builtin.get_url: | ||
| url: "{{ tailscale_rocky_repo }}" | ||
| dest: /etc/yum.repos.d/tailscale.repo | ||
| mode: "0644" | ||
| when: ansible_facts["distribution"] == "Rocky" | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Ensure keys directory exists (Debian) | ||
| file: | ||
| path: /usr/share/keyrings | ||
| state: directory | ||
| owner: root | ||
| group: root | ||
| mode: "0755" | ||
| when: ansible_facts["distribution"] == "Debian" | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Download Tailscale GPG key (Debian) | ||
| ansible.builtin.get_url: | ||
| url: "{{ tailscale_gpg_key_url }}" | ||
| dest: /usr/share/keyrings/tailscale-archive-keyring.gpg | ||
| mode: "0644" | ||
| when: ansible_facts["distribution"] == "Debian" | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Add Tailscale APT repository (Debian) | ||
| ansible.builtin.get_url: | ||
| url: "{{ tailscale_apt_repo }}" | ||
| dest: /etc/apt/sources.list.d/tailscale.list | ||
| mode: "0644" | ||
| when: ansible_facts["distribution"] == "Debian" | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Update APT cache (Debian) | ||
| ansible.builtin.apt: | ||
| update_cache: yes | ||
| when: ansible_facts["distribution"] == "Debian" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could group all of these together in a |
||
| tags: | ||
| - role::tailscale | ||
|
Comment on lines
+40
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion 1: use a handler and then |
||
|
|
||
| - name: Install Tailscale | ||
| package: | ||
| name: tailscale | ||
| state: present | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Ensure Tailscale is enabled and started | ||
| ansible.builtin.systemd: | ||
| name: tailscaled | ||
| enabled: yes | ||
| state: started | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Check if Tailscale is already authenticated | ||
| ansible.builtin.command: tailscale status --json | ||
| register: tailscale_status | ||
| failed_when: false | ||
| changed_when: false | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Parse Tailscale status | ||
| ansible.builtin.set_fact: | ||
| tailscale_authenticated: "{{ tailscale_status.stdout | from_json | json_query('BackendState') not in ['NeedsLogin', 'Stopped'] }}" | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Authenticate Tailscale | ||
| when: not tailscale_authenticated | ||
| ansible.builtin.command: |- | ||
| tailscale up \ | ||
| --authkey '{{ tailscale_oauth2_client_secret }}?preauthorized=true&ephemeral=false' \ | ||
| --advertise-tags '{{ tailscale_advertise_tags }}' \ | ||
| --hostname '{{ inventory_hostname }}' \ | ||
| --accept-routes \ | ||
| --accept-dns | ||
| register: tailscale_up_result | ||
| changed_when: "'Already up to date' not in tailscale_up_result.stdout" | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Fetch hosted Tailscale services | ||
| ansible.builtin.command: tailscale serve get-config --all | ||
| register: tailscale_services_status | ||
| failed_when: false | ||
| changed_when: false | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Parse Tailscale services | ||
| ansible.builtin.set_fact: | ||
| tailscale_hosted_services: "{{ tailscale_services_status.stdout | from_json | json_query('services') }}" | ||
| tags: | ||
| - role::tailscale | ||
|
|
||
| - name: Set tailscale_hosted_services to empty list if not defined | ||
| ansible.builtin.set_fact: | ||
| tailscale_hosted_services: [] | ||
| when: not tailscale_hosted_services | ||
| tags: | ||
| - role::tailscale | ||
|
Comment on lines
+104
to
+109
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way we could get the task above to return this? When would this condition hit? |
||
|
|
||
| - name: Ensure Tailscale services are configured | ||
| ansible.builtin.command: |- | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The linter is right here, we should add |
||
| tailscale serve --yes --service svc:{{ item.ts_service_name }} --{{ item.proto }} {{ item.listen_port }} {{ item.proxy_dest }} | ||
| loop: "{{ tailscale_services }}" | ||
| when: "'svc:' + item.ts_service_name not in tailscale_hosted_services and item.host == inventory_hostname" | ||
| tags: | ||
| - role::tailscale | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| tailscale_oauth2_client_id: "{{ vault_tailscale_oauth2_client_id }}" | ||
| tailscale_oauth2_client_secret: "{{ vault_tailscale_oauth2_client_secret }}" | ||
|
|
||
| tailscale_advertise_tags: "tag:baremetal" | ||
|
|
||
| tailscale_services: | ||
| - host: lovelace | ||
| ts_service_name: "postgres" | ||
| proto: "tcp" | ||
| listen_port: 5432 | ||
| proxy_dest: "127.0.0.1:5432" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| $ANSIBLE_VAULT;1.1;AES256 | ||
| 62316632633033623735393336623133363763323038323630656365363363373138626439316333 | ||
| 6565656364343564393239666334613664323264663562660a366666626333666130396534663733 | ||
| 37386435316135633936623961393461343765346630613064386135376530373964386338623464 | ||
| 3034663939353036620a386463333639396233303332386230376164353633353631376439623136 | ||
| 61346161633661323932633238393863626665663830353762323165613765313433646563656532 | ||
| 64303166343534316531316539303633336433333966353038653363656163663538636464626462 | ||
| 34383732346232313732336462303437346566363632653838363966653461386131633162313630 | ||
| 63653733666165336363313937393034626662333833353631306238316433306164333464313664 | ||
| 39333031383331393436306465636133636131316465333239363435666165643736666363353132 | ||
| 36333962353639333436666334356534393033666236656261663562306436643837613733303664 | ||
| 64666338653162376239643462393036626538316364396235633331336632656566643238323561 | ||
| 31393130323134383462 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||
| # Tailscale | ||||||
|
|
||||||
| We use the Tailscale Kubernetes Operator to allow in-cluster services to connect securely to external services via a secure tunnel. | ||||||
|
|
||||||
| ## Deployment | ||||||
|
|
||||||
| 1. Add the Helm chart `helm repo add tailscale https://pkgs.tailscale.com/helmcharts` | ||||||
| 2. Update the Helm repo `helm repo update` | ||||||
| 3. Install the tailscale operator, replacing OAuth credentials as necessary (from the Trust credentials section of Tailscale admin console): | ||||||
| ```bash | ||||||
| helm upgrade \ | ||||||
| --install \ | ||||||
| tailscale-operator \ | ||||||
| tailscale/tailscale-operator \ | ||||||
| --namespace=tailscale \ | ||||||
| --create-namespace \ | ||||||
| --set-string oauth.clientId="<OAauth client ID>" \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| --set-string oauth.clientSecret="<OAuth client secret>" \ | ||||||
| --wait | ||||||
| ``` | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| annotations: | ||
| tailscale.com/tailnet-fqdn: postgres.opossum-python.ts.net | ||
| name: postgres | ||
| namespace: tailscale | ||
| spec: | ||
| externalName: placeholder # any value - will be overwritten by operator | ||
| type: ExternalName |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is incorrect, this is the input chain. It also restates what the code speaks.