Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
feat: First version (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
lholota authored Jul 1, 2020
1 parent f8477cf commit e1dd679
Show file tree
Hide file tree
Showing 28 changed files with 483 additions and 111 deletions.
35 changes: 0 additions & 35 deletions .github/settings.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/dhcp"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- master

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/dhcp"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/regular_scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
- cron: '0 6 * * *'

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/dhcp"

jobs:
build:
Expand Down
22 changes: 21 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
FROM alpine
FROM homecentr/base:2.4.3-alpine

ENV DHCP_ARGS=""

RUN apk add --no-cache \
dhcp=4.4.2-r1 \
libcap=2.27-r0 && \
rm /etc/dhcp/dhcpd.conf.example && \
mkdir /leases && \
chmod 0777 /leases && \
mkdir /config && \
setcap 'cap_net_raw+ep' /usr/sbin/dhcpd && \
setcap 'cap_net_bind_service=+ep' /usr/sbin/dhcpd && \
deluser dhcp

COPY ./fs/ /

EXPOSE 67/udp

VOLUME /leases
VOLUME /config
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
[![Project status](https://badgen.net/badge/project%20status/stable%20%26%20actively%20maintaned?color=green)](https://github.com/homecentr/docker-$$IMAGE_NAME$$/graphs/commit-activity) [![](https://badgen.net/github/label-issues/homecentr/docker-$$IMAGE_NAME$$/bug?label=open%20bugs&color=green)](https://github.com/homecentr/docker-$$IMAGE_NAME$$/labels/bug) [![](https://badgen.net/github/release/homecentr/docker-$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$)
[![](https://badgen.net/docker/pulls/homecentr/$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$)
[![](https://badgen.net/docker/size/homecentr/$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$)
[![Project status](https://badgen.net/badge/project%20status/stable%20%26%20actively%20maintaned?color=green)](https://github.com/homecentr/docker-dhcp/graphs/commit-activity) [![](https://badgen.net/github/label-issues/homecentr/docker-dhcp/bug?label=open%20bugs&color=green)](https://github.com/homecentr/docker-dhcp/labels/bug) [![](https://badgen.net/github/release/homecentr/docker-dhcp)](https://hub.docker.com/repository/docker/homecentr/dhcp)
[![](https://badgen.net/docker/pulls/homecentr/dhcp)](https://hub.docker.com/repository/docker/homecentr/dhcp)
[![](https://badgen.net/docker/size/homecentr/dhcp)](https://hub.docker.com/repository/docker/homecentr/dhcp)

![CI/CD on master](https://github.com/homecentr/docker-$$IMAGE_NAME$$/workflows/CI/CD%20on%20master/badge.svg)
![Regular Docker image vulnerability scan](https://github.com/homecentr/docker-$$IMAGE_NAME$$/workflows/Regular%20Docker%20image%20vulnerability%20scan/badge.svg)
![CI/CD on master](https://github.com/homecentr/docker-dhcp/workflows/CI/CD%20on%20master/badge.svg)
![Regular Docker image vulnerability scan](https://github.com/homecentr/docker-dhcp/workflows/Regular%20Docker%20image%20vulnerability%20scan/badge.svg)


# HomeCentr - $$IMAGE_NAME$$
# HomeCentr - ISC DHCP Server


## Usage

```yml
version: "3.7"
services:
$$IMAGE_NAME$$:
build: .
image: homecentr/$$IMAGE_NAME$$
dhcp:
image: homecentr/dhcp
network: host
volumes:
- ./example:/config
```
## Environment variables
| Name | Default value | Description |
|------|---------------|-------------|
| PUID | 7077 | UID of the user $$IMAGE_NAME$$ should be running as. |
| PGID | 7077 | GID of the user $$IMAGE_NAME$$ should be running as. |
| PUID | 7077 | UID of the user dhcp should be running as. |
| PGID | 7077 | GID of the user dhcp should be running as. |
## Exposed ports
| Port | Protocol | Description |
|------|------|-------------|
| 80 | TCP | Some useful details |
| 67 | UDP | DHCP Server |
:warning: Due to the nature of the DHCP protocol which is highly dependent on broadcast, exposing the container via a bridge network will not work as explained below. Because of this, the container should be exposed via drivers which allow the container to expose the port directly (host, macvlan, ipvlan).
> Docker daemon will not pass the broadcast packets to the container because the container internally has an IP specific to the bridge network (e.g. 172.16.10.1) but the broadcast packet will be sent with the IP of your host machine (e.g. 192.168.2.50). The bridge will therefore decide the broadcast packet was not meant for the container and will not forward it.
## Volumes
| Container path | Description |
|------------|---------------|
| /config | Some useful details |
| /config | Configuration directory which must contain the `dhcpd.conf` file. See the official [documentation](https://kb.isc.org/docs/aa-00502) on how to configure the DHCP server. |
| /leases | This is where the DHCP server records which IP addresses have been leased to individual clients. The location must be writable by the PUID/PGID. |

## Security
The container is regularly scanned for vulnerabilities and updated. Further info can be found in the [Security tab](https://github.com/homecentr/docker-$$IMAGE_NAME$$/security).
The container is regularly scanned for vulnerabilities and updated. Further info can be found in the [Security tab](https://github.com/homecentr/docker-dhcp/security).

### Container user
The container supports privilege drop. Even though the container starts as root, it will use the permissions only to perform the initial set up. The $$IMAGE_NAME$$ process runs as UID/GID provided in the PUID and PGID environment variables.
The container supports privilege drop. Even though the container starts as root, it will use the permissions only to perform the initial set up. The dhcp process runs as UID/GID provided in the PUID and PGID environment variables.

:warning: Do not change the container user directly using the `user` Docker compose property or using the `--user` argument. This would break the privilege drop logic.
21 changes: 18 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
version: "3.7"
services:
$$IMAGE_NAME$$:
dhcp:
build: .
image: homecentr/$$IMAGE_NAME$$
restart: unless-stopped
image: homecentr/dhcp:local
environment:
PUID: "6065"
PGID: "6066"
volumes:
- ./example:/config
networks:
default:

networks:
default:
driver: bridge
attachable: true
ipam:
driver: default
config:
- subnet: "172.18.250.0/24"
8 changes: 8 additions & 0 deletions example/dhcpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
authoritative;

option client-arch code 93 = unsigned integer 16;

subnet 172.18.250.0 netmask 255.255.255.0 {
range 172.18.250.50 172.18.250.60;
option routers 172.18.250.1;
}
8 changes: 8 additions & 0 deletions fs/etc/cont-init.d/50-leases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/with-contenv ash

if [ ! -f "/leases/dhcp.leases" ]; then
touch "/leases/dhcp.leases"
fi

chown -R "$PUID:$PGID" "/leases"
chown -R "$PUID:$PGID" "/var/lib/dhcp"
3 changes: 3 additions & 0 deletions fs/etc/services.d/dhcpd/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/execlineb -S1

s6-svscanctl -t /var/run/s6/services
7 changes: 7 additions & 0 deletions fs/etc/services.d/dhcpd/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/with-contenv sh

EXEC_USERNAME=$(getent passwd "$PUID" | cut -d: -f1)
EXEC_GROUPNAME=$(getent group "$PGID" | cut -d: -f1)

# Not executed via runas because dhcpd has its own logic of chowning files and switching user executing the process
exec /usr/sbin/dhcpd -4 -f -cf /config/dhcpd.conf -lf /leases/dhcp.leases -user "$EXEC_USERNAME" -group "$EXEC_GROUPNAME" $DHCP_ARGS
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "homecentr-$$IMAGE_NAME$$",
"name": "homecentr-dhcp",
"version": "1.0.0",
"description": "",
"repository": {
"type": "git",
"url": "git+https://github.com/homecentr/docker-$$IMAGE_NAME$$.git"
"url": "git+https://github.com/homecentr/docker-dhcp.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/homecentr/docker-$$IMAGE_NAME$$/issues"
"url": "https://github.com/homecentr/docker-dhcp/issues"
},
"homepage": "https://github.com/homecentr/docker-$$IMAGE_NAME$$#readme"
"homepage": "https://github.com/homecentr/docker-dhcp#readme"
}
6 changes: 0 additions & 6 deletions tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
<attribute name="gradle_used_by_scope" value="test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/resources">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions tests/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e1dd679

Please sign in to comment.