mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-24 22:51:19 +08:00
fix: Optimize SSH key synchronization (#9833)
This commit is contained in:
parent
8542323c0b
commit
0f138c1b7c
12 changed files with 30 additions and 21 deletions
|
|
@ -2,7 +2,6 @@ package repo
|
|||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/agent/app/model"
|
||||
"github.com/1Panel-dev/1Panel/agent/constant"
|
||||
"github.com/1Panel-dev/1Panel/agent/global"
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/encrypt"
|
||||
)
|
||||
|
|
@ -144,7 +143,7 @@ func (u *HostRepo) SyncCert(data []model.RootCert) error {
|
|||
}
|
||||
}
|
||||
for _, val := range oldCertsMap {
|
||||
if err := tx.Model(&model.RootCert{}).Where("id = ?", val).Updates(map[string]interface{}{"status": constant.StatusDeleted}).Error; err != nil {
|
||||
if err := tx.Where("id = ?", val).Delete(&model.RootCert{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,11 +235,6 @@ func (u *SSHService) SyncRootCert() error {
|
|||
return fmt.Errorf("load current user failed, err: %v", err)
|
||||
}
|
||||
sshDir := fmt.Sprintf("%s/.ssh", currentUser.HomeDir)
|
||||
authFilePath := currentUser.HomeDir + "/.ssh/authorized_keys"
|
||||
authItem, err := os.ReadFile(authFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileList, err := os.ReadDir(sshDir)
|
||||
if err != nil {
|
||||
|
|
@ -266,10 +261,6 @@ func (u *SSHService) SyncRootCert() error {
|
|||
continue
|
||||
}
|
||||
cert.EncryptionMode = loadEncryptioMode(string(pubItem))
|
||||
if !bytes.Contains(authItem, pubItem) {
|
||||
global.LOG.Error("the public key is not in authorized_keys, skip...")
|
||||
continue
|
||||
}
|
||||
rootCerts = append(rootCerts, cert)
|
||||
}
|
||||
return hostRepo.SyncCert(rootCerts)
|
||||
|
|
|
|||
|
|
@ -1533,6 +1533,7 @@ const message = {
|
|||
createMode: 'Creation Method',
|
||||
generate: 'Auto-generate',
|
||||
unSyncPass: 'Key password cannot be synchronized',
|
||||
syncHelper: 'The sync operation will clean invalid keys and sync new complete key pairs. Continue?',
|
||||
input: 'Manual Input',
|
||||
import: 'File Upload',
|
||||
pubkey: 'Key info',
|
||||
|
|
|
|||
|
|
@ -1477,6 +1477,7 @@ const message = {
|
|||
createMode: '作成方法',
|
||||
generate: '自動生成',
|
||||
unSyncPass: '鍵パスワードは同期できません',
|
||||
syncHelper: '同期操作は無効なキーをクリーンアップし、新しい完全なキーペアを同期します。続行しますか?',
|
||||
input: '手動入力',
|
||||
import: 'ファイルアップロード',
|
||||
pubkey: '重要な情報',
|
||||
|
|
|
|||
|
|
@ -1461,6 +1461,7 @@ const message = {
|
|||
createMode: '생성 방식',
|
||||
generate: '자동 생성',
|
||||
unSyncPass: '키 비밀번호 동기화 불가',
|
||||
syncHelper: '동기화 작업으로 유효하지 않은 키를 정리하고 새로운 완전한 키 쌍을 동기화합니다. 계속하시겠습니까?',
|
||||
input: '수동 입력',
|
||||
import: '파일 업로드',
|
||||
pubkey: '키 정보',
|
||||
|
|
|
|||
|
|
@ -1519,6 +1519,8 @@ const message = {
|
|||
createMode: 'Kaedah Penciptaan',
|
||||
generate: 'Jana Automatik',
|
||||
unSyncPass: 'Kata laluan kunci tidak dapat diselaraskan',
|
||||
syncHelper:
|
||||
'Operasi segerak akan membersihkan kunci tidak sah dan menyegerakkan pasangan kunci baru yang lengkap. Teruskan?',
|
||||
input: 'Input Manual',
|
||||
import: 'Muat Naik Fail',
|
||||
pubkey: 'Maklumat kunci',
|
||||
|
|
|
|||
|
|
@ -1507,6 +1507,8 @@ const message = {
|
|||
createMode: 'Método de Criação',
|
||||
generate: 'Gerar Automaticamente',
|
||||
unSyncPass: 'Senha da chave não pode ser sincronizada',
|
||||
syncHelper:
|
||||
'A operação de sincronização limpará chaves inválidas e sincronizará novos pares de chaves completos. Continuar?',
|
||||
input: 'Entrada Manual',
|
||||
import: 'Upload de Arquivo',
|
||||
pubkey: 'Informações da chave',
|
||||
|
|
|
|||
|
|
@ -1508,6 +1508,8 @@ const message = {
|
|||
createMode: 'Способ создания',
|
||||
generate: 'Автогенерация',
|
||||
unSyncPass: 'Пароль ключа не может быть синхронизирован',
|
||||
syncHelper:
|
||||
'Операция синхронизации удалит недействительные ключи и синхронизирует новые полные ключевые пары. Продолжить?',
|
||||
input: 'Ручной ввод',
|
||||
import: 'Загрузка файла',
|
||||
pubkey: 'Информация о ключе',
|
||||
|
|
|
|||
|
|
@ -1551,6 +1551,8 @@ const message = {
|
|||
createMode: 'Oluşturma Yöntemi',
|
||||
generate: 'Otomatik Oluştur',
|
||||
unSyncPass: 'Anahtar parolası senkronize edilemez',
|
||||
syncHelper:
|
||||
'Eşitleme işlemi geçersiz anahtarları temizleyecek ve yeni tam anahtar çiftlerini eşitleyecek. Devam edilsin mi?',
|
||||
input: 'Manuel Giriş',
|
||||
import: 'Dosya Yükleme',
|
||||
pubkey: 'Anahtar bilgisi',
|
||||
|
|
|
|||
|
|
@ -1460,6 +1460,7 @@ const message = {
|
|||
createMode: '創建方式',
|
||||
generate: '自動生成',
|
||||
unSyncPass: '密鑰密碼無法同步',
|
||||
syncHelper: '同步操作將清理失效密鑰並同步新增的完整密鑰對,是否繼續?',
|
||||
input: '手動輸入',
|
||||
import: '文件上傳',
|
||||
pubkey: '密鑰信息',
|
||||
|
|
|
|||
|
|
@ -1455,6 +1455,7 @@ const message = {
|
|||
createMode: '创建方式',
|
||||
generate: '自动生成',
|
||||
unSyncPass: '密钥密码无法同步',
|
||||
syncHelper: '同步操作将清理失效密钥并同步新增的完整密钥对,是否继续?',
|
||||
input: '手动输入',
|
||||
import: '文件上传',
|
||||
pubkey: '密钥信息',
|
||||
|
|
|
|||
|
|
@ -393,16 +393,22 @@ const search = async () => {
|
|||
};
|
||||
|
||||
const onSync = async () => {
|
||||
loading.value = true;
|
||||
await syncCert()
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
search();
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
ElMessageBox.confirm(i18n.global.t('ssh.syncHelper'), i18n.global.t('commons.button.sync'), {
|
||||
confirmButtonText: i18n.global.t('commons.button.confirm'),
|
||||
cancelButtonText: i18n.global.t('commons.button.cancel'),
|
||||
type: 'info',
|
||||
}).then(async () => {
|
||||
loading.value = true;
|
||||
await syncCert()
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
search();
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const onDelete = async (row: Host.RootCertInfo | null) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue