Reject unrecognized config keys (#5649)

Instead of using the default `json.Unmarshal`, explicitly
construct and use a `json.Decoder` so that we can set the
`DisallowUnknownFields` flag on the decoder. This causes
any unrecognized config keys to result in errors at boulder
startup time.

Fixes #5643
This commit is contained in:
Aaron Gable 2021-09-24 10:13:44 -07:00 committed by GitHub
parent a6ad023c6a
commit e0c3e2c1df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 18 deletions

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"expvar" "expvar"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"log/syslog" "log/syslog"
"net/http" "net/http"
@ -230,13 +229,19 @@ func FailOnError(err error, msg string) {
// ReadConfigFile takes a file path as an argument and attempts to // ReadConfigFile takes a file path as an argument and attempts to
// unmarshal the content of the file into a struct containing a // unmarshal the content of the file into a struct containing a
// configuration of a boulder component. // configuration of a boulder component. Any config keys in the JSON
// file which do not correspond to expected keys in the config struct
// will result in errors.
func ReadConfigFile(filename string, out interface{}) error { func ReadConfigFile(filename string, out interface{}) error {
configData, err := ioutil.ReadFile(filename) file, err := os.Open(filename)
if err != nil { if err != nil {
return err return err
} }
return json.Unmarshal(configData, out) defer file.Close()
decoder := json.NewDecoder(file)
decoder.DisallowUnknownFields()
return decoder.Decode(out)
} }
// VersionString produces a friendly Application version string. // VersionString produces a friendly Application version string.

View File

@ -122,10 +122,10 @@ func TestReadConfigFile(t *testing.T) {
type config struct { type config struct {
NotifyMailer struct { NotifyMailer struct {
DBConfig DB DBConfig
PasswordConfig
SMTPConfig SMTPConfig
} }
Syslog SyslogConfig
} }
var c config var c config
err = ReadConfigFile("../test/config/notify-mailer.json", &c) err = ReadConfigFile("../test/config/notify-mailer.json", &c)

View File

@ -2,6 +2,8 @@
"akamaiPurger": { "akamaiPurger": {
"debugAddr": ":9666", "debugAddr": ":9666",
"purgeInterval": "1ms", "purgeInterval": "1ms",
"purgeRetries": 10,
"purgeRetryBackoff": "50ms",
"baseURL": "http://localhost:6789", "baseURL": "http://localhost:6789",
"clientToken": "its-a-token", "clientToken": "its-a-token",
"clientSecret": "its-a-secret", "clientSecret": "its-a-secret",

View File

@ -2,6 +2,8 @@
"akamaiPurger": { "akamaiPurger": {
"debugAddr": ":9666", "debugAddr": ":9666",
"purgeInterval": "1ms", "purgeInterval": "1ms",
"purgeRetries": 10,
"purgeRetryBackoff": "50ms",
"baseURL": "http://localhost:6789", "baseURL": "http://localhost:6789",
"clientToken": "its-a-token", "clientToken": "its-a-token",
"clientSecret": "its-a-secret", "clientSecret": "its-a-secret",

View File

@ -9,7 +9,7 @@
"unexpiredOnly": true, "unexpiredOnly": true,
"badResultsOnly": true, "badResultsOnly": true,
"checkPeriod": "72h", "checkPeriod": "72h",
"acceptableValidityPeriods": [7775999, 7776000], "acceptableValidityDurations": ["7775999s", "7776000s"],
"ignoredLints": [ "ignoredLints": [
"n_subject_common_name_included" "n_subject_common_name_included"
] ]

View File

@ -17,15 +17,18 @@
"grpc": { "grpc": {
"address": ":9199", "address": ":9199",
"clientNames": [ "clientNames": [
"health-checker.boulder",
"ra.boulder" "ra.boulder"
] ]
} }
}, },
"syslog": { "syslog": {
"stdoutlevel": 6, "stdoutlevel": 6,
"sysloglevel": 6 "sysloglevel": 6
}, },
"common": { "beeline": {
"issuerCert": "/tmp/intermediate-cert-rsa-a.pem" "mute": true,
"dataset": "Test"
} }
} }

View File

@ -3,17 +3,21 @@
"source": "file:///tmp/intermediate-ocsp-rsa.b64", "source": "file:///tmp/intermediate-ocsp-rsa.b64",
"path": "/", "path": "/",
"listenAddress": "0.0.0.0:4003", "listenAddress": "0.0.0.0:4003",
"issuerCerts": [
"/tmp/intermediate-cert-rsa-a.pem"
],
"maxAge": "10s",
"timeout": "4.9s",
"shutdownStopTimeout": "10s", "shutdownStopTimeout": "10s",
"shutdownKillTimeout": "1m",
"debugAddr": "localhost:8010" "debugAddr": "localhost:8010"
}, },
"common": {
"issuerCert": "/tmp/intermediate-cert-rsa-a.pem"
},
"sql": {
"sqlDebug": true
},
"syslog": { "syslog": {
"stdoutlevel": 6 "stdoutlevel": 6,
} "sysloglevel": 6
},
"beeline": {
"mute": true,
"dataset": "Test"
}
} }