关闭前端私钥安全入口
移除管理页面私钥板块、命令生成与私钥接口请求,服务器配置统一使用密码认证,并补充安全边界测试。
This commit is contained in:
1 parent
7c8826974f
commit
79d8259371
5 files changed
+34
-458
No files matched your search
@@ -19,7 +19,6 @@ export function useDashboard() {
|
|||||||
const canRunRenewal = computed(() => currentUser.value?.role === "super_admin");
|
const canRunRenewal = computed(() => currentUser.value?.role === "super_admin");
|
||||||
const domains = ref([]);
|
const domains = ref([]);
|
||||||
const servers = ref([]);
|
const servers = ref([]);
|
||||||
const sshKeys = ref([]);
|
|
||||||
const certificates = ref([]);
|
const certificates = ref([]);
|
||||||
const tasks = ref([]);
|
const tasks = ref([]);
|
||||||
const auditLogs = ref([]);
|
const auditLogs = ref([]);
|
||||||
@@ -47,13 +46,6 @@ export function useDashboard() {
|
|||||||
const serverEditingId = ref("");
|
const serverEditingId = ref("");
|
||||||
const serverSaving = ref(false);
|
const serverSaving = ref(false);
|
||||||
const serverFormError = ref("");
|
const serverFormError = ref("");
|
||||||
const showSSHKeyForm = ref(false);
|
|
||||||
const showEmbeddedSSHKeyGuide = ref(false);
|
|
||||||
const sshKeySaving = ref(false);
|
|
||||||
const sshKeyFormError = ref("");
|
|
||||||
const sshKeyPlatform = ref("windows");
|
|
||||||
const sshKeyPassphraseVisible = ref(false);
|
|
||||||
const sshKeyRandomSuffix = ref(createSSHKeyRandomSuffix());
|
|
||||||
const showSettings = ref(false);
|
const showSettings = ref(false);
|
||||||
const settingsSaving = ref(false);
|
const settingsSaving = ref(false);
|
||||||
const settingsError = ref("");
|
const settingsError = ref("");
|
||||||
@@ -87,7 +79,6 @@ export function useDashboard() {
|
|||||||
() =>
|
() =>
|
||||||
showForm.value ||
|
showForm.value ||
|
||||||
showServerForm.value ||
|
showServerForm.value ||
|
||||||
showSSHKeyForm.value ||
|
|
||||||
showSettings.value ||
|
showSettings.value ||
|
||||||
showCertificateImport.value ||
|
showCertificateImport.value ||
|
||||||
deploymentResult.value !== null ||
|
deploymentResult.value !== null ||
|
||||||
@@ -128,30 +119,6 @@ export function useDashboard() {
|
|||||||
document.body.style.overflow = previousBodyOverflow;
|
document.body.style.overflow = previousBodyOverflow;
|
||||||
});
|
});
|
||||||
|
|
||||||
const sshKeyFileName = computed(
|
|
||||||
() =>
|
|
||||||
`${sanitizeSSHKeySegment(sshKeyCommandUsername.value, "用户名")}+scert-${sshKeyRandomSuffix.value}`,
|
|
||||||
);
|
|
||||||
const sshKeyPath = computed(() => `/ssl/ssh/${sshKeyFileName.value}`);
|
|
||||||
const sshKeyPrivatePath = computed(() => `${sshKeyPath.value}.key`);
|
|
||||||
const sshKeyPublicPath = computed(() => sshKeyPath.value);
|
|
||||||
const sshKeyRemoteTarget = computed(
|
|
||||||
() =>
|
|
||||||
`${sanitizeSSHKeySegment(sshKeyCommandUsername.value, "用户名")}@${sanitizeSSHHost(sshKeyCommandHost.value)}`,
|
|
||||||
);
|
|
||||||
const sshKeyCommands = computed(() => ({
|
|
||||||
windows:
|
|
||||||
`New-Item -ItemType Directory -Force -Path "/ssl/ssh" | Out-Null; ssh-keygen -t ed25519 -C "scert-deploy" -f "${sshKeyPrivatePath.value}"; Move-Item -Force "${sshKeyPrivatePath.value}.pub" "${sshKeyPublicPath.value}"`,
|
|
||||||
linux:
|
|
||||||
`sudo install -d -m 700 -o "$(id -un)" -g "$(id -gn)" /ssl/ssh && ssh-keygen -t ed25519 -C "scert-deploy" -f "${sshKeyPrivatePath.value}" && mv -f "${sshKeyPrivatePath.value}.pub" "${sshKeyPublicPath.value}" && chmod 644 "${sshKeyPublicPath.value}"`,
|
|
||||||
}));
|
|
||||||
const sshPublicKeyCommands = computed(() => ({
|
|
||||||
windows:
|
|
||||||
`Get-Content "${sshKeyPublicPath.value}" | ssh ${sshKeyRemoteTarget.value} "umask 077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"`,
|
|
||||||
linux:
|
|
||||||
`ssh-copy-id -i "${sshKeyPublicPath.value}" ${sshKeyRemoteTarget.value}`,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const certificateTypeLabels = {
|
const certificateTypeLabels = {
|
||||||
single: "单域名",
|
single: "单域名",
|
||||||
wildcard: "泛域名",
|
wildcard: "泛域名",
|
||||||
@@ -318,22 +285,6 @@ export function useDashboard() {
|
|||||||
const defaultPrivateKeyPath = "/ssl/{域名}/{证书类型}/key.pem";
|
const defaultPrivateKeyPath = "/ssl/{域名}/{证书类型}/key.pem";
|
||||||
|
|
||||||
const serverForm = ref(createEmptyServerForm());
|
const serverForm = ref(createEmptyServerForm());
|
||||||
const sshKeyForm = ref(createEmptySSHKeyForm());
|
|
||||||
|
|
||||||
const sshKeyCommandUsername = computed(
|
|
||||||
() => String(serverForm.value.username || "").trim() || "用户名",
|
|
||||||
);
|
|
||||||
const sshKeyCommandHost = computed(
|
|
||||||
() => String(serverForm.value.address || "").trim() || "服务器地址",
|
|
||||||
);
|
|
||||||
|
|
||||||
watch(sshKeyFileName, (fileName, previousFileName) => {
|
|
||||||
if (!showEmbeddedSSHKeyGuide.value) return;
|
|
||||||
const currentName = String(sshKeyForm.value.name || "").trim();
|
|
||||||
if (!currentName || currentName === previousFileName) {
|
|
||||||
sshKeyForm.value.name = fileName;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
async function fetchAdmin(path, options = {}) {
|
async function fetchAdmin(path, options = {}) {
|
||||||
const response = await fetch(path, {
|
const response = await fetch(path, {
|
||||||
...options,
|
...options,
|
||||||
@@ -381,7 +332,6 @@ export function useDashboard() {
|
|||||||
port: 22,
|
port: 22,
|
||||||
username: "",
|
username: "",
|
||||||
auth_method: "password",
|
auth_method: "password",
|
||||||
private_key_ref: "",
|
|
||||||
password: "",
|
password: "",
|
||||||
passwordConfigured: false,
|
passwordConfigured: false,
|
||||||
host_key_fingerprint: "",
|
host_key_fingerprint: "",
|
||||||
@@ -395,11 +345,7 @@ export function useDashboard() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEmptySSHKeyForm() {
|
function createRandomSuffix() {
|
||||||
return { name: "", private_key: "", passphrase: "" };
|
|
||||||
}
|
|
||||||
|
|
||||||
function createSSHKeyRandomSuffix() {
|
|
||||||
const bytes = new Uint8Array(6);
|
const bytes = new Uint8Array(6);
|
||||||
crypto.getRandomValues(bytes);
|
crypto.getRandomValues(bytes);
|
||||||
return Array.from(bytes, (value) => value.toString(16).padStart(2, "0")).join(
|
return Array.from(bytes, (value) => value.toString(16).padStart(2, "0")).join(
|
||||||
@@ -407,21 +353,6 @@ export function useDashboard() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitizeSSHKeySegment(value, fallback) {
|
|
||||||
const normalized = String(value || "")
|
|
||||||
.trim()
|
|
||||||
.replace(/[^\p{L}\p{N}._-]+/gu, "-")
|
|
||||||
.replace(/^-+|-+$/g, "");
|
|
||||||
return normalized || fallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sanitizeSSHHost(value) {
|
|
||||||
const normalized = String(value || "")
|
|
||||||
.trim()
|
|
||||||
.replace(/[^a-zA-Z0-9.:[\]-]+/g, "");
|
|
||||||
return normalized || "服务器地址";
|
|
||||||
}
|
|
||||||
|
|
||||||
function createEmptySettingsForm() {
|
function createEmptySettingsForm() {
|
||||||
return {
|
return {
|
||||||
server: { host: "", port: 5200, https_mode: "direct", proxy_https_port: 0 },
|
server: { host: "", port: 5200, https_mode: "direct", proxy_https_port: 0 },
|
||||||
@@ -515,49 +446,6 @@ export function useDashboard() {
|
|||||||
return labels[value] || (value ? "未知" : "—");
|
return labels[value] || (value ? "未知" : "—");
|
||||||
}
|
}
|
||||||
|
|
||||||
function serverSSHKey(server) {
|
|
||||||
if (!server?.private_key_ref) return null;
|
|
||||||
return sshKeys.value.find((item) => item.reference === server.private_key_ref) || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function serverSSHKeyStatusLabel(server) {
|
|
||||||
const labels = {
|
|
||||||
not_configured: "未配置",
|
|
||||||
pending: "部署中",
|
|
||||||
deployed: "已部署并验证",
|
|
||||||
manual: "已配置,待验证",
|
|
||||||
failed: "部署失败,保留密码回退",
|
|
||||||
};
|
|
||||||
return labels[server?.ssh_key_status] || "未配置";
|
|
||||||
}
|
|
||||||
|
|
||||||
function serverSSHKeyStatusClass(server) {
|
|
||||||
if (server?.ssh_key_status === "deployed") return "success";
|
|
||||||
if (server?.ssh_key_status === "failed") return "danger";
|
|
||||||
if (server?.ssh_key_status === "pending") return "warning";
|
|
||||||
return "neutral";
|
|
||||||
}
|
|
||||||
|
|
||||||
function serverSSHCommand(server) {
|
|
||||||
if (!server?.address || !server?.username) return "—";
|
|
||||||
const port = Number(server.port || 22);
|
|
||||||
const portOption = port === 22 ? "" : ` -p ${port}`;
|
|
||||||
return `ssh${portOption} ${server.username}@${server.address}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function serverSSHKeyHint(server) {
|
|
||||||
if (server?.ssh_key_status === "deployed") {
|
|
||||||
return "Scert 已自动部署公钥并验证密钥登录,后续部署默认使用托管私钥。";
|
|
||||||
}
|
|
||||||
if (server?.ssh_key_status === "failed") {
|
|
||||||
return server.ssh_key_error || "公钥部署或密钥登录验证失败,当前仍使用密码回退。";
|
|
||||||
}
|
|
||||||
if (server?.auth_method === "private_key") {
|
|
||||||
return "当前使用已配置的私钥连接,尚未完成自动部署验证。";
|
|
||||||
}
|
|
||||||
return "保存服务器后,Scert 会先用密码部署公钥,再自动验证密钥登录。";
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatDate(value) {
|
function formatDate(value) {
|
||||||
if (!value) return "尚未签发";
|
if (!value) return "尚未签发";
|
||||||
return new Intl.DateTimeFormat("zh-CN", {
|
return new Intl.DateTimeFormat("zh-CN", {
|
||||||
@@ -599,6 +487,7 @@ export function useDashboard() {
|
|||||||
serverEditingId.value = item.id;
|
serverEditingId.value = item.id;
|
||||||
serverForm.value = {
|
serverForm.value = {
|
||||||
...item,
|
...item,
|
||||||
|
auth_method: "password",
|
||||||
passwordConfigured: item.password_configured === true,
|
passwordConfigured: item.password_configured === true,
|
||||||
password: "",
|
password: "",
|
||||||
validation_command: (item.validation_command || []).join("\n"),
|
validation_command: (item.validation_command || []).join("\n"),
|
||||||
@@ -611,101 +500,10 @@ export function useDashboard() {
|
|||||||
|
|
||||||
function closeServerForm() {
|
function closeServerForm() {
|
||||||
if (!serverSaving.value) {
|
if (!serverSaving.value) {
|
||||||
showEmbeddedSSHKeyGuide.value = false;
|
|
||||||
showServerForm.value = false;
|
showServerForm.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openSSHKeyCreate(options = {}) {
|
|
||||||
sshKeyForm.value = createEmptySSHKeyForm();
|
|
||||||
sshKeyFormError.value = "";
|
|
||||||
sshKeyPlatform.value = "windows";
|
|
||||||
sshKeyPassphraseVisible.value = false;
|
|
||||||
sshKeyRandomSuffix.value = createSSHKeyRandomSuffix();
|
|
||||||
sshKeyForm.value.name = sshKeyFileName.value;
|
|
||||||
showEmbeddedSSHKeyGuide.value = options.embedded === true;
|
|
||||||
showSSHKeyForm.value = options.embedded !== true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeSSHKeyForm() {
|
|
||||||
if (sshKeySaving.value) return;
|
|
||||||
sshKeyForm.value = createEmptySSHKeyForm();
|
|
||||||
sshKeyFormError.value = "";
|
|
||||||
sshKeyPassphraseVisible.value = false;
|
|
||||||
showEmbeddedSSHKeyGuide.value = false;
|
|
||||||
showSSHKeyForm.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importSSHKeyFile(event) {
|
|
||||||
const file = event.target.files?.[0];
|
|
||||||
event.target.value = "";
|
|
||||||
if (!file) return;
|
|
||||||
try {
|
|
||||||
const content = await file.text();
|
|
||||||
if (!content.trim()) throw new Error("选择的私钥文件为空");
|
|
||||||
sshKeyForm.value.private_key = content;
|
|
||||||
sshKeyFormError.value = "";
|
|
||||||
notice.value = `已读取私钥文件:${file.name}`;
|
|
||||||
} catch (err) {
|
|
||||||
sshKeyFormError.value = err.message || "读取私钥文件失败";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function copySSHKeyCommand(value, message) {
|
|
||||||
try {
|
|
||||||
await navigator.clipboard.writeText(value);
|
|
||||||
notice.value = message;
|
|
||||||
} catch {
|
|
||||||
sshKeyFormError.value = "浏览器未允许访问剪贴板,请手动复制命令";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function saveSSHKey() {
|
|
||||||
sshKeyFormError.value = "";
|
|
||||||
sshKeySaving.value = true;
|
|
||||||
try {
|
|
||||||
const response = await fetchAdmin("/api/v1/ssh-keys", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify(sshKeyForm.value),
|
|
||||||
});
|
|
||||||
const result = await response.json().catch(() => ({}));
|
|
||||||
if (!response.ok) throw new Error(result.error || "保存 SSH 私钥失败");
|
|
||||||
if (showEmbeddedSSHKeyGuide.value && result.reference) {
|
|
||||||
serverForm.value.private_key_ref = result.reference;
|
|
||||||
}
|
|
||||||
sshKeyForm.value = createEmptySSHKeyForm();
|
|
||||||
showEmbeddedSSHKeyGuide.value = false;
|
|
||||||
showSSHKeyForm.value = false;
|
|
||||||
notice.value = "SSH 私钥已加密保存";
|
|
||||||
await loadData();
|
|
||||||
} catch (err) {
|
|
||||||
sshKeyFormError.value = err.message || "保存 SSH 私钥失败";
|
|
||||||
} finally {
|
|
||||||
sshKeySaving.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteSSHKey(item) {
|
|
||||||
if (
|
|
||||||
!window.confirm(
|
|
||||||
`确定删除 SSH 私钥“${item.name}”吗?正在被服务器使用的私钥无法删除。`,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
try {
|
|
||||||
const response = await fetchAdmin(`/api/v1/ssh-keys/${item.id}`, {
|
|
||||||
method: "DELETE",
|
|
||||||
});
|
|
||||||
const result = await response.json().catch(() => ({}));
|
|
||||||
if (!response.ok) throw new Error(result.error || "删除 SSH 私钥失败");
|
|
||||||
notice.value = "SSH 私钥已删除";
|
|
||||||
await loadData();
|
|
||||||
} catch (err) {
|
|
||||||
error.value = err.message || "删除 SSH 私钥失败";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCommand(value) {
|
function parseCommand(value) {
|
||||||
return value
|
return value
|
||||||
.split(/\n/)
|
.split(/\n/)
|
||||||
@@ -722,8 +520,7 @@ export function useDashboard() {
|
|||||||
address: serverForm.value.address,
|
address: serverForm.value.address,
|
||||||
port: Number(serverForm.value.port),
|
port: Number(serverForm.value.port),
|
||||||
username: serverForm.value.username,
|
username: serverForm.value.username,
|
||||||
auth_method: serverForm.value.auth_method,
|
auth_method: "password",
|
||||||
private_key_ref: serverForm.value.private_key_ref,
|
|
||||||
host_key_fingerprint: serverForm.value.host_key_fingerprint,
|
host_key_fingerprint: serverForm.value.host_key_fingerprint,
|
||||||
certificate_path: serverForm.value.certificate_path,
|
certificate_path: serverForm.value.certificate_path,
|
||||||
private_key_path: serverForm.value.private_key_path,
|
private_key_path: serverForm.value.private_key_path,
|
||||||
@@ -732,9 +529,7 @@ export function useDashboard() {
|
|||||||
validation_command: parseCommand(serverForm.value.validation_command),
|
validation_command: parseCommand(serverForm.value.validation_command),
|
||||||
reload_command: parseCommand(serverForm.value.reload_command),
|
reload_command: parseCommand(serverForm.value.reload_command),
|
||||||
};
|
};
|
||||||
if (serverForm.value.auth_method === "password") {
|
payload.password = serverForm.value.password;
|
||||||
payload.password = serverForm.value.password;
|
|
||||||
}
|
|
||||||
const path = serverEditingId.value
|
const path = serverEditingId.value
|
||||||
? `/api/v1/servers/${serverEditingId.value}`
|
? `/api/v1/servers/${serverEditingId.value}`
|
||||||
: "/api/v1/servers";
|
: "/api/v1/servers";
|
||||||
@@ -768,7 +563,7 @@ export function useDashboard() {
|
|||||||
try {
|
try {
|
||||||
const options = { method: "POST" };
|
const options = { method: "POST" };
|
||||||
if (action === "issue") {
|
if (action === "issue") {
|
||||||
const suffix = crypto.randomUUID ? crypto.randomUUID() : createSSHKeyRandomSuffix();
|
const suffix = crypto.randomUUID ? crypto.randomUUID() : createRandomSuffix();
|
||||||
options.headers = { "Idempotency-Key": `issue-${item.id}-${suffix}` };
|
options.headers = { "Idempotency-Key": `issue-${item.id}-${suffix}` };
|
||||||
}
|
}
|
||||||
const response = await fetchAdmin(`/api/v1/domains/${item.id}/${action}`, options);
|
const response = await fetchAdmin(`/api/v1/domains/${item.id}/${action}`, options);
|
||||||
@@ -1152,7 +947,6 @@ export function useDashboard() {
|
|||||||
authResponse,
|
authResponse,
|
||||||
domainResponse,
|
domainResponse,
|
||||||
serverResponse,
|
serverResponse,
|
||||||
sshKeyResponse,
|
|
||||||
certificateResponse,
|
certificateResponse,
|
||||||
taskResponse,
|
taskResponse,
|
||||||
auditResponse,
|
auditResponse,
|
||||||
@@ -1163,7 +957,6 @@ export function useDashboard() {
|
|||||||
fetchAdmin("/api/v1/auth/session"),
|
fetchAdmin("/api/v1/auth/session"),
|
||||||
fetchAdmin("/api/v1/domains"),
|
fetchAdmin("/api/v1/domains"),
|
||||||
fetchAdmin("/api/v1/servers"),
|
fetchAdmin("/api/v1/servers"),
|
||||||
fetchAdmin("/api/v1/ssh-keys"),
|
|
||||||
fetchAdmin("/api/v1/certificates"),
|
fetchAdmin("/api/v1/certificates"),
|
||||||
fetchAdmin("/api/v1/tasks?limit=20"),
|
fetchAdmin("/api/v1/tasks?limit=20"),
|
||||||
fetchAdmin("/api/v1/audit-logs?limit=20"),
|
fetchAdmin("/api/v1/audit-logs?limit=20"),
|
||||||
@@ -1174,7 +967,6 @@ export function useDashboard() {
|
|||||||
statusResponse,
|
statusResponse,
|
||||||
domainResponse,
|
domainResponse,
|
||||||
serverResponse,
|
serverResponse,
|
||||||
sshKeyResponse,
|
|
||||||
certificateResponse,
|
certificateResponse,
|
||||||
taskResponse,
|
taskResponse,
|
||||||
auditResponse,
|
auditResponse,
|
||||||
@@ -1188,7 +980,6 @@ export function useDashboard() {
|
|||||||
currentUser.value = await authResponse.json();
|
currentUser.value = await authResponse.json();
|
||||||
domains.value = (await domainResponse.json()).items || [];
|
domains.value = (await domainResponse.json()).items || [];
|
||||||
servers.value = (await serverResponse.json()).items || [];
|
servers.value = (await serverResponse.json()).items || [];
|
||||||
sshKeys.value = (await sshKeyResponse.json()).items || [];
|
|
||||||
certificates.value = (await certificateResponse.json()).items || [];
|
certificates.value = (await certificateResponse.json()).items || [];
|
||||||
tasks.value = (await taskResponse.json()).items || [];
|
tasks.value = (await taskResponse.json()).items || [];
|
||||||
auditLogs.value = (await auditResponse.json()).items || [];
|
auditLogs.value = (await auditResponse.json()).items || [];
|
||||||
@@ -1240,7 +1031,6 @@ export function useDashboard() {
|
|||||||
canRunRenewal,
|
canRunRenewal,
|
||||||
domains,
|
domains,
|
||||||
servers,
|
servers,
|
||||||
sshKeys,
|
|
||||||
certificates,
|
certificates,
|
||||||
tasks,
|
tasks,
|
||||||
auditLogs,
|
auditLogs,
|
||||||
@@ -1279,10 +1069,6 @@ export function useDashboard() {
|
|||||||
serverEditingId,
|
serverEditingId,
|
||||||
serverSaving,
|
serverSaving,
|
||||||
serverFormError,
|
serverFormError,
|
||||||
showSSHKeyForm,
|
|
||||||
showEmbeddedSSHKeyGuide,
|
|
||||||
sshKeySaving,
|
|
||||||
sshKeyFormError,
|
|
||||||
certificateTypeLabels,
|
certificateTypeLabels,
|
||||||
domainStatusLabels,
|
domainStatusLabels,
|
||||||
taskStatusLabels,
|
taskStatusLabels,
|
||||||
@@ -1295,24 +1081,10 @@ export function useDashboard() {
|
|||||||
environmentLabels,
|
environmentLabels,
|
||||||
webServerLabels,
|
webServerLabels,
|
||||||
serverAuthLabel,
|
serverAuthLabel,
|
||||||
serverSSHKey,
|
|
||||||
serverSSHKeyStatusLabel,
|
|
||||||
serverSSHKeyStatusClass,
|
|
||||||
serverSSHCommand,
|
|
||||||
serverSSHKeyHint,
|
|
||||||
isEditing,
|
isEditing,
|
||||||
formTitle,
|
formTitle,
|
||||||
form,
|
form,
|
||||||
serverForm,
|
serverForm,
|
||||||
sshKeyForm,
|
|
||||||
sshKeyPlatform,
|
|
||||||
sshKeyPassphraseVisible,
|
|
||||||
sshKeyCommandUsername,
|
|
||||||
sshKeyCommandHost,
|
|
||||||
sshKeyFileName,
|
|
||||||
sshKeyPath,
|
|
||||||
sshKeyPrivatePath,
|
|
||||||
sshKeyPublicPath,
|
|
||||||
showSettings,
|
showSettings,
|
||||||
settingsSaving,
|
settingsSaving,
|
||||||
settingsError,
|
settingsError,
|
||||||
@@ -1321,8 +1093,6 @@ export function useDashboard() {
|
|||||||
importSaving,
|
importSaving,
|
||||||
importError,
|
importError,
|
||||||
importResult,
|
importResult,
|
||||||
sshKeyCommands,
|
|
||||||
sshPublicKeyCommands,
|
|
||||||
defaultCertificatePath,
|
defaultCertificatePath,
|
||||||
defaultCertificateChainPath,
|
defaultCertificateChainPath,
|
||||||
defaultPrivateKeyPath,
|
defaultPrivateKeyPath,
|
||||||
@@ -1332,12 +1102,6 @@ export function useDashboard() {
|
|||||||
openServerCreate,
|
openServerCreate,
|
||||||
openServerEdit,
|
openServerEdit,
|
||||||
closeServerForm,
|
closeServerForm,
|
||||||
openSSHKeyCreate,
|
|
||||||
closeSSHKeyForm,
|
|
||||||
importSSHKeyFile,
|
|
||||||
copySSHKeyCommand,
|
|
||||||
saveSSHKey,
|
|
||||||
deleteSSHKey,
|
|
||||||
openCertificateImport,
|
openCertificateImport,
|
||||||
closeCertificateImport,
|
closeCertificateImport,
|
||||||
selectCertificateImportFile,
|
selectCertificateImportFile,
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ test("用户管理导航按权限显示,权限变化后回到基本信息", ()
|
|||||||
assert.equal(navigation.sections.value.length, 7);
|
assert.equal(navigation.sections.value.length, 7);
|
||||||
user.value = null;
|
user.value = null;
|
||||||
assert.equal(navigation.activeSection.value, "overview");
|
assert.equal(navigation.activeSection.value, "overview");
|
||||||
assert.equal(navigation.sections.value.length, 6);
|
assert.equal(navigation.sections.value.length, 5);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("单板块布局使用互斥条件,切换重置滚动且保留弹窗入口", async () => {
|
test("单板块布局使用互斥条件,切换重置滚动且保留弹窗入口", async () => {
|
||||||
@@ -308,24 +308,29 @@ test("编辑服务器正确保留已有密码状态,新建和未配置密码
|
|||||||
assert.equal(state.serverEditingId.value, "");
|
assert.equal(state.serverEditingId.value, "");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("SSH引导目标直接跟随服务器配置中的地址和用户", async (t) => {
|
test("部署服务器仅使用密码认证且不暴露私钥管理入口", async (t) => {
|
||||||
const { state } = await setup(t, () => verifiedResponse());
|
const requests = [];
|
||||||
|
const { state } = await mountComposable(t, useDashboard, async (path, options = {}) => {
|
||||||
|
if (options.method) {
|
||||||
|
requests.push({ path, ...options });
|
||||||
|
return Response.json({});
|
||||||
|
}
|
||||||
|
return verifiedResponse();
|
||||||
|
});
|
||||||
state.openServerCreate();
|
state.openServerCreate();
|
||||||
state.serverForm.value.username = "root";
|
assert.equal(state.serverForm.value.auth_method, "password");
|
||||||
state.serverForm.value.address = "45.136.13.241";
|
assert.equal("openSSHKeyCreate" in state, false);
|
||||||
state.openSSHKeyCreate({ embedded: true });
|
assert.equal("sshKeys" in state, false);
|
||||||
await nextTick();
|
state.serverForm.value.name = "生产服务器";
|
||||||
|
state.serverForm.value.address = "example.test";
|
||||||
assert.equal(state.sshKeyCommandUsername.value, "root");
|
|
||||||
assert.equal(state.sshKeyCommandHost.value, "45.136.13.241");
|
|
||||||
assert.equal(state.sshKeyForm.value.name, state.sshKeyFileName.value);
|
|
||||||
assert.match(state.sshPublicKeyCommands.value.windows, /ssh root@45\.136\.13\.241/);
|
|
||||||
assert.match(state.sshPublicKeyCommands.value.linux, /root@45\.136\.13\.241/);
|
|
||||||
|
|
||||||
state.sshKeyForm.value.name = "manual-key-name";
|
|
||||||
state.serverForm.value.username = "deploy";
|
state.serverForm.value.username = "deploy";
|
||||||
await nextTick();
|
state.serverForm.value.password = "test-password";
|
||||||
assert.equal(state.sshKeyForm.value.name, "manual-key-name");
|
state.serverForm.value.host_key_fingerprint = "SHA256:test";
|
||||||
|
await state.saveServer();
|
||||||
|
const payload = JSON.parse(requests.at(-1).body);
|
||||||
|
assert.equal(payload.auth_method, "password");
|
||||||
|
assert.equal(payload.password, "test-password");
|
||||||
|
assert.equal("private_key_ref" in payload, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function fill(state) {
|
async function fill(state) {
|
||||||
@@ -712,7 +717,6 @@ test("serverModal.compilesAndPreservesDeploymentFields", async () => {
|
|||||||
address: "example.test",
|
address: "example.test",
|
||||||
port: 22,
|
port: 22,
|
||||||
username: "deploy",
|
username: "deploy",
|
||||||
private_key_ref: "key-ref",
|
|
||||||
host_key_fingerprint: "SHA256:test-fingerprint",
|
host_key_fingerprint: "SHA256:test-fingerprint",
|
||||||
certificate_path: "/test/cert.pem",
|
certificate_path: "/test/cert.pem",
|
||||||
certificate_chain_path: "/test/fullchain.pem",
|
certificate_chain_path: "/test/fullchain.pem",
|
||||||
@@ -720,25 +724,6 @@ test("serverModal.compilesAndPreservesDeploymentFields", async () => {
|
|||||||
validation_command: "nginx\n-t",
|
validation_command: "nginx\n-t",
|
||||||
reload_command: "nginx\n-s\nreload",
|
reload_command: "nginx\n-s\nreload",
|
||||||
},
|
},
|
||||||
sshKeys: [],
|
|
||||||
openSSHKeyCreate: () => {},
|
|
||||||
showEmbeddedSSHKeyGuide: false,
|
|
||||||
closeSSHKeyForm: () => {},
|
|
||||||
sshKeySaving: false,
|
|
||||||
sshKeyFormError: "",
|
|
||||||
sshKeyPlatform: "windows",
|
|
||||||
sshKeyFileName: "test-key",
|
|
||||||
sshKeyPrivatePath: "/test/private",
|
|
||||||
sshKeyPublicPath: "/test/public",
|
|
||||||
sshKeyCommandUsername: "deploy",
|
|
||||||
sshKeyCommandHost: "example.test",
|
|
||||||
sshKeyCommands: { windows: "generate-windows", linux: "generate-linux" },
|
|
||||||
sshPublicKeyCommands: { windows: "install-windows", linux: "install-linux" },
|
|
||||||
sshKeyForm: { name: "", private_key: "", passphrase: "" },
|
|
||||||
importSSHKeyFile: () => {},
|
|
||||||
sshKeyPassphraseVisible: false,
|
|
||||||
copySSHKeyCommand: () => {},
|
|
||||||
saveSSHKey: () => {},
|
|
||||||
defaultCertificatePath: "",
|
defaultCertificatePath: "",
|
||||||
defaultCertificateChainPath: "",
|
defaultCertificateChainPath: "",
|
||||||
defaultPrivateKeyPath: "",
|
defaultPrivateKeyPath: "",
|
||||||
@@ -789,67 +774,7 @@ test("changePassword.loadsScopedBaseStylesAndCompiles", async () => {
|
|||||||
assert.match(base, /\.field\s*\{/);
|
assert.match(base, /\.field\s*\{/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("sshKeyModal.compilesAndPreservesCredentialFields", async () => {
|
test("domainAction.refreshesPersistedFailureWithoutLosingError", async (t) => {
|
||||||
const { readFile } = await import("node:fs/promises");
|
|
||||||
const { parse, compileScript, compileTemplate } = await import("@vue/compiler-sfc");
|
|
||||||
const { renderToString } = await import("@vue/server-renderer");
|
|
||||||
const Vue = await import("vue");
|
|
||||||
const source = await readFile(new URL("./SSHKeyModal.vue", import.meta.url), "utf8");
|
|
||||||
const { descriptor, errors } = parse(source);
|
|
||||||
assert.deepEqual(errors, []);
|
|
||||||
assert.ok(compileScript(descriptor, { id: "ssh-key-modal" }));
|
|
||||||
const compiled = compileTemplate({
|
|
||||||
source: descriptor.template.content,
|
|
||||||
filename: "SSHKeyModal.vue",
|
|
||||||
id: "ssh-key-modal",
|
|
||||||
compilerOptions: { mode: "function" },
|
|
||||||
});
|
|
||||||
assert.deepEqual(compiled.errors, []);
|
|
||||||
assert.ok(descriptor.styles.some(style => style.scoped && style.src === "./Dashboard.css"));
|
|
||||||
assert.ok(descriptor.styles.some(style => style.scoped && style.src === "./SSHKeyModal.css"));
|
|
||||||
assert.doesNotMatch(source, /<HelpTip\s+class=/);
|
|
||||||
const render = new Function("Vue", compiled.code)(Vue);
|
|
||||||
for (const platform of ["windows", "linux"]) {
|
|
||||||
const app = Vue.createSSRApp({
|
|
||||||
render,
|
|
||||||
setup: () => ({
|
|
||||||
showSSHKeyForm: true,
|
|
||||||
closeSSHKeyForm: () => {},
|
|
||||||
saveSSHKey: () => {},
|
|
||||||
sshKeyPlatform: platform,
|
|
||||||
sshKeyFileName: "test-key",
|
|
||||||
sshKeyPrivatePath: "/test/private",
|
|
||||||
sshKeyPublicPath: "/test/public",
|
|
||||||
sshKeyCommandUsername: "deploy",
|
|
||||||
sshKeyCommandHost: "example.test",
|
|
||||||
copySSHKeyCommand: () => {},
|
|
||||||
sshKeyCommands: { windows: "generate-windows", linux: "generate-linux" },
|
|
||||||
sshPublicKeyCommands: { windows: "install-windows", linux: "install-linux" },
|
|
||||||
sshKeyForm: { name: "", private_key: "", passphrase: "" },
|
|
||||||
importSSHKeyFile: () => {},
|
|
||||||
sshKeyPassphraseVisible: false,
|
|
||||||
sshKeyFormError: "test-validation-error",
|
|
||||||
sshKeySaving: false,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
app.component("HelpTip", {
|
|
||||||
setup: (_, { slots }) => () => Vue.h("span", { class: "test-help-tip" }, slots.default?.()),
|
|
||||||
});
|
|
||||||
const html = await renderToString(app);
|
|
||||||
assert.match(html, /class="modal-card ssh-key-modal"/);
|
|
||||||
assert.match(html, /type="submit"/);
|
|
||||||
assert.match(html, /type="file"/);
|
|
||||||
assert.match(html, /type="password"/);
|
|
||||||
assert.match(html, /rows="5"/);
|
|
||||||
assert.match(html, /test-validation-error/);
|
|
||||||
assert.equal((html.match(/ required/g) || []).length, 2);
|
|
||||||
assert.ok(html.includes(`generate-${platform}`));
|
|
||||||
assert.ok(html.includes(`install-${platform}`));
|
|
||||||
assert.ok(html.includes("deploy@example.test"));
|
|
||||||
}
|
|
||||||
const css = await readFile(new URL("./SSHKeyModal.css", import.meta.url), "utf8");
|
|
||||||
assert.match(css, /\.ssh-key-modal\s*\{[^}]*overflow:\s*auto;/);
|
|
||||||
});test("domainAction.refreshesPersistedFailureWithoutLosingError", async (t) => {
|
|
||||||
let issued = false;
|
let issued = false;
|
||||||
const { state } = await mountComposable(t, useDashboard, async (path) => {
|
const { state } = await mountComposable(t, useDashboard, async (path) => {
|
||||||
if (path.endsWith("/issue")) {
|
if (path.endsWith("/issue")) {
|
||||||
|
|||||||
@@ -385,107 +385,6 @@ const { activeSection, activeLabel, sections, selectSection } = useDashboardNavi
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section v-if="activeSection === 'keys'" class="panel server-panel">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<div>
|
|
||||||
<p class="eyebrow">安全凭据</p>
|
|
||||||
<h2>服务器 SSH 密钥</h2>
|
|
||||||
</div>
|
|
||||||
<button class="secondary-button" type="button" @click="openServerCreate">
|
|
||||||
添加部署服务器
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div v-if="servers.length === 0" class="empty-state">
|
|
||||||
<strong>还没有部署服务器</strong>
|
|
||||||
<span>添加服务器后,Scert 会自动生成密钥、部署公钥并验证密钥登录。</span>
|
|
||||||
<button class="primary-button" type="button" @click="openServerCreate">
|
|
||||||
添加部署服务器
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div v-else class="ssh-server-list">
|
|
||||||
<article v-for="item in servers" :key="item.id" class="ssh-server-card">
|
|
||||||
<div class="ssh-server-card-heading">
|
|
||||||
<div class="domain-title-line">
|
|
||||||
<strong>{{ item.name }}</strong>
|
|
||||||
<span class="tag">{{ displayLabel(webServerLabels, item.web_server) }}</span>
|
|
||||||
<span :class="['tag', serverSSHKeyStatusClass(item)]">
|
|
||||||
{{ serverSSHKeyStatusLabel(item) }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="row-actions">
|
|
||||||
<button class="text-button" type="button" @click="openServerEdit(item)">
|
|
||||||
编辑
|
|
||||||
</button>
|
|
||||||
<button class="text-button danger-text" type="button" @click="deleteServer(item)">
|
|
||||||
删除
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="ssh-server-meta">
|
|
||||||
<span>{{ item.username }}@{{ item.address }}:{{ item.port }}</span>
|
|
||||||
<span>主机指纹:{{ item.host_key_fingerprint || "未填写" }}</span>
|
|
||||||
<span>认证:{{ serverAuthLabel(item) }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="ssh-server-domain-bindings">
|
|
||||||
<span class="detail-label">托管域名</span>
|
|
||||||
<div v-if="(serverDomains[item.id] || []).length > 0" class="ssh-server-domain-list">
|
|
||||||
<span v-for="domain in serverDomains[item.id]" :key="domain.id" class="tag neutral">
|
|
||||||
{{ domain.name }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<span v-else class="muted">未关联托管域名</span>
|
|
||||||
</div>
|
|
||||||
<div class="ssh-server-details">
|
|
||||||
<div class="ssh-server-detail">
|
|
||||||
<span class="detail-label">托管私钥</span>
|
|
||||||
<strong>{{ serverSSHKey(item)?.name || "尚未生成" }}</strong>
|
|
||||||
<code>{{ serverSSHKey(item)?.fingerprint || item.ssh_key_fingerprint || "—" }}</code>
|
|
||||||
</div>
|
|
||||||
<div class="ssh-server-detail">
|
|
||||||
<span class="detail-label">公钥部署</span>
|
|
||||||
<strong>{{ serverSSHKeyStatusLabel(item) }}</strong>
|
|
||||||
<span>{{ serverSSHKeyHint(item) }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="ssh-server-detail">
|
|
||||||
<span class="detail-label">最近部署 / 测试</span>
|
|
||||||
<span>{{ formatDate(item.ssh_key_deployed_at) }} / {{ formatDate(item.ssh_key_tested_at) }}</span>
|
|
||||||
<span v-if="item.ssh_key_error" class="form-error inline-error">{{ item.ssh_key_error }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="ssh-server-command">
|
|
||||||
<div>
|
|
||||||
<span class="detail-label">服务器 SSH 命令</span>
|
|
||||||
<code>{{ serverSSHCommand(item) }}</code>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
class="inline-button"
|
|
||||||
type="button"
|
|
||||||
@click="copySSHKeyCommand(serverSSHCommand(item), '服务器 SSH 命令已复制')"
|
|
||||||
>
|
|
||||||
复制命令
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</div>
|
|
||||||
<div v-if="servers.length > 0 && sshKeys.length > 0" class="ssh-orphaned-keys">
|
|
||||||
<div class="ssh-orphaned-heading">
|
|
||||||
<div>
|
|
||||||
<span class="eyebrow">兼容入口</span>
|
|
||||||
<strong>未关联服务器的私钥</strong>
|
|
||||||
</div>
|
|
||||||
<button class="inline-button" type="button" @click="openSSHKeyCreate">
|
|
||||||
添加私钥
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="ssh-orphaned-list">
|
|
||||||
<span v-for="item in sshKeys.filter((key) => !servers.some((server) => server.private_key_ref === key.reference))" :key="item.id" class="ssh-orphaned-item">
|
|
||||||
{{ item.name }} · {{ item.fingerprint }}
|
|
||||||
<button class="text-button danger-text" type="button" @click="deleteSSHKey(item)">删除</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section v-if="activeSection === 'servers'" class="panel server-panel">
|
<section v-if="activeSection === 'servers'" class="panel server-panel">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<div>
|
<div>
|
||||||
@@ -507,14 +406,10 @@ const { activeSection, activeLabel, sections, selectSection } = useDashboardNavi
|
|||||||
<div class="domain-title-line">
|
<div class="domain-title-line">
|
||||||
<strong>{{ item.name }}</strong
|
<strong>{{ item.name }}</strong
|
||||||
><span class="tag">{{ displayLabel(webServerLabels, item.web_server) }}</span>
|
><span class="tag">{{ displayLabel(webServerLabels, item.web_server) }}</span>
|
||||||
><span :class="['tag', serverSSHKeyStatusClass(item)]">
|
|
||||||
{{ serverSSHKeyStatusLabel(item) }}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="domain-meta">
|
<div class="domain-meta">
|
||||||
<span>{{ item.username }}@{{ item.address }}:{{ item.port }}</span
|
<span>{{ item.username }}@{{ item.address }}:{{ item.port }}</span
|
||||||
><span>{{ serverAuthLabel(item) }}</span
|
><span>{{ serverAuthLabel(item) }}</span
|
||||||
><span>托管私钥:{{ serverSSHKey(item)?.name || "尚未生成" }}</span
|
|
||||||
><span>指纹:{{ item.host_key_fingerprint }}</span>
|
><span>指纹:{{ item.host_key_fingerprint }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
export function serverAuthLabel(server) {
|
export function serverAuthLabel(server) {
|
||||||
if (server.auth_method === "password") {
|
return server.password_configured ? "SSH 密码已配置" : "SSH 密码未配置";
|
||||||
return server.password_configured ? "SSH 密码已配置" : "SSH 密码未配置";
|
|
||||||
}
|
|
||||||
if (server.auth_method === "private_key") {
|
|
||||||
return server.private_key_ref ? "SSH 私钥已配置" : "SSH 私钥未配置";
|
|
||||||
}
|
|
||||||
return "认证方式未确认";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deploymentSummary(report) {
|
export function deploymentSummary(report) {
|
||||||
|
|||||||
@@ -14,12 +14,11 @@ const report = {
|
|||||||
results: [{ server_id: "server-1", server: "验收服务器", status: "success", message: "部署完成" }],
|
results: [{ server_id: "server-1", server: "验收服务器", status: "success", message: "部署完成" }],
|
||||||
};
|
};
|
||||||
|
|
||||||
test("服务器认证提示区分密码、私钥及缺失配置", () => {
|
test("服务器认证提示只显示密码配置状态", () => {
|
||||||
assert.equal(serverAuthLabel({ auth_method: "password", password_configured: true }), "SSH 密码已配置");
|
assert.equal(serverAuthLabel({ auth_method: "password", password_configured: true }), "SSH 密码已配置");
|
||||||
assert.equal(serverAuthLabel({ auth_method: "password", private_key_ref: "secret://test" }), "SSH 密码未配置");
|
assert.equal(serverAuthLabel({ auth_method: "password", password_configured: false }), "SSH 密码未配置");
|
||||||
assert.equal(serverAuthLabel({ auth_method: "private_key", private_key_ref: "secret://test" }), "SSH 私钥已配置");
|
assert.equal(serverAuthLabel({ auth_method: "private_key", password_configured: false }), "SSH 密码未配置");
|
||||||
assert.equal(serverAuthLabel({ auth_method: "private_key" }), "SSH 私钥未配置");
|
assert.equal(serverAuthLabel({}), "SSH 密码未配置");
|
||||||
assert.equal(serverAuthLabel({}), "认证方式未确认");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("部署汇总不把空目标、缺失结果或部分失败称为成功", () => {
|
test("部署汇总不把空目标、缺失结果或部分失败称为成功", () => {
|
||||||
@@ -145,6 +144,5 @@ test("部署结果组件可编译且认证提示绑定真实配置", async () =>
|
|||||||
assert.match(source, /role="dialog"/);
|
assert.match(source, /role="dialog"/);
|
||||||
const dashboard = await readFile(new URL("./Dashboard.vue", import.meta.url), "utf8");
|
const dashboard = await readFile(new URL("./Dashboard.vue", import.meta.url), "utf8");
|
||||||
assert.match(dashboard, /serverAuthLabel\(item\)/);
|
assert.match(dashboard, /serverAuthLabel\(item\)/);
|
||||||
assert.match(dashboard, /serverSSHKeyStatusLabel\(item\)/);
|
assert.doesNotMatch(dashboard, /serverSSHKeyStatusLabel|serverSSHCommand|SSHKeyModal/);
|
||||||
assert.match(dashboard, /serverSSHCommand\(item\)/);
|
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user