Some fun with reprepro and Apache2
Okish, lets build a package repo :)
First let's install the packages we need, namely Apache2 & reprepro
apt update
apt-cache search apache2 reprepro
apt install apache2 reprepro
Next, we have to add a directory for reprepro under /var/www/, and make a config file.
mkdir /var/www/reprepro
mkdir /var/www/reprepro/conf
Next we add a config file, called distributions.
touch /var/www/rerrepro/conf/distributions
Origin: Blackdragon.se Kali repo
Label: Blackdragon.se
Codename: kali-rolling
Architectures: amd64
Components: main
This is the basic settings we need in the distributions file
The fields are as follows.
Origin is an ID string, that identify the repo. "blackdragon.se Kali Repo"
Label is an identifier string, that can be used for APT pining. Here I used domain.
Codename, identifies what distribution it's for, here it's Kali-rolling
Architectures, What architecture we support. Here it's amd64
components, set this to main, since it's a main repo for private packages
That's it. Initialize repo with
reprepro export
For including packages into the repo use
reprepro includedeb kali-rolling /path/to/package.deb
The next we need to do, is add a config file and define a virtual host under Apache, so let's do that.
<VirtualHost repo.blackdragon.se:80>
ServerName repo.blackdragon.se
ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.
ErrorLog /var/log/apache2/repo.blackdragon.se-error.log
CustomLog /var/log/apache2/repo.blackdragon.se-access.log "%h %l %u %t \"%r\" %>s %O"
DocumentRoot /var/www/reprepro
<Directory "/var/www/reprepro">
Options Indexes FollowSymLinks MultiViews
Require all granted
AllowOverride All
</Directory>
</VirtualHost>
To use it, setup apt. Include a config file under /etc/apt/sources.list.d/repo.list, with content like this. Adjust to your settings :)
deb [trusted=yes] http://your.apt.server kali-rolling main
And now, the moment we all have waited for, update apt, and see if it can find the repo.
apt update
apt-cache search some_package_you_have.deb
The next would be to make a signed repo, and setup ssl, but thats not included here. This is just a very basic repo.
For a signed repo:
The only difference is to generate a couple of keys with gpg, and export them, like this
#generate keys
gpg --gen-keys
#list keys
gpg --list-keys
#list secret keys
gpg --list-secret-keys
#export keys to file
$ gpg --output mygpgkey_pub.gpg --armor --export <keyid>
$ gpg --output mygpgkey_sec.gpg --armor --export-secret-key <keyid>
Next, transfer the keys to server, and add them to keyring, under the user you want, and let's setup reprepro to use them
This is the distributions file, and is placed under /var/www/repo/kali/conf
root@downloads:/var/www/repo/kali/conf# cat distributions
Origin: Blackdragon.se Kali repo
Label: Blackdragon.se
Codename: kali-rolling
Architectures: amd64
Components: main
SignWith: 6FC7D0D5
Next up, we need the options file, placed in the same directory
verbose
basedir /var/www/repo/kali
ask-passphrase
Lastly we setup ssl, so install certbot, and run it like so
certbot --apache
It will guide you on how to set SSL up on you VHost, just follow the prompts, and make sure to take care of errors. reload apache, and check that ssl is working
systemctl reload apache2
Next up, copy the gpg key into the root of your server, that is, the basedir of your virtual host, so it can be downloaded, and install it on the client.
#install apt-https
apt install apt-transport-https
#get the key
wget -q -O - https://server/gpgfile.gpg | apt-key add
#add to /etc/apt/sources.list.d/your-repo.list
deb apt.repo-server/ kali-rolling main
#Update apt
apt update
Now, we need to start the repo, and generate some files for the first time.
#jump into the basedir and run reprepro, my basedir is /var/www/repo/kali/
reprepro --ask-passphrase export
Package some files, for that see Packaging scripts to deb files, and add it to the repo like this
#reprepro includedeb <osrelease> <debfile>
reprepro includedeb kali-rolling some.deb
Ohh, one last thing. We need to take care of apt settings, to adjust for changes, like ssl and keys, let's do that before we take a break.
Remember we placed the keys on the server ?. We need to import them to apt, and tell apt-key to use them, and lastly we change the apt settings, and define the repo.
#get the key
wget -q -O - https://apt.blackdragon.se/dev_pub.gpg | apt-key add
Setup the apt repo file
cd /etc/apt/sources.list.d/
touch blackdragon.list
echo 'deb https://apt.blackdragon.se/ kali-rolling main' > blackdragon.list
Now, your repo should work, but there's one last thing I would like to mention. We can set it up with basic security. That means that only allowed users can se the repo content, and use it. Normally you wouldn't wat this for a repo, but let's do it anyway.
First things first, we need to install some stuff for apache2.
apt install apache2-utils
Now, we need to create a password file for the users, and we do that with the command
#create first use, and make the password file
sudo htpasswd -c /etc/apache2/.htpasswd sammy
#Make second user
sudo htpasswd /etc/apache2/.htpasswd another_user
#NOTE that htpasswd will promt for entering the passwords.
So, now we got a users file, time for setting up apache to use it. There's a couple of ways we can do that.
We can use some settings in the default conf file, located in /etc/apache2/000-default.conf,
# Directive before editing
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# Directive after editing
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
</VirtualHost>
But, there's another way. Sometimes we don't control the main apache file, but if we can use htaccess files, we can do this instead.
# In apache.conf See AllowOverride All. We can use taccess files.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Paste into .htaccess in the sites folder, and change file location for the password file.
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
That's it. Reload apache, and check for errors.
# Stop Apache
systemctl stop apache2
# Start Apache
systemctl start apache2
Try to log in to the APT repo using a browser, it should prompt for a username and password. If it did, it's working. NOw, on with the show. Let's configure APT.
If you allready have setup the repo config in /etc/apt/sources.list or /etc/apt/sources.list.d/somerepo.list, let's configure user and password for APT.
# Jump into /etc/apt/auth.conf.d
cd /etc/apt/auth.conf.d/
touch reponame.conf
echo "machine apt.repo.name" >> reponame.conf
echo "login loginusername" >> reponame.conf
echo "password yourpassword" >> reponame.conf
# Update APT
apt update
That's it. Now you should have a working signed repository running, But do remember to adjust for your own settings, this is just an example... :)

