Skip to content

Commit 1b84e2b

Browse files
fix(core): validate TLS when XTokenPath is set; clarify XTokenPath semantics (#4475)
Co-authored-by: Hlib Kanunnikov <[email protected]>
1 parent d9dd6ff commit 1b84e2b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

nodebuilder/core/config.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ type Config struct {
2424
type EndpointConfig struct {
2525
IP string
2626
Port string
27-
// TLSEnabled specifies whether the connection is secure or not.
28-
// PLEASE NOTE: it should be set to true in order to handle XTokenPath.
27+
// TLSEnabled specifies whether the connection is secure.
28+
// Must be set to true if XTokenPath is provided.
2929
TLSEnabled bool
30-
// XTokenPath specifies the path to the directory with JSON file containing the X-Token for gRPC authentication.
31-
// The JSON file should have a key-value pair where the key is "x-token" and the value is the authentication token.
30+
// XTokenPath specifies the path to the directory that contains a JSON file with the X-Token for gRPC authentication.
31+
// The JSON file must contain a key "x-token" with the authentication token.
3232
// If left empty, the client will not include the X-Token in its requests.
3333
XTokenPath string
3434
}
@@ -79,6 +79,15 @@ func (cfg *EndpointConfig) validate() error {
7979
return fmt.Errorf("nodebuilder/core: invalid grpc port: %s", err.Error())
8080
}
8181

82+
if cfg.XTokenPath != "" {
83+
if !cfg.TLSEnabled {
84+
return fmt.Errorf("nodebuilder/core: TLSEnabled must be true when XTokenPath is set")
85+
}
86+
if !utils.Exists(cfg.XTokenPath) {
87+
return fmt.Errorf("nodebuilder/core: XTokenPath does not exist: %s", cfg.XTokenPath)
88+
}
89+
}
90+
8291
return nil
8392
}
8493

0 commit comments

Comments
 (0)