-
Notifications
You must be signed in to change notification settings - Fork 0
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
config.TLS: Inline PEM-encoded Certs, Keys and CAs #113
base: main
Are you sure you want to change the base?
Conversation
b9a288c
to
42cf4c4
Compare
New ways to configure Icinga DB were introduced in [icingadb-831] and [igl-113]. The first change allows configuring Icinga DB using environment variables instead of or next to the YAML configuration file. In addition, the second change allows setting certificates and keys as PEM-encoded strings next to referencing files. This was now documented. As a structural change, the order of the Database and Redis sections were changed to reflect the order in the example configuration file. Some words about the Logging Components were written, as the documentation previously that they exist. [icingadb-831]: #831 [igl-113]: Icinga/icinga-go-library#113
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would introduce a utility function that does both pem.Decode()
and os.ReadFile()
in order to reduce code complexity. The first part could then look like this:
certPem, err := loadPemOrFile(t.Cert)
if err != nil {
return nil, errors.Wrap(err, "can't load certificate")
}
keyPem, err := loadPemOrFile(t.Key)
if err != nil {
return nil, errors.Wrap(err, "can't load key")
}
crt, err := tls.X509KeyPair(certPem, KeyPem)
if err != nil {
return nil, errors.Wrap(err, "can't load X.509 key pair")
}
tlsConfig.Certificates = []tls.Certificate{crt}
func loadPemOrFile(subject string) ([]byte, error) {
if block, _ := pem.Decode([]byte(subject)); block != nil {
return []byte(subject), nil
}
data, err := os.ReadFile(subject)
if err != nil {
return nil, err
}
return data, nil
}
Introduced support for raw encoded PEM data instead of filenames for TLS.Cert, TLS.Key and TLS.Ca. This should make it easier to get rid of the additional entrypoint program for docker-icingadb and allow direct use of Icinga DB with its environment variable support. In addition to the implementation, new tests were written with the goal of complete coverage. A consumer of this type, database.Config, got another test case using PEMs both as environment variables and as YAML
42cf4c4
to
914dd25
Compare
@lippserd: Valid point. I have moved the decision logic to a helper function like you suggested. Now the body of the actual |
Introduced support for raw encoded PEM data instead of filenames for TLS.Cert, TLS.Key and TLS.Ca. This should make it easier to get rid of the additional entrypoint program for docker-icingadb and allow direct use of Icinga DB with its environment variable support.
In addition to the implementation, new tests were written with the goal of complete coverage. A consumer of this type, database.Config, got another test case using PEMs both as environment variables and as YAML