raijin-server 0.2.2__py3-none-any.whl → 0.2.4__py3-none-any.whl
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.
- raijin_server/__init__.py +1 -1
- raijin_server/cli.py +77 -0
- raijin_server/healthchecks.py +61 -2
- raijin_server/modules/apokolips_demo.py +40 -4
- raijin_server/modules/cert_manager.py +949 -71
- raijin_server/modules/full_install.py +44 -1
- raijin_server/utils.py +57 -1
- {raijin_server-0.2.2.dist-info → raijin_server-0.2.4.dist-info}/METADATA +31 -1
- {raijin_server-0.2.2.dist-info → raijin_server-0.2.4.dist-info}/RECORD +13 -13
- {raijin_server-0.2.2.dist-info → raijin_server-0.2.4.dist-info}/WHEEL +0 -0
- {raijin_server-0.2.2.dist-info → raijin_server-0.2.4.dist-info}/entry_points.txt +0 -0
- {raijin_server-0.2.2.dist-info → raijin_server-0.2.4.dist-info}/licenses/LICENSE +0 -0
- {raijin_server-0.2.2.dist-info → raijin_server-0.2.4.dist-info}/top_level.txt +0 -0
|
@@ -25,6 +25,49 @@ from raijin_server.modules import (
|
|
|
25
25
|
)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
def _cert_manager_install_only(ctx: ExecutionContext) -> None:
|
|
29
|
+
"""Wrapper para instalar cert-manager sem interação."""
|
|
30
|
+
if not cert_manager.install_only(ctx):
|
|
31
|
+
raise RuntimeError("Falha na instalação do cert-manager")
|
|
32
|
+
|
|
33
|
+
# Cria issuer HTTP01 padrão para staging (teste) e produção
|
|
34
|
+
# O usuário pode criar issuers adicionais depois com 'raijin-server cert install'
|
|
35
|
+
email = os.environ.get("RAIJIN_ACME_EMAIL", "")
|
|
36
|
+
if email and "@" in email:
|
|
37
|
+
typer.secho("\n📜 Criando ClusterIssuers padrão...", fg=typer.colors.CYAN)
|
|
38
|
+
|
|
39
|
+
# Cria issuer de staging (para testes)
|
|
40
|
+
cert_manager.create_issuer(
|
|
41
|
+
ctx,
|
|
42
|
+
name="letsencrypt-staging",
|
|
43
|
+
email=email,
|
|
44
|
+
challenge_type="http01",
|
|
45
|
+
staging=True,
|
|
46
|
+
ingress_class="traefik",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# Cria issuer de produção
|
|
50
|
+
cert_manager.create_issuer(
|
|
51
|
+
ctx,
|
|
52
|
+
name="letsencrypt-prod",
|
|
53
|
+
email=email,
|
|
54
|
+
challenge_type="http01",
|
|
55
|
+
staging=False,
|
|
56
|
+
ingress_class="traefik",
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
typer.secho("✓ ClusterIssuers 'letsencrypt-staging' e 'letsencrypt-prod' criados", fg=typer.colors.GREEN)
|
|
60
|
+
else:
|
|
61
|
+
typer.secho(
|
|
62
|
+
"ℹ Para criar ClusterIssuers automaticamente, defina RAIJIN_ACME_EMAIL",
|
|
63
|
+
fg=typer.colors.YELLOW,
|
|
64
|
+
)
|
|
65
|
+
typer.secho(
|
|
66
|
+
" Exemplo: export RAIJIN_ACME_EMAIL=admin@seudominio.com",
|
|
67
|
+
fg=typer.colors.YELLOW,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
28
71
|
# Ordem de execucao dos modulos para instalacao completa
|
|
29
72
|
# Modulos marcados com skip_env podem ser pulados via variavel de ambiente
|
|
30
73
|
INSTALL_SEQUENCE = [
|
|
@@ -36,7 +79,7 @@ INSTALL_SEQUENCE = [
|
|
|
36
79
|
("firewall", firewall.run, "Firewall UFW", None),
|
|
37
80
|
("kubernetes", kubernetes.run, "Cluster Kubernetes (kubeadm)", None),
|
|
38
81
|
("calico", calico.run, "CNI Calico + NetworkPolicy", None),
|
|
39
|
-
("cert_manager",
|
|
82
|
+
("cert_manager", _cert_manager_install_only, "cert-manager (instalacao base)", None),
|
|
40
83
|
("secrets", secrets.run, "Sealed-Secrets + External-Secrets", None),
|
|
41
84
|
("prometheus", prometheus.run, "Monitoramento Prometheus", None),
|
|
42
85
|
("grafana", grafana.run, "Dashboards Grafana", None),
|
raijin_server/utils.py
CHANGED
|
@@ -203,8 +203,64 @@ def ensure_tool(name: str, ctx: ExecutionContext, install_hint: str = "") -> Non
|
|
|
203
203
|
raise typer.Exit(code=1)
|
|
204
204
|
|
|
205
205
|
|
|
206
|
+
def _fix_broken_apt_sources(ctx: ExecutionContext) -> None:
|
|
207
|
+
"""Corrige repositórios APT quebrados (mirrors brasileiros problemáticos)."""
|
|
208
|
+
if ctx.dry_run:
|
|
209
|
+
typer.echo("[dry-run] Verificando/corrigindo repositórios APT...")
|
|
210
|
+
return
|
|
211
|
+
|
|
212
|
+
sources_list = Path("/etc/apt/sources.list")
|
|
213
|
+
|
|
214
|
+
# Detecta se está usando mirror brasileiro quebrado
|
|
215
|
+
needs_fix = False
|
|
216
|
+
if sources_list.exists():
|
|
217
|
+
content = sources_list.read_text()
|
|
218
|
+
if "br.archive.ubuntu.com" in content or "br.ports.ubuntu.com" in content:
|
|
219
|
+
needs_fix = True
|
|
220
|
+
|
|
221
|
+
if not needs_fix:
|
|
222
|
+
return
|
|
223
|
+
|
|
224
|
+
typer.secho(
|
|
225
|
+
"⚠ Detectado mirror brasileiro possivelmente quebrado. Corrigindo...",
|
|
226
|
+
fg=typer.colors.YELLOW,
|
|
227
|
+
)
|
|
228
|
+
logger.warning("Corrigindo mirror brasileiro quebrado em sources.list")
|
|
229
|
+
|
|
230
|
+
# Backup do original
|
|
231
|
+
backup = sources_list.with_suffix(".list.bak")
|
|
232
|
+
if not backup.exists():
|
|
233
|
+
import shutil as sh
|
|
234
|
+
sh.copy2(sources_list, backup)
|
|
235
|
+
|
|
236
|
+
# Substitui mirror brasileiro pelo principal
|
|
237
|
+
new_content = content.replace("br.archive.ubuntu.com", "archive.ubuntu.com")
|
|
238
|
+
new_content = new_content.replace("br.ports.ubuntu.com", "ports.ubuntu.com")
|
|
239
|
+
sources_list.write_text(new_content)
|
|
240
|
+
|
|
241
|
+
typer.secho("✓ Repositórios corrigidos (backup em sources.list.bak)", fg=typer.colors.GREEN)
|
|
242
|
+
|
|
243
|
+
|
|
206
244
|
def apt_update(ctx: ExecutionContext) -> None:
|
|
207
|
-
|
|
245
|
+
"""Executa apt-get update, corrigindo repositórios quebrados se necessário."""
|
|
246
|
+
_fix_broken_apt_sources(ctx)
|
|
247
|
+
|
|
248
|
+
# Tenta o update; se falhar com erro de Release, tenta corrigir
|
|
249
|
+
try:
|
|
250
|
+
run_cmd(["apt-get", "update"], ctx, retries=2)
|
|
251
|
+
except Exception as e:
|
|
252
|
+
error_msg = str(e).lower()
|
|
253
|
+
if "release" in error_msg or "no longer has" in error_msg:
|
|
254
|
+
typer.secho(
|
|
255
|
+
"⚠ Erro de repositório detectado. Tentando fallback...",
|
|
256
|
+
fg=typer.colors.YELLOW,
|
|
257
|
+
)
|
|
258
|
+
# Força correção e tenta novamente
|
|
259
|
+
ctx_temp = ExecutionContext(dry_run=False)
|
|
260
|
+
_fix_broken_apt_sources(ctx_temp)
|
|
261
|
+
run_cmd(["apt-get", "update"], ctx)
|
|
262
|
+
else:
|
|
263
|
+
raise
|
|
208
264
|
|
|
209
265
|
|
|
210
266
|
def apt_install(packages: Iterable[str], ctx: ExecutionContext) -> None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: raijin-server
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: CLI para automacao de setup e hardening de servidores Ubuntu Server.
|
|
5
5
|
Home-page: https://example.com/raijin-server
|
|
6
6
|
Author: Equipe Raijin
|
|
@@ -81,6 +81,36 @@ source .venv/bin/activate
|
|
|
81
81
|
python -m pip install -e .
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
### Instalação em Produção (Recomendado)
|
|
85
|
+
|
|
86
|
+
Para servidores em produção, use um venv isolado e execute com sudo preservando o ambiente:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# 1. Sair do venv atual (se estiver ativo)
|
|
90
|
+
deactivate
|
|
91
|
+
|
|
92
|
+
# 2. (Opcional) Remover venv antigo
|
|
93
|
+
rm -rf ~/.venvs/raijin
|
|
94
|
+
|
|
95
|
+
# 3. Criar venv novo
|
|
96
|
+
python3 -m venv ~/.venvs/raijin
|
|
97
|
+
source ~/.venvs/raijin/bin/activate
|
|
98
|
+
pip install -U pip setuptools
|
|
99
|
+
|
|
100
|
+
# 4. Instalar a versão mais recente
|
|
101
|
+
pip install -U raijin-server
|
|
102
|
+
|
|
103
|
+
# 5. Rodar usando root preservando o venv
|
|
104
|
+
sudo -E ~/.venvs/raijin/bin/raijin-server --version
|
|
105
|
+
sudo -E ~/.venvs/raijin/bin/raijin-server validate
|
|
106
|
+
sudo -E ~/.venvs/raijin/bin/raijin-server full-install
|
|
107
|
+
|
|
108
|
+
# 6. Para sair do venv quando terminar
|
|
109
|
+
deactivate
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
> **Nota**: O `-E` no sudo preserva as variáveis de ambiente, garantindo que o Python use o venv correto mesmo como root.
|
|
113
|
+
|
|
84
114
|
## Uso rapido
|
|
85
115
|
|
|
86
116
|
### Validar Sistema
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
raijin_server/__init__.py,sha256=
|
|
2
|
-
raijin_server/cli.py,sha256=
|
|
1
|
+
raijin_server/__init__.py,sha256=7-69Vj-HYrv98hWrKmwDqDQ-ehtTqJebx1JeP4St6Q4,94
|
|
2
|
+
raijin_server/cli.py,sha256=PfuIXc-pw1yZtJzCrxDVSWSsPAVBt9wqZBF-dWh6mwo,19274
|
|
3
3
|
raijin_server/config.py,sha256=Dta2CS1d6RgNiQ84P6dTXk98boFrjzuvhs_fCdlm0I4,4810
|
|
4
|
-
raijin_server/healthchecks.py,sha256
|
|
5
|
-
raijin_server/utils.py,sha256=
|
|
4
|
+
raijin_server/healthchecks.py,sha256=BJyWyUDtEswEblvGwWMejtMnsUb8kJcULVdS9iycrcc,14565
|
|
5
|
+
raijin_server/utils.py,sha256=oQM-NGL_kmlNZejFvxXk85MI_WkcxNfwaw5LeAsKUFU,11476
|
|
6
6
|
raijin_server/validators.py,sha256=qOZMHgwjHogVf17UPlxfUCpQd9qAGQW7tycd8mUvnEs,9404
|
|
7
7
|
raijin_server/modules/__init__.py,sha256=e_IbkhLGPcF8to9QUmIESP6fpcTOYcIhaXLKIvqRJMY,920
|
|
8
|
-
raijin_server/modules/apokolips_demo.py,sha256=
|
|
8
|
+
raijin_server/modules/apokolips_demo.py,sha256=8ltsXRbVDwlDwLMIvh02NG-FeAfBWw_v6lh7IGOyNqs,13725
|
|
9
9
|
raijin_server/modules/bootstrap.py,sha256=oVIGNRW_JbgY8zXNHGAIP0vGbbHNHyQexthxo5zhbcw,9762
|
|
10
10
|
raijin_server/modules/calico.py,sha256=a8N7YYv7NoaspPKdhRtwHy3V2mM4cP5xA1H8BwslB18,4139
|
|
11
|
-
raijin_server/modules/cert_manager.py,sha256=
|
|
11
|
+
raijin_server/modules/cert_manager.py,sha256=3aXK2ivh0eCFLMllpWjUWS36UA3sWplP40daQRfWv14,34393
|
|
12
12
|
raijin_server/modules/essentials.py,sha256=2xUXCyCQtFGd2DnCKV81N1R6bEJqH8zaet8mLovtQ1I,689
|
|
13
13
|
raijin_server/modules/firewall.py,sha256=h6AISqiZeTinVT7BjmQIS872qRAFZJLg7meqlth3cfw,757
|
|
14
|
-
raijin_server/modules/full_install.py,sha256=
|
|
14
|
+
raijin_server/modules/full_install.py,sha256=aR3yOuD7y0KLI20eMrxuFBNrWWn7JMpI4HFKNizEF3o,7464
|
|
15
15
|
raijin_server/modules/grafana.py,sha256=zxYpWBM-fD8vTgoJ2Hmb9P66wz_JuiidO6_cGK3jG30,1809
|
|
16
16
|
raijin_server/modules/hardening.py,sha256=4hz3ifkMhPlXa2n7gPxN0gitQgzALZ-073vuU3LM4RI,1616
|
|
17
17
|
raijin_server/modules/harness.py,sha256=dhZ89YIhlkuxiRU1deN6wXVWnXm0xeI03PwYf_qgfak,1527
|
|
@@ -36,9 +36,9 @@ raijin_server/scripts/checklist.sh,sha256=j6E0Kmk1EfjLvKK1VpCqzXJAXI_7Bm67LK4ndy
|
|
|
36
36
|
raijin_server/scripts/install.sh,sha256=IZOTujOSGmKpznwgL59picsQNVzYkai6FtfFS3Klf34,3908
|
|
37
37
|
raijin_server/scripts/log_size_metric.sh,sha256=rC2Ck4xnYVJV4Qymu24-indC8bkzfZs4FBqqxGPRl1I,1143
|
|
38
38
|
raijin_server/scripts/pre-deploy-check.sh,sha256=naPUgKjnKgsh-eGDH2623C7zcr9VjDEw1H0lfYaXW8c,4853
|
|
39
|
-
raijin_server-0.2.
|
|
40
|
-
raijin_server-0.2.
|
|
41
|
-
raijin_server-0.2.
|
|
42
|
-
raijin_server-0.2.
|
|
43
|
-
raijin_server-0.2.
|
|
44
|
-
raijin_server-0.2.
|
|
39
|
+
raijin_server-0.2.4.dist-info/licenses/LICENSE,sha256=kJsMCjOiRZE0AQNtxWqBa32z9kMAaF4EUxyHj3hKaJo,1105
|
|
40
|
+
raijin_server-0.2.4.dist-info/METADATA,sha256=4X4baNp5EyOCEl916XlHFbXtd25KWwhtwPky5nzT0lU,17772
|
|
41
|
+
raijin_server-0.2.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
42
|
+
raijin_server-0.2.4.dist-info/entry_points.txt,sha256=3ZvxDX4pvcjkIRsXAJ69wIfVmKa78LKo-C3QhqN2KVM,56
|
|
43
|
+
raijin_server-0.2.4.dist-info/top_level.txt,sha256=Yz1xneCRtsZOzbPIcTAcrSxd-1p80pohMXYAZ74dpok,14
|
|
44
|
+
raijin_server-0.2.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|