fix: t-001 a t-005 correctif
This commit is contained in:
13
README.md
13
README.md
@@ -95,6 +95,19 @@ Consequence visible :
|
|||||||
- si `API_SECRET_KEY` est vide, les appels API sont refusés avec `401 Unauthorized`
|
- si `API_SECRET_KEY` est vide, les appels API sont refusés avec `401 Unauthorized`
|
||||||
- l'application web pose aussi un cookie HTTP-only via `server/middleware/auth-cookie.ts` pour réutiliser ce secret coté navigateur
|
- l'application web pose aussi un cookie HTTP-only via `server/middleware/auth-cookie.ts` pour réutiliser ce secret coté navigateur
|
||||||
|
|
||||||
|
## Securite
|
||||||
|
|
||||||
|
Le comportement actuel du projet repose sur une hypothèse d'exposition très forte.
|
||||||
|
|
||||||
|
- `server/middleware/auth-cookie.ts` pose automatiquement le cookie `api_auth_token` à tout visiteur qui charge l'interface web
|
||||||
|
- ce cookie permet ensuite d'accéder aux routes `/api/*` protégées par `API_SECRET_KEY`
|
||||||
|
- il n'existe pas de login utilisateur ni de contrôle d'identité distinct dans le dépôt
|
||||||
|
|
||||||
|
Conséquence :
|
||||||
|
|
||||||
|
- `Supervisor` doit être déployé uniquement sur un réseau de confiance, derrière un VPN, une restriction d'IP, un proxy d'authentification ou un autre contrôle d'accès externe
|
||||||
|
- si l'application est exposée publiquement sans protection supplémentaire, ce mécanisme ne constitue pas une authentification suffisante
|
||||||
|
|
||||||
### SSH pour les backups
|
### SSH pour les backups
|
||||||
|
|
||||||
Les fonctionnalités de backup utilisent `ssh` avec les options `BatchMode=yes` et `ConnectTimeout=5` dans `server/utils/ssh.ts`. Cela implique un accès sans saisie interactive de mot de passe.
|
Les fonctionnalités de backup utilisent `ssh` avec les options `BatchMode=yes` et `ConnectTimeout=5` dans `server/utils/ssh.ts`. Cela implique un accès sans saisie interactive de mot de passe.
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ export function useApiAuthHeader() {
|
|||||||
|
|
||||||
// Tous les appels frontend vers /api/* reutilisent ce header commun.
|
// Tous les appels frontend vers /api/* reutilisent ce header commun.
|
||||||
return {
|
return {
|
||||||
Authorization: `Bearer ${token}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
|
|
||||||
import {process} from "std-env";
|
import {process} from "std-env";
|
||||||
|
|
||||||
const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES)
|
const MAX_FILES_PER_FOLDER = Math.max(1, Number(process.env.BACKUPS_MAX_FILES) || 50)
|
||||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { exec } from "child_process"
|
import { execFile } from "node:child_process"
|
||||||
|
|
||||||
type DiskSource = {
|
type DiskSource = {
|
||||||
key: "remote" | "local"
|
key: "remote" | "local"
|
||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CommandSpec = {
|
||||||
|
command: string
|
||||||
|
args: string[]
|
||||||
|
cwd?: string
|
||||||
|
}
|
||||||
|
|
||||||
const diskSources: DiskSource[] = [
|
const diskSources: DiskSource[] = [
|
||||||
{
|
{
|
||||||
key: "remote",
|
key: "remote",
|
||||||
@@ -16,33 +22,28 @@ const diskSources: DiskSource[] = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
function getDefaultCommand(source: DiskSource) {
|
function getCommand(source: DiskSource): CommandSpec {
|
||||||
const localScriptDir = process.env.DISK_LOCAL_SCRIPT_DIR || "/home/malio/Malio-ops/CheckStorage"
|
const localScriptDir = process.env.DISK_LOCAL_SCRIPT_DIR || "/home/malio/Malio-ops/CheckStorage"
|
||||||
const remoteHost = process.env.DISK_REMOTE_HOST || "malio-b"
|
const remoteHost = process.env.DISK_REMOTE_HOST || "malio-b"
|
||||||
const remoteScriptDir = process.env.DISK_REMOTE_SCRIPT_DIR || "/home/malio-b/Malio-ops/CheckStorage"
|
const remoteScriptDir = process.env.DISK_REMOTE_SCRIPT_DIR || "/home/malio-b/Malio-ops/CheckStorage"
|
||||||
|
|
||||||
if (source.key === "local") {
|
if (source.key === "local") {
|
||||||
return `cd ${localScriptDir} && bash check-storage.sh`
|
return {
|
||||||
|
command: "bash",
|
||||||
|
args: ["check-storage.sh"],
|
||||||
|
cwd: localScriptDir
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return `ssh ${remoteHost} "cd ${remoteScriptDir} && ./check-storage.sh"`
|
return {
|
||||||
|
command: "ssh",
|
||||||
|
args: [remoteHost, `cd ${remoteScriptDir} && ./check-storage.sh`]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEnvCommand(source: DiskSource) {
|
function runCommand({ command, args, cwd }: CommandSpec): Promise<string> {
|
||||||
const envKey = `DISK_COMMAND_${source.key.toUpperCase()}`
|
|
||||||
const legacyEnvKey =
|
|
||||||
source.key === "remote" ? "DISK_REMOTE_COMMAND" : source.key === "local" ? "DISK_LOCAL_COMMAND" : ""
|
|
||||||
|
|
||||||
return (
|
|
||||||
process.env[envKey] ||
|
|
||||||
(legacyEnvKey ? process.env[legacyEnvKey] : undefined) ||
|
|
||||||
getDefaultCommand(source)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function runShellCommand(command: string): Promise<string> {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(command, (error, stdout, stderr) => {
|
execFile(command, args, { cwd }, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(stderr || error.message)
|
reject(stderr || error.message)
|
||||||
return
|
return
|
||||||
@@ -56,12 +57,7 @@ export default defineEventHandler(async () => {
|
|||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
diskSources.map(async (source) => {
|
diskSources.map(async (source) => {
|
||||||
try {
|
try {
|
||||||
const envCommand = getEnvCommand(source)
|
const output = await runCommand(getCommand(source))
|
||||||
if (!envCommand) {
|
|
||||||
throw new Error(`Commande disque manquante pour ${source.key}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = await runShellCommand(envCommand)
|
|
||||||
return {
|
return {
|
||||||
key: source.key,
|
key: source.key,
|
||||||
label: source.label,
|
label: source.label,
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
// SECURITE:
|
||||||
|
// Ce middleware pose automatiquement le cookie d'authentification pour tout
|
||||||
|
// visiteur de l'interface web. Ce comportement repose sur l'hypothèse que
|
||||||
|
// Supervisor n'est exposé qu'à un réseau de confiance ou derrière un contrôle
|
||||||
|
// d'accès externe. Si l'application devient publiquement accessible, ce
|
||||||
|
// mécanisme ne constitue pas une authentification utilisateur.
|
||||||
export default defineEventHandler((event) => {
|
export default defineEventHandler((event) => {
|
||||||
const path = event.path || event.node.req.url || ""
|
const path = event.path || event.node.req.url || ""
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { execFile } from "node:child_process"
|
import {execFile} from "node:child_process"
|
||||||
import {process} from "std-env";
|
import {process} from "std-env";
|
||||||
import folderMap from "#server/config/backup-folders.json";
|
import folderMap from "#server/config/backup-folders.json";
|
||||||
|
|
||||||
@@ -10,11 +10,14 @@ export const FOLDER_MAP = folderMap as Record<string, string>
|
|||||||
export const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
export const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
||||||
|
|
||||||
export function runSsh(command: string): Promise<string> {
|
export function runSsh(command: string): Promise<string> {
|
||||||
|
if (!REMOTE_HOST) {
|
||||||
|
return Promise.reject(new Error("BACKUPS_REMOTE_HOST is not configured"))
|
||||||
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
execFile(
|
execFile(
|
||||||
"ssh",
|
"ssh",
|
||||||
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", REMOTE_HOST, command],
|
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", REMOTE_HOST, command],
|
||||||
{ maxBuffer: 10 * 1024 * 1024 },
|
{maxBuffer: 10 * 1024 * 1024},
|
||||||
(error, stdout, stderr) => {
|
(error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(stderr || error.message)
|
reject(stderr || error.message)
|
||||||
|
|||||||
Reference in New Issue
Block a user