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

setting config options from cli may break config #740

Closed
jbenet opened this issue Feb 3, 2015 · 6 comments
Closed

setting config options from cli may break config #740

jbenet opened this issue Feb 3, 2015 · 6 comments
Labels
kind/bug A bug in existing code (including security flaws) topic/cleanup Topic cleanup topic/commands Topic commands topic/repo Topic repo

Comments

@jbenet
Copy link
Member

jbenet commented Feb 3, 2015

setting the repo's Log.MaxSizeMB from the cli breaks the config:

> ipfs config Log.MaxSizeMB
0
> ipfs config Log.MaxSizeMB 100
Error: Failed to set config value: Failure to decode config: json: cannot unmarshal string into Go value of type uint64
> ipfs config Log.MaxSizeMB
Error: Failure to decode config: json: cannot unmarshal string into Go value of type uint64
> ipfs config edit
Error: Failure to decode config: json: cannot unmarshal string into Go value of type uint64

the config got a string:

  "Log": {
    "MaxAgeDays": 0,
    "MaxBackups": 0,
    "MaxSizeMB": "100"
  },

changing it to an int fixes it. BUT:

  • this shouldnt break, and
  • this should be recoverable from the cli.
    objects retrieving values from the config should try to parse them from the string.
btc pushed a commit that referenced this issue Feb 4, 2015
When setting config keys, the program doesn't know whether the
key-to-be-modified exists on the Config struct. (Perhaps, with
reflection, it is possible to find the field). To allow callers to write
non-existent keys, the program would...

Before:
1) converts the in-memory *Config to a map
2) sets the key on the map, and
3) writes this map to disk.
4) Then, it converts this map back into an in-memory struct.

This commit swaps 3 and 4 so the map can be validated against the struct
before being written to disk. This prevents the bug identified in #740.
btc pushed a commit that referenced this issue Feb 4, 2015
When setting config keys, the program doesn't know whether the
key-to-be-modified exists on the Config struct. (Perhaps, with
reflection, it is possible to find the field). To allow callers to write
non-existent keys, the program would...

Before:
1) converts the in-memory *Config to a map
2) sets the key on the map, and
3) writes this map to disk.
4) Then, it converts this map back into an in-memory struct.

This commit swaps 3 and 4 so the map can be validated against the struct
before being written to disk. This prevents the bug identified in #740.
btc pushed a commit that referenced this issue Feb 4, 2015
When setting config keys, the program doesn't know whether the
key-to-be-modified exists on the Config struct. (Perhaps, with
reflection, it is possible to find the field). To allow callers to write
non-existent keys, the program would...

Before:
1) converts the in-memory *Config to a map
2) sets the key on the map, and
3) writes this map to disk.
4) Then, it converts this map back into an in-memory struct.

This commit swaps 3 and 4 so the map can be validated against the struct
before being written to disk. This prevents the bug identified in #740.
@btc
Copy link
Contributor

btc commented Feb 4, 2015

One part of this problem is that the config is written to disk before it is validated against the Config struct. (Recall: users are allowed to set keys that don't exist on the struct) This is fixed in #742.

@jbenet jbenet changed the title setting config options from cli make break config setting config options from cli may break config Mar 28, 2015
@jbenet jbenet added topic/commands Topic commands topic/repo Topic repo kind/bug A bug in existing code (including security flaws) topic/cleanup Topic cleanup labels Mar 28, 2015
@jbenet
Copy link
Member Author

jbenet commented May 19, 2015

@rht thanks for picking this up.

I've since implemented the --json option, so maybe we could ask users to use --json. Check it out at:
https://github.com/ipfs/go-ipfs/blob/master/core/commands/config.go#L79-L87

not sure, what do you think is most intuitive?

@rht
Copy link
Contributor

rht commented May 19, 2015

Depends on how the config is used. I will check how postfix, vault, etc nail this, and why.

@jbenet jbenet mentioned this issue May 19, 2015
52 tasks
@rht
Copy link
Contributor

rht commented May 19, 2015

  • current state
    Since '--json' supersedes '--bool', should we get rid of the latter?
    Otherwise if '--bool' is kept then '--integer' (this issue) and '--number' (float type) need to exist, for consistency.
    The bug (for integer case) itself has been fixed by when setting config keys, validate against struct before writing to disk #742
  • what other tools use
  • tests
    • integer
      ipfs config atoms/mol 11666 -> "atoms/mol": 11666
    • number
      • ipfs config atoms/mol 11666.66 -> "atoms/mol": "11666.66"
      • ipfs config --json atoms/mol 11666.66 -> "atoms/mol": 11666.66
      • ipfs config --json atoms/mol "11666.66" -> "atoms/mol": 11666.66
      • ipfs config --json atoms/mol "\"11666.66\"" -> "atoms/mol": "11666.66"

From the test result, for intuitiveness sake I'd say why not assume the value is json by default and then put escaped quote around numbers when you need them to be string (e.g. the value of Version.CheckPeriod? Why this is string I have no idea).

@rht
Copy link
Contributor

rht commented Jul 14, 2015

@jbenet This is fixed.

@jbenet
Copy link
Member Author

jbenet commented Jul 14, 2015

@rht, that's right, thanks!

@jbenet jbenet closed this as completed Jul 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) topic/cleanup Topic cleanup topic/commands Topic commands topic/repo Topic repo
Projects
None yet
Development

No branches or pull requests

3 participants