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

Document pid_file_name and explain some other flags #243

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ringerc
Copy link
Contributor

@ringerc ringerc commented Jan 30, 2025

Update the README to:

  • Explain the various modes in which spiffe-helper can be used and why each one might be useful
  • Document the previously undocumented pid_file_name config option
  • Add explanation of how cmd and cmd_args is interpreted, including:
    • double quoting to protect spaces
    • escape double quotes by pairing them not with backslashes
    • single quotes are not special and don't protect spaces or double quotes
    • shell metacharacters are not special
  • Warn that stdin is not forwarded, and the exit code of the child process is not forwarded on exit (in fact, spiffe-helper does not exit at all in daemon mode, or run a command at all in non-daemon mode), so spiffe-helper cannot be used as a pass-through wrapper for another command
  • Document that an exited cmd is re-launched only when the cert is rotated
  • Explain how daemon_mode=false works and that it ignores cmd, pid_file_name and renew_signal

README.md Outdated Show resolved Hide resolved
@faisal-memon
Copy link
Collaborator

@ringerc thanks for looking in to the docs.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@faisal-memon faisal-memon added this to the 0.10.0 milestone Jan 31, 2025
@ringerc
Copy link
Contributor Author

ringerc commented Feb 2, 2025

@faisal-memon @keeganwitt Rebased and suggested changes made. I also corrected a mistake where I incorrectly suggested that the cmd would be restarted if it was running; I meant if it was not running.

@ringerc ringerc force-pushed the spiffe-helper-readme-updates branch from a4c3498 to e1a06d0 Compare February 2, 2025 20:44
ringerc added a commit to ringerc/spiffe-helper-PRs that referenced this pull request Feb 2, 2025
Per spiffe#243 (comment)
the -exitWhenReady flag and corresponding ExitWhenReady option were
never in a released version. So this obsolete, now-unused field can be
deleted without backwards compatibility impact.

The separate PR spiffe#243 updates
the docs to remove reference to the CLI argument -exitWhenReady.
ringerc added a commit to ringerc/spiffe-helper-PRs that referenced this pull request Feb 3, 2025
Per spiffe#243 (comment)
the -exitWhenReady flag and corresponding ExitWhenReady option were
never in a released version. So this obsolete, now-unused field can be
deleted without backwards compatibility impact.

Remove the reference from the README too.

Signed-off-by: Craig Ringer <[email protected]>
@ringerc ringerc force-pushed the spiffe-helper-readme-updates branch from e1a06d0 to 365c714 Compare February 3, 2025 20:59
@ringerc
Copy link
Contributor Author

ringerc commented Feb 3, 2025

@faisal-memon @keeganwitt I've revised this a bit more based on what I've learned working on the codebase in the last couple of days. I moved it to subheads rather than bullet points and tried to structure it into groups based on the different ways of using spiffe-helper.

You can view the rendered version here or the marked-up diff here.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
Comment on lines 83 to 85
are NOT respected for argument quoting, so `cmd` = `touch` and `cmd_args` =
`'some file'` will create two files named `'some` and `file'` (including the quotes
in the file name), not a single file named `some file`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway to support escaping the quotes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following what you mean by escape here. You're talking about single quotes? Or double quotes?

Copy link
Contributor Author

@ringerc ringerc Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that spiffe-helper uses a csv parser with the delimiter set to " " (space) to process its command-line args and split them to an argument vector.

This is the test case I wrote that this README text was based on: https://github.com/ringerc/spiffe-helper-PRs/blob/31a134b2438ea865739673779c23c99beb410815/pkg/sidecar/sidecar_test.go#L116-L131 . The arguments there would be correct as a shell argument string, but is not handled correctly by spiffe-helper because spiffe-helper only supports double-quoted arguments.

To confirm my understanding of its parser behaviour I've banged out some test cases here #256 - see in particular #256 (review) for this case. This also showed that double quotes are escaped by pairing them, not backslash-escaping them.

Using a csv parser produces surprising and confusing results, as the semantics of csv are not the same as the semantics of a command line argument string, particularly when nesting double quotes within single quotes (which in the shell's parser, protects the double quotes) and when escaping double quotes.

This could result in surprising and even dangerous behaviour, hence the documentation for it. I don't recommend trying to change or fix the parser as getting it right is too hard, and "right" depends on the OS anyway. It's much better to use an argument vector (array) instead and deprecate the string-based cmd_args.

I implemented an argument-vector replacement in my working tree but I haven't had time to extract it into a separate PR, and I'd rather wait until some of the current ones are merged so it doesn't get too hard to keep track of things and rebase.

So I documented the current behaviour in the meantime. Would it be clearer if I split this into whole hcl lines?

Copy link
Contributor Author

@ringerc ringerc Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revised the explanation to hopefully make it clearer at the expense of making it longer: a558254

Please resolve if satisfied

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@faisal-memon
Copy link
Collaborator

Thanks @ringerc this looks great. Just some minor comments and its ready to go.

faisal-memon added a commit that referenced this pull request Feb 4, 2025
Per #243 (comment)
the -exitWhenReady flag and corresponding ExitWhenReady option were
never in a released version. So this obsolete, now-unused field can be
deleted without backwards compatibility impact.

Remove the reference from the README too.

Signed-off-by: Craig Ringer <[email protected]>
Co-authored-by: Faisal Memon <[email protected]>
@ringerc ringerc force-pushed the spiffe-helper-readme-updates branch 2 times, most recently from 8ad2d6b to 7517efa Compare February 4, 2025 21:06
@ringerc ringerc force-pushed the spiffe-helper-readme-updates branch 2 times, most recently from 312ce82 to a558254 Compare February 4, 2025 21:08
Update the README to:

* Explain the different modes spiffe-helper can be used in and how
  they relate to the configuration settings.
* Document the previously undocumented pid_file_name config option
* Document that spiffe-helper restarts 'cmd' when it next rotates
  certificates if it's not running
* Document that spiffe-helper does NOT restart 'cmd' until the next
  cert rotation if it exits.
* Add explanation of how cmd and cmd_args is interpreted
* Warn about surprises in cmd_args parsing with single quotes
* Warn that stdin is not forwarded, and the exit code of the child
  process is not forwarded on exit, so spiffe-helper cannot be used
  as a pass-through wrapper for another command
* Explicitly note that `cmd_args` is not subject to shell metacharacter
  expansion

Signed-off-by: Craig Ringer <[email protected]>
Signed-off-by: Craig Ringer <[email protected]>
@ringerc ringerc force-pushed the spiffe-helper-readme-updates branch from a558254 to da30c07 Compare February 4, 2025 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants