Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use Cert Manager to Create Certificates for News Aggregator Server #15

Merged
merged 44 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cd922ef
feat: Added dynamic Certificate And Private Key registration
werniq Aug 17, 2024
7dad759
refactor: moved string vars to constants
werniq Aug 19, 2024
6ed39a8
feat: Use k8s client instead of client set
werniq Aug 29, 2024
ee52caa
test: added test for loadCertsFromSecrest
werniq Aug 29, 2024
865de67
feat: Pulled from feature/migrate-to-taskfile
werniq Sep 2, 2024
0604013
feat: Applied updates from feature/helm
werniq Sep 2, 2024
2a17bda
feat: Resolved merge conflicts
werniq Sep 9, 2024
4bb214e
Revert "feat: Removed conflicts"
werniq Sep 9, 2024
ee3df59
Merge branch 'feature/cert-manager' of https://github.com/werniq/Go-G…
werniq Sep 9, 2024
b97ccbb
feat: Reverted changes in start server
werniq Sep 9, 2024
40d18e9
feat: Resolved staticcheck errors
werniq Sep 9, 2024
8f9de39
refactor: Putted cert-manager related files to appropriate folders
werniq Sep 15, 2024
825e7c6
feat: Repaired certificate creation
werniq Sep 17, 2024
7a195ea
refactor: moved CA certificate to issuer folder
werniq Sep 17, 2024
d4c86d4
refactor: Moved client initialization a bit forward
werniq Sep 17, 2024
a66a82a
fix: download required dependencies
werniq Sep 17, 2024
dad4d81
refactor: removed labels from certs_secrets
werniq Sep 17, 2024
f3dafb4
erge branch 'feature/helm' of https://github.com/werniq/Go-Gator into…
werniq Sep 19, 2024
ee61aad
feat: Removed subdirectories with cert-manager resources
werniq Sep 19, 2024
0e67f06
feat: Added cert manager related object to Helm
werniq Sep 19, 2024
2464fd3
refactor: Removed redundant code
werniq Sep 25, 2024
ee66460
feat: Pulled data from feature/helm
werniq Sep 25, 2024
5800a5e
feat: Resolved comments from Pull request
werniq Sep 25, 2024
55bf968
feat: Removed certs from git
werniq Sep 25, 2024
d14e850
test: removed test file from pr
werniq Sep 25, 2024
6ae4117
fix: removed makefile
werniq Sep 25, 2024
4f690f2
feat: Added previously updated vals to helm chart
werniq Sep 25, 2024
6f15967
feat: Integrated helm calues for secret and issuer
werniq Sep 25, 2024
583a28b
fix: Removed unused data
werniq Sep 26, 2024
abc3b55
Merge branch 'feature/helm' of https://github.com/werniq/Go-Gator int…
werniq Sep 26, 2024
32f29c5
feat: Removed certs from dockerfile
werniq Sep 26, 2024
602682a
feat: Creating certs data dir in dockerfile
werniq Sep 26, 2024
94159af
feat: Added certs repo
werniq Sep 26, 2024
7d63695
feat: Added cert manager as dependency and removed DNS names
werniq Sep 26, 2024
47419cf
feat: Remove particular go-gator chart from gitignore
werniq Sep 26, 2024
263e196
feat: Removed createChart ask
werniq Sep 26, 2024
b06a798
feat: Added certificate to helm chart
werniq Sep 27, 2024
2163edb
feat: Pulled data from feature/helm
werniq Sep 27, 2024
300bda5
fix: removed redundant createChart task
werniq Sep 27, 2024
b2e848a
fix: Removed taskfile from pull request changed files
werniq Sep 27, 2024
ee15686
feat: removed templates directory
werniq Sep 30, 2024
32c6408
feat: removed duplicate files
werniq Sep 30, 2024
767c1b3
feat: added cert secret and gitignore back
werniq Sep 30, 2024
a607852
fix: removed go.mod go.sum from Pull Request
werniq Oct 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ RUN go build -o go-gator .
FROM alpine:3.20

ENV PORT=443
ENV CERT_FILE=/app/cmd/server/certs/certificate.pem
ENV CERT_KEY=/app/cmd/server/certs/key.pem
ENV STORAGE_PATH=./data

COPY --from=build /app/cmd/server/certs ./cmd/server/certs
COPY --from=build /app/cmd/parsers/data $STORAGE_PATH
COPY --from=build /app/go-gator .
COPY --from=build $CERT_FILE $CERT_FILE
COPY --from=build $CERT_KEY $CERT_KEY

ENTRYPOINT /go-gator -p=$PORT -c=$CERT_FILE -k=$CERT_KEY -fs=$STORAGE_PATH
ENTRYPOINT /go-gator -p=$PORT -fs=$STORAGE_PATH
1 change: 1 addition & 0 deletions cmd/server/certs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pem
21 changes: 0 additions & 21 deletions cmd/server/certs/certificate.pem

This file was deleted.

28 changes: 0 additions & 28 deletions cmd/server/certs/key.pem

This file was deleted.

21 changes: 10 additions & 11 deletions cmd/server/start_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,31 @@ import (
var (
// defaultCertsPath is default path to server
defaultCertsPath = filepath.Join("cmd", "server", "certs")

// defaultDataDirPath is a default path to the directory where all data will be stored
defaultDataDirPath = filepath.Join("cmd", "parsers", "data")
)

const (
// defaultServerPort is a default port on which this server will be running
defaultServerPort = 443

// defaultCertName represents default name of server's certificate file
defaultCertName = "certificate.pem"

// defaultPrivateKey identifies the default name of server's private key
defaultPrivateKey = "key.pem"
defaultPrivateKey = "tls.key"

// defaultCertName represents default name of server's certificate file
defaultCertName = "tls.crt"

// errNotSpecified helps us to check if error was related to initializing sources file
errNotSpecified = "The system cannot find the file specified."
errNotSpecified = "no such file or directory"

// errInitializingSources is thrown when func responsible for initialization of sources fails
errInitializingSources = "Error initializing sources file: "
)

// ConfAndRun initializes and runs an HTTPS server using the Gin framework.
// This function sets up server routes and handlers, and starts the server
// on a user-specified port or defaults to port 443. It also launches a concurrent job
// which is fetching news feeds at a specified frequency.
// on a user-specified port or defaults to port 443.
//
// Optional parameters (specified via flags):
// / -p (serverPort): Specifies the port on which the server will run. Defaults to 443 if not specified.
Expand Down Expand Up @@ -71,12 +73,10 @@ func ConfAndRun() error {
"Absolute path to the certificate for the HTTPs server")
flag.StringVar(&keyFile, "k", filepath.Join(cwdPath, defaultCertsPath, defaultPrivateKey),
"Absolute path to the private key for the HTTPs server")
flag.StringVar(&storagePath, "fs", filepath.Join(parsers.CmdDir, parsers.ParsersDir, parsers.DataDir),
flag.StringVar(&storagePath, "fs", defaultDataDirPath,
"Path to directory where all data will be stored")
flag.Parse()

parsers.StoragePath = storagePath

err = parsers.LoadSourcesFile()
if err != nil {
if strings.Contains(err.Error(), errNotSpecified) {
Expand All @@ -94,7 +94,6 @@ func ConfAndRun() error {
err = server.RunTLS(fmt.Sprintf(":%d", serverPort),
certFile,
keyFile)

if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion go-gator/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

charts
charts
Chart.lock
6 changes: 2 additions & 4 deletions go-gator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ version: 0.1.0
appVersion: "1.16.0"
dependencies:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why removed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong branch, added dependencies

- name: cert-manager
version: v1.15.3
repository: https://charts.jetstack.io
alias: cert-manager
condition: cert-manager.enabled
version: 1.15.3
repository: https://charts.jetstack.io
7 changes: 7 additions & 0 deletions go-gator/templates/_go_gator_issuer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: {{ .Values.issuer.name }}
namespace: {{ .Values.namespace }}
spec:
selfSigned: {}
5 changes: 5 additions & 0 deletions go-gator/templates/cert_secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the secret will be created automatically by certificate CR (cert-manager)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how do we assign it to the deployment? It will add random sequence of letters after cert name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can specify secret name in the cert itself

Copy link
Owner Author

@werniq werniq Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to reproduce this without secret, but:
image

It is not creating the secret with exactly same name from values.

kind: Secret
metadata:
name: {{ .Values.certSecret.name }}
namespace: {{ .Values.namespace }}
10 changes: 0 additions & 10 deletions go-gator/templates/feed_group_source.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions go-gator/templates/go_gator_cert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: cert-manager.io/v1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need that cert? how is this used? I see you have almost similar below.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

kind: Certificate
metadata:
name: {{ .Values.certificate.name }}
namespace: {{ .Values.namespace }}
spec:
isCA: false
commonName: go-gator-server
secretName: cert-secret
privateKey:
algorithm: {{ .Values.certificate.privateKey.algorithm }}
size: {{ .Values.certificate.privateKey.size }}
usages:
- server auth
- client auth
issuerRef:
name: {{ .Values.issuer.name }}
19 changes: 19 additions & 0 deletions go-gator/templates/go_gator_secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: go-gator-server
namespace: {{ .Values.namespace }}
spec:
isCA: false
commonName: go-gator-server
secretName: {{ .Values.certSecret.name }}
privateKey:
algorithm: ECDSA
size: 256
usages:
- server auth
- client auth
dnsNames:
- "go-gator-server"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have such dns name?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is creating without dnsNames, removed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want you to put a dns name which you use. not just removing it.
what dns name do you use?

issuerRef:
name: {{ .Values.issuer.name }}
19 changes: 18 additions & 1 deletion go-gator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ resources:
cpu: 100m
memory: 128Mi

issuer:
name: go-gator-issuer

certSecret:
name: cert-secret

certificate:
name: go-gator-server
privateKey:
algorithm: ECDSA
size: 256

autoscaling:
enabled: false
minReplicas: 1
Expand All @@ -74,7 +86,12 @@ volumes:
- name: go-gator-pv
persistentVolumeClaim:
claimName: go-gator-pvc
- name: cert-secret
secret:
secretName: cert-secret

volumeMounts:
- mountPath: /tmp/
name: go-gator-pv
name: go-gator-pv
- mountPath: /cmd/server/certs
name: cert-secret
64 changes: 56 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,89 @@ require (
github.com/PuerkitoBio/goquery v1.9.2
github.com/gin-gonic/gin v1.10.0
github.com/jarcoal/httpmock v1.3.1
github.com/spf13/cobra v1.8.0
github.com/spf13/cobra v1.8.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why changed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure from where this changes are, but I will revert to previous version

github.com/stretchr/testify v1.9.0
)

require (
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.31.0 // indirect
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/apimachinery v0.31.0 // indirect
k8s.io/client-go v0.31.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/controller-runtime v0.19.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading
Loading