-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add ability to read pass from env variables #171
Conversation
Thanks @meain . Interesting idea. I don't have an opinion on whether this is a good idea or a bad one. Do you know any other clients that do this? Is this considered a good practice? Why is env considered safer than your config file to store passwords? |
@osa1
I don't think it is necessarily more secure than having the password in the file, but it lets you to have the config file committed into something like a dotfiles repo and tracked. |
OK. This is a user-facing change and a new feature so we should be updating README and CHANGELOG. Let me know if you don't have time for that. |
Sure, I'll add that in. I was looking into the shellexpand package and I don't think we need the full package. If you this this could be added in I think I will refactor it to use just Once small issue that might come up is that if the user's password is something like What do you think? |
The library is small, has no dependencies, and the code is not entirely trivial, so it should be fine to use it. If the code was trivial or the library did too much/brought a set of dependencies then I'd be more inclined to implement it in tiny.
How does
I don't like this. If my password was |
shellexpand actually lets you expand stuff like
I seems to error out: |
There should be some way of escaping |
Looks like you can use a second One other thing I have noticed is that some programs can differentiate between if it is a var or string based on if there are quotes arround it, but don't think we can do that with yaml. This whole thing feels a bit hacky, maybe we shouldn't have this feature. |
I think the only concern is UX -- implementation does not look too bad, and escaping with two
If we had a new syntax for escaped strings it'd be perfect, but not sure if that's possible with YAML. |
My idea was to expand only if
This will be reduced significantly if we use the specific case with the above three rules. Plus we can give a warning (including how to escape) if we cannot resolve env variable.
A One other option would be have a completely different key if the user wants to use passwords, but that seems like a bit too much. I looked a bit more into |
That's too much to explain to a user. A rule I follow basically is; if it's hard to explain that it's probably a bad idea. Hard to explain sometimes means hard to implement too. Bad for code, bad for UX.
Yeah this is not great. I guess we'll have to roll our own implementation if we want this feature. |
What I was going for was if it is a shell variable and there is only one of it. |
Hmm, right, that doesn't sound too bad. We could probably say something like "If password is one word and starts with |
Hi, I have an implementation of what we discussed. We cannot really use
I will get the following error :
We could use In the case of not finding a shell variable for One option would be to show a message in the messages window when the passwords fails to authenticate and starts with Also, might have to change the error message that we are giving right now. |
Hi @meain. Would you like to revive this? Few other people also asked for using
I don't use any of these so I don't know how this would work, but if splicing env varibles in strings in the config file will allow that then this seems like a good addition to me. @Kabouik could you tell more about how you'd use @meain spec-wise this is what I have in mind:
|
I'm no expert, but here is what
Meaning I can set And here is what
|
Hmm, matterhorn seems to support arbitrary commands. If we want to do this with env variables only, would running tiny this way be acceptable?
and then the config file would have I wonder why they chose to implement arbitrary command execution rather than just env lookup. |
Sure, would love to get on this. I am a bit busy these days, so I might not be able to get anything up pretty soon. I don't know if populating We have to do the |
No worries, we're not in a hurry. Good points regarding allowing commands vs. env variables. It seems like a good idea to allow commands for passwords. We have more than one way to log in to an IRC server
So we'll have to accept the new command syntax in all of these. The main difficulty is we need to distinguish a plain text password from a command to run, so that e.g. if a user has
We know whether to run the command |
Maybe backticks?
|
That looks good but I think it's not valid YAML. Just tried it using http://yaml-online-parser.appspot.com/ , apparently strings can't start with backtick. |
Oh, so this isn't valid:
but this is valid:
Though it also looks worse. |
Oh, yeah, that doesn't look so great. What about making a command anything in a list? Regular password: Command returning password: Or just have the separate field "passCmd" like @meain said. |
I'm not a fan of the array syntax for this purpose. I think ideally user would just paste the command that they would use in the shell directly and it would work. The problem with Another idea: |
I did not think about that fact that we have multiple ways to authenticate, it sure might get messy if we have to add cmd versions to each. |
I wonder if we could do something simpler though. The problem with I think a simpler approach would be to add a marker as prefix so that when the string starts with the the rest (regardless of what's in the there) will be the command. For example
This is valid YAML according to the YAML parser linked above. Parsing this is much simpler: if the first character is We won't have the ability to splice command results in the middle of a string, e.g.
will no longer run |
What if we add another field called |
I'm not sure if I understand the suggestion correctly. Could you give a concrete
or when using NickServ:
|
Parsing wise it should be pretty easy, I was just concerned if prefixing with |
|
If we are going with a prefix, Maybe |
Another issue keeping it same is that we will have to provide them a way to escape if they use the same thing for pass. |
If the command prefix is " |
So if your password if |
Yeah, forget what I said. I completely forgot that spaces are valid in passwords |
My main concern with the Note that I am not a programmer, I have no knowledge whatsoever of what @meain's suggestion would imply under the hood, but from a simple user's perspective, it looks cool. Just select the authentication type in a single config section and always format it the same way, instead of having different section names ( Speaking of sanitizing the config if his suggestion is doable, would it be possible to parse |
Came across this blog post about storing secrets in env variables: https://diogomonica.com/2017/03/27/why-you-shouldnt-use-env-variables-for-secret-data/ Seems like supporting arbitrary commands (rather than only env variables) is a good idea. |
Yeah, I have some not so sensitive passwords in env vars. But most of them are stored in OS keychain or using pass. |
Are you asking about the config file syntax? I think we can use the |
@meain let us know if you won't be able to finish this so that we can pick it up. Thanks! |
Will submit a patch by today or tomorrow. Was a bit busy before. |
@meain I'm a bit confused. |
Oh, OK. I was thinking it was |
Are we adding an option to use an env variable? |
I think we don't need anything special for env variables as you can get value of env variables by running e.g. |
@osa1 Should be good to go now. |
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.
Thanks for the update @meain ! I added some inline comments. Again, let us know if you don't have the time or don't want to work on this anymore.
fn is_command(val: &str) -> bool { | ||
let re = Regex::new(r"^![^!].*$").unwrap(); | ||
return re.is_match(val); | ||
} |
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.
Let's avoid regexes unless absolutely necessary. They're hard to read, understand, maintain. Here's a simpler implementation:
fn is_command(val: &str) -> bool {
let val = val.trim_start();
if val.starts_with("!!") {
false
} else if val.starts_with('!') {
true
} else {
false
}
}
Or slightly more efficient:
fn is_command(val: &str) -> bool {
if val.starts_with('!') {
// Value starts with '!', it's a command unless '!' is escaped
if val[1..].starts_with('!') {
// Escaped '!', not a command
false
} else {
true
}
} else {
// Value doesn't start with '!', not a command
false
}
}
Secondly, instead of checking whether the string is a command here and then
doing the same !!
check again later, you can do it once. Just introduce a new
type: (feel free to pick another name)
enum CmdOrText<'a> {
Cmd(&'a str), // NOTE: ! prefix removed
Text(&'a str),
}
then the check function becomes
fn is_command(val: &str) -> CmdOrText {
...
}
@@ -27,7 +30,7 @@ pub(crate) struct Server { | |||
pub(crate) tls: bool, | |||
|
|||
/// Server password (optional) | |||
#[serde(default)] | |||
#[serde(default, deserialize_with = "with_expand_envs")] |
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 wonder if we run the commands later, when we actually need them, and every time we need them. Reasons:
- If we do this in parse time we'll running the commands for servers we won't be connecting to. E.g. if I run
tiny freenode
it shouldn't need the command for my OFTC password. - If I update a password in my password manager currently
/connect
won't pick it up.
What do you think?
@osa1 The second change seems to be a bit more involved and the codebase has changed from the last time I went thought it. If someone else wants to take over, feel free. I might get a bit busy. |
We should open an issue for this feature and close the PR. |
With this you could write something like below and the password will be read from the env variable.