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

Shortcircuit commands with version or help flags #7683

Merged
merged 2 commits into from
Jun 7, 2023

Conversation

dereknola
Copy link
Member

Proposed Changes

Before attempting to open config files, we check if the arguments provided contain a --version, -v, --help, -h flag. If so, we shortcircuit the search. As -h and -v flags always override the given command anyway, this enables users who do not have permission to access /etc/rancher/k3s/config.yaml or other root guarded files to still run these basic commands.

Types of Changes

Verification

  1. Create a config file: touch /etc/rancher/k3s/config.yaml
  2. Change the permissions so only root can read it: sudo chmod 700 /etc/rancher/k3s/config.yaml
  3. Call k3s --help, k3s --version, k3s -h, k3s server -h. Note that these commands now complete successfully.

Testing

Linked Issues

#4321

User-Facing Change

Non root users can now call `k3s --help` and `k3s --version` commands without running into permission errors over the default config file.

Further Comments

This change is injected into FindString because this function is called when attemtping to find data-dir or prefer-bundled-bin arguments before running a command. FindString in turn attempts to open the default config file (/etc/rancher/k3s/config.yaml), and if permission is not given on that file, the whole process will fail.

@dereknola dereknola requested a review from a team as a code owner June 7, 2023 20:17
@codecov
Copy link

codecov bot commented Jun 7, 2023

Codecov Report

Patch coverage: 42.85% and project coverage change: +4.35 🎉

Comparison is base (e5e1a67) 47.55% compared to head (c4df6fb) 51.91%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7683      +/-   ##
==========================================
+ Coverage   47.55%   51.91%   +4.35%     
==========================================
  Files         141      141              
  Lines       14347    14358      +11     
==========================================
+ Hits         6823     7454     +631     
+ Misses       6442     5728     -714     
- Partials     1082     1176      +94     
Flag Coverage Δ
e2etests 48.02% <10.00%> (?)
inttests 44.88% <7.14%> (-0.05%) ⬇️
unittests 19.90% <42.85%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/configfilearg/defaultparser.go 17.64% <0.00%> (+0.98%) ⬆️
pkg/configfilearg/parser.go 72.88% <46.15%> (-1.68%) ⬇️

... and 41 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dereknola dereknola merged commit dc6c569 into k3s-io:master Jun 7, 2023
dereknola added a commit to dereknola/k3s that referenced this pull request Jun 8, 2023
* Shortcircuit search with help and version flag

Signed-off-by: Derek Nola <[email protected]>

* Keep functions seperate

Signed-off-by: Derek Nola <[email protected]>

---------

Signed-off-by: Derek Nola <[email protected]>
dereknola added a commit to dereknola/k3s that referenced this pull request Jun 8, 2023
* Shortcircuit search with help and version flag

Signed-off-by: Derek Nola <[email protected]>

* Keep functions seperate

Signed-off-by: Derek Nola <[email protected]>

---------

Signed-off-by: Derek Nola <[email protected]>
dereknola added a commit that referenced this pull request Jun 8, 2023
* Bump docker go.mod (#7681)
* Shortcircuit commands with version or help flags (#7683)
* Fix for longhorn integration test
* Add Rotation certification Check (#7097)
* Add Certification Test to Validate Cluster
* Fix to stop/start for k3s certificate rotation
* E2E: Use sudo for all RunCmdOnNode
* Remove unnecessary daemonset addition/deletion

Signed-off-by: Derek Nola <[email protected]>
Signed-off-by: est-suse <[email protected]>
Signed-off-by: Brad Davidson <[email protected]>
Co-authored-by: Esteban Esquivel Alvarado <[email protected]>
Co-authored-by: est-suse <[email protected]>
Co-authored-by: Brad Davidson <[email protected]>
dereknola added a commit that referenced this pull request Jun 9, 2023
* Shortcircuit search with help and version flag

Signed-off-by: Derek Nola <[email protected]>

* Keep functions seperate

Signed-off-by: Derek Nola <[email protected]>

---------

Signed-off-by: Derek Nola <[email protected]>
dereknola added a commit to dereknola/k3s that referenced this pull request Jun 9, 2023
* Shortcircuit search with help and version flag

Signed-off-by: Derek Nola <[email protected]>

* Keep functions seperate

Signed-off-by: Derek Nola <[email protected]>

---------

Signed-off-by: Derek Nola <[email protected]>
dereknola added a commit that referenced this pull request Jun 10, 2023
* Shortcircuit search with help and version flag

Signed-off-by: Derek Nola <[email protected]>

* Keep functions seperate

Signed-off-by: Derek Nola <[email protected]>

---------

Signed-off-by: Derek Nola <[email protected]>
@dereknola dereknola deleted the version_help_search branch October 2, 2023 17:35
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