내가 만든rpm에 서명을 넣는 방법에 대해 알아봅시다.
우선 rpm에 서명(signature)를 넣는 방법은 크게 두 가지가 있을 수 있습니다.
- rpm 빌드 할 때 서명을 넣는 방법
- rpm 생성을 완료한 후 서명을 넣는 방법
저는 젠킨스(Jenkins)라는 CI(Continuous Integration)를 사용하고 있기 때문에, 젠킨스를 통해 rpm 생성 시점에서 서명을 넣는 방법을 택하였습니다.
수행 절차:
1. 서명 만들기
gpg 명령어를 써서 서명을 만들어봅시다.
서명을 만드는 절차를 모두 보고 싶다면..
# gpg --gen-key
gpg (GnuPG) 1.4.10; Copyright (C) 2008 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 2
DSA keys may be between 1024 and 3072 bits long.
What keysize do you want? (2048) 1024
Requested keysize is 1024 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y
You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
Real name: RealName
Email address: email@test.com
Comment: mysignature
You selected this USER-ID:
"RealName (mysignature) <email@test.com>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
Enter pass phrase :**********
Repeat pass phrase :**********
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need 283 more bytes)
Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need 128 more bytes)
.+++++
gpg: key F9156809 marked as ultimately trusted
public and secret key created and signed.
키 생성 완료!!
키 생성은 DSA로 하였으며, 키 길이는 1024로 해줬습니다.
'Real name'에 입력한 값은 꼭 기억해 둬야 합니다.
2. rpm 만들때 서명 넣기
$ rpm --addsign -D '_signature gpg' -D '_gpg_name Realname' -D '_gpg_path ~/.gnupg/' sign_to_this.rpm"
Enter pass phrase: *****
Pass phrase is good.
- 서명 타입(
_signature ) - gpg로 생성했으므로 gpg
- 서명 이름( _gpg_name ) - 서명을 만들 때 'Real name'에 입력했던 이름
- 서명 경로( _gpg_path ) - 일반적으로 'home'경로의 '.gnupg' 폴더에 생성됨
- 서명을 넣고자 하는 rpm 경로 및 이름
/home/.rpmmacros 파일에 위 정보들을 넣어두면 매번 수동으로 입력해주지 않아도 됩니다.
%_signature gpg
%_gpg_path ~/.gnupg
%_gpg_name UserName (Example GPG Key Signature For RPM Packages) <user@signature.com>
%_gpgbin /usr/bin/gpg <- which gpg로 확인 가능
3. rpm에 넣은 서명 확인
$ rpm --checksig <rpm_name>
혹은 -K 옵션도 동일
예) $ rpmsign -K my_signed.x86_64.rpm
my_signed.x86_64.rpm: (SHA1) DSA sha1 md5 (GPG)
4. yum으로 서명이 들어간 rpm 설치하기
먼저 KEY파일을 rpm을 설치하는 장비에 옮겨놔야합니다.
/etc/pki/rpm-gpg 폴더에 fedora에서 사용하는 key파일이 있으므로 이곳으로 옮겨줍니다.
그 다음..
/etc/yum.repos.d/<name>.repo 파일을 열어서 다음 옵션을 사용해서 설치할 rpm의 서명을 확인 하도록 'gpgcheck'값을 1로 변경해줍니다.
물론, gpgkey 경로도 설정해줘야 하구요.
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/Username-GPG-KEY
5. 서명 자동화
위 작업을 빌드 자동화 시스템에 추가하고자 한다면 매번 수동으로 서명을 넣는 것은 미친 짓일겁니다.
이제 반복잡업을 군소리 없이 잘 해주는 컴퓨터에게 매번 알아서 하도록 시켜줘야겠죠?
자동화 작업의 최대 난관은 서명을 추가할 때 마다 비밀번호를 입력 받는다는 것입니다.
비밀번호를 요구할 때 자동으로 지정해준 비밀번호를 넣어주도록 해줘야 하는데 이를 위해 expect를 사용하기로 했습니다.
expect 를 이용하면 다른 어플리케이션과 상호대화를 할수 있게 됨으로 자동화된 프로그램을 만들수가 있다.
expect에 대한 설명 뿐 아니라 perl을 사용해서 자동화 프로그램을 작성하는 법 및 예문까지 친절하게 나와있답니다.
참고로, 위 작업을 위해서는 expect와 perl-Expect를 설치해주셔야 합니다.
$ yum install perl-Expect
Downloading Packages:
(1/2): perl-Expect-1.21-3.fc12.noarch.rpm | 70 kB 00:00
(2/2): perl-IO-Tty-1.08-3.fc12.x86_64.rpm | 39 kB 00:00
-------------------------------------------------------------------------------------------------------------
$ yum install expect
Downloading Packages:
(1/2): expect-5.43.0-19.fc12.x86_64.rpm | 238 kB 00:00
(2/2): tcl-8.5.7-5.fc12.x86_64.rpm | 1.9 MB 00:00
-------------------------------------------------------------------------------------------------------------
스크립트는 다음만 조심해서 작성하면 됩니다.
상호대화할 프로그램을 띄우기 위한 목적으로 사용됩니다. 여기서는 rpm 으로 서명을 넣는 명령을 정의해 주면 됩니다.
예)
my $exp = Expect->spawn("rpm --addsign -D '_signature gpg' -D '_gpg_name UserName' -D '_gpg_path ~/.gnupg/' sign_to_this.rpm");
특정한 문자열을 기다리고, 해당 문자열을 발견하게 되면, 어떤 행동을 취할수 있도록 인터페이스를 제공해줍니다.
여기서는 서명에 대한 비밀번호 입력 요청을 기다리게 됩니다.
예)
$exp->expect($timeout,
[qr 'Enter pass phrase:' => \&inputpassphrase],);
sub inputpassphrase
{
my $lexp = shift;
$lexp->send("mypassword\n");
exp_continue;
}
원하는 문자열을 전달합니다. 위의 예제를 보시면 알 수 있듯 비밀번호를 전송하게 됩니다.
예)
$lexp->send("mypassword\n");
6. 검증
이제 자동화 스크립트에 의해 서명이 들어간 rpm이 제대로 설치 되는지만 확인해보면 된답니다.