반응형
Credential 설정 복호화하는 방법을 쉘 스크립트를 통해 만들어 보았다.
decrypt_xml.sh
1. show_menu 함수 : 번호를 클릭해 복호화 할 Credential 종류를 지정한다.
2. decrypted 함수 : 실제 복호화 하는 부분으로 case 문을 통해 show_menu에서 입력 받은 값을 기준으로 kind 변수를 설정하여 기존파일 및 복호화 파일 저장 위치를 지정하여 복호화한다.
#!/bin/bash
show_menu(){
normal=`echo "\033[m"`
menu=`echo "\033[36m"` #Blue
number=`echo "\033[33m"` #yellow
bgred=`echo "\033[41m"`
fgred=`echo "\033[31m"`
printf "\n${menu}*********************************************${normal}\n"
printf "${menu}**${number} 1)${menu} Username with password ${normal}\n"
printf "${menu}**${number} 2)${menu} Google Service Account from private key ${normal}\n"
printf "${menu}**${number} 3)${menu} Secret text ${normal}\n"
printf "${menu}**${number} 4)${menu} Secret file ${normal}\n"
printf "${menu}**${number} 5)${menu} AWS Credential ${normal}\n"
printf "${menu}**${number} 6)${menu} tt15 ${normal}\n"
printf "${menu}*********************************************${normal}\n"
printf "Please enter a menu option and enter or ${fgred}x to exit. ${normal}"
read opt
}
decrypted(){
echo "ex) ${kind}name"
read -p "Enter xml name: " xml_name
# 암호화된 파일 경로와 복호화된 파일 저장 경로
encrypted_file="./encrypted_file/${kind}/${kind}_${xml_name}_credential.xml.enc"
decrypted_file="./decrypted_file/${kind}/${kind}_${xml_name}_credential_decrypted.xml"
# 복호화에 사용할 비밀번호 입력 받기
read -sp "Enter decryption password: " dec_password
echo
# 파일 복호화 (AES-256-CBC 알고리즘 사용)
openssl enc -aes-256-cbc -d -in "$encrypted_file" -out "$decrypted_file" -pass pass:"$dec_password"
# 복호화된 파일 확인
if [ $? -eq 0 ]; then
echo "File has been decrypted successfully: $decrypted_file"
else
echo "File decryption failed"
fi
}
show_menu
while [ $opt != '' ]
do
if [ $opt = '' ]; then
exit;
else
case $opt in
1) clear;
option_picked "Username with password";
kind="user";
decrypted;
show_menu;
;;
2) clear;
option_picked "Google Service Account from private key";
kind="gcp";
decrypted;
show_menu;
;;
3) clear;
option_picked "Secret text";
kind="secret_text";
decrypted;
show_menu;
;;
4) clear;
option_picked "Secret file";
kind="secret_file";
decrypted;
show_menu;
;;
5) clear;
option_picked "AWS Credential";
kind="aws";
decrypted;
show_menu;
;;
6) clear;
option_picked "SSH Username with private key";
kind="ssh";
decrypted;
show_menu;
;;
x) exit;
;;
*) clear;
show_menu;
;;
esac
fi
done
Jenkins CLI - Credential 설정 (1) Username with password (https://fanic2022.tistory.com/74)글에서 생성했던 Username with password xml.enc 파일을 복호화 하는 쉘 스크립트로 테스트한 결과이다.
먼저 xml_name을 입력 받고 이전에 설정한 패스워드를 입력하면 복호화된 파일이 저장된다.
복호화된 파일 정보
<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
<scope>GLOBAL</scope>
<id>cli_test</id>
<description>Test Credential</description>
<username>cli_test</username>
<password>test1234</password>
</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
만약 틀린 패스워드를 입력하게 되면 bad decrypt라고 알린 후 생성된 파일도 암호화가 되어 있는걸 볼 수 있다.
틀린 패스워드 입력시 파일 정보
X��;�����G-�ϲ#�c�ϸ���~+W�l5���?�f.ɔaT#5������S���a���O�u�K��>�p�>������Y�D� f�1�d�=�)Wa�;a�Wt�ZÆ����kң���@��Ɣ��,�̼�Ľn}qO]rۧ��qA��-�/�Fx9�
�Y9���f�9���3z�qp���z�lߴ�AGP~Cڪ�F�g@��J�h�j+�,{�җ� s��^���&4jUo���j�0Z�O�4]+�[���B��Vy�J���q
반응형
'Devops > Jenkins' 카테고리의 다른 글
Jenkins CLI - CLI 통합 쉘 스크립트 구성 (0) | 2024.07.13 |
---|---|
Jenkins CLI - Credential 설정 (0) | 2024.07.13 |
Jenkins CLI - Jenkins 유저 설정 (0) | 2024.07.12 |
Jenkins CLI - 플러그인 설정 (0) | 2024.07.12 |
Jenkins CLI - Kubernetes Cloud 등록 (0) | 2024.07.11 |