UI review, stage 2: nginx security headers, gzip, cache; npm ci; no v-html
default.conf.template: X-Content-Type-Options, X-Frame-Options, Referrer-Policy, CSP, gzip, immutable cache for /assets/, no-cache for index.html and config.json, server_tokens off, drop proxy_pass_header. Dockerfile uses npm ci, .dockerignore added (nginx stays root: the image entrypoint and port 80 need it). Status badge is a component instead of v-html. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b78de98f26
commit
600119cdd1
6 files changed
+76
-32
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
.vscode
|
||||||
|
.git
|
||||||
|
*.bak
|
||||||
|
*.log
|
||||||
+3
-2
@@ -2,14 +2,15 @@
|
|||||||
FROM node:20-alpine AS build-stage
|
FROM node:20-alpine AS build-stage
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install
|
RUN npm ci
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Serve
|
# Stage 2: Serve
|
||||||
|
# nginx runs as root here: the image entrypoint renders the template into /etc/nginx/conf.d and port 80
|
||||||
|
# is published by docker-compose. An unprivileged variant would change the port and the image.
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
||||||
COPY default.conf.template /etc/nginx/templates/default.conf.template
|
COPY default.conf.template /etc/nginx/templates/default.conf.template
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|
||||||
@@ -1,21 +1,54 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
|
server_tokens off;
|
||||||
|
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
|
# Security headers. add_header in a location replaces the ones inherited from the server block,
|
||||||
|
# so the /assets/ location below repeats them. CSP: the bundle is served from this origin only;
|
||||||
|
# style-src 'unsafe-inline' is needed by Bootstrap and Chart.js (inline style attributes);
|
||||||
|
# connect-src 'self' means config.json must point to proxied paths (the defaults /api/v1 and /profiles-api).
|
||||||
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
add_header X-Frame-Options "DENY" always;
|
||||||
|
add_header Referrer-Policy "no-referrer" always;
|
||||||
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||||
|
|
||||||
|
gzip on;
|
||||||
|
gzip_vary on;
|
||||||
|
gzip_min_length 1024;
|
||||||
|
gzip_types text/plain text/css text/javascript application/javascript application/json image/svg+xml;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Hashed build files never change under the same name
|
||||||
|
location /assets/ {
|
||||||
|
try_files $uri =404;
|
||||||
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||||
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
add_header X-Frame-Options "DENY" always;
|
||||||
|
add_header Referrer-Policy "no-referrer" always;
|
||||||
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||||
|
}
|
||||||
|
|
||||||
|
# The entry page and the runtime configuration must be revalidated after an update
|
||||||
|
# (expires -1 sends "Cache-Control: no-cache" and keeps the server-level headers)
|
||||||
|
location = /index.html {
|
||||||
|
expires -1;
|
||||||
|
}
|
||||||
|
location = /config.json {
|
||||||
|
expires -1;
|
||||||
|
}
|
||||||
|
|
||||||
# Модуль 1: Мониторинг (Flask, порт 5001)
|
# Модуль 1: Мониторинг (Flask, порт 5001)
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://${OVP_API_HOST}:${OVP_API_PORT};
|
proxy_pass http://${OVP_API_HOST}:${OVP_API_PORT};
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_pass_header Authorization;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Модуль 2: Управление профилями (FastAPI, порт 8000)
|
# Модуль 2: Управление профилями (FastAPI, порт 8000)
|
||||||
@@ -34,4 +67,4 @@ server {
|
|||||||
location = /50x.html {
|
location = /50x.html {
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<template #header>
|
<template #header>
|
||||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||||
<h5 class="modal-title fw-bold mb-0" style="color: var(--text-heading);">{{ profile?.username }}</h5>
|
<h5 class="modal-title fw-bold mb-0" style="color: var(--text-heading);">{{ profile?.username }}</h5>
|
||||||
<span v-if="profile" class="status-badge" :class="status.cls">{{ status.label }}</span>
|
<StatusBadge v-if="profile" :profile="profile" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #body>
|
<template #body>
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue';
|
import { ref, computed } from 'vue';
|
||||||
import BaseModal from './BaseModal.vue';
|
import BaseModal from './BaseModal.vue';
|
||||||
|
import StatusBadge from './StatusBadge.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['save']);
|
const emit = defineEmits(['save']);
|
||||||
const modal = ref(null);
|
const modal = ref(null);
|
||||||
@@ -44,14 +45,6 @@ const note = ref('');
|
|||||||
|
|
||||||
const dirty = computed(() => note.value !== (profile.value?.note || ''));
|
const dirty = computed(() => note.value !== (profile.value?.note || ''));
|
||||||
|
|
||||||
const status = computed(() => {
|
|
||||||
const p = profile.value;
|
|
||||||
if (p?.is_revoked) return { label: 'Revoked', cls: 'status-expired' };
|
|
||||||
if (p?.is_expired) return { label: 'Expired', cls: 'status-expired' };
|
|
||||||
if (p?.days_remaining != null && p.days_remaining <= 30) return { label: 'Expiring Soon', cls: 'status-warning' };
|
|
||||||
return { label: 'Active', cls: 'status-valid' };
|
|
||||||
});
|
|
||||||
|
|
||||||
const daysLabel = computed(() => {
|
const daysLabel = computed(() => {
|
||||||
const days = profile.value?.days_remaining;
|
const days = profile.value?.days_remaining;
|
||||||
if (days == null) return '';
|
if (days == null) return '';
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<template>
|
||||||
|
<span class="status-badge" :class="badge.cls">
|
||||||
|
<i class="fas me-1" :class="badge.icon"></i>{{ badge.label }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
// Profile as returned by GET /profiles
|
||||||
|
profile: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const badge = computed(() => {
|
||||||
|
const p = props.profile;
|
||||||
|
if (p.is_revoked) return { label: 'Revoked', cls: 'status-expired', icon: 'fa-ban' };
|
||||||
|
if (p.is_expired) return { label: 'Expired', cls: 'status-expired', icon: 'fa-times-circle' };
|
||||||
|
if (p.days_remaining != null && p.days_remaining <= 30) {
|
||||||
|
return { label: 'Expiring Soon', cls: 'status-warning', icon: 'fa-exclamation-triangle' };
|
||||||
|
}
|
||||||
|
return { label: 'Active', cls: 'status-valid', icon: 'fa-check-circle' };
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
<td class="fw-semibold" :class="getDaysClass(cert.days_remaining)">
|
<td class="fw-semibold" :class="getDaysClass(cert.days_remaining)">
|
||||||
{{ cert.days_remaining }}
|
{{ cert.days_remaining }}
|
||||||
</td>
|
</td>
|
||||||
<td v-html="getStatusBadgeHTML(cert)"></td>
|
<td><StatusBadge :profile="cert" /></td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-sm btn-link text-warning p-0 me-2" title="Download Config" @click.stop="downloadConfig(cert)">
|
<button class="btn btn-sm btn-link text-warning p-0 me-2" title="Download Config" @click.stop="downloadConfig(cert)">
|
||||||
<i class="fas fa-download"></i>
|
<i class="fas fa-download"></i>
|
||||||
@@ -131,7 +131,7 @@
|
|||||||
<td class="fw-semibold text-muted">
|
<td class="fw-semibold text-muted">
|
||||||
{{ cert.days_remaining }}
|
{{ cert.days_remaining }}
|
||||||
</td>
|
</td>
|
||||||
<td v-html="getStatusBadgeHTML(cert)"></td>
|
<td><StatusBadge :profile="cert" /></td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-sm btn-link text-danger p-0" title="Revoke" @click.stop="revokeClient(cert)" :disabled="cert.is_revoked">
|
<button class="btn btn-sm btn-link text-danger p-0" title="Revoke" @click.stop="revokeClient(cert)" :disabled="cert.is_revoked">
|
||||||
<i class="fas fa-ban"></i>
|
<i class="fas fa-ban"></i>
|
||||||
@@ -156,6 +156,7 @@ import { useApi } from '../composables/useApi';
|
|||||||
import NewClientModal from '../components/NewClientModal.vue';
|
import NewClientModal from '../components/NewClientModal.vue';
|
||||||
import ConfirmModal from '../components/ConfirmModal.vue';
|
import ConfirmModal from '../components/ConfirmModal.vue';
|
||||||
import ProfileDetailsModal from '../components/ProfileDetailsModal.vue';
|
import ProfileDetailsModal from '../components/ProfileDetailsModal.vue';
|
||||||
|
import StatusBadge from '../components/StatusBadge.vue';
|
||||||
import vNoteTooltip from '../directives/noteTooltip';
|
import vNoteTooltip from '../directives/noteTooltip';
|
||||||
import { useToast } from '../composables/useToast';
|
import { useToast } from '../composables/useToast';
|
||||||
import { usePkiStatus } from '../composables/usePkiStatus';
|
import { usePkiStatus } from '../composables/usePkiStatus';
|
||||||
@@ -190,23 +191,6 @@ const getDaysClass = (days) => {
|
|||||||
return 'text-success';
|
return 'text-success';
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStatusBadgeHTML = (cert) => {
|
|
||||||
if (cert.is_revoked) {
|
|
||||||
return '<span class="status-badge status-expired"><i class="fas fa-ban me-1"></i>Revoked</span>';
|
|
||||||
}
|
|
||||||
if (cert.is_expired) {
|
|
||||||
return '<span class="status-badge status-expired"><i class="fas fa-times-circle me-1"></i>Expired</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Days check logic for expiring soon warning
|
|
||||||
if (cert.days_remaining !== null && cert.days_remaining <= 30) {
|
|
||||||
return '<span class="status-badge status-warning"><i class="fas fa-exclamation-triangle me-1"></i>Expiring Soon</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return '<span class="status-badge status-valid"><i class="fas fa-check-circle me-1"></i>Active</span>';
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Data Processing
|
// Data Processing
|
||||||
const filteredData = computed(() => {
|
const filteredData = computed(() => {
|
||||||
let data = allProfiles.value;
|
let data = allProfiles.value;
|
||||||
|
|||||||
Reference in new issue
Block a user