Compare commits

...

120 Commits
v2.7.4 ... main

Author SHA1 Message Date
dependabot[bot]
0d8d35889d
chore: bump github.com/go-acme/lego/v4 from 4.22.2 to 4.25.2 (#224) 2025-08-06 21:55:29 +02:00
vgdh
ef2b9f9e1b
docs: disable network access inside examples (#223) 2025-07-06 22:27:30 +02:00
dependabot[bot]
d83e436bbb
chore: bump golang.org/x/net from 0.37.0 to 0.38.0 (#219) 2025-04-17 01:46:09 +02:00
Fernandez Ludovic
00ebf584ff chore: update linter 2025-03-25 03:34:46 +01:00
Fernandez Ludovic
38dd4b1898 chore: update linter 2025-03-09 19:36:21 +01:00
Fernandez Ludovic
ece40e90d6 chore: update dependencies 2025-03-09 19:35:45 +01:00
Fernandez Ludovic
5e2a080d2a chore: publish Docker images in GHCR 2025-03-09 19:32:33 +01:00
Fernandez Ludovic
07decbb976 chore: restrict workflows 2025-03-09 19:32:33 +01:00
Fernandez Ludovic
9a7fa88d60 docs: update readme 2025-02-21 22:35:42 +01:00
Fernandez Ludovic
a32520bcba docs: update examples 2025-02-21 22:34:35 +01:00
Fernandez Ludovic
39b542952b docs: update documentation 2025-02-21 22:30:27 +01:00
Fernandez Ludovic
b0aafdcc54 docs: improve readme 2025-02-13 03:04:45 +01:00
Fernandez Ludovic
565e4316ca chore: linting 2025-02-13 03:03:12 +01:00
Fernandez Ludovic
961192eb9b chore: update dependencies and Go version 2025-02-13 03:00:13 +01:00
Fernandez Ludovic
1bd1c094f2 chore: update linter 2025-02-13 02:53:42 +01:00
Fernandez Ludovic
380fa0efda chore: update linter 2025-02-13 02:51:32 +01:00
Ludovic Fernandez
059bfd27eb
chore: update donation URL 2025-01-24 22:38:24 +01:00
Fernandez Ludovic
45954b02ca chore: update funding 2025-01-06 20:17:49 +01:00
dependabot[bot]
e1b924f614
chore: bump golang.org/x/crypto from 0.28.0 to 0.31.0 (#212) 2024-12-12 02:10:59 +01:00
Blackmoon
865dceddf9
docs: adds all counts to one sum (#211) 2024-12-06 13:12:30 +00:00
Fernandez Ludovic
172bd870c6 feat: improve binary size 2024-12-05 14:58:48 +01:00
Fernandez Ludovic
ee3231c879 docs: fix examples 2024-12-05 14:51:38 +01:00
Fernandez Ludovic
d18ae5e249 fix: Docker image 2024-12-05 13:29:27 +01:00
Fernandez Ludovic
48166b4990 chore: update dependencies, and linter 2024-12-04 22:43:30 +01:00
Fernandez Ludovic
ec006d3466 chore: use goreleaser to publish Docker images 2024-12-04 22:43:30 +01:00
Fernandez Ludovic
754051fcb4 chore: help popup 2024-12-04 22:43:30 +01:00
Fernandez Ludovic
a4f74712d8 chore: update workflow 2024-12-02 22:19:30 +01:00
dependabot[bot]
4f9ee0b2aa
chore: bump github.com/traefik/traefik/v3 from 3.2.0 to 3.2.1 (#208) 2024-12-02 18:56:52 +01:00
dependabot[bot]
06a6f04be9
chore: bump github.com/traefik/traefik/v2 from 2.11.13 to 2.11.14 (#207) 2024-12-02 17:36:13 +00:00
Fernandez Ludovic
094a429688 fix: release workflow 2024-11-08 20:20:01 +01:00
Fernandez Ludovic
520caaf67f feat: dedicated Traefik v3 implementation 2024-11-08 18:34:59 +01:00
dependabot[bot]
cffec51d48
chore: bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1 (#204) 2024-11-05 01:45:35 +01:00
dependabot[bot]
8ccd28a009
chore: bump github.com/traefik/traefik/v2 from 2.11.6 to 2.11.9 (#202) 2024-09-19 18:21:18 +00:00
Fernandez Ludovic
5ecc336d73 chore: update Go, linter, dependencies, and CI 2024-09-19 20:09:28 +02:00
Fernandez Ludovic
8fb6765066 chore: update Go, linter, dependencies, and CI 2024-09-19 20:06:57 +02:00
dependabot[bot]
3e8a362a1b
chore: bump github.com/traefik/traefik/v2 from 2.11.5 to 2.11.6 (#201) 2024-07-09 22:20:31 +00:00
dependabot[bot]
7a3d5d053b
chore: bump github.com/traefik/traefik/v2 from 2.11.4 to 2.11.5 (#200) 2024-06-20 16:42:36 +00:00
dependabot[bot]
6cd6e89652
chore: bump github.com/Azure/azure-sdk-for-go/sdk/azidentity (#199) 2024-06-11 23:57:42 +02:00
dependabot[bot]
22beab49f0
chore: bump github.com/traefik/traefik/v2 from 2.11.3 to 2.11.4 (#198) 2024-06-11 21:57:12 +02:00
Fernandez Ludovic
72a6e2e8e4 docs: add Traefik v3 2024-05-29 06:04:18 +02:00
Fernandez Ludovic
588ece1608 docs: update Traefik version 2024-05-29 06:03:31 +02:00
Fernandez Ludovic
cbe95869b0 chore: update license 2024-05-29 06:03:14 +02:00
Fernandez Ludovic
21c8f5fa9c chore: update linter 2024-05-29 06:03:00 +02:00
dependabot[bot]
2d6d95b809
chore: bump github.com/traefik/traefik/v2 from 2.11.2 to 2.11.3 (#197) 2024-05-23 15:31:48 +00:00
dependabot[bot]
09413952ec
chore: bump github.com/traefik/traefik/v2 from 2.11.0 to 2.11.2 (#196) 2024-04-12 18:16:19 +00:00
Fernandez Ludovic
3e89131ae2 chore: update Go, dependencies, and linter 2024-04-12 20:05:47 +02:00
dependabot[bot]
381e90d319
chore: bump google.golang.org/protobuf from 1.31.0 to 1.33.0 (#194) 2024-03-13 23:26:05 +00:00
dependabot[bot]
b70afe012b
chore: bump github.com/go-jose/go-jose/v3 from 3.0.1 to 3.0.3 (#193) 2024-03-08 00:15:18 +01:00
Fernandez Ludovic
a437576753 chore: update sponsoring sources 2024-01-31 20:50:54 +01:00
Fernandez Ludovic
8c96f62349 chore: update Go, dependencies, and linter 2024-01-31 20:36:49 +01:00
dependabot[bot]
f0b114e8d8
chore: bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#192) 2023-12-18 23:40:10 +00:00
Fernandez Ludovic
7b2c71435e chore: fix CI 2023-12-05 23:05:16 +01:00
dependabot[bot]
20d34c6c0a
chore: bump github.com/traefik/traefik/v2 from 2.10.3 to 2.10.6 (#191)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2023-12-05 19:54:28 +01:00
dependabot[bot]
b1ebb09184
chore: bump github.com/go-jose/go-jose/v3 from 3.0.0 to 3.0.1 (#190) 2023-11-22 00:50:33 +01:00
dependabot[bot]
756e93fbbb
chore: bump google.golang.org/grpc from 1.55.0 to 1.56.3 (#189) 2023-10-26 12:42:12 +02:00
dependabot[bot]
40e28f9677
chore: bump golang.org/x/net from 0.11.0 to 0.17.0 (#188) 2023-10-12 01:27:59 +02:00
Fernandez Ludovic
9d10b07e10 chore: update Go, and linter 2023-07-23 23:16:21 +02:00
Fernandez Ludovic
1ad5a1eb42 chore: update Go, linter, and dependencies 2023-05-29 22:00:08 +02:00
dependabot[bot]
d60c333193
chore: bump github.com/traefik/traefik/v2 from 2.9.8 to 2.9.10 (#185) 2023-04-12 08:24:35 +02:00
Fernandez Ludovic
a9d5a3da9d chore: update Go, CI, and linter 2023-02-22 10:06:39 +01:00
Fernandez Ludovic
c11dd6630f feat: update traefik and valkeyrie 2023-01-29 16:42:14 +01:00
dependabot[bot]
78234b674c
chore: bump github.com/traefik/traefik/v2 from 2.8.3 to 2.8.8 (#181) 2022-10-10 23:48:31 +02:00
Fernandez Ludovic
7b9a0b72d6 chore: update Go, linter, and dependencies 2022-08-29 08:57:30 +02:00
Fernandez Ludovic
a645d164e0 chore: update whoami 2022-07-28 03:52:54 +02:00
Fernandez Ludovic
f58a7a9b06 chore: update dependencies 2022-07-27 23:01:35 +02:00
Fernandez Ludovic
cd16576a1f chore: update linter 2022-07-27 22:00:35 +02:00
Fernandez Ludovic
b02023370b doc: note about contrib directory 2022-07-27 21:57:03 +02:00
Fernandez Ludovic
3acdd86c88 doc: update versions 2022-07-27 21:54:50 +02:00
Jens Kohl
52a46ce079
docs: add systemd service unit (#178) 2022-07-17 12:23:48 +00:00
dependabot[bot]
c30cddfa06
chore: bump github.com/traefik/traefik/v2 from 2.6.0 to 2.6.1 (#175) 2022-02-17 14:26:36 +00:00
Fernandez Ludovic
3b7bdfc16e chore: fix workflow 2022-02-13 16:13:58 +01:00
Fernandez Ludovic
cc9161d223 chore: change CI process 2022-01-26 17:34:02 +01:00
Fernandez Ludovic
1de505f615 chore: update linter 2022-01-26 14:32:08 +01:00
Fernandez Ludovic
32293934dd chore: update dependencies 2022-01-26 14:31:40 +01:00
Fernandez Ludovic
740891ff39 doc: update version 2021-12-12 01:46:53 +01:00
Fernandez Ludovic
1b91299899 chore: increase goreleaser timeout 2021-12-12 01:45:55 +01:00
Fernandez Ludovic
372fb3c434 doc: update version 2021-12-12 00:40:17 +01:00
Fernandez Ludovic
d8a1a2644f chore: update seihon 2021-12-12 00:22:52 +01:00
Fernandez Ludovic
dd3c206955 doc: replace microbadger 2021-12-12 00:22:06 +01:00
Fernandez Ludovic
4db6310bf8 chore: upgrade to go1.17 and linter 2021-12-12 00:18:07 +01:00
Fernandez Ludovic
91e301ab39 chore: update dependencies 2021-12-12 00:07:41 +01:00
Ludovic Fernandez
8a775d55bb
chore: remove dependabot 2021-12-11 15:23:24 +01:00
Matthieu Talbot
e7fcbd70ad
Add a docker-compose hook example (#170)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2021-11-22 23:06:55 +01:00
dependabot[bot]
a8beef4f92
chore: bump github.com/go-acme/lego/v4 from 4.5.2 to 4.5.3 (#169) 2021-10-07 12:33:02 +02:00
dependabot[bot]
31028809c4
chore: bump github.com/go-acme/lego/v4 from 4.4.0 to 4.5.2 (#168) 2021-10-06 09:37:33 +02:00
dependabot[bot]
018323851f
chore: bump github.com/spf13/viper from 1.8.1 to 1.9.0 (#167) 2021-09-20 09:33:20 +02:00
dependabot[bot]
2d83180d3e
chore: bump github.com/fsnotify/fsnotify from 1.5.0 to 1.5.1 (#166) 2021-08-25 11:44:38 +02:00
dependabot[bot]
8209dc2b9d
chore: bump github.com/fsnotify/fsnotify from 1.4.9 to 1.5.0 (#165) 2021-08-19 11:30:49 +02:00
dependabot[bot]
25b4a44d79
chore: bump github.com/traefik/traefik/v2 from 2.4.13 to 2.4.14 (#164) 2021-08-17 10:26:21 +02:00
dependabot[bot]
de2ae2dd93
chore: bump github.com/traefik/traefik/v2 from 2.4.12 to 2.4.13 (#163) 2021-08-02 07:36:26 +02:00
dependabot[bot]
05deaa3d15
chore: bump github.com/traefik/traefik/v2 from 2.4.11 to 2.4.12 (#162) 2021-07-27 11:16:44 +02:00
Fernandez Ludovic
29d75cac57 chore: fix github action cache. 2021-07-16 20:18:17 +02:00
dependabot[bot]
526a001ee8
chore: bump github.com/traefik/traefik/v2 from 2.4.10 to 2.4.11 (#161) 2021-07-16 04:37:43 +00:00
dependabot[bot]
b1a0560f70
chore: bump github.com/traefik/traefik/v2 from 2.4.9 to 2.4.10 (#160) 2021-07-14 04:45:40 +00:00
Fernandez Ludovic
3c7141923c chore: update linter 2021-07-09 10:46:58 +02:00
Fernandez Ludovic
ca6eb2f04a chore: update dependencies 2021-07-09 09:07:45 +02:00
dependabot[bot]
fae0bc765c
chore: bump github.com/spf13/viper from 1.7.1 to 1.8.1 (#156) 2021-07-09 08:57:54 +02:00
dependabot[bot]
1331346177
chore: bump github.com/abronan/valkeyrie from 0.1.0 to 0.2.0 (#159) 2021-07-09 08:36:51 +02:00
dependabot[bot]
c459caf95b
chore: bump github.com/traefik/traefik/v2 from 2.4.8 to 2.4.9 (#155) 2021-06-22 08:07:05 +00:00
dependabot[bot]
83c551d915
chore: bump github.com/go-acme/lego/v4 from 4.3.1 to 4.4.0 (#153) 2021-06-09 10:02:07 +02:00
dependabot[bot]
a909fe7184
chore: bump github.com/traefik/traefik/v2 from 2.4.7 to 2.4.8 (#150) 2021-03-24 10:01:17 +01:00
dependabot[bot]
94652cf772
chore: bump github.com/go-acme/lego/v4 from 4.2.0 to 4.3.1 (#149) 2021-03-12 08:16:23 +00:00
dependabot[bot]
125bf4dcc2
chore: bump github.com/traefik/traefik/v2 from 2.4.6 to 2.4.7 (#148) 2021-03-09 10:13:44 +00:00
Fernandez Ludovic
0c0662615b chore: go1.16 and linter update 2021-03-09 10:54:00 +01:00
dependabot[bot]
c1eebcb16e
chore: bump github.com/traefik/traefik/v2 from 2.4.5 to 2.4.6 (#147) 2021-03-02 09:16:00 +01:00
dependabot-preview[bot]
082667a542
chore: create Dependabot config file (#146) 2021-02-26 00:59:07 +00:00
dependabot-preview[bot]
6b4855d571
chore(deps): bump github.com/traefik/traefik/v2 from 2.4.3 to 2.4.5 (#145) 2021-02-19 11:07:17 +00:00
dependabot-preview[bot]
3c9a239f96
chore(deps): bump github.com/traefik/traefik/v2 from 2.4.2 to 2.4.3 (#144) 2021-02-16 08:20:01 +00:00
dependabot-preview[bot]
14600988d8
chore(deps): bump github.com/spf13/cobra from 1.1.2 to 1.1.3 (#143) 2021-02-11 04:42:30 +00:00
dependabot-preview[bot]
ec35c93bb7
chore(deps): bump github.com/spf13/cobra from 1.1.1 to 1.1.2 (#142) 2021-02-10 08:15:40 +00:00
dependabot-preview[bot]
352457da76
chore(deps): bump github.com/traefik/traefik/v2 from 2.4.1 to 2.4.2 (#141) 2021-02-03 08:18:55 +00:00
dependabot-preview[bot]
1e5c66ddd6
chore(deps): bump github.com/traefik/traefik/v2 from 2.4.0 to 2.4.1 (#140) 2021-02-02 08:18:05 +00:00
dependabot-preview[bot]
a656e813f8
chore(deps): bump github.com/go-acme/lego/v4 from 4.1.3 to 4.2.0 (#139) 2021-01-25 09:21:51 +00:00
dependabot-preview[bot]
7905b608b9
chore(deps): bump github.com/traefik/traefik/v2 from 2.3.7 to 2.4.0 (#138) 2021-01-20 11:44:52 +00:00
dependabot-preview[bot]
6e422fe9c2
chore(deps): bump github.com/stretchr/testify from 1.6.1 to 1.7.0 (#137)
* chore(deps): bump github.com/stretchr/testify from 1.6.1 to 1.7.0

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.6.1 to 1.7.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.6.1...v1.7.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* go mod tidy

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2021-01-14 05:36:29 +00:00
dependabot-preview[bot]
36df44fdbf
chore(deps): bump github.com/traefik/traefik/v2 from 2.3.6 to 2.3.7 (#136)
* chore(deps): bump github.com/traefik/traefik/v2 from 2.3.6 to 2.3.7

Bumps [github.com/traefik/traefik/v2](https://github.com/traefik/traefik) from 2.3.6 to 2.3.7.
- [Release notes](https://github.com/traefik/traefik/releases)
- [Changelog](https://github.com/traefik/traefik/blob/v2.3.7/CHANGELOG.md)
- [Commits](https://github.com/traefik/traefik/compare/v2.3.6...v2.3.7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* go mod tidy

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2021-01-12 08:46:52 +00:00
dependabot-preview[bot]
26e5525cef
chore(deps): bump github.com/traefik/traefik/v2 from 2.3.5 to 2.3.6 (#133)
* chore(deps): bump github.com/traefik/traefik/v2 from 2.3.5 to 2.3.6

Bumps [github.com/traefik/traefik/v2](https://github.com/traefik/traefik) from 2.3.5 to 2.3.6.
- [Release notes](https://github.com/traefik/traefik/releases)
- [Changelog](https://github.com/traefik/traefik/blob/v2.3.6/CHANGELOG.md)
- [Commits](https://github.com/traefik/traefik/compare/v2.3.5...v2.3.6)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* go mod tidy

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2020-12-18 05:47:00 +00:00
Ludovic Fernandez
e90655c23b
chore: clean go module replace directives. 2020-12-16 22:46:57 +00:00
dependabot-preview[bot]
f82d5fff7a
chore(deps): bump github.com/traefik/traefik/v2 from 2.3.4 to 2.3.5 (#131) 2020-12-11 09:22:44 +01:00
Ludovic Fernandez
cb06f5f58d
doc: add Traefik v2 example. (#129) 2020-12-05 21:23:25 +01:00
60 changed files with 1844 additions and 1498 deletions

3
.github/FUNDING.yml vendored
View File

@ -1 +1,4 @@
github: ldez
ko_fi: ldez_oss
liberapay: ldez
thanks_dev: u/gh/ldez

View File

@ -1,5 +1,12 @@
name: Go Matrix
on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
@ -11,32 +18,20 @@ jobs:
strategy:
matrix:
go-version: [ 1.14, 1.15, 1.x ]
go-version: [ stable ]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
path: |
~/go/pkg/mod # Module download cache
~/.cache/go-build # Build cache (Linux)
~/Library/Caches/go-build # Build cache (Mac)
'%LocalAppData%\go-build' # Build cache (Windows)
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go-version }}-go-
go-version: ${{ matrix.go-version }}
- name: Test
run: go test -v -cover ./...

View File

@ -3,10 +3,10 @@ name: Main
on:
push:
branches:
- master
tags:
- v*
- main
pull_request:
branches:
- main
jobs:
@ -14,75 +14,28 @@ jobs:
name: Main Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.15
GOLANGCI_LINT_VERSION: v1.33.0
SEIHON_VERSION: v0.5.1
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v2.0.1
CGO_ENABLED: 0
steps:
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
# https://github.com/marketplace/actions/checkout
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0
# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Check and get dependencies
run: |
go mod download
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum
go mod download
# https://golangci-lint.run/usage/install#other-ci
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
golangci-lint --version
- name: Make
run: make
# https://goreleaser.com/ci/actions/
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Install Docker image multi-arch builder
- name: Install seihon ${{ env.SEIHON_VERSION }}
if: startsWith(github.ref, 'refs/tags/v')
run: |
curl -sSfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | sh -s -- -b $(go env GOPATH)/bin ${SEIHON_VERSION}
seihon --version
- name: Docker Login
if: startsWith(github.ref, 'refs/tags/v')
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
- name: Deploy Docker Images (seihon)
if: startsWith(github.ref, 'refs/tags/v')
run: make publish-images

70
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,70 @@
name: "Release a tag"
on:
push:
tags:
- v*
jobs:
release:
name: Release Process
runs-on: ubuntu-latest
env:
GO_VERSION: stable
CGO_ENABLED: 0
steps:
# temporary workaround for an error in free disk space action
# https://github.com/jlumbroso/free-disk-space/issues/14
- name: Update Package List and Remove Dotnet
run: |
sudo apt-get update
sudo apt-get remove -y '^dotnet-.*'
# https://github.com/marketplace/actions/free-disk-space-ubuntu
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed
tool-cache: false
# all of these default to true
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: false
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: dockerhub-login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: ghcr-login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release -p 1 --clean --timeout=90m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,51 +0,0 @@
[run]
timeout = "5m"
skip-files = []
[linters-settings]
[linters-settings.govet]
check-shadowing = true
[linters-settings.gocyclo]
min-complexity = 12.0
[linters-settings.maligned]
suggest-new = true
[linters-settings.goconst]
min-len = 3.0
min-occurrences = 3.0
[linters-settings.misspell]
locale = "US"
[linters]
enable-all = true
disable = [
"maligned",
"lll",
"gosec",
"dupl",
"prealloc",
"scopelint",
"wsl",
"nlreturn",
"gomnd",
"testpackage",
"paralleltest",
"tparallel",
"goerr113",
"wrapcheck",
"exhaustive",
"exhaustivestruct",
]
[issues]
exclude-use-default = false
max-per-linter = 0
max-same-issues = 0
exclude = ["ST1000: at least one file in a package should have a package comment"]
[[issues.exclude-rules]]
path = "cmd/"
linters = ["gochecknoglobals", "gochecknoinits"]

108
.golangci.yml Normal file
View File

@ -0,0 +1,108 @@
version: "2"
formatters:
enable:
- gci
- gofumpt
settings:
gofumpt:
extra-rules: true
linters:
default: all
disable:
- cyclop # duplicate of gocyclo
- dupl
- err113
- exhaustive
- exhaustruct
- lll
- mnd
- nilnil
- nlreturn
- paralleltest
- prealloc
- rowserrcheck # not relevant (SQL)
- sqlclosecheck # not relevant (SQL)
- testpackage
- tparallel
- varnamelen
- wrapcheck
- wsl
settings:
depguard:
rules:
main:
deny:
- pkg: github.com/instana/testify
desc: not allowed
- pkg: github.com/pkg/errors
desc: Should be replaced by standard lib errors package
forbidigo:
forbid:
- pattern: ^print(ln)?$
- pattern: ^spew\.Print(f|ln)?$
- pattern: ^spew\.Dump$
funlen:
lines: -1
statements: 40
goconst:
min-len: 3
min-occurrences: 3
gocritic:
disabled-checks:
- sloppyReassign
- rangeValCopy
- octalLiteral
- paramTypeCombine # already handle by gofumpt.extra-rules
enabled-tags:
- diagnostic
- style
- performance
settings:
hugeParam:
sizeThreshold: 100
gocyclo:
min-complexity: 12
godox:
keywords:
- FIXME
gomoddirectives:
replace-allow-list:
- github.com/abbot/go-http-auth
- github.com/go-check/check
- github.com/gorilla/mux
- github.com/mailgun/minheap
- github.com/mailgun/multibuf
- github.com/jaguilar/vt100
gosec:
excludes:
- G204 # Subprocess launched with a potential tainted input or cmd arguments
- G301 # Expect directory permissions to be 0750 or less
- G306 # Expect WriteFile permissions to be 0600 or less
govet:
disable:
- fieldalignment
enable-all: true
misspell:
locale: US
exclusions:
presets:
- comments
rules:
- linters:
- gochecknoglobals
- gochecknoinits
path: cmd/
- linters:
- tagalign
path: internal/traefikv[1-3]/
- path: (.+)\.go$
text: 'ST1000: at least one file in a package should have a package comment'
- path: (.+)\.go$
text: 'package-comments: should have a package comment'
issues:
max-issues-per-linter: 0
max-same-issues: 0

View File

@ -1,3 +1,4 @@
version: 2
project_name: traefik-certs-dumper
builds:
@ -5,7 +6,7 @@ builds:
ldflags:
- -s -w -X github.com/ldez/traefik-certs-dumper/cmd.version={{.Version}} -X github.com/ldez/traefik-certs-dumper/cmd.commit={{.ShortCommit}} -X github.com/ldez/traefik-certs-dumper/cmd.date={{.Date}}
env:
- GO111MODULE=on
- CGO_ENABLED=0
goos:
- linux
- darwin
@ -40,9 +41,182 @@ changelog:
archives:
- id: tcd
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format: tar.gz
formats: [ 'tar.gz' ]
format_overrides:
- goos: windows
format: zip
formats: [ 'zip' ]
files:
- LICENSE
docker_manifests:
- name_template: 'ldez/traefik-certs-dumper:{{ .Tag }}'
image_templates:
- 'ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-386'
- name_template: 'ldez/traefik-certs-dumper:latest'
image_templates:
- 'ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-386'
- name_template: 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}'
image_templates:
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-amd64'
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-arm64'
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv7'
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv6'
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-386'
- name_template: 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}'
image_templates:
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-386'
- name_template: 'ghcr.io/ldez/traefik-certs-dumper:latest'
image_templates:
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-386'
- name_template: 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}'
image_templates:
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-amd64'
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-arm64'
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv7'
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv6'
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-386'
dockers:
- use: buildx
goos: linux
goarch: amd64
dockerfile: buildx.Dockerfile
image_templates:
- 'ldez/traefik-certs-dumper:latest-amd64'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-amd64'
- 'ghcr.io/ldez/traefik-certs-dumper:latest-amd64'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-amd64'
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-amd64'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/amd64'
- use: buildx
goos: linux
goarch: arm64
dockerfile: buildx.Dockerfile
image_templates:
- 'ldez/traefik-certs-dumper:latest-arm64'
- 'ldez/traefik-certs-dumper:latest-arm.v8' # only for compatibility with Seihon
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm.v8' # only for compatibility with Seihon
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-arm64'
- 'ghcr.io/ldez/traefik-certs-dumper:latest-arm64'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-arm64'
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-arm64'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/arm64'
- use: buildx
goos: linux
goarch: arm
goarm: '7'
dockerfile: buildx.Dockerfile
image_templates:
- 'ldez/traefik-certs-dumper:latest-armv7'
- 'ldez/traefik-certs-dumper:latest-arm.v7' # only for compatibility with Seihon
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm.v7' # only for compatibility with Seihon
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv7'
- 'ghcr.io/ldez/traefik-certs-dumper:latest-armv7'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv7'
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv7'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/arm/v7'
- use: buildx
goos: linux
goarch: arm
goarm: '6'
dockerfile: buildx.Dockerfile
image_templates:
- 'ldez/traefik-certs-dumper:latest-armv6'
- 'ldez/traefik-certs-dumper:latest-arm.v6' # only for compatibility with Seihon
- 'ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-arm.v6' # only for compatibility with Seihon
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv6'
- 'ghcr.io/ldez/traefik-certs-dumper:latest-armv6'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-armv6'
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-armv6'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/arm/v6'
- use: buildx
goos: linux
goarch: '386'
dockerfile: buildx.Dockerfile
image_templates:
- 'ldez/traefik-certs-dumper:latest-386'
- 'ldez/traefik-certs-dumper:{{ .Tag }}-386'
- 'ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-386'
- 'ghcr.io/ldez/traefik-certs-dumper:latest-386'
- 'ghcr.io/ldez/traefik-certs-dumper:{{ .Tag }}-386'
- 'ghcr.io/ldez/traefik-certs-dumper:v{{ .Major }}.{{ .Minor }}-386'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Dump ACME data from Traefik to certificates'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation=https://github.com/ldez/traefik-certs-dumper'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/386'

View File

@ -1,21 +0,0 @@
FROM golang:1-alpine as builder
RUN apk --update upgrade \
&& apk --no-cache --no-progress add git make gcc musl-dev
WORKDIR /go/src/github.com/ldez/traefik-certs-dumper
ENV GO111MODULE on
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN make build
FROM alpine:3.10
RUN apk --update upgrade \
&& apk --no-cache --no-progress add ca-certificates
COPY --from=builder /go/src/github.com/ldez/traefik-certs-dumper/traefik-certs-dumper /usr/bin/traefik-certs-dumper
ENTRYPOINT ["/usr/bin/traefik-certs-dumper"]

View File

@ -1,4 +1,4 @@
Copyright 2019 Fernandez Ludovic
Copyright 2019-2024 Fernandez Ludovic
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -25,6 +25,3 @@ checks:
doc:
go run . doc
publish-images:
seihon publish -v "$(TAG_NAME)" -v "latest" --image-name ldez/traefik-certs-dumper --dry-run=false

9
buildx.Dockerfile Normal file
View File

@ -0,0 +1,9 @@
# syntax=docker/dockerfile:1.4
FROM alpine:3
RUN apk --no-cache --no-progress add git ca-certificates tzdata jq \
&& rm -rf /var/cache/apk/*
COPY traefik-certs-dumper /usr/bin/traefik-certs-dumper
ENTRYPOINT ["/usr/bin/traefik-certs-dumper"]

View File

@ -1,8 +1,10 @@
package cmd
import (
"github.com/abronan/valkeyrie/store"
"github.com/abronan/valkeyrie/store/boltdb"
"context"
"time"
"github.com/kvtools/boltdb"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
"github.com/spf13/cobra"
@ -29,11 +31,20 @@ func boltdbRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error {
return err
}
config.Options.Bucket = cmd.Flag("bucket").Value.String()
config.Options.PersistConnection, _ = cmd.Flags().GetBool("persist-connection")
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
if err != nil {
return err
}
config.Backend = store.BOLTDB
boltdb.Register()
persistConnection, _ := cmd.Flags().GetBool("persist-connection")
return kv.Dump(config, baseConfig)
config.Options = &boltdb.Config{
Bucket: cmd.Flag("bucket").Value.String(),
PersistConnection: persistConnection,
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
}
config.StoreName = boltdb.StoreName
return kv.Dump(context.Background(), config, baseConfig)
}

View File

@ -1,8 +1,10 @@
package cmd
import (
"github.com/abronan/valkeyrie/store"
"github.com/abronan/valkeyrie/store/consul"
"context"
"time"
"github.com/kvtools/consul"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
"github.com/spf13/cobra"
@ -28,10 +30,24 @@ func consulRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error {
return err
}
config.Options.Token = cmd.Flag("token").Value.String()
tlsConfig, err := createTLSConfig(cmd)
if err != nil {
return err
}
config.Backend = store.CONSUL
consul.Register()
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
if err != nil {
return err
}
return kv.Dump(config, baseConfig)
config.Options = &consul.Config{
TLS: tlsConfig,
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
Token: cmd.Flag("token").Value.String(),
Namespace: "",
}
config.StoreName = consul.StoreName
return kv.Dump(context.Background(), config, baseConfig)
}

View File

@ -10,7 +10,7 @@ var docCmd = &cobra.Command{
Use: "doc",
Short: "Generate documentation",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return doc.GenMarkdownTree(rootCmd, "./docs")
},
}

View File

@ -1,11 +1,11 @@
package cmd
import (
"context"
"time"
"github.com/abronan/valkeyrie/store"
etcdv2 "github.com/abronan/valkeyrie/store/etcd/v2"
etcdv3 "github.com/abronan/valkeyrie/store/etcd/v3"
"github.com/kvtools/etcdv2"
"github.com/kvtools/etcdv3"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
"github.com/spf13/cobra"
@ -32,25 +32,47 @@ func etcdRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error {
return err
}
backend, err := cmd.Flags().GetString("etcd-version")
if err != nil {
return err
}
tlsConfig, err := createTLSConfig(cmd)
if err != nil {
return err
}
synPeriod, err := cmd.Flags().GetInt("sync-period")
if err != nil {
return err
}
config.Options.SyncPeriod = time.Duration(synPeriod) * time.Second
backend, err := cmd.Flags().GetString("etcd-version")
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
if err != nil {
return err
}
switch backend {
case "etcdv3":
config.Backend = store.ETCDV3
etcdv3.Register()
config.Options = &etcdv3.Config{
TLS: tlsConfig,
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
SyncPeriod: time.Duration(synPeriod) * time.Second,
Username: cmd.Flag("password").Value.String(),
Password: cmd.Flag("username").Value.String(),
}
config.StoreName = etcdv3.StoreName
default:
config.Backend = store.ETCD
etcdv2.Register()
config.Options = &etcdv2.Config{
TLS: tlsConfig,
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
SyncPeriod: time.Duration(synPeriod) * time.Second,
Username: cmd.Flag("password").Value.String(),
Password: cmd.Flag("username").Value.String(),
}
config.StoreName = etcdv2.StoreName
}
return kv.Dump(config, baseConfig)
return kv.Dump(context.Background(), config, baseConfig)
}

View File

@ -1,12 +1,13 @@
package cmd
import (
"context"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
"github.com/ldez/traefik-certs-dumper/v2/dumper/file"
"github.com/spf13/cobra"
)
// fileCmd represents the file command.
var fileCmd = &cobra.Command{
Use: "file",
Short: `Dump the content of the "acme.json" file.`,
@ -16,7 +17,7 @@ var fileCmd = &cobra.Command{
baseConfig.Version = cmd.Flag("version").Value.String()
return file.Dump(acmeFile, baseConfig)
return file.Dump(context.Background(), acmeFile, baseConfig)
}),
}
@ -24,5 +25,5 @@ func init() {
rootCmd.AddCommand(fileCmd)
fileCmd.Flags().String("source", "./acme.json", "Path to 'acme.json' file.")
fileCmd.Flags().String("version", "", "Traefik version. If empty use v1. Possible values: 'v2'.")
fileCmd.Flags().String("version", "", "Traefik version. If empty use v1. Possible values: 'v2', 'v3'.")
}

View File

@ -3,13 +3,11 @@ package cmd
import (
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/abronan/valkeyrie/store"
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
"github.com/spf13/cobra"
)
@ -45,26 +43,10 @@ func getKvConfig(cmd *cobra.Command) (*kv.Config, error) {
return nil, err
}
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
if err != nil {
return nil, err
}
tlsConfig, err := createTLSConfig(cmd)
if err != nil {
return nil, err
}
return &kv.Config{
Endpoints: endpoints,
Prefix: cmd.Flag("prefix").Value.String(),
Suffix: cmd.Flag("suffix").Value.String(),
Options: &store.Config{
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
Username: cmd.Flag("password").Value.String(),
Password: cmd.Flag("username").Value.String(),
TLS: tlsConfig,
},
}, nil
}
@ -87,8 +69,8 @@ func createTLSConfig(cmd *cobra.Command) (*tls.Config, error) {
privateKey := cmd.Flag("tls.key").Value.String()
certContent := cmd.Flag("tls.cert").Value.String()
if !insecureSkipVerify && (len(certContent) == 0 || len(privateKey) == 0) {
return nil, fmt.Errorf("TLS Certificate or Key file must be set when TLS configuration is created")
if !insecureSkipVerify && (certContent == "" || privateKey == "") {
return nil, errors.New("TLS Certificate or Key file must be set when TLS configuration is created")
}
cert, err := getCertificate(privateKey, certContent)
@ -99,7 +81,7 @@ func createTLSConfig(cmd *cobra.Command) (*tls.Config, error) {
return &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: caPool,
InsecureSkipVerify: insecureSkipVerify,
InsecureSkipVerify: insecureSkipVerify, //nolint:gosec // it's a CLI option.
ClientAuth: clientAuth,
}, nil
}
@ -114,7 +96,7 @@ func getCertPool(ca string) (*x509.CertPool, error) {
}
if !caPool.AppendCertsFromPEM(caContent) {
return nil, fmt.Errorf("failed to parse CA")
return nil, errors.New("failed to parse CA")
}
}
@ -122,11 +104,14 @@ func getCertPool(ca string) (*x509.CertPool, error) {
}
func getCAContent(ca string) ([]byte, error) {
if _, errCA := os.Stat(ca); errCA != nil {
return []byte(ca), nil
if _, err := os.Stat(ca); err != nil {
if os.IsNotExist(err) {
return []byte(ca), nil
}
return nil, err
}
caContent, err := ioutil.ReadFile(filepath.Clean(ca))
caContent, err := os.ReadFile(filepath.Clean(ca))
if err != nil {
return nil, err
}
@ -153,11 +138,11 @@ func getCertificate(privateKey, certContent string) (tls.Certificate, error) {
_, errCertIsFile := os.Stat(certContent)
if errCertIsFile == nil && os.IsNotExist(errKeyIsFile) {
return tls.Certificate{}, fmt.Errorf("tls cert is a file, but tls key is not")
return tls.Certificate{}, errors.New("tls cert is a file, but tls key is not")
}
if os.IsNotExist(errCertIsFile) && errKeyIsFile == nil {
return tls.Certificate{}, fmt.Errorf("TLS key is a file, but tls cert is not")
return tls.Certificate{}, errors.New("TLS key is a file, but tls cert is not")
}
// string

View File

@ -1,15 +1,18 @@
package cmd
import (
"crypto/rand"
"fmt"
"io/ioutil"
"log"
"math/big"
"os"
"path/filepath"
"strconv"
"time"
"github.com/charmbracelet/lipgloss"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
homedir "github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@ -21,7 +24,7 @@ var rootCmd = &cobra.Command{
Use: "traefik-certs-dumper",
Short: "Dump Let's Encrypt certificates from Traefik.",
Long: `Dump Let's Encrypt certificates from Traefik.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
if cmd.Name() == "version" {
return nil
}
@ -35,6 +38,7 @@ var rootCmd = &cobra.Command{
return fmt.Errorf("--crt-ext (%q) and --key-ext (%q) are identical, in this case --domain-subdir is required", crtExt, keyExt)
}
}
return nil
},
}
@ -46,6 +50,8 @@ func Execute() {
log.Println(err)
os.Exit(1)
}
help()
}
func init() {
@ -117,7 +123,7 @@ func tree(root, indent string) error {
return nil
}
fis, err := ioutil.ReadDir(root)
fis, err := os.ReadDir(root)
if err != nil {
return fmt.Errorf("could not read dir %s: %w", root, err)
}
@ -132,10 +138,10 @@ func tree(root, indent string) error {
for i, name := range names {
add := "│ "
if i == len(names)-1 {
fmt.Printf(indent + "└──")
fmt.Print(indent + "└──")
add = " "
} else {
fmt.Printf(indent + "├──")
fmt.Print(indent + "├──")
}
if err := tree(filepath.Join(root, name), indent+add); err != nil {
@ -178,3 +184,34 @@ func getBaseConfig(cmd *cobra.Command) (*dumper.BaseConfig, error) {
Hook: cmd.Flag("post-hook").Value.String(),
}, nil
}
func help() {
var maxInt int64 = 2 // -> 50%
if time.Now().Month() == time.December {
maxInt = 1 // -> 100%
}
n, _ := rand.Int(rand.Reader, big.NewInt(maxInt))
if n.Cmp(big.NewInt(0)) != 0 {
return
}
log.SetFlags(0)
pStyle := lipgloss.NewStyle().
Padding(1).
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.Color("161")).
Align(lipgloss.Center)
hStyle := lipgloss.NewStyle().Bold(true)
s := fmt.Sprintln(hStyle.Render("Request for Donation."))
s += `
I need your help!
Donations fund the maintenance and development of traefik-certs-dumper.
Click on this link to donate: https://donate.ldez.dev`
log.Println(pStyle.Render(s))
log.SetFlags(log.LstdFlags | log.Lshortfile)
}

View File

@ -17,7 +17,7 @@ var (
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display version",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
displayVersion(rootCmd.Name())
},
}

View File

@ -1,8 +1,10 @@
package cmd
import (
"github.com/abronan/valkeyrie/store"
"github.com/abronan/valkeyrie/store/zookeeper"
"context"
"time"
"github.com/kvtools/zookeeper"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
"github.com/ldez/traefik-certs-dumper/v2/dumper/kv"
"github.com/spf13/cobra"
@ -26,8 +28,19 @@ func zookeeperRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error {
return err
}
config.Backend = store.ZK
zookeeper.Register()
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout")
if err != nil {
return err
}
return kv.Dump(config, baseConfig)
config.Options = &zookeeper.Config{
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second,
Username: cmd.Flag("password").Value.String(),
Password: cmd.Flag("username").Value.String(),
MaxBufferSize: 0,
}
config.StoreName = zookeeper.StoreName
return kv.Dump(context.Background(), config, baseConfig)
}

1
contrib/readme.md Normal file
View File

@ -0,0 +1 @@
This directory content external contributions that are not maintain by @ldez.

View File

@ -0,0 +1,40 @@
[Unit]
Description=traefik certs dumper
; If you do not start traefik via systemd, choose network.target or docker.target
After=traefik.target
Wants=network-online.target systemd-networkd-wait-online.service
[Service]
Restart=on-abnormal
User=root
ExecStart=/usr/local/bin/traefik-certs-dumper file --version v2 --source /etc/traefik/acme/acme.json --dest /etc/ssl --watch
RestartSec=30
TimeoutSec=30
;WatchdogSec=30
; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
; LimitNOFILE=1048576
; Limit number of processes in this unit
LimitNPROC=1
; Use private /tmp and /var/tmp, which are discarded after traefik stops.
PrivateTmp=true
; Use a minimal /dev (May bring additional security if switched to 'true', but it may not work on Raspberry Pis or other devices)
PrivateDevices=true
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
ProtectHome=true
; Make cgroups /sys/fs/cgroup read-only
ProtectControlGroups=true
; Make kernel settings (procfs and sysfs) read-only
ProtectKernelTunables=true
; Make /usr, /boot, /etc and possibly some more folders read-only.
ProtectSystem=full
; This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
ReadWriteDirectories=/etc/ssl
ReadOnlyPaths=/etc/traefik/acme/acme.json
; The following additional security directives only work with systemd v229 or later.
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target

View File

@ -1,5 +1,3 @@
version: '3.7'
services:
traefik:
image: traefik:v1.7
@ -25,10 +23,9 @@ services:
- ./letsencrypt:/letsencrypt
traefik-certs-dumper:
image: ldez/traefik-certs-dumper:v2.7.0
image: ldez/traefik-certs-dumper:v2.9.3
entrypoint: sh -c '
apk add jq
; while ! [ -e /data/acme.json ]
while ! [ -e /data/acme.json ]
|| ! [ `jq ".Certificates | length" /data/acme.json` != 0 ]; do
sleep 1
; done
@ -36,9 +33,10 @@ services:
--source /data/acme.json --dest /data/certs'
volumes:
- ./letsencrypt:/data
network_mode: "none"
whoami:
image: containous/whoami
image: traefik/whoami:v1.8.1
labels:
traefik.enable: true
traefik.frontend.rule: Host:example.com

View File

@ -0,0 +1,44 @@
services:
traefik:
image: traefik:v2.11.3
command:
- --log.level=INFO
- --entrypoints.web.address=:80
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.websecure.address=:443
- --entrypoints.websecure.http.tls=true
- --entrypoints.websecure.http.tls.certResolver=le
- --providers.docker.exposedbydefault=false
- --certificatesresolvers.le.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
- --certificatesresolvers.le.acme.email=email@example.com
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
- --certificatesresolvers.le.acme.tlsChallenge=true
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./letsencrypt/:/letsencrypt
traefik-certs-dumper:
image: ldez/traefik-certs-dumper:v2.9.3
entrypoint: sh -c '
while ! [ -e /data/acme.json ]
|| ! [ `jq ".[] | .Certificates | length" /data/acme.json | jq -s "add" ` != 0 ]; do
sleep 1
; done
&& traefik-certs-dumper file --version v2 --watch
--source /data/acme.json --dest /data/certs'
volumes:
- ./letsencrypt:/data
network_mode: "none"
whoami:
image: traefik/whoami:v1.8.1
labels:
traefik.enable: 'true'
traefik.http.routers.app.rule: Host(`example.com`)
traefik.http.routers.app.entrypoints: websecure

View File

@ -24,8 +24,9 @@ Dump Let's Encrypt certificates from Traefik.
### SEE ALSO
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
* [traefik-certs-dumper file](traefik-certs-dumper_file.md) - Dump the content of the "acme.json" file.
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
* [traefik-certs-dumper version](traefik-certs-dumper_version.md) - Display version
###### Auto generated by spf13/cobra on 9-Oct-2019
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -0,0 +1,40 @@
## traefik-certs-dumper completion
Generate the autocompletion script for the specified shell
### Synopsis
Generate the autocompletion script for traefik-certs-dumper for the specified shell.
See each sub-command's help for details on how to use the generated script.
### Options
```
-h, --help help for completion
```
### Options inherited from parent commands
```
--clean Clean destination folder before dumping content. (default true)
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
--crt-ext string The file extension of the generated certificates. (default ".crt")
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
--dest string Path to store the dump content. (default "./dump")
--domain-subdir Use domain as sub-directory.
--key-ext string The file extension of the generated private keys. (default ".key")
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
--watch Enable watching changes.
```
### SEE ALSO
* [traefik-certs-dumper](traefik-certs-dumper.md) - Dump Let's Encrypt certificates from Traefik.
* [traefik-certs-dumper completion bash](traefik-certs-dumper_completion_bash.md) - Generate the autocompletion script for bash
* [traefik-certs-dumper completion fish](traefik-certs-dumper_completion_fish.md) - Generate the autocompletion script for fish
* [traefik-certs-dumper completion powershell](traefik-certs-dumper_completion_powershell.md) - Generate the autocompletion script for powershell
* [traefik-certs-dumper completion zsh](traefik-certs-dumper_completion_zsh.md) - Generate the autocompletion script for zsh
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -0,0 +1,59 @@
## traefik-certs-dumper completion bash
Generate the autocompletion script for bash
### Synopsis
Generate the autocompletion script for the bash shell.
This script depends on the 'bash-completion' package.
If it is not installed already, you can install it via your OS's package manager.
To load completions in your current shell session:
source <(traefik-certs-dumper completion bash)
To load completions for every new session, execute once:
#### Linux:
traefik-certs-dumper completion bash > /etc/bash_completion.d/traefik-certs-dumper
#### macOS:
traefik-certs-dumper completion bash > $(brew --prefix)/etc/bash_completion.d/traefik-certs-dumper
You will need to start a new shell for this setup to take effect.
```
traefik-certs-dumper completion bash
```
### Options
```
-h, --help help for bash
--no-descriptions disable completion descriptions
```
### Options inherited from parent commands
```
--clean Clean destination folder before dumping content. (default true)
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
--crt-ext string The file extension of the generated certificates. (default ".crt")
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
--dest string Path to store the dump content. (default "./dump")
--domain-subdir Use domain as sub-directory.
--key-ext string The file extension of the generated private keys. (default ".key")
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
--watch Enable watching changes.
```
### SEE ALSO
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -0,0 +1,50 @@
## traefik-certs-dumper completion fish
Generate the autocompletion script for fish
### Synopsis
Generate the autocompletion script for the fish shell.
To load completions in your current shell session:
traefik-certs-dumper completion fish | source
To load completions for every new session, execute once:
traefik-certs-dumper completion fish > ~/.config/fish/completions/traefik-certs-dumper.fish
You will need to start a new shell for this setup to take effect.
```
traefik-certs-dumper completion fish [flags]
```
### Options
```
-h, --help help for fish
--no-descriptions disable completion descriptions
```
### Options inherited from parent commands
```
--clean Clean destination folder before dumping content. (default true)
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
--crt-ext string The file extension of the generated certificates. (default ".crt")
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
--dest string Path to store the dump content. (default "./dump")
--domain-subdir Use domain as sub-directory.
--key-ext string The file extension of the generated private keys. (default ".key")
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
--watch Enable watching changes.
```
### SEE ALSO
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -0,0 +1,47 @@
## traefik-certs-dumper completion powershell
Generate the autocompletion script for powershell
### Synopsis
Generate the autocompletion script for powershell.
To load completions in your current shell session:
traefik-certs-dumper completion powershell | Out-String | Invoke-Expression
To load completions for every new session, add the output of the above command
to your powershell profile.
```
traefik-certs-dumper completion powershell [flags]
```
### Options
```
-h, --help help for powershell
--no-descriptions disable completion descriptions
```
### Options inherited from parent commands
```
--clean Clean destination folder before dumping content. (default true)
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
--crt-ext string The file extension of the generated certificates. (default ".crt")
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
--dest string Path to store the dump content. (default "./dump")
--domain-subdir Use domain as sub-directory.
--key-ext string The file extension of the generated private keys. (default ".key")
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
--watch Enable watching changes.
```
### SEE ALSO
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -0,0 +1,61 @@
## traefik-certs-dumper completion zsh
Generate the autocompletion script for zsh
### Synopsis
Generate the autocompletion script for the zsh shell.
If shell completion is not already enabled in your environment you will need
to enable it. You can execute the following once:
echo "autoload -U compinit; compinit" >> ~/.zshrc
To load completions in your current shell session:
source <(traefik-certs-dumper completion zsh)
To load completions for every new session, execute once:
#### Linux:
traefik-certs-dumper completion zsh > "${fpath[1]}/_traefik-certs-dumper"
#### macOS:
traefik-certs-dumper completion zsh > $(brew --prefix)/share/zsh/site-functions/_traefik-certs-dumper
You will need to start a new shell for this setup to take effect.
```
traefik-certs-dumper completion zsh [flags]
```
### Options
```
-h, --help help for zsh
--no-descriptions disable completion descriptions
```
### Options inherited from parent commands
```
--clean Clean destination folder before dumping content. (default true)
--config string config file (default is $HOME/.traefik-certs-dumper.yaml)
--crt-ext string The file extension of the generated certificates. (default ".crt")
--crt-name string The file name (without extension) of the generated certificates. (default "certificate")
--dest string Path to store the dump content. (default "./dump")
--domain-subdir Use domain as sub-directory.
--key-ext string The file extension of the generated private keys. (default ".key")
--key-name string The file name (without extension) of the generated private keys. (default "privatekey")
--post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode)
--watch Enable watching changes.
```
### SEE ALSO
* [traefik-certs-dumper completion](traefik-certs-dumper_completion.md) - Generate the autocompletion script for the specified shell
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -15,7 +15,7 @@ traefik-certs-dumper file [flags]
```
-h, --help help for file
--source string Path to 'acme.json' file. (default "./acme.json")
--version string Traefik version. If empty use v1. Possible values: 'v2'.
--version string Traefik version. If empty use v1. Possible values: 'v2', 'v3'.
```
### Options inherited from parent commands
@ -37,4 +37,4 @@ traefik-certs-dumper file [flags]
* [traefik-certs-dumper](traefik-certs-dumper.md) - Dump Let's Encrypt certificates from Traefik.
###### Auto generated by spf13/cobra on 9-Oct-2019
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -47,4 +47,4 @@ Dump the content of a KV store.
* [traefik-certs-dumper kv etcd](traefik-certs-dumper_kv_etcd.md) - Dump the content of etcd.
* [traefik-certs-dumper kv zookeeper](traefik-certs-dumper_kv_zookeeper.md) - Dump the content of zookeeper.
###### Auto generated by spf13/cobra on 9-Oct-2019
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -49,4 +49,4 @@ traefik-certs-dumper kv boltdb [flags]
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
###### Auto generated by spf13/cobra on 9-Oct-2019
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -48,4 +48,4 @@ traefik-certs-dumper kv consul [flags]
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
###### Auto generated by spf13/cobra on 9-Oct-2019
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -49,4 +49,4 @@ traefik-certs-dumper kv etcd [flags]
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
###### Auto generated by spf13/cobra on 9-Oct-2019
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -47,4 +47,4 @@ traefik-certs-dumper kv zookeeper [flags]
* [traefik-certs-dumper kv](traefik-certs-dumper_kv.md) - Dump the content of a KV store.
###### Auto generated by spf13/cobra on 9-Oct-2019
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -2,10 +2,6 @@
Display version
### Synopsis
Display version
```
traefik-certs-dumper version [flags]
```
@ -35,4 +31,4 @@ traefik-certs-dumper version [flags]
* [traefik-certs-dumper](traefik-certs-dumper.md) - Dump Let's Encrypt certificates from Traefik.
###### Auto generated by spf13/cobra on 9-Oct-2019
###### Auto generated by spf13/cobra on 21-Feb-2025

View File

@ -2,7 +2,8 @@ package file
import (
"bytes"
"crypto/md5"
"context"
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
@ -14,61 +15,95 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
v1 "github.com/ldez/traefik-certs-dumper/v2/dumper/v1"
v2 "github.com/ldez/traefik-certs-dumper/v2/dumper/v2"
dumperv1 "github.com/ldez/traefik-certs-dumper/v2/dumper/v1"
dumperv2 "github.com/ldez/traefik-certs-dumper/v2/dumper/v2"
dumperv3 "github.com/ldez/traefik-certs-dumper/v2/dumper/v3"
"github.com/ldez/traefik-certs-dumper/v2/hook"
"github.com/traefik/traefik/v2/pkg/provider/acme"
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv1"
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv2"
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv3"
)
// Dump Dumps "acme.json" file to certificates.
func Dump(acmeFile string, baseConfig *dumper.BaseConfig) error {
func Dump(ctx context.Context, acmeFile string, baseConfig *dumper.BaseConfig) error {
err := dump(acmeFile, baseConfig)
if err != nil {
return err
}
if baseConfig.Watch {
hook.Exec(baseConfig.Hook)
hook.Exec(ctx, baseConfig.Hook)
return watch(acmeFile, baseConfig)
return watch(ctx, acmeFile, baseConfig)
}
return nil
}
func dump(acmeFile string, baseConfig *dumper.BaseConfig) error {
if baseConfig.Version == "v2" {
switch baseConfig.Version {
case "v3":
err := dumpV3(acmeFile, baseConfig)
if err != nil {
return fmt.Errorf("v3: dump failed: %w", err)
}
return nil
case "v2":
err := dumpV2(acmeFile, baseConfig)
if err != nil {
return fmt.Errorf("v2: dump failed: %w", err)
}
return nil
case "v1":
err := dumpV1(acmeFile, baseConfig)
if err != nil {
return fmt.Errorf("v1: dump failed: %w", err)
}
return nil
default:
err := dumpV1(acmeFile, baseConfig)
if err != nil {
return fmt.Errorf("v1: dump failed: %w", err)
}
return nil
}
err := dumpV1(acmeFile, baseConfig)
if err != nil {
return fmt.Errorf("v1: dump failed: %w", err)
}
return nil
}
func dumpV1(acmeFile string, baseConfig *dumper.BaseConfig) error {
data := &v1.StoredData{}
data := &traefikv1.StoredData{}
err := readJSONFile(acmeFile, data)
if err != nil {
return err
}
return v1.Dump(data, baseConfig)
return dumperv1.Dump(data, baseConfig)
}
func dumpV2(acmeFile string, baseConfig *dumper.BaseConfig) error {
data := map[string]*acme.StoredData{}
data := map[string]*traefikv2.StoredData{}
err := readJSONFile(acmeFile, &data)
if err != nil {
return err
}
return v2.Dump(data, baseConfig)
return dumperv2.Dump(data, baseConfig)
}
func dumpV3(acmeFile string, baseConfig *dumper.BaseConfig) error {
data := map[string]*traefikv3.StoredData{}
err := readJSONFile(acmeFile, &data)
if err != nil {
return err
}
return dumperv3.Dump(data, baseConfig)
}
func readJSONFile(acmeFile string, data interface{}) error {
@ -90,7 +125,7 @@ func readJSONFile(acmeFile string, data interface{}) error {
return nil
}
func watch(acmeFile string, baseConfig *dumper.BaseConfig) error {
func watch(ctx context.Context, acmeFile string, baseConfig *dumper.BaseConfig) error {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return fmt.Errorf("failed to create new watcher: %w", err)
@ -113,7 +148,7 @@ func watch(acmeFile string, baseConfig *dumper.BaseConfig) error {
log.Println("event:", event)
}
hash, errW := manageEvent(watcher, event, acmeFile, previousHash, baseConfig)
hash, errW := manageEvent(ctx, watcher, event, acmeFile, previousHash, baseConfig)
if errW != nil {
log.Println("error:", errW)
done <- true
@ -144,7 +179,7 @@ func watch(acmeFile string, baseConfig *dumper.BaseConfig) error {
return nil
}
func manageEvent(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile string, previousHash []byte, baseConfig *dumper.BaseConfig) ([]byte, error) {
func manageEvent(ctx context.Context, watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile string, previousHash []byte, baseConfig *dumper.BaseConfig) ([]byte, error) {
err := manageRename(watcher, event, acmeFile)
if err != nil {
return nil, fmt.Errorf("watcher renewal failed: %w", err)
@ -168,7 +203,7 @@ func manageEvent(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile strin
log.Println("Dumped new certificate data.")
}
hook.Exec(baseConfig.Hook)
hook.Exec(ctx, baseConfig.Hook)
}
return hash, nil
@ -193,7 +228,7 @@ func calculateHash(acmeFile string) ([]byte, error) {
}
defer func() { _ = file.Close() }()
h := md5.New()
h := sha256.New()
_, err = io.Copy(h, file)
if err != nil {
return nil, err

View File

@ -1,8 +1,6 @@
package file
import (
"io/ioutil"
"os"
"testing"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
@ -28,16 +26,18 @@ func TestDump(t *testing.T) {
acmeFile: "./fixtures/acme-v2.json",
version: "v2",
},
{
desc: "should dump traefik v3 file content",
acmeFile: "./fixtures/acme-v3.json",
version: "v3",
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
dir, err := ioutil.TempDir("", "traefik-cert-dumper")
require.NoError(t, err)
defer func() { _ = os.RemoveAll(dir) }()
dir := t.TempDir()
cfg := &dumper.BaseConfig{
DumpPath: dir,
@ -53,7 +53,7 @@ func TestDump(t *testing.T) {
Version: test.version,
}
err = Dump(test.acmeFile, cfg)
err := Dump(t.Context(), test.acmeFile, cfg)
require.NoError(t, err)
})
}

View File

@ -0,0 +1,36 @@
{
"default": {
"Account": {
"Email": "test@email.com",
"Registration": {
"body": {
"status": "valid",
"contact": [
"mailto:test@email.com"
]
},
"uri": "https://acme-v02.api.letsencrypt.org/acme/acct/12345678"
},
"PrivateKey": "Q2VydGlmaWNhdGUgS2V5",
"KeyType": "4096"
},
"Certificates": [
{
"domain": {
"main": "my.domain.com"
},
"certificate": "Q2VydGlmaWNhdGU=",
"key": "Q2VydGlmaWNhdGUgS2V5",
"Store": "default"
},
{
"domain": {
"main": "my.domain2.com"
},
"certificate": "Q2VydGlmaWNhdGU=",
"key": "Q2VydGlmaWNhdGUgS2V5",
"Store": "default"
}
]
}
}

View File

@ -1,12 +1,14 @@
package kv
import "github.com/abronan/valkeyrie/store"
import (
"github.com/kvtools/valkeyrie"
)
// Config KV configuration.
type Config struct {
Backend store.Backend
StoreName string
Prefix string
Suffix string
Endpoints []string
Options *store.Config
Options valkeyrie.Config
}

View File

@ -3,7 +3,7 @@ package kv
import (
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/registration"
v1 "github.com/ldez/traefik-certs-dumper/v2/dumper/v1"
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv1"
)
// CertificateOld is used to store certificate info.
@ -39,14 +39,14 @@ type ChallengeCert struct {
// DomainsCertificate contains a certificate for multiple domains.
type DomainsCertificate struct {
Domains v1.Domain
Domains traefikv1.Domain
Certificate *CertificateOld
}
// convertOldAccount converts account information from old account format.
func convertOldAccount(account *AccountOld) *v1.StoredData {
storedData := &v1.StoredData{
Account: &v1.Account{
func convertOldAccount(account *AccountOld) *traefikv1.StoredData {
storedData := &traefikv1.StoredData{
Account: &traefikv1.Account{
PrivateKey: account.PrivateKey,
Registration: account.Registration,
Email: account.Email,
@ -54,9 +54,9 @@ func convertOldAccount(account *AccountOld) *v1.StoredData {
},
}
var certs []*v1.Certificate
var certs []*traefikv1.Certificate
for _, oldCert := range account.DomainsCertificate.Certs {
certs = append(certs, &v1.Certificate{
certs = append(certs, &traefikv1.Certificate{
Certificate: oldCert.Certificate.Certificate,
Domain: oldCert.Domains,
Key: oldCert.Certificate.PrivateKey,

View File

@ -3,26 +3,28 @@ package kv
import (
"bytes"
"compress/gzip"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strings"
"github.com/abronan/valkeyrie"
"github.com/abronan/valkeyrie/store"
"github.com/kvtools/valkeyrie"
"github.com/kvtools/valkeyrie/store"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
v1 "github.com/ldez/traefik-certs-dumper/v2/dumper/v1"
"github.com/ldez/traefik-certs-dumper/v2/hook"
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv1"
)
// DefaultStoreKeySuffix is the default suffix/storage.
const DefaultStoreKeySuffix = "/acme/account/object"
// Dump Dumps KV content to certificates.
func Dump(config *Config, baseConfig *dumper.BaseConfig) error {
kvStore, err := valkeyrie.NewStore(config.Backend, config.Endpoints, config.Options)
func Dump(ctx context.Context, config *Config, baseConfig *dumper.BaseConfig) error {
kvStore, err := valkeyrie.NewStore(ctx, config.StoreName, config.Endpoints, config.Options)
if err != nil {
return fmt.Errorf("unable to create client of the store: %w", err)
}
@ -30,10 +32,10 @@ func Dump(config *Config, baseConfig *dumper.BaseConfig) error {
storeKey := config.Prefix + config.Suffix
if baseConfig.Watch {
return watch(kvStore, storeKey, baseConfig)
return watch(ctx, kvStore, storeKey, baseConfig)
}
pair, err := kvStore.Get(storeKey, nil)
pair, err := kvStore.Get(ctx, storeKey, nil)
if err != nil {
return fmt.Errorf("unable to retrieve %s value: %w", storeKey, err)
}
@ -41,10 +43,8 @@ func Dump(config *Config, baseConfig *dumper.BaseConfig) error {
return dumpPair(pair, baseConfig)
}
func watch(kvStore store.Store, storeKey string, baseConfig *dumper.BaseConfig) error {
stopCh := make(<-chan struct{})
pairs, err := kvStore.Watch(storeKey, stopCh, nil)
func watch(ctx context.Context, kvStore store.Store, storeKey string, baseConfig *dumper.BaseConfig) error {
pairs, err := kvStore.Watch(ctx, storeKey, nil)
if err != nil {
return err
}
@ -64,7 +64,7 @@ func watch(kvStore store.Store, storeKey string, baseConfig *dumper.BaseConfig)
log.Println("Dumped new certificate data.")
}
hook.Exec(baseConfig.Hook)
hook.Exec(ctx, baseConfig.Hook)
}
}
@ -77,18 +77,19 @@ func dumpPair(pair *store.KVPair, baseConfig *dumper.BaseConfig) error {
return v1.Dump(data, baseConfig)
}
func getStoredDataFromGzip(pair *store.KVPair) (*v1.StoredData, error) {
func getStoredDataFromGzip(pair *store.KVPair) (*traefikv1.StoredData, error) {
reader, err := gzip.NewReader(bytes.NewBuffer(pair.Value))
if err != nil {
return nil, fmt.Errorf("fail to create GZip reader: %w", err)
}
acmeData, err := ioutil.ReadAll(reader)
acmeData, err := io.ReadAll(reader)
if err != nil {
return nil, fmt.Errorf("unable to read the pair content: %w", err)
}
account := &AccountOld{}
//nolint:musttag // old format
if err := json.Unmarshal(acmeData, &account); err != nil {
return nil, fmt.Errorf("unable marshal AccountOld: %w", err)
}

View File

@ -3,12 +3,12 @@ package v1
import (
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv1"
)
const (
@ -17,7 +17,7 @@ const (
)
// Dump Dumps data to certificates.
func Dump(data *StoredData, baseConfig *dumper.BaseConfig) error {
func Dump(data *traefikv1.StoredData, baseConfig *dumper.BaseConfig) error {
if baseConfig.Clean {
err := cleanDir(baseConfig.DumpPath)
if err != nil {
@ -26,12 +26,12 @@ func Dump(data *StoredData, baseConfig *dumper.BaseConfig) error {
}
if !baseConfig.DomainSubDir {
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, certsSubDir), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, certsSubDir), 0o755); err != nil {
return fmt.Errorf("certs folder creation failure: %w", err)
}
}
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, keysSubDir), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, keysSubDir), 0o755); err != nil {
return fmt.Errorf("keys folder creation failure: %w", err)
}
@ -52,34 +52,34 @@ func Dump(data *StoredData, baseConfig *dumper.BaseConfig) error {
}
privateKeyPem := extractPEMPrivateKey(data.Account)
return ioutil.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0600)
return os.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0o600)
}
func writeCert(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSubDir bool) error {
func writeCert(dumpPath string, cert *traefikv1.Certificate, info dumper.FileInfo, domainSubDir bool) error {
certPath := filepath.Join(dumpPath, certsSubDir, safeName(cert.Domain.Main+info.Ext))
if domainSubDir {
certPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0o755); err != nil {
return err
}
}
return ioutil.WriteFile(certPath, cert.Certificate, 0666)
return os.WriteFile(certPath, cert.Certificate, 0o666)
}
func writeKey(dumpPath string, cert *Certificate, info dumper.FileInfo, domainSubDir bool) error {
func writeKey(dumpPath string, cert *traefikv1.Certificate, info dumper.FileInfo, domainSubDir bool) error {
keyPath := filepath.Join(dumpPath, keysSubDir, safeName(cert.Domain.Main+info.Ext))
if domainSubDir {
keyPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0o755); err != nil {
return err
}
}
return ioutil.WriteFile(keyPath, cert.Key, 0600)
return os.WriteFile(keyPath, cert.Key, 0o600)
}
func extractPEMPrivateKey(account *Account) []byte {
func extractPEMPrivateKey(account *traefikv1.Account) []byte {
var block *pem.Block
switch account.KeyType {
case certcrypto.RSA2048, certcrypto.RSA4096, certcrypto.RSA8192:
@ -93,7 +93,7 @@ func extractPEMPrivateKey(account *Account) []byte {
Bytes: account.PrivateKey,
}
default:
panic("unsupported key type")
panic(fmt.Sprintf("unsupported key type: '%v'", account.KeyType))
}
return pem.EncodeToMemory(block)
@ -109,7 +109,7 @@ func cleanDir(dumpPath string) error {
return errExists
}
dir, err := ioutil.ReadDir(dumpPath)
dir, err := os.ReadDir(dumpPath)
if err != nil {
return err
}

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package v1

View File

@ -3,13 +3,12 @@ package v2
import (
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
"github.com/traefik/traefik/v2/pkg/provider/acme"
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv2"
)
const (
@ -18,7 +17,7 @@ const (
)
// Dump Dumps data to certificates.
func Dump(data map[string]*acme.StoredData, baseConfig *dumper.BaseConfig) error {
func Dump(data map[string]*traefikv2.StoredData, baseConfig *dumper.BaseConfig) error {
if baseConfig.Clean {
err := cleanDir(baseConfig.DumpPath)
if err != nil {
@ -27,12 +26,12 @@ func Dump(data map[string]*acme.StoredData, baseConfig *dumper.BaseConfig) error
}
if !baseConfig.DomainSubDir {
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, certsSubDir), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, certsSubDir), 0o755); err != nil {
return fmt.Errorf("certs folder creation failure: %w", err)
}
}
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, keysSubDir), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, keysSubDir), 0o755); err != nil {
return fmt.Errorf("keys folder creation failure: %w", err)
}
@ -55,7 +54,7 @@ func Dump(data map[string]*acme.StoredData, baseConfig *dumper.BaseConfig) error
privateKeyPem := extractPEMPrivateKey(store.Account)
err := ioutil.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0600)
err := os.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0o600)
if err != nil {
return fmt.Errorf("failed to write private key: %w", err)
}
@ -64,31 +63,31 @@ func Dump(data map[string]*acme.StoredData, baseConfig *dumper.BaseConfig) error
return nil
}
func writeCert(dumpPath string, cert acme.Certificate, info dumper.FileInfo, domainSubDir bool) error {
func writeCert(dumpPath string, cert traefikv2.Certificate, info dumper.FileInfo, domainSubDir bool) error {
certPath := filepath.Join(dumpPath, certsSubDir, safeName(cert.Domain.Main+info.Ext))
if domainSubDir {
certPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0o755); err != nil {
return err
}
}
return ioutil.WriteFile(certPath, cert.Certificate, 0666)
return os.WriteFile(certPath, cert.Certificate, 0o666)
}
func writeKey(dumpPath string, cert acme.Certificate, info dumper.FileInfo, domainSubDir bool) error {
func writeKey(dumpPath string, cert traefikv2.Certificate, info dumper.FileInfo, domainSubDir bool) error {
keyPath := filepath.Join(dumpPath, keysSubDir, safeName(cert.Domain.Main+info.Ext))
if domainSubDir {
keyPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0o755); err != nil {
return err
}
}
return ioutil.WriteFile(keyPath, cert.Key, 0600)
return os.WriteFile(keyPath, cert.Key, 0o600)
}
func extractPEMPrivateKey(account *acme.Account) []byte {
func extractPEMPrivateKey(account *traefikv2.Account) []byte {
var block *pem.Block
switch account.KeyType {
case certcrypto.RSA2048, certcrypto.RSA4096, certcrypto.RSA8192:
@ -102,7 +101,7 @@ func extractPEMPrivateKey(account *acme.Account) []byte {
Bytes: account.PrivateKey,
}
default:
panic("unsupported key type")
panic(fmt.Sprintf("unsupported key type: '%v'", account.KeyType))
}
return pem.EncodeToMemory(block)
@ -118,7 +117,7 @@ func cleanDir(dumpPath string) error {
return errExists
}
dir, err := ioutil.ReadDir(dumpPath)
dir, err := os.ReadDir(dumpPath)
if err != nil {
return err
}

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package v2

132
dumper/v3/dumper.go Normal file
View File

@ -0,0 +1,132 @@
package v3
import (
"encoding/pem"
"fmt"
"os"
"path/filepath"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/ldez/traefik-certs-dumper/v2/dumper"
"github.com/ldez/traefik-certs-dumper/v2/internal/traefikv3"
)
const (
certsSubDir = "certs"
keysSubDir = "private"
)
// Dump Dumps data to certificates.
func Dump(data map[string]*traefikv3.StoredData, baseConfig *dumper.BaseConfig) error {
if baseConfig.Clean {
err := cleanDir(baseConfig.DumpPath)
if err != nil {
return fmt.Errorf("folder cleaning failed: %w", err)
}
}
if !baseConfig.DomainSubDir {
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, certsSubDir), 0o755); err != nil {
return fmt.Errorf("certs folder creation failure: %w", err)
}
}
if err := os.MkdirAll(filepath.Join(baseConfig.DumpPath, keysSubDir), 0o755); err != nil {
return fmt.Errorf("keys folder creation failure: %w", err)
}
for _, store := range data {
for _, cert := range store.Certificates {
err := writeCert(baseConfig.DumpPath, cert.Certificate, baseConfig.CrtInfo, baseConfig.DomainSubDir)
if err != nil {
return fmt.Errorf("failed to write certificates: %w", err)
}
err = writeKey(baseConfig.DumpPath, cert.Certificate, baseConfig.KeyInfo, baseConfig.DomainSubDir)
if err != nil {
return fmt.Errorf("failed to write certificate keys: %w", err)
}
}
if store.Account == nil {
continue
}
privateKeyPem := extractPEMPrivateKey(store.Account)
err := os.WriteFile(filepath.Join(baseConfig.DumpPath, keysSubDir, "letsencrypt"+baseConfig.KeyInfo.Ext), privateKeyPem, 0o600)
if err != nil {
return fmt.Errorf("failed to write private key: %w", err)
}
}
return nil
}
func writeCert(dumpPath string, cert traefikv3.Certificate, info dumper.FileInfo, domainSubDir bool) error {
certPath := filepath.Join(dumpPath, certsSubDir, safeName(cert.Domain.Main+info.Ext))
if domainSubDir {
certPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0o755); err != nil {
return err
}
}
return os.WriteFile(certPath, cert.Certificate, 0o666)
}
func writeKey(dumpPath string, cert traefikv3.Certificate, info dumper.FileInfo, domainSubDir bool) error {
keyPath := filepath.Join(dumpPath, keysSubDir, safeName(cert.Domain.Main+info.Ext))
if domainSubDir {
keyPath = filepath.Join(dumpPath, safeName(cert.Domain.Main), info.Name+info.Ext)
if err := os.MkdirAll(filepath.Join(dumpPath, safeName(cert.Domain.Main)), 0o755); err != nil {
return err
}
}
return os.WriteFile(keyPath, cert.Key, 0o600)
}
func extractPEMPrivateKey(account *traefikv3.Account) []byte {
var block *pem.Block
switch account.KeyType {
case certcrypto.RSA2048, certcrypto.RSA4096, certcrypto.RSA8192:
block = &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: account.PrivateKey,
}
case certcrypto.EC256, certcrypto.EC384:
block = &pem.Block{
Type: "EC PRIVATE KEY",
Bytes: account.PrivateKey,
}
default:
panic(fmt.Sprintf("unsupported key type: '%v'", account.KeyType))
}
return pem.EncodeToMemory(block)
}
func cleanDir(dumpPath string) error {
_, errExists := os.Stat(dumpPath)
if os.IsNotExist(errExists) {
return nil
}
if errExists != nil {
return errExists
}
dir, err := os.ReadDir(dumpPath)
if err != nil {
return err
}
for _, f := range dir {
if err := os.RemoveAll(filepath.Join(dumpPath, f.Name())); err != nil {
return err
}
}
return nil
}

8
dumper/v3/filename.go Normal file
View File

@ -0,0 +1,8 @@
//go:build !windows
// +build !windows
package v3
func safeName(filename string) string {
return filename
}

View File

@ -0,0 +1,10 @@
//go:build windows
// +build windows
package v3
import "strings"
func safeName(filename string) string {
return strings.ReplaceAll(filename, "*", "_")
}

101
go.mod
View File

@ -1,27 +1,90 @@
module github.com/ldez/traefik-certs-dumper/v2
go 1.14
go 1.24.0
require (
github.com/abronan/valkeyrie v0.1.0
github.com/fsnotify/fsnotify v1.4.9
github.com/go-acme/lego/v4 v4.1.3
github.com/charmbracelet/lipgloss v1.0.0
github.com/fsnotify/fsnotify v1.9.0
github.com/go-acme/lego/v4 v4.25.2
github.com/kvtools/boltdb v1.0.2
github.com/kvtools/consul v1.0.2
github.com/kvtools/etcdv2 v1.0.2
github.com/kvtools/etcdv3 v1.0.2
github.com/kvtools/valkeyrie v1.0.0
github.com/kvtools/zookeeper v1.0.2
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.1.1
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1
github.com/traefik/traefik/v2 v2.3.4
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
)
// related to Traefik
replace github.com/docker/docker => github.com/docker/engine v0.0.0-20190725163905-fa8dd90ceb7b
// related to Traefik: Containous forks
replace (
github.com/abbot/go-http-auth => github.com/containous/go-http-auth v0.4.1-0.20180112153951-65b0cdae8d7f
github.com/go-check/check => github.com/containous/check v0.0.0-20170915194414-ca0bf163426a
github.com/gorilla/mux => github.com/containous/mux v0.0.0-20181024131434-c33f32e26898
github.com/mailgun/minheap => github.com/containous/minheap v0.0.0-20190809180810-6e71eb837595
github.com/mailgun/multibuf => github.com/containous/multibuf v0.0.0-20190809014333-8b6c9a7e6bba
github.com/rancher/go-rancher-metadata => github.com/containous/go-rancher-metadata v0.0.0-20190402144056-c6a65f8b7a28
require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/charmbracelet/x/ansi v0.4.2 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/go-jose/go-jose/v4 v4.1.1 // indirect
github.com/go-zookeeper/zk v1.0.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/consul/api v1.28.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.4 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/hashicorp/serf v0.10.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.9 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.etcd.io/etcd/api/v3 v3.5.14 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect
go.etcd.io/etcd/client/v2 v2.305.12 // indirect
go.etcd.io/etcd/client/v3 v3.5.14 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.40.0 // indirect
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
golang.org/x/net v0.42.0 // indirect
golang.org/x/sys v0.34.0 // indirect
golang.org/x/text v0.27.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
google.golang.org/grpc v1.73.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
exclude github.com/tencentcloud/tencentcloud-sdk-go v3.0.83+incompatible

1358
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -11,21 +11,21 @@ import (
)
// Exec Execute a command on a go routine.
func Exec(command string) {
func Exec(ctx context.Context, command string) {
if command == "" {
return
}
go func() {
errH := execute(command)
errH := execute(ctx, command)
if errH != nil {
panic(errH)
}
}()
}
func execute(command string) error {
ctxCmd, cancel := context.WithTimeout(context.Background(), 30*time.Second)
func execute(ctx context.Context, command string) error {
ctxCmd, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
parts := strings.Fields(os.ExpandEnv(command))

View File

@ -1,6 +1,8 @@
package hook
import "testing"
import (
"testing"
)
func Test_execute(t *testing.T) {
testCases := []struct {
@ -19,7 +21,7 @@ func Test_execute(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
err := execute(test.command)
err := execute(t.Context(), test.command)
if err != nil {
t.Fatal(err)
}

View File

@ -3,17 +3,17 @@ package main
import (
"bytes"
"compress/gzip"
"io/ioutil"
"context"
"log"
"os"
"path/filepath"
"time"
"github.com/abronan/valkeyrie"
"github.com/abronan/valkeyrie/store"
"github.com/abronan/valkeyrie/store/boltdb"
"github.com/abronan/valkeyrie/store/consul"
etcdv3 "github.com/abronan/valkeyrie/store/etcd/v3"
"github.com/abronan/valkeyrie/store/zookeeper"
"github.com/kvtools/boltdb"
"github.com/kvtools/consul"
"github.com/kvtools/etcdv3"
"github.com/kvtools/valkeyrie"
"github.com/kvtools/zookeeper"
)
const storeKey = "traefik/acme/account/object"
@ -22,38 +22,43 @@ func main() {
log.SetFlags(log.Lshortfile)
source := "./acme.json"
err := loadData(source)
err := loadData(context.Background(), source)
if err != nil {
log.Fatal(err)
}
}
func loadData(source string) error {
func loadData(ctx context.Context, source string) error {
content, err := readFile(source)
if err != nil {
return err
}
// Consul
err = putData(store.CONSUL, []string{"localhost:8500"}, content)
err = putData(ctx, consul.StoreName, []string{"localhost:8500"},
&consul.Config{ConnectionTimeout: 3 * time.Second}, content)
if err != nil {
return err
}
// ETCD v3
err = putData(store.ETCDV3, []string{"localhost:2379"}, content)
err = putData(ctx, etcdv3.StoreName, []string{"localhost:2379"},
&etcdv3.Config{ConnectionTimeout: 3 * time.Second}, content)
if err != nil {
return err
}
// Zookeeper
err = putData(store.ZK, []string{"localhost:2181"}, content)
err = putData(ctx, zookeeper.StoreName, []string{"localhost:2181"},
&zookeeper.Config{ConnectionTimeout: 3 * time.Second}, content)
if err != nil {
return err
}
// BoltDB
err = putData(store.BOLTDB, []string{"/tmp/test-traefik-certs-dumper.db"}, content)
err = putData(ctx, boltdb.StoreName, []string{"/tmp/test-traefik-certs-dumper.db"},
&boltdb.Config{ConnectionTimeout: 3 * time.Second, Bucket: "traefik"}, content)
if err != nil {
return err
}
@ -61,29 +66,13 @@ func loadData(source string) error {
return nil
}
func putData(backend store.Backend, addrs []string, content []byte) error {
storeConfig := &store.Config{
ConnectionTimeout: 3 * time.Second,
Bucket: "traefik",
}
switch backend {
case store.CONSUL:
consul.Register()
case store.ETCDV3:
etcdv3.Register()
case store.ZK:
zookeeper.Register()
case store.BOLTDB:
boltdb.Register()
}
kvStore, err := valkeyrie.NewStore(backend, addrs, storeConfig)
func putData(ctx context.Context, backend string, addrs []string, options valkeyrie.Config, content []byte) error {
kvStore, err := valkeyrie.NewStore(ctx, backend, addrs, options)
if err != nil {
return err
}
if err := kvStore.Put(storeKey, content, nil); err != nil {
if err := kvStore.Put(ctx, storeKey, content, nil); err != nil {
return err
}
@ -92,7 +81,7 @@ func putData(backend store.Backend, addrs []string, content []byte) error {
}
func readFile(source string) ([]byte, error) {
content, err := ioutil.ReadFile(filepath.Clean(source))
content, err := os.ReadFile(filepath.Clean(source))
if err != nil {
return nil, err
}

View File

@ -1,4 +1,4 @@
package v1
package traefikv1
import (
"github.com/go-acme/lego/v4/certcrypto"

101
internal/traefikv2/acme.go Normal file
View File

@ -0,0 +1,101 @@
package traefikv2
import (
"crypto"
"crypto/x509"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/registration"
)
// StoredData represents the data managed by Store.
type StoredData struct {
Account *Account
Certificates []*CertAndStore
}
// Account is used to store lets encrypt registration info.
type Account struct {
Email string
Registration *registration.Resource
PrivateKey []byte
KeyType certcrypto.KeyType
}
// GetEmail returns email.
func (a *Account) GetEmail() string {
return a.Email
}
// GetRegistration returns lets encrypt registration resource.
func (a *Account) GetRegistration() *registration.Resource {
return a.Registration
}
// GetPrivateKey returns private key.
func (a *Account) GetPrivateKey() crypto.PrivateKey {
privateKey, err := x509.ParsePKCS1PrivateKey(a.PrivateKey)
if err != nil {
return nil
}
return privateKey
}
// CertAndStore allows mapping a TLS certificate to a TLS store.
type CertAndStore struct {
Certificate
Store string
}
// Certificate is a struct which contains all data needed from an ACME certificate.
type Certificate struct {
Domain Domain `json:"domain,omitempty" toml:"domain,omitempty" yaml:"domain,omitempty"`
Certificate []byte `json:"certificate,omitempty" toml:"certificate,omitempty" yaml:"certificate,omitempty"`
Key []byte `json:"key,omitempty" toml:"key,omitempty" yaml:"key,omitempty"`
}
// Domain holds a domain name with SANs.
type Domain struct {
// Main defines the main domain name.
Main string `description:"Default subject name." json:"main,omitempty" toml:"main,omitempty" yaml:"main,omitempty"`
// SANs defines the subject alternative domain names.
SANs []string `description:"Subject alternative names." json:"sans,omitempty" toml:"sans,omitempty" yaml:"sans,omitempty"`
}
// ToStrArray convert a domain into an array of strings.
func (d *Domain) ToStrArray() []string {
var domains []string
if d.Main != "" {
domains = []string{d.Main}
}
return append(domains, d.SANs...)
}
// Set sets a domains from an array of strings.
func (d *Domain) Set(domains []string) {
if len(domains) > 0 {
d.Main = domains[0]
d.SANs = domains[1:]
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (d *Domain) DeepCopyInto(out *Domain) {
*out = *d
if d.SANs != nil {
in, out := &d.SANs, &out.SANs
*out = make([]string, len(*in))
copy(*out, *in)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Domain.
func (d *Domain) DeepCopy() *Domain {
if d == nil {
return nil
}
out := new(Domain)
d.DeepCopyInto(out)
return out
}

101
internal/traefikv3/acme.go Normal file
View File

@ -0,0 +1,101 @@
package traefikv3
import (
"crypto"
"crypto/x509"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/registration"
)
// StoredData represents the data managed by Store.
type StoredData struct {
Account *Account
Certificates []*CertAndStore
}
// Account is used to store lets encrypt registration info.
type Account struct {
Email string
Registration *registration.Resource
PrivateKey []byte
KeyType certcrypto.KeyType
}
// GetEmail returns email.
func (a *Account) GetEmail() string {
return a.Email
}
// GetRegistration returns lets encrypt registration resource.
func (a *Account) GetRegistration() *registration.Resource {
return a.Registration
}
// GetPrivateKey returns private key.
func (a *Account) GetPrivateKey() crypto.PrivateKey {
privateKey, err := x509.ParsePKCS1PrivateKey(a.PrivateKey)
if err != nil {
return nil
}
return privateKey
}
// CertAndStore allows mapping a TLS certificate to a TLS store.
type CertAndStore struct {
Certificate
Store string
}
// Certificate is a struct which contains all data needed from an ACME certificate.
type Certificate struct {
Domain Domain `json:"domain,omitempty" toml:"domain,omitempty" yaml:"domain,omitempty"`
Certificate []byte `json:"certificate,omitempty" toml:"certificate,omitempty" yaml:"certificate,omitempty"`
Key []byte `json:"key,omitempty" toml:"key,omitempty" yaml:"key,omitempty"`
}
// Domain holds a domain name with SANs.
type Domain struct {
// Main defines the main domain name.
Main string `description:"Default subject name." json:"main,omitempty" toml:"main,omitempty" yaml:"main,omitempty"`
// SANs defines the subject alternative domain names.
SANs []string `description:"Subject alternative names." json:"sans,omitempty" toml:"sans,omitempty" yaml:"sans,omitempty"`
}
// ToStrArray convert a domain into an array of strings.
func (d *Domain) ToStrArray() []string {
var domains []string
if d.Main != "" {
domains = []string{d.Main}
}
return append(domains, d.SANs...)
}
// Set sets a domains from an array of strings.
func (d *Domain) Set(domains []string) {
if len(domains) > 0 {
d.Main = domains[0]
d.SANs = domains[1:]
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (d *Domain) DeepCopyInto(out *Domain) {
*out = *d
if d.SANs != nil {
in, out := &d.SANs, &out.SANs
*out = make([]string, len(*in))
copy(*out, *in)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Domain.
func (d *Domain) DeepCopy() *Domain {
if d == nil {
return nil
}
out := new(Domain)
d.DeepCopyInto(out)
return out
}

View File

@ -2,7 +2,7 @@
[![GitHub release](https://img.shields.io/github/release/ldez/traefik-certs-dumper.svg)](https://github.com/ldez/traefik-certs-dumper/releases/latest)
[![Build Status](https://github.com/ldez/traefik-certs-dumper/workflows/Main/badge.svg?branch=master)](https://github.com/ldez/traefik-certs-dumper/actions)
[![Docker Information](https://images.microbadger.com/badges/image/ldez/traefik-certs-dumper.svg)](https://hub.docker.com/r/ldez/traefik-certs-dumper/)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/ldez/traefik-certs-dumper)](https://hub.docker.com/r/ldez/traefik-certs-dumper/)
[![Go Report Card](https://goreportcard.com/badge/github.com/ldez/traefik-certs-dumper)](https://goreportcard.com/report/github.com/ldez/traefik-certs-dumper)
If you appreciate this project:
@ -18,16 +18,17 @@ If you appreciate this project:
- from file ("acme.json")
- from KV stores (Consul, Etcd, Zookeeper)
- Output formats:
- use domain as sub-directory (allow custom names and extensions)
- use domain as subdirectory (allow custom names and extensions)
- flat (domain as filename)
- Hook (only with watch mode and if the data source changes)
- Support Traefik v1, v2, and v3.
## Installation
### Download / CI Integration
```bash
curl -sfL https://raw.githubusercontent.com/ldez/traefik-certs-dumper/master/godownloader.sh | bash -s -- -b $GOPATH/bin v2.7.0
curl -sfL https://raw.githubusercontent.com/ldez/traefik-certs-dumper/master/godownloader.sh | bash -s -- -b $(go env GOPATH)/bin v2.9.3
```
<!--
@ -56,7 +57,11 @@ You can use pre-compiled binaries:
docker run ldez/traefik-certs-dumper:<tag_name>
```
Example: [docker-compose](docs/docker-compose-traefik-v1.yml)
Examples:
- Traefik v1: [docker-compose](docs/docker-compose-traefik-v1.yml)
- Traefik v2: [docker-compose](docs/docker-compose-traefik-v2.yml)
- Traefik v3: TODO
## Usage
@ -66,12 +71,10 @@ Example: [docker-compose](docs/docker-compose-traefik-v1.yml)
## Examples
**Note:** to dump data from Traefik v2, the CLI flag `--version v2` must be added.
### Simple Dump
```console
$ traefik-certs-dumper file
$ traefik-certs-dumper file --version v3
dump
├──certs
│ └──my.domain.com.key
@ -83,7 +86,7 @@ dump
### Change source and destination
```console
$ traefik-certs-dumper file --source ./acme.json --dest ./dump/test
$ traefik-certs-dumper file --version v3 --source ./acme.json --dest ./dump/test
test
├──certs
│ └──my.domain.com.key
@ -95,7 +98,7 @@ test
### Use domain as sub-directory
```console
$ traefik-certs-dumper file --domain-subdir=true
$ traefik-certs-dumper file --version v3 --domain-subdir=true
dump
├──my.domain.com
│ ├──certificate.crt
@ -107,7 +110,7 @@ dump
#### Change file extension
```console
$ traefik-certs-dumper file --domain-subdir --crt-ext=.pem --key-ext=.pem
$ traefik-certs-dumper file --version v3 --domain-subdir --crt-ext=.pem --key-ext=.pem
dump
├──my.domain.com
│ ├──certificate.pem
@ -119,7 +122,7 @@ dump
#### Change file name
```console
$ traefik-certs-dumper file --domain-subdir --crt-name=fullchain --key-name=privkey
$ traefik-certs-dumper file --version v3 --domain-subdir --crt-name=fullchain --key-name=privkey
dump
├──my.domain.com
│ ├──fullchain.crt
@ -128,6 +131,37 @@ dump
└──letsencrypt.key
```
## Hook
Hook can be a one-liner passed as a string, or a file for more complex post-hook scenarios.
For the former, create a file (ex: `hook.sh`) and mount it, then pass `sh hooksh` as a parameter to `--post-hook`.
Here is a docker-compose example:
```yml
services:
# ...
traefik-certs-dumper:
image: ldez/traefik-certs-dumper:v2.9.3
container_name: traefik-certs-dumper
entrypoint: sh -c '
while ! [ -e /data/acme.json ]
|| ! [ `jq ".[] | .Certificates | length" /data/acme.json | jq -s "add" ` != 0 ]; do
sleep 1
; done
&& traefik-certs-dumper file --version v2 --watch
--source /data/acme.json --dest /data/certs
--post-hook "sh /hook.sh"'
labels:
traefik.enable: false
volumes:
- ./letsencrypt:/data
- ./hook.sh:/hook.sh
# ...
```
### KV store
#### Consul

View File

@ -1,24 +0,0 @@
FROM golang:1-alpine as builder
RUN apk --update upgrade \
&& apk --no-cache --no-progress add git make gcc musl-dev ca-certificates tzdata
WORKDIR /go/src/github.com/ldez/traefik-certs-dumper
ENV GO111MODULE on
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN GOARCH={{ .GoARCH }} GOARM={{ .GoARM }} make build
FROM {{ .RuntimeImage }}
# Not supported for multi-arch without Buildkit or QEMU
#RUN apk --update upgrade \
# && apk --no-cache --no-progress add ca-certificates
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/src/github.com/ldez/traefik-certs-dumper/traefik-certs-dumper /usr/bin/traefik-certs-dumper
ENTRYPOINT ["/usr/bin/traefik-certs-dumper"]