charmarr-lib-vpn 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- charmarr_lib_vpn-0.2.2/.gitignore +207 -0
- charmarr_lib_vpn-0.2.2/CHANGELOG.md +23 -0
- charmarr_lib_vpn-0.2.2/PKG-INFO +139 -0
- charmarr_lib_vpn-0.2.2/README.md +116 -0
- charmarr_lib_vpn-0.2.2/pyproject.toml +44 -0
- charmarr_lib_vpn-0.2.2/src/charmarr_lib/vpn/__init__.py +50 -0
- charmarr_lib_vpn-0.2.2/src/charmarr_lib/vpn/_k8s/__init__.py +53 -0
- charmarr_lib_vpn-0.2.2/src/charmarr_lib/vpn/_k8s/_gateway.py +189 -0
- charmarr_lib_vpn-0.2.2/src/charmarr_lib/vpn/_k8s/_gateway_client.py +175 -0
- charmarr_lib_vpn-0.2.2/src/charmarr_lib/vpn/_k8s/_kill_switch.py +212 -0
- charmarr_lib_vpn-0.2.2/src/charmarr_lib/vpn/_version.py +3 -0
- charmarr_lib_vpn-0.2.2/src/charmarr_lib/vpn/constants.py +22 -0
- charmarr_lib_vpn-0.2.2/src/charmarr_lib/vpn/interfaces/__init__.py +20 -0
- charmarr_lib_vpn-0.2.2/src/charmarr_lib/vpn/interfaces/_vpn_gateway.py +148 -0
- charmarr_lib_vpn-0.2.2/tests/unit/k8s/conftest.py +64 -0
- charmarr_lib_vpn-0.2.2/tests/unit/k8s/test_gateway.py +170 -0
- charmarr_lib_vpn-0.2.2/tests/unit/k8s/test_gateway_client.py +191 -0
- charmarr_lib_vpn-0.2.2/tests/unit/k8s/test_kill_switch.py +130 -0
- charmarr_lib_vpn-0.2.2/tests/unit/test_vpn_gateway.py +204 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.2.2](https://github.com/charmarr/charmarr-lib/compare/charmarr-lib-vpn-v0.2.1...charmarr-lib-vpn-v0.2.2) (2025-12-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **vpn:** fixes local version file update ([c4b5ce2](https://github.com/charmarr/charmarr-lib/commit/c4b5ce27825522ff07aee1e194755ced42401f8c))
|
|
9
|
+
|
|
10
|
+
## [0.2.1](https://github.com/charmarr/charmarr-lib/compare/charmarr-lib-vpn-v0.2.0...charmarr-lib-vpn-v0.2.1) (2025-12-16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **vpn:** fixes release please process ([72c0ea3](https://github.com/charmarr/charmarr-lib/commit/72c0ea3998188b96b74445e7076ac9e0ac5cebd2))
|
|
16
|
+
|
|
17
|
+
## [0.2.0](https://github.com/charmarr/charmarr-lib/compare/charmarr-lib-vpn-v0.1.0...charmarr-lib-vpn-v0.2.0) (2025-12-15)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* adds dev envs for charmarr lib packages ([b8ee5b2](https://github.com/charmarr/charmarr-lib/commit/b8ee5b29bf07a9c4e53a5443da3742c62ec4191c))
|
|
23
|
+
* scaffolds monorepo with required packages ([eca8d38](https://github.com/charmarr/charmarr-lib/commit/eca8d38bec8f03dcabd4363b84e1743e495fed4c))
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: charmarr-lib-vpn
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: VPN gateway charm library for Kubernetes
|
|
5
|
+
Author-email: Adhitya Ravi <adhityashan95@gmail.com>
|
|
6
|
+
License: LGPL-3.0-or-later
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Requires-Dist: charmarr-lib-krm>=0.1
|
|
14
|
+
Requires-Dist: lightkube>=0.15
|
|
15
|
+
Requires-Dist: ops>=2.0
|
|
16
|
+
Requires-Dist: pydantic>=2.0
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: mypy>=1.8; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
21
|
+
Requires-Dist: ruff>=0.1; extra == 'dev'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
<p align="center">
|
|
25
|
+
<img src="../assets/charmarr-charmarr-lib.png" width="350" alt="Charmarr Lib">
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
<h1 align="center">charmarr-lib-vpn</h1>
|
|
29
|
+
|
|
30
|
+
VPN gateway charm library for Kubernetes.
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- VPN gateway Juju relation interface
|
|
35
|
+
- StatefulSet patching utilities for pod-gateway integration
|
|
36
|
+
- NetworkPolicy kill switch implementation
|
|
37
|
+
- Reusable beyond Charmarr ecosystem
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install charmarr-lib-vpn
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
### Interfaces
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from charmarr_lib.vpn.interfaces import (
|
|
51
|
+
VPNGatewayProvider,
|
|
52
|
+
VPNGatewayRequirer,
|
|
53
|
+
VPNGatewayProviderData,
|
|
54
|
+
VPNGatewayRequirerData,
|
|
55
|
+
VPNGatewayChangedEvent,
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Gateway Patching (VPN gateway side - gluetun)
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from charmarr_lib.vpn import (
|
|
63
|
+
reconcile_gateway,
|
|
64
|
+
build_gateway_patch,
|
|
65
|
+
is_gateway_patched,
|
|
66
|
+
)
|
|
67
|
+
from charmarr_lib.krm import K8sResourceManager
|
|
68
|
+
|
|
69
|
+
manager = K8sResourceManager()
|
|
70
|
+
provider_data = VPNGatewayProviderData(
|
|
71
|
+
vxlan_id=42,
|
|
72
|
+
vxlan_ip_network="172.16.0.0/24",
|
|
73
|
+
cluster_cidrs="10.1.0.0/16,10.152.183.0/24",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Idempotent reconciliation
|
|
77
|
+
result = reconcile_gateway(
|
|
78
|
+
manager=manager,
|
|
79
|
+
statefulset_name="gluetun",
|
|
80
|
+
namespace="vpn-gateway",
|
|
81
|
+
data=provider_data,
|
|
82
|
+
pod_cidr="10.1.0.0/16",
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Client Patching (Download client side - qBittorrent)
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from charmarr_lib.vpn import (
|
|
90
|
+
reconcile_gateway_client,
|
|
91
|
+
build_gateway_client_patch,
|
|
92
|
+
build_gateway_client_configmap_data,
|
|
93
|
+
is_gateway_client_patched,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# Create client-side VPN routing
|
|
97
|
+
result = reconcile_gateway_client(
|
|
98
|
+
manager=manager,
|
|
99
|
+
statefulset_name="qbittorrent",
|
|
100
|
+
namespace="download-clients",
|
|
101
|
+
data=requirer_data,
|
|
102
|
+
configmap_name="qbittorrent-vpn-config",
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Kill Switch (NetworkPolicy)
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from charmarr_lib.vpn import (
|
|
110
|
+
KillSwitchConfig,
|
|
111
|
+
reconcile_kill_switch,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# Create NetworkPolicy that blocks non-VPN egress
|
|
115
|
+
config = KillSwitchConfig(
|
|
116
|
+
app_name="qbittorrent",
|
|
117
|
+
namespace="download-clients",
|
|
118
|
+
cluster_cidrs=["10.1.0.0/16", "10.152.183.0/24"],
|
|
119
|
+
dns_namespace="kube-system",
|
|
120
|
+
)
|
|
121
|
+
reconcile_kill_switch(manager, "qbittorrent", "download-clients", config)
|
|
122
|
+
|
|
123
|
+
# Remove kill switch on relation-broken
|
|
124
|
+
reconcile_kill_switch(manager, "qbittorrent", "download-clients", None)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Constants
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from charmarr_lib.vpn import (
|
|
131
|
+
POD_GATEWAY_IMAGE,
|
|
132
|
+
DEFAULT_VXLAN_ID,
|
|
133
|
+
DEFAULT_VXLAN_IP_NETWORK,
|
|
134
|
+
GATEWAY_INIT_CONTAINER_NAME,
|
|
135
|
+
GATEWAY_SIDECAR_CONTAINER_NAME,
|
|
136
|
+
CLIENT_INIT_CONTAINER_NAME,
|
|
137
|
+
CLIENT_SIDECAR_CONTAINER_NAME,
|
|
138
|
+
)
|
|
139
|
+
```
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="../assets/charmarr-charmarr-lib.png" width="350" alt="Charmarr Lib">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">charmarr-lib-vpn</h1>
|
|
6
|
+
|
|
7
|
+
VPN gateway charm library for Kubernetes.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- VPN gateway Juju relation interface
|
|
12
|
+
- StatefulSet patching utilities for pod-gateway integration
|
|
13
|
+
- NetworkPolicy kill switch implementation
|
|
14
|
+
- Reusable beyond Charmarr ecosystem
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install charmarr-lib-vpn
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Interfaces
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from charmarr_lib.vpn.interfaces import (
|
|
28
|
+
VPNGatewayProvider,
|
|
29
|
+
VPNGatewayRequirer,
|
|
30
|
+
VPNGatewayProviderData,
|
|
31
|
+
VPNGatewayRequirerData,
|
|
32
|
+
VPNGatewayChangedEvent,
|
|
33
|
+
)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Gateway Patching (VPN gateway side - gluetun)
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from charmarr_lib.vpn import (
|
|
40
|
+
reconcile_gateway,
|
|
41
|
+
build_gateway_patch,
|
|
42
|
+
is_gateway_patched,
|
|
43
|
+
)
|
|
44
|
+
from charmarr_lib.krm import K8sResourceManager
|
|
45
|
+
|
|
46
|
+
manager = K8sResourceManager()
|
|
47
|
+
provider_data = VPNGatewayProviderData(
|
|
48
|
+
vxlan_id=42,
|
|
49
|
+
vxlan_ip_network="172.16.0.0/24",
|
|
50
|
+
cluster_cidrs="10.1.0.0/16,10.152.183.0/24",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Idempotent reconciliation
|
|
54
|
+
result = reconcile_gateway(
|
|
55
|
+
manager=manager,
|
|
56
|
+
statefulset_name="gluetun",
|
|
57
|
+
namespace="vpn-gateway",
|
|
58
|
+
data=provider_data,
|
|
59
|
+
pod_cidr="10.1.0.0/16",
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Client Patching (Download client side - qBittorrent)
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from charmarr_lib.vpn import (
|
|
67
|
+
reconcile_gateway_client,
|
|
68
|
+
build_gateway_client_patch,
|
|
69
|
+
build_gateway_client_configmap_data,
|
|
70
|
+
is_gateway_client_patched,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# Create client-side VPN routing
|
|
74
|
+
result = reconcile_gateway_client(
|
|
75
|
+
manager=manager,
|
|
76
|
+
statefulset_name="qbittorrent",
|
|
77
|
+
namespace="download-clients",
|
|
78
|
+
data=requirer_data,
|
|
79
|
+
configmap_name="qbittorrent-vpn-config",
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Kill Switch (NetworkPolicy)
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from charmarr_lib.vpn import (
|
|
87
|
+
KillSwitchConfig,
|
|
88
|
+
reconcile_kill_switch,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Create NetworkPolicy that blocks non-VPN egress
|
|
92
|
+
config = KillSwitchConfig(
|
|
93
|
+
app_name="qbittorrent",
|
|
94
|
+
namespace="download-clients",
|
|
95
|
+
cluster_cidrs=["10.1.0.0/16", "10.152.183.0/24"],
|
|
96
|
+
dns_namespace="kube-system",
|
|
97
|
+
)
|
|
98
|
+
reconcile_kill_switch(manager, "qbittorrent", "download-clients", config)
|
|
99
|
+
|
|
100
|
+
# Remove kill switch on relation-broken
|
|
101
|
+
reconcile_kill_switch(manager, "qbittorrent", "download-clients", None)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Constants
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from charmarr_lib.vpn import (
|
|
108
|
+
POD_GATEWAY_IMAGE,
|
|
109
|
+
DEFAULT_VXLAN_ID,
|
|
110
|
+
DEFAULT_VXLAN_IP_NETWORK,
|
|
111
|
+
GATEWAY_INIT_CONTAINER_NAME,
|
|
112
|
+
GATEWAY_SIDECAR_CONTAINER_NAME,
|
|
113
|
+
CLIENT_INIT_CONTAINER_NAME,
|
|
114
|
+
CLIENT_SIDECAR_CONTAINER_NAME,
|
|
115
|
+
)
|
|
116
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "charmarr-lib-vpn"
|
|
3
|
+
description = "VPN gateway charm library for Kubernetes"
|
|
4
|
+
dynamic = ["version"]
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = { text = "LGPL-3.0-or-later" }
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Adhitya Ravi", email = "adhityashan95@gmail.com" }
|
|
10
|
+
]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"charmarr-lib-krm>=0.1",
|
|
20
|
+
"ops>=2.0",
|
|
21
|
+
"pydantic>=2.0",
|
|
22
|
+
"lightkube>=0.15",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = [
|
|
27
|
+
"pytest>=8.0",
|
|
28
|
+
"pytest-cov>=4.0",
|
|
29
|
+
"ruff>=0.1",
|
|
30
|
+
"mypy>=1.8",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["hatchling"]
|
|
35
|
+
build-backend = "hatchling.build"
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.wheel]
|
|
38
|
+
packages = ["src/charmarr_lib"]
|
|
39
|
+
|
|
40
|
+
[tool.hatch.version]
|
|
41
|
+
path = "src/charmarr_lib/vpn/_version.py"
|
|
42
|
+
|
|
43
|
+
[tool.uv.sources]
|
|
44
|
+
charmarr-lib-krm = { workspace = true }
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Copyright 2025 The Charmarr Project
|
|
2
|
+
# See LICENSE file for licensing details.
|
|
3
|
+
|
|
4
|
+
"""VPN gateway charm library for Kubernetes."""
|
|
5
|
+
|
|
6
|
+
from charmarr_lib.vpn._k8s import (
|
|
7
|
+
KillSwitchConfig,
|
|
8
|
+
build_gateway_client_configmap_data,
|
|
9
|
+
build_gateway_client_patch,
|
|
10
|
+
build_gateway_patch,
|
|
11
|
+
is_gateway_client_patched,
|
|
12
|
+
is_gateway_patched,
|
|
13
|
+
reconcile_gateway,
|
|
14
|
+
reconcile_gateway_client,
|
|
15
|
+
reconcile_kill_switch,
|
|
16
|
+
)
|
|
17
|
+
from charmarr_lib.vpn.constants import (
|
|
18
|
+
CLIENT_INIT_CONTAINER_NAME,
|
|
19
|
+
CLIENT_SIDECAR_CONTAINER_NAME,
|
|
20
|
+
DEFAULT_VPN_BLOCK_OTHER_TRAFFIC,
|
|
21
|
+
DEFAULT_VPN_INTERFACE,
|
|
22
|
+
DEFAULT_VXLAN_GATEWAY_FIRST_DYNAMIC_IP,
|
|
23
|
+
DEFAULT_VXLAN_ID,
|
|
24
|
+
DEFAULT_VXLAN_IP_NETWORK,
|
|
25
|
+
GATEWAY_INIT_CONTAINER_NAME,
|
|
26
|
+
GATEWAY_SIDECAR_CONTAINER_NAME,
|
|
27
|
+
POD_GATEWAY_IMAGE,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"CLIENT_INIT_CONTAINER_NAME",
|
|
32
|
+
"CLIENT_SIDECAR_CONTAINER_NAME",
|
|
33
|
+
"DEFAULT_VPN_BLOCK_OTHER_TRAFFIC",
|
|
34
|
+
"DEFAULT_VPN_INTERFACE",
|
|
35
|
+
"DEFAULT_VXLAN_GATEWAY_FIRST_DYNAMIC_IP",
|
|
36
|
+
"DEFAULT_VXLAN_ID",
|
|
37
|
+
"DEFAULT_VXLAN_IP_NETWORK",
|
|
38
|
+
"GATEWAY_INIT_CONTAINER_NAME",
|
|
39
|
+
"GATEWAY_SIDECAR_CONTAINER_NAME",
|
|
40
|
+
"POD_GATEWAY_IMAGE",
|
|
41
|
+
"KillSwitchConfig",
|
|
42
|
+
"build_gateway_client_configmap_data",
|
|
43
|
+
"build_gateway_client_patch",
|
|
44
|
+
"build_gateway_patch",
|
|
45
|
+
"is_gateway_client_patched",
|
|
46
|
+
"is_gateway_patched",
|
|
47
|
+
"reconcile_gateway",
|
|
48
|
+
"reconcile_gateway_client",
|
|
49
|
+
"reconcile_kill_switch",
|
|
50
|
+
]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Copyright 2025 The Charmarr Project
|
|
2
|
+
# See LICENSE file for licensing details.
|
|
3
|
+
|
|
4
|
+
"""StatefulSet patching and NetworkPolicy for pod-gateway VPN routing.
|
|
5
|
+
|
|
6
|
+
This module provides functions to patch Kubernetes StatefulSets with
|
|
7
|
+
pod-gateway containers for VXLAN overlay VPN routing, plus NetworkPolicy
|
|
8
|
+
kill switch for traffic protection.
|
|
9
|
+
|
|
10
|
+
Gateway-side patching (for gluetun-k8s):
|
|
11
|
+
- gateway-init: Creates VXLAN tunnel, sets up iptables forwarding
|
|
12
|
+
- gateway-sidecar: Runs DHCP and DNS server for client pods
|
|
13
|
+
|
|
14
|
+
Gateway client patching (for qbittorrent-k8s, sabnzbd-k8s):
|
|
15
|
+
- vpn-route-init: Creates VXLAN interface, gets IP via DHCP
|
|
16
|
+
- vpn-route-sidecar: Monitors gateway connectivity
|
|
17
|
+
|
|
18
|
+
Kill switch (for qbittorrent-k8s, sabnzbd-k8s):
|
|
19
|
+
- NetworkPolicy that blocks egress except cluster CIDRs + DNS
|
|
20
|
+
- Prevents traffic leaks if VXLAN routing fails
|
|
21
|
+
|
|
22
|
+
See ADRs:
|
|
23
|
+
- lib/adr-002-charmarr-vpn.md
|
|
24
|
+
- networking/adr-004-vpn-kill-switch.md
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from charmarr_lib.vpn._k8s._gateway import (
|
|
28
|
+
build_gateway_patch,
|
|
29
|
+
is_gateway_patched,
|
|
30
|
+
reconcile_gateway,
|
|
31
|
+
)
|
|
32
|
+
from charmarr_lib.vpn._k8s._gateway_client import (
|
|
33
|
+
build_gateway_client_configmap_data,
|
|
34
|
+
build_gateway_client_patch,
|
|
35
|
+
is_gateway_client_patched,
|
|
36
|
+
reconcile_gateway_client,
|
|
37
|
+
)
|
|
38
|
+
from charmarr_lib.vpn._k8s._kill_switch import (
|
|
39
|
+
KillSwitchConfig,
|
|
40
|
+
reconcile_kill_switch,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
__all__ = [
|
|
44
|
+
"KillSwitchConfig",
|
|
45
|
+
"build_gateway_client_configmap_data",
|
|
46
|
+
"build_gateway_client_patch",
|
|
47
|
+
"build_gateway_patch",
|
|
48
|
+
"is_gateway_client_patched",
|
|
49
|
+
"is_gateway_patched",
|
|
50
|
+
"reconcile_gateway",
|
|
51
|
+
"reconcile_gateway_client",
|
|
52
|
+
"reconcile_kill_switch",
|
|
53
|
+
]
|