This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: IPv4 DHCP support for leases in server attributes (#1)
This provides the initial support to serve IPv4 DHCP requests from the serverservice based on the attributes of a server
- Loading branch information
1 parent
0f5a2d2
commit ba7da3f
Showing
21 changed files
with
1,916 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @metal-toolbox/hollow-core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: goreleaser | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Login to GHCR | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- | ||
name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17 | ||
- | ||
name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
run: | ||
build-tags: | ||
- testtools | ||
|
||
linters-settings: | ||
goimports: | ||
local-prefixes: go.hollow.sh/dhcpserver | ||
gofumpt: | ||
extra-rules: true | ||
|
||
linters: | ||
enable: | ||
# default linters | ||
- deadcode | ||
- errcheck | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- staticcheck | ||
- structcheck | ||
- typecheck | ||
- unused | ||
- varcheck | ||
|
||
# additional linters | ||
- bodyclose | ||
- gocritic | ||
- gocyclo | ||
- goerr113 | ||
- gofmt | ||
# - gofumpt | ||
- goimports | ||
- gomnd | ||
- govet | ||
- misspell | ||
- noctx | ||
- revive | ||
- stylecheck | ||
- whitespace | ||
- wsl | ||
|
||
# - bod | ||
issues: | ||
exclude: | ||
# Default excludes from `golangci-lint run --help` with EXC0002 removed | ||
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok | ||
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked | ||
# EXC0002 golint: Annoying issue about not having a comment. The rare codebase has such comments | ||
# - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form) | ||
# EXC0003 golint: False positive when tests are defined in package 'test' | ||
- func name will be used as test\.Test.* by other packages, and that stutters; consider calling this | ||
# EXC0004 govet: Common false positives | ||
- (possible misuse of unsafe.Pointer|should have signature) | ||
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore | ||
- ineffective break statement. Did you mean to break out of the outer loop | ||
# EXC0006 gosec: Too many false-positives on 'unsafe' usage | ||
- Use of unsafe calls should be audited | ||
# EXC0007 gosec: Too many false-positives for parametrized shell calls | ||
- Subprocess launch(ed with variable|ing should be audited) | ||
# EXC0008 gosec: Duplicated errcheck checks | ||
- (G104|G307) | ||
# EXC0009 gosec: Too many issues in popular repos | ||
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) | ||
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' | ||
- Potential file inclusion via variable | ||
exclude-use-default: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
project_name: dhcpserver | ||
before: | ||
hooks: | ||
- go mod download | ||
|
||
builds: | ||
- | ||
id: go | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
ldflags: | ||
- -s -w | ||
- -X go.hollow.sh/toolbox/version.appName={{.ProjectName}} | ||
- -X go.hollow.sh/toolbox/version.version={{.Version}} | ||
- -X go.hollow.sh/toolbox/version.commit={{.Commit}} | ||
- -X go.hollow.sh/toolbox/version.date={{.Date}} | ||
- -X go.hollow.sh/toolbox/version.builtBy=goreleaser | ||
|
||
archives: | ||
- | ||
id: go | ||
format: tar.gz | ||
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}" | ||
replacements: | ||
amd64: 64bit | ||
386: 32bit | ||
arm: ARM | ||
arm64: ARM64 | ||
darwin: macOS | ||
linux: Linux | ||
files: | ||
- README.md | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
|
||
snapshot: | ||
name_template: "{{ .Tag }}-next" | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
dockers: | ||
- | ||
image_templates: | ||
- "ghcr.io/metal-toolbox/hollow-{{.ProjectName}}:{{ .Tag }}" | ||
dockerfile: Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM alpine:3 as alpine | ||
RUN apk add --no-cache ca-certificates | ||
|
||
FROM scratch | ||
# Copy ca-certs from alpine | ||
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
|
||
# Copy the binary that goreleaser built | ||
COPY dhcpserver /dhcpserver | ||
|
||
# Run the dhcp service on container startup. | ||
ENTRYPOINT ["/dhcpserver"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM golang:1.17 as builder | ||
|
||
# Create and change to the app directory. | ||
WORKDIR /app | ||
|
||
# Retrieve application dependencies using go modules. | ||
# Allows container builds to reuse downloaded dependencies. | ||
COPY go.* ./ | ||
RUN go mod download | ||
|
||
# Copy local code to the container image. | ||
COPY . ./ | ||
|
||
RUN go mod tidy -compat=1.17 | ||
|
||
# Build the binary. | ||
# -mod=readonly ensures immutable go.mod and go.sum in container builds. | ||
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o dhcpserver | ||
|
||
FROM alpine:3 as alpine | ||
RUN apk add --no-cache ca-certificates | ||
|
||
FROM scratch | ||
# Copy ca-certs from alpine | ||
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
# Copy the binary to the production image from the builder stage. | ||
COPY --from=builder /app/dhcpserver /dhcpserver | ||
|
||
COPY config /etc/coredhcp/config.yml | ||
|
||
# Run the web service on container startup. | ||
ENTRYPOINT ["/dhcpserver"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
all: lint test | ||
PHONY: test coverage lint golint clean vendor local-dev-databases docker-up docker-down integration-test unit-test | ||
GOOS=linux | ||
OS_NAME := $(shell uname -s | tr A-Z a-z) | ||
GOLANGCILINTCMD :=$(if ifeq darwin $(OS_NAME), docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.42 golangci-lint, golangci-lint) | ||
GOCMD :=$(if ifeq darwin $(OS_NAME), docker run --rm -v $(shell pwd):/app -w /app golang:1.17 go, go) | ||
|
||
test: | unit-test | ||
|
||
unit-test: | lint | ||
@echo Running unit tests... | ||
@$(GOCMD) test -cover -short -tags testtools ./... | ||
|
||
coverage: | ||
@echo Generating coverage report... | ||
@$(GOCMD) test ./... -race -coverprofile=coverage.out -covermode=atomic -tags testtools -p 1 | ||
@go tool cover -func=coverage.out | ||
@go tool cover -html=coverage.out | ||
|
||
lint: golint | ||
|
||
golint: | vendor | ||
@echo Linting Go files... | ||
@$(GOLANGCILINTCMD) run | ||
|
||
clean: docker-clean | ||
@echo Cleaning... | ||
@rm -rf ./dist/ | ||
@rm -rf coverage.out | ||
@go clean -testcache | ||
|
||
vendor: | ||
@go mod download | ||
@go mod tidy -compat=1.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
# hollow-dhcpserver | ||
# Hollow CoreDHCP Plugin & DHCP Server Build | ||
|
||
[![codecov](https://codecov.io/gh/metal-toolbox/hollow-dhcpserver/branch/main/graph/badge.svg?token=xXNVOjjWJ7)](https://codecov.io/gh/metal-toolbox/hollow-dhcpserver) | ||
|
||
|
||
This provides a plugin that can be used for serving dhcp request from hollow data sources. | ||
|
||
## How to use | ||
|
||
You will need to store the DHCP information on a server or instance attribute with the namespace `sh.hollow.dhcpserver.lease`. | ||
|
||
The format of this data needs to look like: | ||
|
||
```json | ||
{ | ||
"ipv4": [ | ||
{ | ||
"boot_file": "ipxe.efi", | ||
"boot_server": "10.0.0.1", | ||
"cidr": "10.0.0.20/24", | ||
"gateway": "10.0.0.1", | ||
"mac_address": "02:42:ac:13:00:05", | ||
"resolvers": [ | ||
"1.1.1.1", | ||
"8.8.8.8" | ||
] | ||
}, | ||
{ | ||
"boot_file": "", | ||
"boot_server": "", | ||
"cidr": "10.0.0.100/24", | ||
"gateway": "10.0.0.1", | ||
"mac_address": "02:42:ac:13:00:01", | ||
"resolvers": [ | ||
"1.1.1.1", | ||
"8.8.8.8" | ||
] | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
server4: | ||
plugins: | ||
- dns: 1.1.1.1 1.0.0.1 | ||
- hollow: http://serverservice:8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module go.hollow.sh/dhcpserver | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/coredhcp/coredhcp v0.0.0-20210830115404-2176f33418f4 | ||
github.com/friendsofgo/errors v0.9.2 | ||
github.com/insomniacslk/dhcp v0.0.0-20210827173440-b95caade3eac | ||
github.com/sirupsen/logrus v1.7.0 | ||
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c | ||
github.com/stretchr/testify v1.7.0 | ||
go.hollow.sh/serverservice v0.13.0 | ||
go.hollow.sh/toolbox v0.0.0-20210826144247-5ed6c7643625 | ||
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602 | ||
) | ||
|
||
require ( | ||
github.com/chappjc/logrus-prefix v0.0.0-20180227015900-3a1d64819adb // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/ericlagergren/decimal v0.0.0-20181231230500-73749d4874d5 // indirect | ||
github.com/fsnotify/fsnotify v1.5.1 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/gin-gonic/gin v1.7.4 // indirect | ||
github.com/go-playground/locales v0.13.0 // indirect | ||
github.com/go-playground/universal-translator v0.17.0 // indirect | ||
github.com/go-playground/validator/v10 v10.4.1 // indirect | ||
github.com/gofrs/uuid v3.2.0+incompatible // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/gopacket v1.1.19 // indirect | ||
github.com/google/uuid v1.2.0 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.11 // indirect | ||
github.com/leodido/go-urn v1.2.0 // indirect | ||
github.com/lib/pq v1.10.3 // indirect | ||
github.com/magiconair/properties v1.8.5 // indirect | ||
github.com/mattn/go-colorable v0.1.8 // indirect | ||
github.com/mattn/go-isatty v0.0.12 // indirect | ||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect | ||
github.com/mitchellh/mapstructure v1.4.2 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.1 // indirect | ||
github.com/pelletier/go-toml v1.9.4 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 // indirect | ||
github.com/spf13/afero v1.6.0 // indirect | ||
github.com/spf13/cast v1.4.1 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/viper v1.8.1 // indirect | ||
github.com/subosito/gotenv v1.2.0 // indirect | ||
github.com/u-root/uio v0.0.0-20210528114334-82958018845c // indirect | ||
github.com/ugorji/go/codec v1.1.7 // indirect | ||
github.com/volatiletech/inflect v0.0.1 // indirect | ||
github.com/volatiletech/null/v8 v8.1.2 // indirect | ||
github.com/volatiletech/randomize v0.0.1 // indirect | ||
github.com/volatiletech/sqlboiler/v4 v4.6.0 // indirect | ||
github.com/volatiletech/strmangle v0.0.1 // indirect | ||
github.com/willf/bitset v1.1.11 // indirect | ||
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf // indirect | ||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect | ||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect | ||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect | ||
golang.org/x/text v0.3.6 // indirect | ||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.26.0 // indirect | ||
gopkg.in/ini.v1 v1.63.1 // indirect | ||
gopkg.in/square/go-jose.v2 v2.6.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
) |
Oops, something went wrong.