hashsploit/clank

Consider allowing environment variables to be used.

Closed this issue · 3 comments

LKNSI commented

Suggestion to allow Clank to use environment variables instead of relying on JSON. (Not suggesting removing JSON support, but adding environmental variable support), e.g;

	public String getAddress() {
               ....
		return System.getenv("CLANK_ADDRESS").toString();
	}

        .....

	public int getPort() {
               ....
		return Integer.parseInt(System.getenv("CLANK_PORT"));
	}

Built a copy and seemed to work, leave it up to you!

image

Thanks for the suggestion. I agree that would probably be a good feature to add. How do you propose we handle environment variables for more complicated JSON structures, such as whitelist or channels?

LKNSI commented

Thanks for the suggestion. I agree that would probably be a good feature to add. How do you propose we handle environment variables for more complicated JSON structures, such as whitelist or channels?

If anything I'd be heavily leaning on Redis or some DB for quasi-persistent data like that. I usually write in Python and NodeJS so I'm unaware exactly how feasible that would be normally in Java.

Typically I'd suggest a minecraft approach (hardcode them to file) for stuff like whitelists/allowlists - but Redis/DB would allow for easier future proofing if someone wanted to make idk a UI backend, or have some distributed manager for deployments.

For example a Redis Set would return an Array when queried, which is perfect I'd imagine for iterating through. As for non-array items, I'd recommend to do it in this way:

https://github.com/jknack/handlebars.java

Have a JSON file, whereby the values are interpolated based on boolean logic (is there env variables? else something default). That way you can keep the JSON approach but also allow ENV to be used.

Off the top of my head; you'd have a copy of the JSON file that shouldn't be edited (that has interpolation targets as key values); and a user-editable mirror of the JSON file. If the key from User-accessible JSON file is present; it will overwrite the internal KV of the object in code.

value.key1 = "Hello"
value.key2 = "World"
(Internal Copy of JSON)
{
   "key1":{{value.key1}}, // As above, default would be 'Hello'
   "key2":{{value.key2}} // As above, default would be 'World'
}
(User Copy of JSON)
{
   "key2":"Dude"
}
(Final Copy of JSON. Handlebars will check to see if userconfig has keys, and if so, use them as interpolation else, use the existing value inside code)
{
   "key1":"Hello",
   "key2":"Dude"
}

A random snippet of code from a go program might be able to describe this better:

func DefaultConfig() *Config {
	hostname, err := os.Hostname()
	if err != nil {
		panic(err)
	}

	c := &Config{
		Region:                           DefaultRegion,
		AuthoritativeRegion:              DefaultRegion,
		Datacenter:                       DefaultDC,
		NodeName:                         hostname,
		NodeID:                           uuid.Generate(),
		ProtocolVersion:                  ProtocolVersionMax,
		RaftConfig:                       raft.DefaultConfig(),
		RaftTimeout:                      10 * time.Second,
		LogOutput:                        os.Stderr,
		RPCAddr:                          DefaultRPCAddr(),
		SerfConfig:                       serf.DefaultConfig(),
		NumSchedulers:                    1,
		ReconcileInterval:                60 * time.Second,
		EvalGCInterval:                   5 * time.Minute,
		EvalGCThreshold:                  1 * time.Hour,
		JobGCInterval:                    5 * time.Minute,
		JobGCThreshold:                   4 * time.Hour,
		NodeGCInterval:                   5 * time.Minute,
		NodeGCThreshold:                  24 * time.Hour,
		DeploymentGCInterval:             5 * time.Minute,
		DeploymentGCThreshold:            1 * time.Hour,
		CSIPluginGCInterval:              5 * time.Minute,
		CSIPluginGCThreshold:             1 * time.Hour,
		CSIVolumeClaimGCInterval:         5 * time.Minute,
		CSIVolumeClaimGCThreshold:        5 * time.Minute,
		EvalNackTimeout:                  60 * time.Second,
LKNSI commented

Side note: If you have the time to flesh out gRPC more; I'd love to contribute with code in other languages - but I don't think my quality of Java would be up to par!