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

Add write-kubeconfig-group flag to server #9233

Merged
merged 2 commits into from
May 31, 2024

Conversation

kittydoor
Copy link
Contributor

@kittydoor kittydoor commented Jan 13, 2024

Proposed Changes

Add the flag as discussed in issue #9209 in order to enable configuring of group for writing kubeconfig.

Types of Changes

New Feature

Verification

Manually run k3s server with the flag --write-kubeconfig-group and check if kubeconfig has appropriate groups.

Testing

It seems there is no relevant test I found for write-kubeconfig-mode (other than it incidentally being used in some tests. If there is a request for tests please point me in the right direction!

Linked Issues

User-Facing Change

Yes, it creates a new optional flag.

New flag in k3s server: --write-kubeconfig-group

Further Comments

Unfortunately, my laptop doesn't have Linux on it at the moment (due to some suspend issues with new hardware support I'm procrastinating), and under WSL2 I'm having trouble running the final binary to test whether this commit works. Once I have time again I will try this in a VM or on baremetal linux and update here with any changes needed.

pkg/util/file.go Show resolved Hide resolved
@brandond
Copy link
Member

brandond commented Jan 16, 2024

https://systemd.io/USER_NAMES/ seems like a good reference document

In strict mode, only uppercase and lowercase characters are allowed, as well as digits, underscores and hyphens. The first character may not be a digit or hyphen.

I would suggest:

  1. Attempt to parse the value as an integer
  2. If the value can be parsed as an integer, attempt to look it up as a numeric group ID
  3. If the group ID lookup succeeded, use it as the group
  4. If step 1 or 2 failed, attempt to look up the value as a name.
  5. If step 4 failed, return an error.

If someone has a group with a numeric name, that conflicts with the ID of a different group, that is a problem they will have to solve on their own. Preventing that is why most sane systems require group names to start with a letter.

@kittydoor
Copy link
Contributor Author

Awesome! 👍 I don't know enough about BSD land or Apple land, and who knows other OS' or unique distros, but generally speaking as long as we are saying known issue / goes against common ground rules for naming so we won't take into consideration, I'm happy to implement the magic.

I'll update this PR with your suggestions @brandond

@brandond
Copy link
Member

brandond commented Jan 16, 2024

If the value can be parsed as an integer, attempt to look it up as a numeric group ID

Now that I think about this, perhaps we should skip looking up numeric IDs - chown for example allows you to use numeric IDs that don't resolve to a valid user or group. So lets say, if it can be parsed as a valid int, just use that as the numeric ID.

Signed-off-by: Katherine Pata <me@kitty.sh>
@kittydoor
Copy link
Contributor Author

Apologies for the delay, life got in the way. I've modified the feature as requested.

If there are any style changes, better organization across files, or whatever else, please let me know. I'll try and get to it asap :)

This should also be documented on the website and perhaps other places? Also, some test to cover this code would be helpful, no idea what is preferred in actual implementation of this though. #itworksonmymachine

@kittydoor kittydoor marked this pull request as ready for review April 28, 2024 23:26
@kittydoor kittydoor requested a review from a team as a code owner April 28, 2024 23:26
@kittydoor kittydoor changed the title Add flag: write-kubeconfig-group Add write-kubeconfig-group flag to server Apr 28, 2024
@brandond brandond requested a review from a team April 29, 2024 16:53
Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 5.55556% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 43.56%. Comparing base (94e29e2) to head (d22ddd9).
Report is 1 commits behind head on master.

Files Patch % Lines
pkg/util/file.go 0.00% 11 Missing ⚠️
pkg/server/server.go 0.00% 3 Missing and 1 partial ⚠️
pkg/kubectl/main.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9233      +/-   ##
==========================================
- Coverage   50.07%   43.56%   -6.51%     
==========================================
  Files         158      158              
  Lines       14032    14049      +17     
==========================================
- Hits         7027     6121     -906     
- Misses       5676     6764    +1088     
+ Partials     1329     1164     -165     
Flag Coverage Δ
e2etests 36.41% <5.55%> (-10.17%) ⬇️
inttests 37.05% <5.55%> (-0.10%) ⬇️
unittests 16.56% <0.00%> (-0.02%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kittydoor
Copy link
Contributor Author

@brandond a friendly hello :) Is this PR waiting for anything from my side, or just low-prio so waiting till you or someone else can get around to it?

@brandond
Copy link
Member

brandond commented May 19, 2024

We are in an extended code freeze due to overlapping release cycles. We will merge non essential things again soon, probably sometime this coming week.

@brandond brandond merged commit 7a0ea3c into k3s-io:master May 31, 2024
26 of 27 checks passed
brandond pushed a commit to brandond/k3s that referenced this pull request May 31, 2024
* Add write-kubeconfig-group flag to server
* update kubectl unable to read config message for kubeconfig mode/group

Signed-off-by: Katherine Pata <me@kitty.sh>
(cherry picked from commit 7a0ea3c)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
brandond pushed a commit to brandond/k3s that referenced this pull request May 31, 2024
* Add write-kubeconfig-group flag to server
* update kubectl unable to read config message for kubeconfig mode/group

Signed-off-by: Katherine Pata <me@kitty.sh>
(cherry picked from commit 7a0ea3c)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
brandond pushed a commit to brandond/k3s that referenced this pull request May 31, 2024
* Add write-kubeconfig-group flag to server
* update kubectl unable to read config message for kubeconfig mode/group

Signed-off-by: Katherine Pata <me@kitty.sh>
(cherry picked from commit 7a0ea3c)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
brandond pushed a commit to brandond/k3s that referenced this pull request May 31, 2024
* Add write-kubeconfig-group flag to server
* update kubectl unable to read config message for kubeconfig mode/group

Signed-off-by: Katherine Pata <me@kitty.sh>
(cherry picked from commit 7a0ea3c)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
brandond pushed a commit to brandond/k3s that referenced this pull request May 31, 2024
* Add write-kubeconfig-group flag to server
* update kubectl unable to read config message for kubeconfig mode/group

Signed-off-by: Katherine Pata <me@kitty.sh>
(cherry picked from commit 7a0ea3c)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
brandond pushed a commit to brandond/k3s that referenced this pull request May 31, 2024
* Add write-kubeconfig-group flag to server
* update kubectl unable to read config message for kubeconfig mode/group

Signed-off-by: Katherine Pata <me@kitty.sh>
(cherry picked from commit 7a0ea3c)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
brandond pushed a commit that referenced this pull request May 31, 2024
* Add write-kubeconfig-group flag to server
* update kubectl unable to read config message for kubeconfig mode/group

Signed-off-by: Katherine Pata <me@kitty.sh>
(cherry picked from commit 7a0ea3c)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
brandond pushed a commit that referenced this pull request May 31, 2024
* Add write-kubeconfig-group flag to server
* update kubectl unable to read config message for kubeconfig mode/group

Signed-off-by: Katherine Pata <me@kitty.sh>
(cherry picked from commit 7a0ea3c)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
brandond pushed a commit that referenced this pull request May 31, 2024
* Add write-kubeconfig-group flag to server
* update kubectl unable to read config message for kubeconfig mode/group

Signed-off-by: Katherine Pata <me@kitty.sh>
(cherry picked from commit 7a0ea3c)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
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