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

Bug 2107113: Fix .ssh directory not owned by core when created by Machine Config D… #3250

Merged
merged 1 commit into from Aug 23, 2022

Conversation

palonsoro
Copy link
Contributor

Fixes BZ#2107113:

  • What I did: Create the ~core/.ssh directory in advance if it didn't previously exist and chown it to core user
  • How to verify it: Create a cluster without SSH keys and configure those via machine-config post-install. Before fix, ~core/.ssh user was owned by root, with this fix, it is owned by core user as expected
  • Description for the changelog: Fix .ssh directory not owned by core when created by Machine Config Daemon

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 14, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 14, 2022

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci bot added bugzilla/severity-low Referenced Bugzilla bug's severity is low for the branch this PR is targeting. bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. labels Jul 14, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 14, 2022

@palonsoro: This pull request references Bugzilla bug 2107113, which is invalid:

  • expected the bug to target the "4.12.0" release, but it targets "---" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

In response to this:

Bug 2107113: Fix .ssh directory not owned by core when created by Machine Config D…

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@palonsoro palonsoro marked this pull request as ready for review July 14, 2022 16:32
@palonsoro
Copy link
Contributor Author

/bugzilla refresh

@openshift-ci openshift-ci bot added bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. and removed bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. labels Jul 14, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 14, 2022

@palonsoro: This pull request references Bugzilla bug 2107113, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.12.0) matches configured target release for branch (4.12.0)
  • bug is in the state NEW, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

Requesting review from QA contact:
/cc @rioliu-rh

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot requested a review from rioliu-rh July 14, 2022 16:33
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 14, 2022
@openshift-ci openshift-ci bot requested a review from yuqi-zhang July 14, 2022 16:35
@palonsoro
Copy link
Contributor Author

/assign @sinnykumari

Copy link
Contributor

@yuqi-zhang yuqi-zhang left a comment

Choose a reason for hiding this comment

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

Generally seems fine, will also let others have a chance to take a look

Thanks for the fix!

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 19, 2022
Comment on lines 1801 to 1806
if _, err := os.Stat(coreUserSSHPath); os.IsNotExist(err) {
os.MkdirAll(coreUserSSHPath, os.FileMode(0o700))
os.Chown(coreUserSSHPath, uid, gid)
}
Copy link
Member

Choose a reason for hiding this comment

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

This introduces a race condition - if we're interrupted between creating the directory and calling chown(), the directory will remain owned by root forever.

More generally, privileged code operating on directories owned by unprivileged users is full of huge traps. For example, assuming the core user has sudo permissions removed, this might be subject to symlink attacks.

Both of these issues can be fixed by switching to the core user temporarily. While it's possible to use low-level kernel APIs for this, in this case I'd say it's a lot simpler to fork off this as a subprocess: runuser -u core -- mkdir -m 0700 -p ~/.ssh.

Copy link
Member

Choose a reason for hiding this comment

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

Really this applies anywhere in the MCO we want to write files that are in directories owned by lesser privileged users - but the core user ssh keys are probably the only case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed the code with runuser. Now testing...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested. It worked on my test scenario. Code now just calls runuser -u core -- mkdir -m 0070 -p /home/core/.ssh

@palonsoro
Copy link
Contributor Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 20, 2022
@palonsoro
Copy link
Contributor Author

Tested. It worked

@palonsoro
Copy link
Contributor Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 20, 2022
@palonsoro
Copy link
Contributor Author

/retest-required

@palonsoro
Copy link
Contributor Author

/retest

@sinnykumari
Copy link
Contributor

it took a while to get back to this PR.
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 23, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 23, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: palonsoro, sinnykumari, yuqi-zhang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [sinnykumari,yuqi-zhang]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@palonsoro
Copy link
Contributor Author

/retest-required

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 2 against base HEAD f21482c and 8 for PR HEAD 71e88ad in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 1 against base HEAD f21482c and 7 for PR HEAD 71e88ad in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD f21482c and 6 for PR HEAD 71e88ad in total

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 23, 2022

@palonsoro: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot merged commit 29d06d8 into openshift:master Aug 23, 2022
9 checks passed
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 23, 2022

@palonsoro: All pull requests linked via external trackers have merged:

Bugzilla bug 2107113 has been moved to the MODIFIED state.

In response to this:

Bug 2107113: Fix .ssh directory not owned by core when created by Machine Config D…

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@palonsoro
Copy link
Contributor Author

/cherry-pick release-4.11

@openshift-cherrypick-robot

@palonsoro: new pull request created: #3307

In response to this:

/cherry-pick release-4.11

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/severity-low Referenced Bugzilla bug's severity is low for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants