cli icon indicating copy to clipboard operation
cli copied to clipboard

Follow XDG base directory specification instead of using ~/.step

Open pxeger opened this issue 4 years ago • 3 comments

What would you like to be added

On Linux, Step CLI should follow the XDG Base Directory specification for storing data (essentially, use $XDG_CONFIG_HOME/step rather than ~/.step by default).

I am aware you can specify a custom path with $STEPPATH, but the XDG spec is a standard that has predictable locations for users without further configuration. $STEPPATH should probably still override it if set though.

Why this is needed

This reduces clutter in the user's home directory and gives them more flexibility in deciding where and how to store their data.

If backwards-compatibility is an issue, I'd suggest using ~/.step if that location exists, and otherwise using the above.

pxeger avatar Apr 14 '21 13:04 pxeger

Similar issue: https://github.com/smallstep/certificates/issues/386.

Long term, adding $XDG_CONFIG_HOME to the resolution path is probably the right fix. Something like:

  1. If $STEPPATH exists then use $STEPPATH.
  2. If $XDG_CONFIG_HOME exists then use $XDG_CONFIG_HOME.
  3. Use ~/.step.

Our hesitance here is around taking on OS specific dependencies. We encourage the use of $STEPPATH because it is OS agnostic and therefore the least amount of work for us as maintainers. This isn't to say that we shouldn't or won't do this -- just trying to give some background to our thought process and why we haven't already prioritized.

dopey avatar Apr 20 '21 19:04 dopey

Disappointing. step joins only firefox and thunderbird as still polluting my homedir.

colemickens avatar Sep 22 '23 15:09 colemickens

Long term, adding $XDG_CONFIG_HOME to the resolution path is probably the right fix.

And also XDG_DATA_HOME.

  1. If $STEPPATH exists then use $STEPPATH.
  2. If $XDG_CONFIG_HOME exists then use $XDG_CONFIG_HOME.
  3. Use ~/.step.

FWIW, this is not how this is not exactly how the XDG base-dir spec works. If an XDG_* env var is not defined, the program must fallback to the specified defaults:

env fallback
XDG_DATA_HOME ~/.local/share
XDG_CONFIG_HOME ~/.config
XDG_STATE_HOME ~/.local/state
XDG_CACHE_HOME ~/.cache

So the directory layout mapping should look like the following:

current xdg compliant
~/.step/config ~/.config/step
~/.step/certs ~/.local/share/step/certs

So the correct thing to do would be:

  • If STEPPATH is set then use ${STEPPATH}.
  • Otherwise if the ${HOME}/.step directory already exists, then use that for backward compatibility.
  • Otherwise use the specified XDG directories.

Our hesitance here is around taking on OS specific dependencies. We encourage the use of $STEPPATH because it is OS agnostic and therefore the least amount of work for us as maintainers. This isn't to say that we shouldn't or won't do this -- just trying to give some background to our thought process and why we haven't already prioritized.

Fortunately, there's already a go package for that, so this would be a rather simple change to make implementation-wise.

ju1ius avatar Nov 02 '23 18:11 ju1ius